From: Joakim Erdfelt Date: Wed, 21 Mar 2007 14:30:32 +0000 (+0000) Subject: More work against model/database unit testing. X-Git-Tag: archiva-1.0-alpha-1~113^2~108 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1451e3ef75b64846ee3d39a9bcef4a48ffaf3e09;p=archiva.git More work against model/database unit testing. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@520899 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-database/pom.xml b/archiva-database/pom.xml index 32ede8488..b5ce7540f 100755 --- a/archiva-database/pom.xml +++ b/archiva-database/pom.xml @@ -95,7 +95,6 @@ org.apache.derby derby 10.2.1.6 - org.apache.derby @@ -105,11 +104,11 @@ - - + + org.codehaus.plexus plexus-maven-plugin - - + + diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java index 6033a6924..175fb29be 100644 --- a/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java @@ -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 index 000000000..a359b9b66 --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java @@ -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 Joakim Erdfelt + * @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() ); + } +} + diff --git a/archiva-database/src/test/resources/META-INF/plexus/components.xml b/archiva-database/src/test/resources/META-INF/plexus/components.xml index 9be2e75bc..cd924e95c 100644 --- a/archiva-database/src/test/resources/META-INF/plexus/components.xml +++ b/archiva-database/src/test/resources/META-INF/plexus/components.xml @@ -1,30 +1,24 @@ - + - org.codehaus.plexus.ibatis.PlexusIbatisHelper - org.codehaus.plexus.ibatis.DefaultPlexusIbatisHelper - metadata + org.codehaus.plexus.jdo.JdoFactory + archiva + org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory - ibatis-config.xml - + org.jpox.PersistenceManagerFactoryImpl + - jdbc.driver - org.apache.derby.jdbc.EmbeddedDriver + javax.jdo.PersistenceManagerFactoryClass + org.jpox.PersistenceManagerFactoryImpl - - jdbc.url - jdbc:derby:${plexus.home}/testdb;create=true - - - jdbc.username - app - - - jdbc.password - - - + + + + org.codehaus.plexus.logging.LoggerManager + org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager + - \ No newline at end of file + + diff --git a/archiva-database/src/test/resources/ibatis-config.xml b/archiva-database/src/test/resources/ibatis-config.xml deleted file mode 100644 index b7013e013..000000000 --- a/archiva-database/src/test/resources/ibatis-config.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ 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 index a30a9049a..000000000 --- a/archiva-database/src/test/resources/log4j.properties +++ /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 index 000000000..395941ac3 --- /dev/null +++ b/archiva-database/src/test/resources/log4j.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/archiva-model/pom.xml b/archiva-model/pom.xml index 313ece24d..bd8ba014b 100755 --- a/archiva-model/pom.xml +++ b/archiva-model/pom.xml @@ -65,21 +65,29 @@ org.codehaus.modello modello-maven-plugin 1.0-alpha-15-SNAPSHOT + + 1.0.0 + false + src/main/mdo/archiva-base.xml + archiva-base java xsd - jpox-jdo-mapping jpox-metadata-class xpp3-writer xpp3-reader + + + jdo + + jpox-jdo-mapping + - 1.0.0 - false - src/main/mdo/archiva-base.xml + ${basedir}/target/classes/org/apache/maven/archiva/model @@ -88,8 +96,52 @@ org.codehaus.mojo jpox-maven-plugin 1.1.6 + + + org.apache.derby + derby + 10.2.1.6 + + + create-ddl + generate-test-resources + + schema-create + + + ${basedir}/target/classes/org/apache/maven/archiva/model/schema.ddl + + + javax.jdo.option.ConnectionDriverName + org.apache.derby.jdbc.EmbeddedDriver + + + javax.jdo.option.ConnectionURL + jdbc:derby:target/jdo-schema-create;create=true + + + javax.jdo.option.ConnectionUserName + sa + + + javax.jdo.option.ConnectionPassword + + + + log4j.configuration + ${basedir}/src/test/resources/log4j.xml + + + org.jpox.autoCreateTables + true + + + + + + enhance enhance diff --git a/archiva-model/src/test/resources/log4j.xml b/archiva-model/src/test/resources/log4j.xml new file mode 100644 index 000000000..395941ac3 --- /dev/null +++ b/archiva-model/src/test/resources/log4j.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +