1 package org.apache.maven.archiva.reporting.artifact;
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.apache.maven.archiva.database.ArchivaDAO;
23 import org.codehaus.plexus.PlexusTestCase;
24 import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
25 import org.codehaus.plexus.jdo.JdoFactory;
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 * AbstractArtifactReportsTestCase
40 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
43 public class AbstractArtifactReportsTestCase
44 extends PlexusTestCase
46 protected ArchivaDAO dao;
48 protected void setUp()
53 DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "archiva" );
54 assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
56 jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
59 File derbyDbDir = new File( "target/plexus-home/testdb" );
60 if ( derbyDbDir.exists() )
62 FileUtils.deleteDirectory( derbyDbDir );
65 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" ) );
69 jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) );
70 jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:hsqldb:mem:" + getName() ) );
72 jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) );
74 jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) );
76 jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
78 jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );
80 jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );
82 jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" );
84 jdoFactory.setProperty( "javax.jdo.option.RestoreValues", "true" );
86 // jdoFactory.setProperty( "org.jpox.autoCreateColumns", "true" );
88 jdoFactory.setProperty( "org.jpox.validateTables", "true" );
90 jdoFactory.setProperty( "org.jpox.validateColumns", "true" );
92 jdoFactory.setProperty( "org.jpox.validateConstraints", "true" );
94 Properties properties = jdoFactory.getProperties();
96 for ( Iterator it = properties.entrySet().iterator(); it.hasNext(); )
98 Map.Entry entry = (Map.Entry) it.next();
100 System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
103 URL jdoFileUrls[] = new URL[] { getClass().getResource( "/org/apache/maven/archiva/model/package.jdo" ) };
105 if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
107 fail( "Unable to process test " + getName() + " - missing package.jdo." );
110 File propsFile = null; // intentional
111 boolean verbose = true;
113 SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose );
114 SchemaTool.createSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose, null );
116 PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
118 assertNotNull( pmf );
120 PersistenceManager pm = pmf.getPersistenceManager();
124 this.dao = (ArchivaDAO) lookup( ArchivaDAO.class.getName(), "jdo" );