]> source.dussan.org Git - archiva.git/commitdiff
Boilerplate unit testing with hsqldb for other devs ...
authorJoakim Erdfelt <joakime@apache.org>
Thu, 22 Mar 2007 15:11:37 +0000 (15:11 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Thu, 22 Mar 2007 15:11:37 +0000 (15:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@521303 13f79535-47bb-0310-9956-ffa450edef68

archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java
archiva-model/pom.xml
archiva-model/src/main/mdo/archiva-base.xml

index a359b9b66bf8ddabe35c59d7b7705f65037a9006..5697afd1115b11b1aa0a52a10b5d8459e942ffba 100644 (file)
@@ -25,6 +25,8 @@ import org.apache.maven.archiva.model.ArchivaRepositoryModel;
 
 import java.util.List;
 
+import javax.jdo.JDOHelper;
+
 /**
  * JdoArchivaDAOTest 
  *
@@ -35,33 +37,54 @@ public class JdoArchivaDAOTest extends AbstractArchivaDatabaseTestCase
 {
     public void testRepositoryCRUD() throws ArchivaDatabaseException
     {
+        // Create it
         ArchivaRepositoryModel repo = dao.createRepository( "testRepo", "http://localhost:8080/repository/foo" );
-
         assertNotNull( repo );
 
-        repo.setName( "The Test Repostitory." );
+        // Set some mandatory values
+        repo.setName( "The Test Repository." );
+        repo.setCreationSource( "Test Case" );
         repo.setLayoutName( "default" );
 
+        // Save it. 
         ArchivaRepositoryModel repoSaved = dao.saveRepository( repo );
         assertNotNull( repoSaved );
+        assertEquals( "testRepo", JDOHelper.getObjectId( repoSaved ).toString() );
 
+        // Test that something has been saved.
         List repos = dao.getRepositories();
         assertNotNull( repos );
         assertEquals( 1, repos.size() );
-        
+
+        // Test that retreived object is what we expect.
+        ArchivaRepositoryModel firstRepo = (ArchivaRepositoryModel) repos.get( 0 );
+        assertNotNull( firstRepo );
+        assertEquals( "testRepo", repo.getId() );
+        assertEquals( "The Test Repository.", repo.getName() );
+        assertEquals( "Test Case", repo.getCreationSource() );
+        assertEquals( "default", repo.getLayoutName() );
+
+        // Change value and save.
         repoSaved.setName( "Saved Again" );
         dao.saveRepository( repoSaved );
-        
+
+        // Test that only 1 object is saved.
+        assertEquals( 1, dao.getRepositories().size() );
+
+        // Get the specific repo.
         ArchivaRepositoryModel actualRepo = dao.getRepository( "testRepo" );
         assertNotNull( actualRepo );
+
+        // Test expected values.
         assertEquals( "testRepo", actualRepo.getId() );
         assertEquals( "http://localhost:8080/repository/foo", actualRepo.getUrl() );
         assertEquals( "Saved Again", actualRepo.getName() );
-        
+
+        // Test that only 1 object is saved.
         assertEquals( 1, dao.getRepositories().size() );
-        
+
+        // Delete object.
         dao.deleteRepository( actualRepo );
         assertEquals( 0, dao.getRepositories().size() );
     }
 }
-
index bd8ba014b828165ed689296f5bb48af955b4253f..3fcb6843f0eb02236ab45eb260f6fd496460fbaf 100755 (executable)
             <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>
-              <outputDirectory>${basedir}/target/classes/org/apache/maven/archiva/model</outputDirectory>
-            </configuration>
-          </execution>
         </executions>
       </plugin>
       <plugin>
index 55f6d227cbf78ba6f86fb4de4fac0d8d4d2db9c4..a6cc0fc40b835af71a7db65e2d9ac9bdef3e075c 100644 (file)
@@ -1,5 +1,6 @@
 <?xml version="1.0" ?>
-<model jpox.table-prefix="ARCHIVA_"
+<model jpox.mapping-in-package="true"
+       jpox.table-prefix="ARCHIVA_"
        xsd.namespace="http://maven.apache.org/archiva/MODEL-1.0.0"
        xsd.target-namespace="http://maven.apache.org/archiva/MODEL-1.0.0">
   <id>archiva-base-model</id>
       -->
 
     <class stash.storable="true"
-           jpox.table="REPOSITORIES">
+           jpox.table="REPOSITORIES"
+           jpox.not-persisted-fields="modelEncoding">
       <name>ArchivaRepositoryModel</name>
       <version>1.0.0+</version>
       <fields>
-        <field>
+        <field jpox.primary-key="true"
+               jpox.value-strategy="off">
           <name>id</name>
           <identity>true</identity>
           <version>1.0.0+</version>
             The layout of the repository.
             (Either 'default', or 'legacy')
           </description>
+          <defaultValue>default</defaultValue>
         </field>
         <field>
           <name>releasePolicy</name>
           <identity>false</identity>
           <version>1.0.0+</version>
-          <type>String</type>
+          <type>boolean</type>
           <required>true</required>
           <description>
             The releases policy of the repository.
           </description>
+          <defaultValue>true</defaultValue>
         </field>
         <field>
           <name>snapshotPolicy</name>
           <identity>false</identity>
           <version>1.0.0+</version>
-          <type>String</type>
+          <type>boolean</type>
           <required>true</required>
           <description>
             The snapshot policy of the repository.
           </description>
+          <defaultValue>false</defaultValue>
         </field>
       </fields>
     </class>