1 package org.apache.maven.archiva.database;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.codehaus.plexus.PlexusTestCase;
23 import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
24 import org.codehaus.plexus.jdo.JdoFactory;
25 import org.codehaus.plexus.util.FileUtils;
26 import org.jpox.SchemaTool;
30 import java.util.Iterator;
32 import java.util.Properties;
34 import javax.jdo.PersistenceManager;
35 import javax.jdo.PersistenceManagerFactory;
38 * AbstractArchivaDatabaseTestCase
40 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
43 public class AbstractArchivaDatabaseTestCase
44 extends PlexusTestCase
46 protected ArchivaDAO dao;
48 protected void setUp()
51 File derbyDbDir = new File( "target/plexus-home/testdb" );
52 if ( derbyDbDir.exists() )
54 FileUtils.deleteDirectory( derbyDbDir );
59 DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "archiva" );
60 assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
62 jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
64 jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.apache.derby.jdbc.EmbeddedDriver" ) );
66 jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:derby:" + derbyDbDir.getAbsolutePath() + ";create=true" ) );
68 jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) );
70 jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) );
72 jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
74 jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );
76 jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );
78 jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" );
80 jdoFactory.setProperty( "javax.jdo.option.RestoreValues", "true" );
82 // jdoFactory.setProperty( "org.jpox.autoCreateColumns", "true" );
84 jdoFactory.setProperty( "org.jpox.validateTables", "true" );
86 jdoFactory.setProperty( "org.jpox.validateColumns", "true" );
88 jdoFactory.setProperty( "org.jpox.validateConstraints", "true" );
90 Properties properties = jdoFactory.getProperties();
92 for ( Iterator it = properties.entrySet().iterator(); it.hasNext(); )
94 Map.Entry entry = (Map.Entry) it.next();
96 System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
99 URL jdoFileUrls[] = new URL[] { getClass()
100 .getResource( "/org/apache/maven/archiva/model/package.jdo" ) };
102 if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
104 fail( "Unable to process test " + getName() + " - missing package.jdo." );
107 File propsFile = null; // intentional
108 boolean verbose = true;
110 SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose );
111 SchemaTool.createSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose, null );
113 PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
115 assertNotNull( pmf );
117 PersistenceManager pm = pmf.getPersistenceManager();
121 this.dao = (ArchivaDAO) lookup( ArchivaDAO.class.getName(), "jdo" );