View Javadoc

1   package org.apache.maven.archiva.reporting.artifact;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.net.URL;
24  import java.util.Properties;
25  import java.util.Map.Entry;
26  
27  import javax.jdo.PersistenceManager;
28  import javax.jdo.PersistenceManagerFactory;
29  
30  import org.apache.maven.archiva.database.ArchivaDAO;
31  import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
32  import org.codehaus.plexus.jdo.JdoFactory;
33  import org.codehaus.plexus.spring.PlexusInSpringTestCase;
34  import org.jpox.SchemaTool;
35  
36  /**
37   * AbstractArtifactReportsTestCase 
38   *
39   * @version $Id: AbstractArtifactReportsTestCase.java 755239 2009-03-17 13:40:10Z brett $
40   */
41  public abstract class AbstractArtifactReportsTestCase
42      extends PlexusInSpringTestCase
43  {
44      protected ArchivaDAO dao;
45      
46      protected void setUp()
47          throws Exception
48      {
49          super.setUp();
50  
51          DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "archiva" );
52          assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
53  
54          jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
55  
56          /* derby version
57           File derbyDbDir = new File( "target/plexus-home/testdb" );
58           if ( derbyDbDir.exists() )
59           {
60           FileUtils.deleteDirectory( derbyDbDir );
61           }
62  
63           jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.apache.derby.jdbc.EmbeddedDriver" ) );   
64           jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:derby:" + derbyDbDir.getAbsolutePath() + ";create=true" ) );
65           */
66  
67          jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) );
68          jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:hsqldb:mem:" + getName() ) );
69  
70          jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) );
71  
72          jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) );
73  
74          jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
75  
76          jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );
77  
78          jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );
79  
80          jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" );
81  
82          jdoFactory.setProperty( "javax.jdo.option.RestoreValues", "true" );
83  
84          // jdoFactory.setProperty( "org.jpox.autoCreateColumns", "true" );
85  
86          jdoFactory.setProperty( "org.jpox.validateTables", "true" );
87  
88          jdoFactory.setProperty( "org.jpox.validateColumns", "true" );
89  
90          jdoFactory.setProperty( "org.jpox.validateConstraints", "true" );
91  
92          Properties properties = jdoFactory.getProperties();
93  
94          for ( Entry<Object, Object> entry : properties.entrySet() )
95          {
96              System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
97          }
98  
99          URL jdoFileUrls[] = new URL[] { getClass().getResource( "/org/apache/maven/archiva/model/package.jdo" ) };
100 
101         if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
102         {
103             fail( "Unable to process test " + getName() + " - missing package.jdo." );
104         }
105 
106         File propsFile = null; // intentional
107         boolean verbose = true;
108 
109         SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose );
110         SchemaTool.createSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose, null );
111 
112         PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
113 
114         assertNotNull( pmf );
115 
116         PersistenceManager pm = pmf.getPersistenceManager();
117 
118         pm.close();
119 
120         this.dao = (ArchivaDAO) lookup( ArchivaDAO.class.getName(), "jdo" );
121     }
122 }