]> source.dussan.org Git - archiva.git/blob
8ec912e9223c5c08913613a1b00f772657904a47
[archiva.git] /
1 package org.apache.archiva.redback.keys.jdo;
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 org.apache.archiva.redback.keys.KeyManager;
23 import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
24 import org.codehaus.plexus.redback.keys.KeyManagerTestCase;
25 import org.jpox.SchemaTool;
26 import org.junit.Before;
27
28 import javax.inject.Inject;
29 import javax.inject.Named;
30 import javax.jdo.PersistenceManager;
31 import javax.jdo.PersistenceManagerFactory;
32 import java.net.URL;
33 import java.util.Map;
34 import java.util.Properties;
35
36 /**
37  * JdoKeyManagerTest 
38  *
39  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
40  * @version $Id$
41  */
42 public class JdoKeyManagerTest
43     extends KeyManagerTestCase
44 {
45
46     @Inject
47     @Named(value = "jdoFactory#users")
48     DefaultConfigurableJdoFactory jdoFactory;
49
50     @Inject @Named(value = "keyManager#jdo")
51     KeyManager keyManager;
52
53
54     @Before
55     public void setUp()
56         throws Exception
57     {
58         
59         super.setUp();
60
61         assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
62
63         jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" ); //$NON-NLS-1$
64
65         jdoFactory.setDriverName( "org.hsqldb.jdbcDriver" ); //$NON-NLS-1$
66
67         jdoFactory.setUrl( "jdbc:hsqldb:mem:" + getName() ); //$NON-NLS-1$
68
69         jdoFactory.setUserName( "sa" ); //$NON-NLS-1$
70
71         jdoFactory.setPassword( "" ); //$NON-NLS-1$
72
73         jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$
74
75         jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$
76
77         jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" ); //$NON-NLS-1$ //$NON-NLS-2$
78         
79         jdoFactory.setProperty( "org.jpox.rdbms.dateTimezone", "JDK_DEFAULT_TIMEZONE" );  //$NON-NLS-1$ //$NON-NLS-2$
80
81         Properties properties = jdoFactory.getProperties();
82
83         for ( Map.Entry<Object,Object> entry : properties.entrySet() )
84         {
85             System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
86         }
87
88         SchemaTool.createSchemaTables( new URL[] { getClass()
89             .getResource( "/org/codehaus/plexus/redback/keys/jdo/package.jdo" ) }, new URL[] {}, null, false, null ); //$NON-NLS-1$
90
91         PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
92
93         assertNotNull( pmf );
94
95         PersistenceManager pm = pmf.getPersistenceManager();
96
97         pm.close();
98         keyManager.eraseDatabase();
99         setKeyManager( keyManager );
100     }
101     
102 }