]> source.dussan.org Git - archiva.git/commitdiff
More work against model/database unit testing.
authorJoakim Erdfelt <joakime@apache.org>
Wed, 21 Mar 2007 14:30:32 +0000 (14:30 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Wed, 21 Mar 2007 14:30:32 +0000 (14:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@520899 13f79535-47bb-0310-9956-ffa450edef68

archiva-database/pom.xml
archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java
archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java [new file with mode: 0644]
archiva-database/src/test/resources/META-INF/plexus/components.xml
archiva-database/src/test/resources/ibatis-config.xml [deleted file]
archiva-database/src/test/resources/log4j.properties [deleted file]
archiva-database/src/test/resources/log4j.xml [new file with mode: 0644]
archiva-model/pom.xml
archiva-model/src/test/resources/log4j.xml [new file with mode: 0644]

index 32ede8488a984820c5ef886c726802bd6083db1c..b5ce7540fe5711f098688af2b5666c1f7841aa2e 100755 (executable)
@@ -95,7 +95,6 @@
       <groupId>org.apache.derby</groupId>
       <artifactId>derby</artifactId>
       <version>10.2.1.6</version>
-      <!--<scope>test</scope>-->
     </dependency>
     <dependency>
       <groupId>org.apache.derby</groupId>
     </dependency>
   </dependencies>
   <build>
-  <plugins>
-    <plugin>
+    <plugins>
+      <plugin>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-maven-plugin</artifactId>
-    </plugin>
-  </plugins>
+      </plugin>
+    </plugins>
   </build>
 </project>
index 6033a6924c24a266c1a5c812871643e9cefc7f9d..175fb29be0d6198209d36077cc4036ce3ad362a3 100644 (file)
@@ -20,9 +20,19 @@ package org.apache.maven.archiva.database;
  */
 
 import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
+import org.codehaus.plexus.jdo.JdoFactory;
 import org.codehaus.plexus.util.FileUtils;
+import org.jpox.SchemaTool;
 
 import java.io.File;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
 
 /**
  * AbstractArchivaDatabaseTestCase 
@@ -33,6 +43,8 @@ import java.io.File;
 public class AbstractArchivaDatabaseTestCase
     extends PlexusTestCase
 {
+    protected ArchivaDAO dao;
+    
     protected void setUp()
         throws Exception
     {
@@ -43,5 +55,69 @@ public class AbstractArchivaDatabaseTestCase
         }
 
         super.setUp();
+        
+        DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "archiva" );
+        assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
+
+        jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" ); 
+
+        jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.apache.derby.jdbc.EmbeddedDriver" ) );   
+
+        jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:derby:" + derbyDbDir.getAbsolutePath() + ";create=true" ) );   
+
+        jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) ); 
+
+        jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) ); 
+
+        jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );  
+
+        jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );  
+
+        jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );  
+
+        jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" );
+
+        jdoFactory.setProperty( "javax.jdo.option.RestoreValues", "true" );
+
+        // jdoFactory.setProperty( "org.jpox.autoCreateColumns", "true" );
+
+        jdoFactory.setProperty( "org.jpox.validateTables", "true" );
+
+        jdoFactory.setProperty( "org.jpox.validateColumns", "true" );
+
+        jdoFactory.setProperty( "org.jpox.validateConstraints", "true" );
+
+        Properties properties = jdoFactory.getProperties();
+
+        for ( Iterator it = properties.entrySet().iterator(); it.hasNext(); )
+        {
+            Map.Entry entry = (Map.Entry) it.next();
+
+            System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
+        }
+
+        URL jdoFileUrls[] = new URL[] { getClass()
+            .getResource( "/org/apache/maven/archiva/model/package.jdo" ) }; 
+
+        if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
+        {
+            fail( "Unable to process test " + getName() + " - missing package.jdo." );
+        }
+
+        File propsFile = null; // intentional
+        boolean verbose = true;
+
+        SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose );
+        SchemaTool.createSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose, null );
+
+        PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
+
+        assertNotNull( pmf );
+
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        pm.close();
+
+        this.dao = (ArchivaDAO) lookup( ArchivaDAO.class.getName(), "jdo" );
     }
 }
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java
new file mode 100644 (file)
index 0000000..a359b9b
--- /dev/null
@@ -0,0 +1,67 @@
+package org.apache.maven.archiva.database.jdo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.model.ArchivaRepositoryModel;
+
+import java.util.List;
+
+/**
+ * JdoArchivaDAOTest 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class JdoArchivaDAOTest extends AbstractArchivaDatabaseTestCase
+{
+    public void testRepositoryCRUD() throws ArchivaDatabaseException
+    {
+        ArchivaRepositoryModel repo = dao.createRepository( "testRepo", "http://localhost:8080/repository/foo" );
+
+        assertNotNull( repo );
+
+        repo.setName( "The Test Repostitory." );
+        repo.setLayoutName( "default" );
+
+        ArchivaRepositoryModel repoSaved = dao.saveRepository( repo );
+        assertNotNull( repoSaved );
+
+        List repos = dao.getRepositories();
+        assertNotNull( repos );
+        assertEquals( 1, repos.size() );
+        
+        repoSaved.setName( "Saved Again" );
+        dao.saveRepository( repoSaved );
+        
+        ArchivaRepositoryModel actualRepo = dao.getRepository( "testRepo" );
+        assertNotNull( actualRepo );
+        assertEquals( "testRepo", actualRepo.getId() );
+        assertEquals( "http://localhost:8080/repository/foo", actualRepo.getUrl() );
+        assertEquals( "Saved Again", actualRepo.getName() );
+        
+        assertEquals( 1, dao.getRepositories().size() );
+        
+        dao.deleteRepository( actualRepo );
+        assertEquals( 0, dao.getRepositories().size() );
+    }
+}
+
index 9be2e75bce216686a131a75cb37c2b9187927bab..cd924e95cf79d0a1768dd0acbe99f4c80c973af0 100644 (file)
@@ -1,30 +1,24 @@
-<plexus>
+<component-set>
   <components>
     <component>
-      <role>org.codehaus.plexus.ibatis.PlexusIbatisHelper</role>
-      <implementation>org.codehaus.plexus.ibatis.DefaultPlexusIbatisHelper</implementation>
-      <role-hint>metadata</role-hint>
+      <role>org.codehaus.plexus.jdo.JdoFactory</role>
+      <role-hint>archiva</role-hint>
+      <implementation>org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory</implementation>
       <configuration>
-        <resource>ibatis-config.xml</resource>
-        <properties>
+        <persistenceManagerFactoryClass>org.jpox.PersistenceManagerFactoryImpl</persistenceManagerFactoryClass>
+        <otherProperties>
           <property>
-            <name>jdbc.driver</name>
-            <value>org.apache.derby.jdbc.EmbeddedDriver</value>
+            <name>javax.jdo.PersistenceManagerFactoryClass</name>
+            <value>org.jpox.PersistenceManagerFactoryImpl</value>
           </property>
-          <property>
-            <name>jdbc.url</name>
-            <value>jdbc:derby:${plexus.home}/testdb;create=true</value>
-          </property>
-          <property>
-            <name>jdbc.username</name>
-            <value>app</value>
-          </property>
-          <property>
-            <name>jdbc.password</name>
-            <value></value>
-          </property>
-        </properties>
+        </otherProperties>
       </configuration>
     </component>
+
+    <component>
+      <role>org.codehaus.plexus.logging.LoggerManager</role>
+      <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>
+    </component>
   </components>
-</plexus>
\ No newline at end of file
+</component-set>
+
diff --git a/archiva-database/src/test/resources/ibatis-config.xml b/archiva-database/src/test/resources/ibatis-config.xml
deleted file mode 100644 (file)
index b7013e0..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE sqlMapConfig
-    PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
-    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
-
-<sqlMapConfig>
-  <settings
-    cacheModelsEnabled="true"
-    enhancementEnabled="true"
-    lazyLoadingEnabled="false"
-    maxRequests="32"
-    maxSessions="10"
-    maxTransactions="5"
-    useStatementNamespaces="false"
-    />
-
-  <transactionManager type="JDBC">
-    <dataSource type="SIMPLE">
-      <property name="JDBC.Driver" value="${jdbc.driver}"/>
-      <property name="JDBC.ConnectionURL" value="${jdbc.url}"/>
-      <property name="JDBC.Username" value="${jdbc.username}"/>
-      <property name="JDBC.Password" value="${jdbc.password}"/>
-    </dataSource>
-  </transactionManager>
-
-  <!--
-  <resultObjectFactory type="org.codehaus.plexus.ibatis.PlexusResultObjectFactory" >
-       <property name="foo" value="bar"/>
-  </resultObjectFactory> 
-  -->
-
-  <sqlMap resource="org/apache/maven/archiva/database/ManageTables.xml"/>
-  <sqlMap resource="org/apache/maven/archiva/database/MetadataKey.xml"/>
-  <sqlMap resource="org/apache/maven/archiva/database/ArtifactKey.xml"/>
-  <sqlMap resource="org/apache/maven/archiva/database/RepositoryMetadata.xml"/>
-  
-</sqlMapConfig>
\ No newline at end of file
diff --git a/archiva-database/src/test/resources/log4j.properties b/archiva-database/src/test/resources/log4j.properties
deleted file mode 100644 (file)
index a30a904..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-log4j.rootCategory=DEBUG, root
-
-## Define the destination and format of our logging
-log4j.appender.root=org.apache.log4j.ConsoleAppender
-log4j.appender.root.layout=org.apache.log4j.PatternLayout
-log4j.appender.root.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n
-
-# SqlMap logging configuration...
-log4j.logger.com.ibatis=INFO
-log4j.logger.java.sql=INFO
diff --git a/archiva-database/src/test/resources/log4j.xml b/archiva-database/src/test/resources/log4j.xml
new file mode 100644 (file)
index 0000000..395941a
--- /dev/null
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+  <appender name="console" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out"/>
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%d [%t] %-5p %-30c{1} - %m%n"/>
+    </layout>
+  </appender>
+
+  <!-- Help identify bugs during testing -->
+  <logger name="org.apache.maven">
+    <level value="info"/>
+  </logger>
+
+  <logger name="org.codehaus.plexus.security">
+    <level value="info"/>
+  </logger>
+
+  <!-- squelch noisy objects (for now) -->
+  <logger name="org.codehaus.plexus.mailsender.MailSender">
+    <level value="info"/>
+  </logger>
+
+  <logger name="org.quartz">
+    <level value="info"/>
+  </logger>
+
+  <logger name="org.apache.jasper">
+    <level value="info"/>
+  </logger>
+
+  <logger name="com.opensymphony.xwork">
+    <level value="info"/>
+  </logger>
+
+  <logger name="com.opensymphony.webwork">
+    <level value="info"/>
+  </logger>
+
+  <logger name="org.codehaus.plexus.PlexusContainer">
+    <level value="info"/>
+  </logger>
+
+  <logger name="JPOX">
+    <level value="warn"/>
+  </logger>
+
+  <logger name="JPOX.MetaData">
+    <level value="error"/>
+  </logger>
+
+  <logger name="JPOX.RDBMS.SQL">
+    <level value="error"/>
+  </logger>
+
+  <logger name="SQL">
+    <level value="error"/>
+  </logger>
+
+  <logger name="freemarker">
+    <level value="warn"/>
+  </logger>
+
+  <logger name="org.codehaus.plexus.component.manager.ClassicSingletonComponentManager">
+    <level value="error"/>
+  </logger>
+
+  <root>
+    <priority value ="info" />
+    <appender-ref ref="console" />
+  </root>
+
+</log4j:configuration>
index 313ece24d757ed80b25e75996390826295d81df2..bd8ba014b828165ed689296f5bb48af955b4253f 100755 (executable)
         <groupId>org.codehaus.modello</groupId>
         <artifactId>modello-maven-plugin</artifactId>
         <version>1.0-alpha-15-SNAPSHOT</version>
+        <configuration>
+          <version>1.0.0</version>
+          <packageWithVersion>false</packageWithVersion>
+          <model>src/main/mdo/archiva-base.xml</model>
+        </configuration>
         <executions>
           <execution>
             <id>archiva-base</id>
             <goals>
               <goal>java</goal>
               <goal>xsd</goal>
-              <goal>jpox-jdo-mapping</goal>
               <goal>jpox-metadata-class</goal>
               <goal>xpp3-writer</goal>
               <goal>xpp3-reader</goal>
             </goals>
+          </execution>
+          <execution>
+            <id>jdo</id>
+            <goals>
+              <goal>jpox-jdo-mapping</goal>
+            </goals>
             <configuration>
-              <version>1.0.0</version>
-              <packageWithVersion>false</packageWithVersion>
-              <model>src/main/mdo/archiva-base.xml</model>
+              <outputDirectory>${basedir}/target/classes/org/apache/maven/archiva/model</outputDirectory>
             </configuration>
           </execution>
         </executions>
        <groupId>org.codehaus.mojo</groupId>
         <artifactId>jpox-maven-plugin</artifactId>
         <version>1.1.6</version>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <version>10.2.1.6</version>
+          </dependency>
+        </dependencies>
         <executions>
           <execution>
+            <id>create-ddl</id>
+            <phase>generate-test-resources</phase>
+            <goals>
+              <goal>schema-create</goal>
+            </goals>
+            <configuration>
+              <outputFile>${basedir}/target/classes/org/apache/maven/archiva/model/schema.ddl</outputFile>
+              <toolProperties>
+                <property>
+                  <name>javax.jdo.option.ConnectionDriverName</name>
+                  <value>org.apache.derby.jdbc.EmbeddedDriver</value>
+                </property>
+                <property>
+                  <name>javax.jdo.option.ConnectionURL</name>
+                  <value>jdbc:derby:target/jdo-schema-create;create=true</value>
+                </property>
+                <property>
+                  <name>javax.jdo.option.ConnectionUserName</name>
+                  <value>sa</value>
+                </property>
+                <property>
+                  <name>javax.jdo.option.ConnectionPassword</name>
+                  <value></value>
+                </property>
+                <property>
+                  <name>log4j.configuration</name>
+                  <value>${basedir}/src/test/resources/log4j.xml</value>
+                </property>
+                <property>
+                  <name>org.jpox.autoCreateTables</name>
+                  <value>true</value>
+                </property>
+              </toolProperties>
+            </configuration>
+          </execution>
+          <execution>
+            <id>enhance</id>
             <goals>
               <goal>enhance</goal>
             </goals>
diff --git a/archiva-model/src/test/resources/log4j.xml b/archiva-model/src/test/resources/log4j.xml
new file mode 100644 (file)
index 0000000..395941a
--- /dev/null
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+  <appender name="console" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out"/>
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%d [%t] %-5p %-30c{1} - %m%n"/>
+    </layout>
+  </appender>
+
+  <!-- Help identify bugs during testing -->
+  <logger name="org.apache.maven">
+    <level value="info"/>
+  </logger>
+
+  <logger name="org.codehaus.plexus.security">
+    <level value="info"/>
+  </logger>
+
+  <!-- squelch noisy objects (for now) -->
+  <logger name="org.codehaus.plexus.mailsender.MailSender">
+    <level value="info"/>
+  </logger>
+
+  <logger name="org.quartz">
+    <level value="info"/>
+  </logger>
+
+  <logger name="org.apache.jasper">
+    <level value="info"/>
+  </logger>
+
+  <logger name="com.opensymphony.xwork">
+    <level value="info"/>
+  </logger>
+
+  <logger name="com.opensymphony.webwork">
+    <level value="info"/>
+  </logger>
+
+  <logger name="org.codehaus.plexus.PlexusContainer">
+    <level value="info"/>
+  </logger>
+
+  <logger name="JPOX">
+    <level value="warn"/>
+  </logger>
+
+  <logger name="JPOX.MetaData">
+    <level value="error"/>
+  </logger>
+
+  <logger name="JPOX.RDBMS.SQL">
+    <level value="error"/>
+  </logger>
+
+  <logger name="SQL">
+    <level value="error"/>
+  </logger>
+
+  <logger name="freemarker">
+    <level value="warn"/>
+  </logger>
+
+  <logger name="org.codehaus.plexus.component.manager.ClassicSingletonComponentManager">
+    <level value="error"/>
+  </logger>
+
+  <root>
+    <priority value ="info" />
+    <appender-ref ref="console" />
+  </root>
+
+</log4j:configuration>