aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-database/src
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-03-21 14:30:32 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-03-21 14:30:32 +0000
commit1451e3ef75b64846ee3d39a9bcef4a48ffaf3e09 (patch)
tree09f6f3c35b8c92a3bd66e7a6280b304b051a68d7 /archiva-database/src
parent3bdf3b8e70a764edfb2b5b5e94fdcab3a652b033 (diff)
downloadarchiva-1451e3ef75b64846ee3d39a9bcef4a48ffaf3e09.tar.gz
archiva-1451e3ef75b64846ee3d39a9bcef4a48ffaf3e09.zip
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
Diffstat (limited to 'archiva-database/src')
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java76
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java67
-rw-r--r--archiva-database/src/test/resources/META-INF/plexus/components.xml38
-rw-r--r--archiva-database/src/test/resources/ibatis-config.xml37
-rw-r--r--archiva-database/src/test/resources/log4j.properties10
-rw-r--r--archiva-database/src/test/resources/log4j.xml76
6 files changed, 235 insertions, 69 deletions
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 <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() );
+ }
+}
+
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 @@
-<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
index b7013e013..000000000
--- a/archiva-database/src/test/resources/ibatis-config.xml
+++ /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
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 @@
+<?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>