<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.2.1.6</version>
- <!--<scope>test</scope>-->
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
</dependency>
</dependencies>
<build>
- <plugins>
- <plugin>
+ <plugins>
+ <plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-maven-plugin</artifactId>
- </plugin>
- </plugins>
+ </plugin>
+ </plugins>
</build>
</project>
*/
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
public class AbstractArchivaDatabaseTestCase
extends PlexusTestCase
{
+ protected ArchivaDAO dao;
+
protected void setUp()
throws Exception
{
}
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" );
}
}
--- /dev/null
+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() );
+ }
+}
+
-<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>
+
+++ /dev/null
-<?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
+++ /dev/null
-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
--- /dev/null
+<?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>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-15-SNAPSHOT</version>
+ <configuration>
+ <version>1.0.0</version>
+ <packageWithVersion>false</packageWithVersion>
+ <model>src/main/mdo/archiva-base.xml</model>
+ </configuration>
<executions>
<execution>
<id>archiva-base</id>
<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>
- <version>1.0.0</version>
- <packageWithVersion>false</packageWithVersion>
- <model>src/main/mdo/archiva-base.xml</model>
+ <outputDirectory>${basedir}/target/classes/org/apache/maven/archiva/model</outputDirectory>
</configuration>
</execution>
</executions>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jpox-maven-plugin</artifactId>
<version>1.1.6</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.2.1.6</version>
+ </dependency>
+ </dependencies>
<executions>
<execution>
+ <id>create-ddl</id>
+ <phase>generate-test-resources</phase>
+ <goals>
+ <goal>schema-create</goal>
+ </goals>
+ <configuration>
+ <outputFile>${basedir}/target/classes/org/apache/maven/archiva/model/schema.ddl</outputFile>
+ <toolProperties>
+ <property>
+ <name>javax.jdo.option.ConnectionDriverName</name>
+ <value>org.apache.derby.jdbc.EmbeddedDriver</value>
+ </property>
+ <property>
+ <name>javax.jdo.option.ConnectionURL</name>
+ <value>jdbc:derby:target/jdo-schema-create;create=true</value>
+ </property>
+ <property>
+ <name>javax.jdo.option.ConnectionUserName</name>
+ <value>sa</value>
+ </property>
+ <property>
+ <name>javax.jdo.option.ConnectionPassword</name>
+ <value></value>
+ </property>
+ <property>
+ <name>log4j.configuration</name>
+ <value>${basedir}/src/test/resources/log4j.xml</value>
+ </property>
+ <property>
+ <name>org.jpox.autoCreateTables</name>
+ <value>true</value>
+ </property>
+ </toolProperties>
+ </configuration>
+ </execution>
+ <execution>
+ <id>enhance</id>
<goals>
<goal>enhance</goal>
</goals>
--- /dev/null
+<?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>