]> source.dussan.org Git - archiva.git/blob
c57b82f792a665d6249b62d7ba133d2a295e4c4a
[archiva.git] /
1 package org.apache.archiva.redback.users.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.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
23 import org.apache.archiva.redback.common.jdo.test.StoreManagerDebug;
24 import org.apache.archiva.redback.users.provider.test.AbstractUserManagerTestCase;
25 import org.jpox.AbstractPersistenceManagerFactory;
26 import org.jpox.SchemaTool;
27 import org.junit.Before;
28
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.jdo.PersistenceManager;
32 import javax.jdo.PersistenceManagerFactory;
33 import java.net.URL;
34 import java.util.Map;
35 import java.util.Properties;
36
37 /**
38  * JdoUserManagerTest
39  *
40  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
41  * @version $Id$
42  */
43 public class JdoUserManagerTest
44     extends AbstractUserManagerTestCase
45 {
46     @Inject
47     @Named( value = "jdoFactory#users" )
48     DefaultConfigurableJdoFactory jdoFactory;
49
50     @Inject
51     @Named( value = "userManager#jdo" )
52     JdoUserManager jdoUserManager;
53
54     private StoreManagerDebug storeManager;
55
56     @Before
57     public void setUp()
58         throws Exception
59     {
60         super.setUp();
61
62         jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" ); //$NON-NLS-1$
63
64         jdoFactory.setDriverName( "org.hsqldb.jdbcDriver" ); //$NON-NLS-1$
65
66         jdoFactory.setUrl( "jdbc:hsqldb:mem:" + getName() ); //$NON-NLS-1$
67
68         jdoFactory.setUserName( "sa" ); //$NON-NLS-1$
69
70         jdoFactory.setPassword( "" ); //$NON-NLS-1$
71
72         jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$
73
74         jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$
75
76         jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" ); //$NON-NLS-1$ //$NON-NLS-2$
77
78         Properties properties = jdoFactory.getProperties();
79
80         for ( Map.Entry<?, ?> entry : properties.entrySet() )
81         {
82             System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
83         }
84
85         PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
86
87         assertNotNull( pmf );
88
89         /* set our own Store Manager to allow counting SQL statements */
90         StoreManagerDebug.setup( (AbstractPersistenceManagerFactory) pmf );
91
92         SchemaTool.createSchemaTables(
93             new URL[]{ getClass().getResource( "/org/codehaus/plexus/redback/users/jdo/package.jdo" ) }, new URL[]{ },
94             null, false, null ); //$NON-NLS-1$
95
96         PersistenceManager pm = pmf.getPersistenceManager();
97
98         pm.close();
99
100         setUserManager( jdoUserManager );
101
102         /* save the store manager to access the queries executed */
103         JdoUserManager userManager = (JdoUserManager) getUserManager();
104         storeManager = StoreManagerDebug.getConfiguredStoreManager( userManager.getPersistenceManager() );
105
106     }
107
108     protected void assertCleanUserManager()
109     {
110         // database cleanup
111         ( (JdoUserManager) getUserManager()).eraseDatabase();
112
113
114
115         super.assertCleanUserManager();
116     }
117
118
119 }