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.jdo.DefaultConfigurableJdoFactory;
24 import org.codehaus.plexus.jdo.JdoFactory;
25 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
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
42 public abstract class AbstractArtifactReportsTestCase
43 extends PlexusInSpringTestCase
45 protected ArchivaDAO dao;
47 protected void setUp()
52 DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "archiva" );
53 assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
55 jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
58 File derbyDbDir = new File( "target/plexus-home/testdb" );
59 if ( derbyDbDir.exists() )
61 FileUtils.deleteDirectory( derbyDbDir );
64 jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.apache.derby.jdbc.EmbeddedDriver" ) );
65 jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:derby:" + derbyDbDir.getAbsolutePath() + ";create=true" ) );
68 jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) );
69 jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:hsqldb:mem:" + getName() ) );
71 jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) );
73 jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) );
75 jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
77 jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );
79 jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );
81 jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" );
83 jdoFactory.setProperty( "javax.jdo.option.RestoreValues", "true" );
85 // jdoFactory.setProperty( "org.jpox.autoCreateColumns", "true" );
87 jdoFactory.setProperty( "org.jpox.validateTables", "true" );
89 jdoFactory.setProperty( "org.jpox.validateColumns", "true" );
91 jdoFactory.setProperty( "org.jpox.validateConstraints", "true" );
93 Properties properties = jdoFactory.getProperties();
95 for ( Iterator it = properties.entrySet().iterator(); it.hasNext(); )
97 Map.Entry entry = (Map.Entry) it.next();
99 System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
102 URL jdoFileUrls[] = new URL[] { getClass().getResource( "/org/apache/maven/archiva/model/package.jdo" ) };
104 if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
106 fail( "Unable to process test " + getName() + " - missing package.jdo." );
109 File propsFile = null; // intentional
110 boolean verbose = true;
112 SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose );
113 SchemaTool.createSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose, null );
115 PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
117 assertNotNull( pmf );
119 PersistenceManager pm = pmf.getPersistenceManager();
123 this.dao = (ArchivaDAO) lookup( ArchivaDAO.class.getName(), "jdo" );