From: Joakim Erdfelt Date: Thu, 22 Mar 2007 15:11:37 +0000 (+0000) Subject: Boilerplate unit testing with hsqldb for other devs ... X-Git-Tag: archiva-1.0-alpha-1~113^2~106 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3e1c7a3ad2173d3a29032fd893e28ec7d13b10ac;p=archiva.git Boilerplate unit testing with hsqldb for other devs ... git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@521303 13f79535-47bb-0310-9956-ffa450edef68 --- 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 index a359b9b66..5697afd11 100644 --- 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 @@ -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() ); } } - diff --git a/archiva-model/pom.xml b/archiva-model/pom.xml index bd8ba014b..3fcb6843f 100755 --- a/archiva-model/pom.xml +++ b/archiva-model/pom.xml @@ -76,20 +76,12 @@ java xsd + jpox-jdo-mapping jpox-metadata-class xpp3-writer xpp3-reader - - jdo - - jpox-jdo-mapping - - - ${basedir}/target/classes/org/apache/maven/archiva/model - - diff --git a/archiva-model/src/main/mdo/archiva-base.xml b/archiva-model/src/main/mdo/archiva-base.xml index 55f6d227c..a6cc0fc40 100644 --- a/archiva-model/src/main/mdo/archiva-base.xml +++ b/archiva-model/src/main/mdo/archiva-base.xml @@ -1,5 +1,6 @@ - archiva-base-model @@ -93,11 +94,13 @@ --> + jpox.table="REPOSITORIES" + jpox.not-persisted-fields="modelEncoding"> ArchivaRepositoryModel 1.0.0+ - + id true 1.0.0+ @@ -148,26 +151,29 @@ The layout of the repository. (Either 'default', or 'legacy') + default releasePolicy false 1.0.0+ - String + boolean true The releases policy of the repository. + true snapshotPolicy false 1.0.0+ - String + boolean true The snapshot policy of the repository. + false