From 3e1c7a3ad2173d3a29032fd893e28ec7d13b10ac Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Mar 2007 15:11:37 +0000 Subject: [PATCH] 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 --- .../database/jdo/JdoArchivaDAOTest.java | 37 +++++++++++++++---- archiva-model/pom.xml | 10 +---- archiva-model/src/main/mdo/archiva-base.xml | 16 +++++--- 3 files changed, 42 insertions(+), 21 deletions(-) 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 -- 2.39.5