Repository: archiva-redback-core Updated Branches: refs/heads/jpa [created] 62efc70bd
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/62efc70b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java ---------------------------------------------------------------------- diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java new file mode 100644 index 0000000..4556755 --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java @@ -0,0 +1,86 @@ +package org.apache.archiva.redback.users.jpa; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.redback.policy.UserSecurityPolicy; +import org.apache.archiva.redback.users.User; +import org.apache.archiva.redback.users.UserManager; +import org.apache.archiva.redback.users.provider.test.AbstractUserManagerTestCase; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * Created by martin on 21.09.16. + */ + +public class JpaUserManagerTest extends AbstractUserManagerTestCase { + + Log log = LogFactory.getLog(JpaUserManagerTest.class); + + @Inject + @Named("userManager#jpa") + JpaUserManager jpaUserManager; + + + @Inject + private UserSecurityPolicy securityPolicy; + + @Before + @Override + public void setUp() throws Exception { + + super.setUp(); + Properties props = new Properties(); + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties"); + assert is!=null; + props.load(is); + is.close(); + EntityManagerFactory emf = Persistence.createEntityManagerFactory("redback-jpa",props); + + log.info("test setup"); + jpaUserManager.setEntityManager(emf.createEntityManager()); + super.setUserManager(jpaUserManager); + assertNotNull(jpaUserManager); + log.info("injected usermanager "+jpaUserManager); + + // create the factory defined by the "openjpa" entity-manager entry + + } + + @Test + public void testInit() { + jpaUserManager.initialize(); + } + + + + +} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/62efc70b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml ---------------------------------------------------------------------- diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml new file mode 100644 index 0000000..4d7802e --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml @@ -0,0 +1,50 @@ +<?xml version="1.0"?> + +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + + <context:component-scan base-package="org.apache.archiva.redback.users.jpa" /> + + + <bean name="userConfiguration#default" class="org.apache.archiva.redback.configuration.DefaultUserConfiguration"> + <property name="registry" ref="test-conf"/> + </bean> + + <bean name="commons-configuration" class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry"> + <property name="properties"> + <value> + <![CDATA[ + <configuration> + <properties fileName="test.properties" config-name="properties"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <alias name="commons-configuration" alias="test-conf"/> + +</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/62efc70b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties ---------------------------------------------------------------------- diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties new file mode 100644 index 0000000..df848c4 --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +openjpa.ConnectionURL=jdbc:hsqldb:mem:reback-jpa +openjpa.ConnectionDriverName=org.hsqldb.jdbcDriver +openjpa.ConnectionUserName=sa +openjpa.ConnectionPassword= +openjp.Log=DefaultLevel=WARN,Tool=INFO +openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=true) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/62efc70b/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java ---------------------------------------------------------------------- diff --git a/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java b/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java index 6da8ac8..d293bda 100644 --- a/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java +++ b/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java @@ -97,10 +97,12 @@ public class AbstractUserManagerTestCase throws UserManagerException { + assertNotNull(userManager); getUserManager().eraseDatabase(); getEventTracker().userManagerInit( true ); assertNotNull( getUserManager() ); + assertNotNull(userManager.getUsers()); assertEquals( "New UserManager should contain no users. " + userManager.getUsers(), 0, userManager.getUsers().size() ); }
