Author: jawi
Date: Thu Oct 25 13:06:52 2012
New Revision: 1402138

URL: http://svn.apache.org/viewvc?rev=1402138&view=rev
Log:
Added some integration tests for UserAdmin (also to test FELIX-3735)

Added:
    felix/trunk/useradmin/itest/   (with props)
    felix/trunk/useradmin/itest/pom.xml   (with props)
    felix/trunk/useradmin/itest/src/
    felix/trunk/useradmin/itest/src/test/
    felix/trunk/useradmin/itest/src/test/java/
    felix/trunk/useradmin/itest/src/test/java/org/
    felix/trunk/useradmin/itest/src/test/java/org/apache/
    felix/trunk/useradmin/itest/src/test/java/org/apache/felix/
    felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/
    felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/
    
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/BaseIntegrationTest.java
   (with props)
    
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/FileStoreInitializationTest.java
   (with props)
    
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/UserAdminIntegrationTest.java
   (with props)
    felix/trunk/useradmin/itest/src/test/resources/
    felix/trunk/useradmin/itest/src/test/resources/logback.xml   (with props)

Propchange: felix/trunk/useradmin/itest/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Oct 25 13:06:52 2012
@@ -0,0 +1,20 @@
+.settings
+.classpath
+.project
+bin
+build
+target
+classes
+.wtpmodules
+.deployables
+*.iml
+*.ipr
+*.iws
+*.log
+lib
+bundle
+dist
+*.patch
+.externalToolBuilders
+maven-eclipse.xml
+

Added: felix/trunk/useradmin/itest/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/useradmin/itest/pom.xml?rev=1402138&view=auto
==============================================================================
--- felix/trunk/useradmin/itest/pom.xml (added)
+++ felix/trunk/useradmin/itest/pom.xml Thu Oct 25 13:06:52 2012
@@ -0,0 +1,164 @@
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>felix-parent</artifactId>
+               <groupId>org.apache.felix</groupId>
+               <version>1.2.0</version>
+        <relativePath>../../../pom/pom.xml</relativePath>
+       </parent>
+       <properties>
+               <osgi.version>4.0.0</osgi.version>
+               <pax.exam.version>2.4.0</pax.exam.version>
+               <pax.exam.plugin.version>1.2.4</pax.exam.plugin.version>
+               <pax.url.aether.version>1.4.0</pax.url.aether.version>
+               <pax.swissbox.version>1.3.1</pax.swissbox.version>
+               <pax.runner.version>1.7.6</pax.runner.version>
+       </properties>
+       <artifactId>org.apache.felix.useradmin.itest</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+       <packaging>jar</packaging>
+       <description>Integration tests for the UserAdmin OSGi compendium 
service.</description>
+       <dependencies>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.core</artifactId>
+                       <version>${osgi.version}</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.compendium</artifactId>
+                       <version>${osgi.version}</version>
+               </dependency>
+               <dependency>
+            <groupId>org.apache.felix</groupId>
+                       <artifactId>org.apache.felix.useradmin</artifactId>
+                       <version>1.0.3-SNAPSHOT</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+            <groupId>org.apache.felix</groupId>
+                       
<artifactId>org.apache.felix.useradmin.filestore</artifactId>
+                       <version>1.0.2-SNAPSHOT</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+            <groupId>org.apache.felix</groupId>
+                       
<artifactId>org.apache.felix.dependencymanager</artifactId>
+                       <version>3.0.0</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <version>4.10</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.exam</groupId>
+                       <artifactId>pax-exam-junit4</artifactId>
+                       <version>${pax.exam.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.exam</groupId>
+                       <artifactId>pax-exam-container-forked</artifactId>
+                       <version>${pax.exam.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.runner</groupId>
+                       <artifactId>pax-runner-no-jcl</artifactId>
+                       <version>${pax.runner.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.exam</groupId>
+                       <artifactId>pax-exam-link-assembly</artifactId>
+                       <version>${pax.exam.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.exam</groupId>
+                       <artifactId>pax-exam-link-mvn</artifactId>
+                       <version>${pax.exam.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.url</groupId>
+                       <artifactId>pax-url-aether</artifactId>
+                       <version>${pax.url.aether.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.url</groupId>
+                       <artifactId>pax-url-wrap</artifactId>
+                       <version>${pax.url.aether.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>javax.inject</groupId>
+                       <artifactId>javax.inject</artifactId>
+                       <version>1</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.felix</groupId>
+                       <artifactId>org.apache.felix.framework</artifactId>
+                       <version>4.0.2</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-simple</artifactId>
+                       <version>1.6.0</version>
+                       <scope>compile</scope>
+               </dependency>
+       </dependencies>
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-compiler-plugin</artifactId>
+                               <configuration>
+                                       <target>1.6</target>
+                                       <source>1.6</source>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.codehaus.mojo</groupId>
+                               <artifactId>rat-maven-plugin</artifactId>
+                               <configuration>
+                                       
<excludeSubProjects>false</excludeSubProjects>
+                                       
<useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
+                                       
<useMavenDefaultExcludes>true</useMavenDefaultExcludes>
+                                       <excludes>
+                                               <param>doc/*</param>
+                                               <param>maven-eclipse.xml</param>
+                                               <param>.checkstyle</param>
+                                               
<param>.externalToolBuilders/*</param>
+                                       </excludes>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+</project>

Propchange: felix/trunk/useradmin/itest/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/BaseIntegrationTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/BaseIntegrationTest.java?rev=1402138&view=auto
==============================================================================
--- 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/BaseIntegrationTest.java
 (added)
+++ 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/BaseIntegrationTest.java
 Thu Oct 25 13:06:52 2012
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+package org.apache.felix.useradmin.itest;
+
+import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.Constants.START_LEVEL_SYSTEM_BUNDLES;
+import static org.ops4j.pax.exam.Constants.START_LEVEL_TEST_BUNDLE;
+import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackage;
+import static org.ops4j.pax.exam.CoreOptions.cleanCaches;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.url;
+
+import javax.inject.Inject;
+
+import org.junit.Before;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * Base class for integration tests.
+ *  
+ * @author <a href="mailto:[email protected]";>Felix Project Team</a>
+ */
+public abstract class BaseIntegrationTest {
+
+       private static final int DEFAULT_TIMEOUT = 10000;
+       
+       protected static final String ORG_APACHE_FELIX_USERADMIN = 
"org.apache.felix.useradmin";
+       protected static final String ORG_APACHE_FELIX_USERADMIN_FILESTORE = 
"org.apache.felix.useradmin.filestore";
+
+    @Inject
+    protected volatile BundleContext m_context;
+
+    @Configuration
+    public Option[] config() {
+        return options(
+            bootDelegationPackage("sun.*"),
+            cleanCaches(),
+            
CoreOptions.systemProperty("logback.configurationFile").value("file:src/test/resources/logback.xml"),
+//            
CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787"),
+
+            mavenBundle("org.slf4j", 
"slf4j-api").version("1.6.5").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("ch.qos.logback", 
"logback-core").version("1.0.6").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("ch.qos.logback", 
"logback-classic").version("1.0.6").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+
+            
url("link:classpath:META-INF/links/org.ops4j.pax.exam.link").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            
url("link:classpath:META-INF/links/org.ops4j.pax.exam.inject.link").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            
url("link:classpath:META-INF/links/org.ops4j.pax.extender.service.link").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            
url("link:classpath:META-INF/links/org.ops4j.base.link").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            
url("link:classpath:META-INF/links/org.ops4j.pax.swissbox.core.link").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            
url("link:classpath:META-INF/links/org.ops4j.pax.swissbox.extender.link").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            
url("link:classpath:META-INF/links/org.ops4j.pax.swissbox.lifecycle.link").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            
url("link:classpath:META-INF/links/org.ops4j.pax.swissbox.framework.link").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            
url("link:classpath:META-INF/links/org.apache.geronimo.specs.atinject.link").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+
+            mavenBundle("org.osgi", 
"org.osgi.core").version("4.2.0").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.osgi", 
"org.osgi.compendium").version("4.2.0").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.apache.felix", 
"org.apache.felix.log").version("1.0.1").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.apache.felix", 
ORG_APACHE_FELIX_USERADMIN).version("1.0.3-SNAPSHOT").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.apache.felix", 
ORG_APACHE_FELIX_USERADMIN_FILESTORE).version("1.0.2-SNAPSHOT").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            
+            junitBundles(),
+            frameworkStartLevel(START_LEVEL_TEST_BUNDLE),
+            felix());
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        assertNotNull("No bundle context?!", m_context);
+    }
+
+    /**
+     * Waits for a service to become available in certain time interval.
+     * @param serviceName
+     * @return
+     * @throws Exception
+     */
+    protected <T> T awaitService(String serviceName) throws Exception {
+        ServiceTracker tracker = new ServiceTracker(m_context, serviceName, 
null);
+        tracker.open();
+        T result;
+        try {
+            result = (T) tracker.waitForService(DEFAULT_TIMEOUT);
+        }
+        finally {
+            tracker.close();
+        }
+        return result;
+    }
+
+    /**
+     * Obtains a service without waiting for it to become available.
+     * @param serviceName
+     * @return
+     * @throws Exception
+     */
+    protected <T> T getService(String serviceName) throws Exception {
+        ServiceTracker tracker = new ServiceTracker(m_context, serviceName, 
null);
+        tracker.open();
+        T result;
+        try {
+            result = (T) tracker.getService();
+        }
+        finally {
+            tracker.close();
+        }
+        return result;
+    }
+
+    /**
+     * @param bsn
+     * @return
+     */
+    protected Bundle findBundle(String bsn) {
+       for (Bundle bundle : m_context.getBundles()) {
+               if (bsn.equals(bundle.getSymbolicName())) {
+                       return bundle;
+               }
+       }
+       return null;
+    }
+}

Propchange: 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/BaseIntegrationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/FileStoreInitializationTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/FileStoreInitializationTest.java?rev=1402138&view=auto
==============================================================================
--- 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/FileStoreInitializationTest.java
 (added)
+++ 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/FileStoreInitializationTest.java
 Thu Oct 25 13:06:52 2012
@@ -0,0 +1,131 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.useradmin.itest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.felix.useradmin.RoleRepositoryStore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.useradmin.Role;
+
+/**
+ * @author <a href="mailto:[email protected]";>Felix Project Team</a>
+ */
+@RunWith(JUnit4TestRunner.class)
+public class FileStoreInitializationTest extends BaseIntegrationTest {
+
+       /**
+        * Provides a mock file store that does nothing but track the number of
+        * times the {@link #initialize()} and {@link #close()} methods are 
called.
+        */
+       public static class MockRoleRepositoryStore implements 
RoleRepositoryStore {
+
+               final AtomicInteger m_initCount = new AtomicInteger(0);
+               final AtomicInteger m_closeCount = new AtomicInteger(0);
+
+               @Override
+               public boolean addRole(Role role) throws IOException {
+                       return false;
+               }
+
+               @Override
+               public void close() throws IOException {
+                       m_closeCount.incrementAndGet();
+               }
+
+               @Override
+               public Role[] getAllRoles() throws IOException {
+                       return null;
+               }
+
+               @Override
+               public Role getRoleByName(String roleName) throws IOException {
+                       return null;
+               }
+
+               @Override
+               public void initialize() throws IOException {
+                       m_initCount.incrementAndGet();
+               }
+
+               @Override
+               public boolean removeRole(Role role) throws IOException {
+                       return false;
+               }
+       }
+
+       /**
+        * Tests that initialization and closing of the repository store is
+        * performed correctly.
+        */
+       @Test
+       public void testStoreIsInitializedAndClosedProperlyOk() throws 
Exception {
+               final String serviceName = RoleRepositoryStore.class.getName();
+               final MockRoleRepositoryStore mockStore = new 
MockRoleRepositoryStore();
+
+               // Stop the file store...
+               Bundle fileStoreBundle = 
findBundle(ORG_APACHE_FELIX_USERADMIN_FILESTORE);
+               assertNotNull(fileStoreBundle);
+               fileStoreBundle.stop();
+
+               // Manually register our mock store...
+               ServiceRegistration serviceReg = 
m_context.registerService(serviceName, mockStore, null);
+
+               // Wait until it becomes available...
+               awaitService(serviceName);
+
+               assertEquals(1, mockStore.m_initCount.get());
+               assertEquals(0, mockStore.m_closeCount.get());
+
+               serviceReg.unregister();
+
+               Thread.sleep(100); // sleep a tiny bit to allow service to be 
properly unregistered...
+
+               assertEquals(1, mockStore.m_initCount.get());
+               assertEquals(1, mockStore.m_closeCount.get());
+
+               // Re-register the service again...
+               serviceReg = m_context.registerService(serviceName, mockStore, 
null);
+
+               assertEquals(2, mockStore.m_initCount.get());
+               assertEquals(1, mockStore.m_closeCount.get());
+
+               // Stop & start the UserAdmin bundle to verify the 
initialization is
+               // still only performed once...
+               Bundle userAdminBundle = findBundle(ORG_APACHE_FELIX_USERADMIN);
+               assertNotNull(userAdminBundle);
+               userAdminBundle.stop();
+
+               Thread.sleep(100); // sleep a tiny bit to allow service to be 
properly unregistered...
+
+               userAdminBundle.start();
+
+               assertEquals(3, mockStore.m_initCount.get());
+               assertEquals(2, mockStore.m_closeCount.get());
+       }
+}

Propchange: 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/FileStoreInitializationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/UserAdminIntegrationTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/UserAdminIntegrationTest.java?rev=1402138&view=auto
==============================================================================
--- 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/UserAdminIntegrationTest.java
 (added)
+++ 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/UserAdminIntegrationTest.java
 Thu Oct 25 13:06:52 2012
@@ -0,0 +1,142 @@
+/*
+ * 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.
+ */
+package org.apache.felix.useradmin.itest;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+import org.osgi.service.useradmin.UserAdmin;
+
+/**
+ * Main integration test for the user admin service.
+ * 
+ * @author <a href="mailto:[email protected]";>Felix Project Team</a>
+ */
+@RunWith(JUnit4TestRunner.class)
+public class UserAdminIntegrationTest extends BaseIntegrationTest {
+       
+       /**
+        * Tests that stopping a filled store and starting it again will cause 
it to
+        * properly restore its state.
+        */
+       @Test
+       public void testFelix3735_StopRunningStoreRetainsDataOk() throws 
Exception {
+               final String userName = "testUser";
+               final String groupName = "testGroup";
+
+               UserAdmin userAdmin = awaitService(UserAdmin.class.getName());
+
+               // Fill the user admin with some data...
+               User testUser = (User) userAdmin.createRole(userName, 
Role.USER);
+               testUser.getProperties().put("key", "value");
+
+               Group testGroup = (Group) userAdmin.createRole(groupName, 
Role.GROUP);
+               testGroup.addMember(testUser);
+
+               // Stop the file store...
+               Bundle fileStoreBundle = 
findBundle(ORG_APACHE_FELIX_USERADMIN_FILESTORE);
+               assertNotNull(fileStoreBundle);
+               fileStoreBundle.stop();
+
+               // retrieve the useradmin again...
+               userAdmin = awaitService(UserAdmin.class.getName());
+
+               // Verify the user + group are gone (no store available)...
+               assertNull(userAdmin.getRole(userName));
+               assertNull(userAdmin.getRole(groupName));
+
+               // Start the file store...
+               fileStoreBundle.start();
+
+               // Verify the user + group are gone (no store available)...
+               User readUser = (User) userAdmin.getRole(userName);
+               assertNotNull(readUser);
+               assertEquals(userName, readUser.getName());
+               assertEquals("value", readUser.getProperties().get("key"));
+
+               Group readGroup = (Group) userAdmin.getRole(groupName);
+               assertNotNull(readGroup);
+               assertEquals(groupName, readGroup.getName());
+               assertEquals(1, readGroup.getMembers().length);
+               assertEquals(readUser, readGroup.getMembers()[0]);
+       }
+
+       /**
+        * Tests that starting the file store <em>after</em> the user admin 
service
+        * is started will cause it to be properly initialized.
+        */
+       @Test
+       public void testFelix3735_StartStoreAfterUserAdminInitializesOk() 
throws Exception {
+               final String userName = "anotherTestUser";
+               final String groupName = "anotherTestGroup";
+
+               UserAdmin userAdmin = awaitService(UserAdmin.class.getName());
+
+               // Fill the user admin with some data...
+               User testUser = (User) userAdmin.createRole(userName, 
Role.USER);
+               testUser.getProperties().put("key", "value");
+
+               Group testGroup = (Group) userAdmin.createRole(groupName, 
Role.GROUP);
+               testGroup.addMember(testUser);
+
+               // Stop the file store...
+               Bundle fileStoreBundle = 
findBundle(ORG_APACHE_FELIX_USERADMIN_FILESTORE);
+               assertNotNull(fileStoreBundle);
+               fileStoreBundle.stop();
+
+               Bundle userAdminBundle = findBundle(ORG_APACHE_FELIX_USERADMIN);
+               assertNotNull(userAdminBundle);
+               userAdminBundle.stop();
+
+               // Obtain user admin service again; shouldn't be available...
+               userAdmin = getService(UserAdmin.class.getName());
+               assertNull(userAdmin);
+
+               userAdminBundle.start();
+
+               // Obtain user admin service again; should be available now...
+               userAdmin = awaitService(UserAdmin.class.getName());
+               assertNotNull(userAdmin);
+
+               // Verify the user + group are gone (no store available)...
+               assertNull(userAdmin.getRole(userName));
+               assertNull(userAdmin.getRole(groupName));
+
+               // Start the file store...
+               fileStoreBundle.start();
+
+               // Verify the user + group are gone (no store available)...
+               User readUser = (User) userAdmin.getRole(userName);
+               assertNotNull(readUser);
+               assertEquals(userName, readUser.getName());
+               assertEquals("value", readUser.getProperties().get("key"));
+
+               Group readGroup = (Group) userAdmin.getRole(groupName);
+               assertNotNull(readGroup);
+               assertEquals(groupName, readGroup.getName());
+               assertEquals(1, readGroup.getMembers().length);
+               assertEquals(readUser, readGroup.getMembers()[0]);
+       }
+}

Propchange: 
felix/trunk/useradmin/itest/src/test/java/org/apache/felix/useradmin/itest/UserAdminIntegrationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/trunk/useradmin/itest/src/test/resources/logback.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/useradmin/itest/src/test/resources/logback.xml?rev=1402138&view=auto
==============================================================================
--- felix/trunk/useradmin/itest/src/test/resources/logback.xml (added)
+++ felix/trunk/useradmin/itest/src/test/resources/logback.xml Thu Oct 25 
13:06:52 2012
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+       <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+               <encoder>
+                       <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level 
%logger{36} - %msg%n</pattern>
+               </encoder>
+       </appender>
+
+       <root level="WARN">
+               <appender-ref ref="STDOUT" />
+       </root>
+
+       <logger name="org.ops4j" level="WARN" />
+</configuration>

Propchange: felix/trunk/useradmin/itest/src/test/resources/logback.xml
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to