-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FELIX-4399, FELIX-4400: UserAdmin MongoDB store:
- when creating a new role, we should return the created role if we have good indications that the creation was successful; - MongoDB returns null for empty properties, causing NPEs on several occassions. git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1560612 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Jan Willem Janssen
committed
Jan 23, 2014
1 parent
ddc72e4
commit dd6edec
Showing
7 changed files
with
520 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,22 +46,26 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Felix Project Team</a> | ||
*/ | ||
public abstract class BaseIntegrationTest { | ||
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"; | ||
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"; | ||
protected static final String ORG_APACHE_FELIX_USERADMIN_MONGODBSTORE = "org.apache.felix.useradmin.mongodb"; | ||
protected static final String ORG_MONGODB_MONGO_JAVA_DRIVER = "org.mongodb.mongo-java-driver"; | ||
|
||
@Inject | ||
protected volatile BundleContext m_context; | ||
|
||
@Configuration | ||
public Option[] config() { | ||
public Option[] config() | ||
{ | ||
return options( | ||
bootDelegationPackage("sun.*"), | ||
cleanCaches(), | ||
CoreOptions.systemProperty("logback.configurationFile").value("file:src/test/resources/logback.xml"), | ||
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), | ||
|
@@ -79,15 +83,15 @@ public Option[] config() { | |
url("link:classpath:META-INF/links/org.apache.geronimo.specs.atinject.link").startLevel(START_LEVEL_SYSTEM_BUNDLES), | ||
|
||
mavenBundle("org.apache.felix", ORG_APACHE_FELIX_USERADMIN).versionAsInProject().startLevel(START_LEVEL_SYSTEM_BUNDLES), | ||
mavenBundle("org.apache.felix", ORG_APACHE_FELIX_USERADMIN_FILESTORE).versionAsInProject().startLevel(START_LEVEL_SYSTEM_BUNDLES), | ||
|
||
junitBundles(), | ||
frameworkStartLevel(START_LEVEL_TEST_BUNDLE), | ||
felix()); | ||
mavenBundle("org.apache.felix", ORG_APACHE_FELIX_USERADMIN_FILESTORE).versionAsInProject().noStart(), | ||
mavenBundle("org.apache.felix", ORG_APACHE_FELIX_USERADMIN_MONGODBSTORE).versionAsInProject().noStart(), mavenBundle("org.mongodb", "mongo-java-driver").versionAsInProject().noStart(), | ||
|
||
junitBundles(), frameworkStartLevel(START_LEVEL_TEST_BUNDLE), felix()); | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
public void setUp() throws Exception | ||
{ | ||
assertNotNull("No bundle context?!", m_context); | ||
} | ||
|
||
|
@@ -97,55 +101,86 @@ public void setUp() throws Exception { | |
* @return | ||
* @throws Exception | ||
*/ | ||
protected <T> T awaitService(String serviceName) throws Exception { | ||
protected <T> T awaitService(String serviceName) throws Exception | ||
{ | ||
ServiceTracker tracker = new ServiceTracker(m_context, serviceName, null); | ||
tracker.open(); | ||
T result; | ||
try { | ||
try | ||
{ | ||
result = (T) tracker.waitForService(DEFAULT_TIMEOUT); | ||
} | ||
finally { | ||
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; | ||
} | ||
|
||
protected Bundle getFileStoreBundle() | ||
{ | ||
Bundle b = findBundle(ORG_APACHE_FELIX_USERADMIN_FILESTORE); | ||
assertNotNull("Filestore bundle not found?!", b); | ||
return b; | ||
} | ||
|
||
protected Bundle getMongoDBStoreBundle() | ||
{ | ||
Bundle b = findBundle(ORG_APACHE_FELIX_USERADMIN_MONGODBSTORE); | ||
assertNotNull("MongoDB store bundle not found?!", b); | ||
return b; | ||
} | ||
|
||
protected Bundle getMongoDBBundle() | ||
{ | ||
Bundle b = findBundle(ORG_MONGODB_MONGO_JAVA_DRIVER); | ||
assertNotNull("MongoDB bundle not found?!", b); | ||
return b; | ||
} | ||
|
||
/** | ||
* Obtains a service without waiting for it to become available. | ||
* @param serviceName | ||
* @return | ||
* @throws Exception | ||
*/ | ||
protected <T> T getService(String serviceName) throws Exception { | ||
protected <T> T getService(String serviceName) throws Exception | ||
{ | ||
ServiceTracker tracker = new ServiceTracker(m_context, serviceName, null); | ||
tracker.open(); | ||
T result; | ||
try { | ||
try | ||
{ | ||
result = (T) tracker.getService(); | ||
} | ||
finally { | ||
finally | ||
{ | ||
tracker.close(); | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* @return the {@link UserAdmin} service instance. | ||
*/ | ||
protected UserAdmin getUserAdmin() throws Exception { | ||
protected UserAdmin getUserAdmin() throws Exception | ||
{ | ||
return getService(UserAdmin.class.getName()); | ||
} | ||
|
||
/** | ||
* @param bsn | ||
* @return | ||
*/ | ||
protected Bundle findBundle(String bsn) { | ||
for (Bundle bundle : m_context.getBundles()) { | ||
if (bsn.equals(bundle.getSymbolicName())) { | ||
return bundle; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,51 +36,54 @@ | |
* @author <a href="mailto:[email protected]">Felix Project Team</a> | ||
*/ | ||
@RunWith(JUnit4TestRunner.class) | ||
public class FileStoreInitializationTest extends BaseIntegrationTest { | ||
|
||
/** | ||
* Tests that initialization and closing of the repository store is | ||
* performed correctly. | ||
*/ | ||
@Test | ||
public void testStoreIsInitializedAndClosedProperlyOk() throws Exception { | ||
UserAdmin ua = getUserAdmin(); | ||
|
||
// Create two roles... | ||
User user = (User) ua.createRole("user1", Role.USER); | ||
assertNotNull(user); | ||
|
||
Group group = (Group) ua.createRole("group1", Role.GROUP); | ||
assertNotNull(group); | ||
|
||
group.addMember(user); | ||
group.addRequiredMember(ua.getRole(Role.USER_ANYONE)); | ||
|
||
// Stop the file store; should persist the two roles... | ||
Bundle fileStoreBundle = findBundle(ORG_APACHE_FELIX_USERADMIN_FILESTORE); | ||
assertNotNull(fileStoreBundle); | ||
fileStoreBundle.stop(); | ||
|
||
Thread.sleep(100); // Wait a little until the bundle is really stopped... | ||
|
||
// Retrieve the roles again; should both yield null due to the store not being available... | ||
user = (User) ua.getRole("user1"); | ||
assertNull(user); | ||
|
||
group = (Group) ua.getRole("group1"); | ||
assertNull(group); | ||
|
||
// This will not succeed: no backend to store the user in... | ||
assertNull(ua.createRole("user2", Role.USER)); | ||
|
||
fileStoreBundle.start(); | ||
|
||
awaitService(ORG_APACHE_FELIX_USERADMIN_FILESTORE); | ||
|
||
public class FileStoreInitializationTest extends BaseIntegrationTest | ||
{ | ||
|
||
/** | ||
* Tests that initialization and closing of the repository store is | ||
* performed correctly. | ||
*/ | ||
@Test | ||
public void testStoreIsInitializedAndClosedProperlyOk() throws Exception | ||
{ | ||
UserAdmin ua = getUserAdmin(); | ||
// Start the file store bundle... | ||
Bundle fileStoreBundle = getFileStoreBundle(); | ||
fileStoreBundle.start(); | ||
|
||
// Create two roles... | ||
User user = (User) ua.createRole("user1", Role.USER); | ||
assertNotNull(user); | ||
|
||
Group group = (Group) ua.createRole("group1", Role.GROUP); | ||
assertNotNull(group); | ||
|
||
group.addMember(user); | ||
group.addRequiredMember(ua.getRole(Role.USER_ANYONE)); | ||
|
||
// Stop the file store; should persist the two roles... | ||
fileStoreBundle.stop(); | ||
|
||
Thread.sleep(100); // Wait a little until the bundle is really stopped... | ||
|
||
// Retrieve the roles again; should both yield null due to the store not being available... | ||
user = (User) ua.getRole("user1"); | ||
assertNull(user); | ||
|
||
group = (Group) ua.getRole("group1"); | ||
assertNull(group); | ||
|
||
// This will not succeed: no backend to store the user in... | ||
assertNull(ua.createRole("user2", Role.USER)); | ||
|
||
fileStoreBundle.start(); | ||
|
||
awaitService(ORG_APACHE_FELIX_USERADMIN_FILESTORE); | ||
|
||
// Retrieve the roles again; should both yield valid values... | ||
user = (User) ua.getRole("user1"); | ||
assertNotNull(user); | ||
|
||
group = (Group) ua.getRole("group1"); | ||
assertNotNull(group); | ||
|
||
|
@@ -93,8 +96,8 @@ public void testStoreIsInitializedAndClosedProperlyOk() throws Exception { | |
assertNotNull(members); | ||
assertEquals(1, members.length); | ||
assertEquals(Role.USER_ANYONE, members[0].getName()); | ||
|
||
user = (User) ua.getRole("user2"); | ||
assertNull(user); | ||
} | ||
} | ||
} |
Oops, something went wrong.