1 package org.apache.archiva.redback.users.jdo;
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.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;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.jdo.PersistenceManager;
32 import javax.jdo.PersistenceManagerFactory;
35 import java.util.Properties;
40 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
43 public class JdoUserManagerTest
44 extends AbstractUserManagerTestCase
47 @Named( value = "jdoFactory#users" )
48 DefaultConfigurableJdoFactory jdoFactory;
51 @Named( value = "userManager#jdo" )
52 JdoUserManager jdoUserManager;
54 private StoreManagerDebug storeManager;
62 jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" ); //$NON-NLS-1$
64 jdoFactory.setDriverName( "org.hsqldb.jdbcDriver" ); //$NON-NLS-1$
66 jdoFactory.setUrl( "jdbc:hsqldb:mem:" + getName() ); //$NON-NLS-1$
68 jdoFactory.setUserName( "sa" ); //$NON-NLS-1$
70 jdoFactory.setPassword( "" ); //$NON-NLS-1$
72 jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$
74 jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$
76 jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" ); //$NON-NLS-1$ //$NON-NLS-2$
78 Properties properties = jdoFactory.getProperties();
80 for ( Map.Entry<?, ?> entry : properties.entrySet() )
82 System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
85 PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
89 /* set our own Store Manager to allow counting SQL statements */
90 StoreManagerDebug.setup( (AbstractPersistenceManagerFactory) pmf );
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$
96 PersistenceManager pm = pmf.getPersistenceManager();
100 setUserManager( jdoUserManager );
102 /* save the store manager to access the queries executed */
103 JdoUserManager userManager = (JdoUserManager) getUserManager();
104 storeManager = StoreManagerDebug.getConfiguredStoreManager( userManager.getPersistenceManager() );
108 protected void assertCleanUserManager()
111 ( (JdoUserManager) getUserManager()).eraseDatabase();
115 super.assertCleanUserManager();