aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ross2013-08-21 16:43:15 (EDT)
committerJohn Ross2013-08-21 16:43:15 (EDT)
commita05ababadcb9e30b5f56cc311b9419b3a011927b (patch)
tree96acaa842d10d4483b0057493b8be526390d3f7c
parentcd940bf8013c9db305eda9a3006178577dcfd859 (diff)
downloadrt.equinox.bundles-a05ababadcb9e30b5f56cc311b9419b3a011927b.zip
rt.equinox.bundles-a05ababadcb9e30b5f56cc311b9419b3a011927b.tar.gz
rt.equinox.bundles-a05ababadcb9e30b5f56cc311b9419b3a011927b.tar.bz2
[Bug 415622] UserTest.testGetUser fails.
Refactored to make all tests independent so that execution order no longer matters.
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserTest.java168
1 files changed, 97 insertions, 71 deletions
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserTest.java
index f0f53f3..3dfff0d 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserTest.java
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/useradmin/tests/UserTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others
+ * Copyright (c) 2008, 2013 IBM Corporation and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
package org.eclipse.equinox.useradmin.tests;
import java.util.Dictionary;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.eclipse.equinox.compendium.tests.Activator;
import org.osgi.framework.InvalidSyntaxException;
@@ -18,12 +19,83 @@ import org.osgi.framework.ServiceReference;
import org.osgi.service.useradmin.*;
public class UserTest extends TestCase {
-
private UserAdmin userAdmin;
private ServiceReference userAdminReference;
- boolean locked = false;
- Object lock = new Object();
+ public void testUser1() {
+ try {
+ createUser1();
+ User user = userAdmin.getUser("test", "valu"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertNotNull(user);
+ assertEquals("testUserCreate1", user.getName()); //$NON-NLS-1$
+ assertTrue(user.getType() == Role.USER);
+ try {
+ Role[] roles = userAdmin.getRoles("(test=valu)"); //$NON-NLS-1$
+ assertNotNull(roles);
+ assertEquals("number of roles", 1, roles.length); //$NON-NLS-1$
+ } catch (InvalidSyntaxException e) {
+ fail(e.getMessage());
+ }
+ removeUser1();
+ } finally {
+ removeUser1Silently();
+ }
+ }
+
+ public void testUser2() {
+ try {
+ createUser2();
+ Role user = userAdmin.getRole("testUserCreate2"); //$NON-NLS-1$
+ assertNotNull(user);
+ assertEquals("testUserCreate2", user.getName()); //$NON-NLS-1$
+ assertTrue(user.getType() == Role.USER);
+
+ Object test1 = user.getProperties().get("test1"); //$NON-NLS-1$
+ assertEquals("test1", "valu", test1); //$NON-NLS-1$ //$NON-NLS-2$
+ Object test2 = user.getProperties().get("test2"); //$NON-NLS-1$
+ assertEquals("test2", "xxxyyyzzz", test2); //$NON-NLS-1$ //$NON-NLS-2$
+ Object test3 = user.getProperties().get("test3"); //$NON-NLS-1$
+ assertTrue("test3 not byte[]", test3 instanceof byte[]); //$NON-NLS-1$
+ byte[] bytes = (byte[]) test3;
+ assertEquals("wrong size", 3, bytes.length); //$NON-NLS-1$
+ assertEquals("1", 1, bytes[0]); //$NON-NLS-1$
+ assertEquals("2", 2, bytes[1]); //$NON-NLS-1$
+ assertEquals("3", 3, bytes[2]); //$NON-NLS-1$
+
+ Dictionary creds = ((User) user).getCredentials();
+ test1 = creds.get("test1"); //$NON-NLS-1$
+ assertEquals("test1", "valu", test1); //$NON-NLS-1$ //$NON-NLS-2$
+ test2 = creds.get("test2"); //$NON-NLS-1$
+ assertEquals("test2", "xxxyyyzzz", test2); //$NON-NLS-1$ //$NON-NLS-2$
+ test3 = creds.get("test3"); //$NON-NLS-1$
+ assertTrue("test3 not byte[]", test3 instanceof byte[]); //$NON-NLS-1$
+ bytes = (byte[]) test3;
+ assertEquals("wrong size", 3, bytes.length); //$NON-NLS-1$
+ assertEquals("1", 1, bytes[0]); //$NON-NLS-1$
+ assertEquals("2", 2, bytes[1]); //$NON-NLS-1$
+ assertEquals("3", 3, bytes[2]); //$NON-NLS-1$
+
+ try {
+ Role[] roles = userAdmin.getRoles("(test3=1)"); //$NON-NLS-1$
+ assertNotNull(roles);
+ assertEquals("number of roles", 1, roles.length); //$NON-NLS-1$
+ } catch (InvalidSyntaxException e) {
+ fail(e.getMessage());
+ }
+ removeUser2();
+ } finally {
+ removeUser2Silently();
+ }
+ }
+
+ public void testUserCreateAndRemove() throws Exception {
+ User user = (User) userAdmin.createRole("testUserCreateAndRemove", Role.USER); //$NON-NLS-1$
+ assertNotNull(user);
+ assertEquals("testUserCreateAndRemove", user.getName()); //$NON-NLS-1$
+ assertTrue(user.getType() == Role.USER);
+ assertTrue(userAdmin.removeRole("testUserCreateAndRemove")); //$NON-NLS-1$
+ assertNull(userAdmin.getRole("testUserCreateAndRemove")); //$NON-NLS-1$
+ }
protected void setUp() throws Exception {
Activator.getBundle(Activator.BUNDLE_USERADMIN).start();
@@ -36,7 +108,7 @@ public class UserTest extends TestCase {
Activator.getBundle(Activator.BUNDLE_USERADMIN).stop();
}
- public void testCreate() throws Exception {
+ private void createUser1() {
User user = (User) userAdmin.createRole("testUserCreate1", Role.USER); //$NON-NLS-1$
assertNotNull(user);
assertEquals("testUserCreate1", user.getName()); //$NON-NLS-1$
@@ -44,26 +116,21 @@ public class UserTest extends TestCase {
user.getProperties().put("test", "valu"); //$NON-NLS-1$ //$NON-NLS-2$
}
- public void testGetUser() {
- User user = userAdmin.getUser("test", "valu"); //$NON-NLS-1$ //$NON-NLS-2$
- assertNotNull(user);
- assertEquals("testUserCreate1", user.getName()); //$NON-NLS-1$
- assertTrue(user.getType() == Role.USER);
- try {
- Role[] roles = userAdmin.getRoles("(test=valu)"); //$NON-NLS-1$
- assertNotNull(roles);
- assertEquals("number of roles", 1, roles.length); //$NON-NLS-1$
- } catch (InvalidSyntaxException e) {
- fail(e.getMessage());
- }
- userAdmin.removeRole(user.getName());
+ private void removeUser1() {
+ assertTrue(userAdmin.removeRole("testUserCreate1")); //$NON-NLS-1$
}
- public void testRemovedUser() {
- assertNull(userAdmin.getRole("testUserCreate1")); //$NON-NLS-1$
+ private void removeUser1Silently() {
+ try {
+ removeUser1();
+ } catch (Exception e) {
+ // Ignore.
+ } catch (AssertionFailedError e) {
+ // Ignore.
+ }
}
- public void testCreate02() throws Exception {
+ private void createUser2() {
User user = (User) userAdmin.createRole("testUserCreate2", Role.USER); //$NON-NLS-1$
assertNotNull(user);
assertEquals("testUserCreate2", user.getName()); //$NON-NLS-1$
@@ -77,58 +144,17 @@ public class UserTest extends TestCase {
user.getCredentials().put("test3", new byte[] {1, 2, 3}); //$NON-NLS-1$
}
- public void testGetUser02() {
- Role user = userAdmin.getRole("testUserCreate2"); //$NON-NLS-1$
- assertNotNull(user);
- assertEquals("testUserCreate2", user.getName()); //$NON-NLS-1$
- assertTrue(user.getType() == Role.USER);
-
- Object test1 = user.getProperties().get("test1"); //$NON-NLS-1$
- assertEquals("test1", "valu", test1); //$NON-NLS-1$ //$NON-NLS-2$
- Object test2 = user.getProperties().get("test2"); //$NON-NLS-1$
- assertEquals("test2", "xxxyyyzzz", test2); //$NON-NLS-1$ //$NON-NLS-2$
- Object test3 = user.getProperties().get("test3"); //$NON-NLS-1$
- assertTrue("test3 not byte[]", test3 instanceof byte[]); //$NON-NLS-1$
- byte[] bytes = (byte[]) test3;
- assertEquals("wrong size", 3, bytes.length); //$NON-NLS-1$
- assertEquals("1", 1, bytes[0]); //$NON-NLS-1$
- assertEquals("2", 2, bytes[1]); //$NON-NLS-1$
- assertEquals("3", 3, bytes[2]); //$NON-NLS-1$
-
- Dictionary creds = ((User) user).getCredentials();
- test1 = creds.get("test1"); //$NON-NLS-1$
- assertEquals("test1", "valu", test1); //$NON-NLS-1$ //$NON-NLS-2$
- test2 = creds.get("test2"); //$NON-NLS-1$
- assertEquals("test2", "xxxyyyzzz", test2); //$NON-NLS-1$ //$NON-NLS-2$
- test3 = creds.get("test3"); //$NON-NLS-1$
- assertTrue("test3 not byte[]", test3 instanceof byte[]); //$NON-NLS-1$
- bytes = (byte[]) test3;
- assertEquals("wrong size", 3, bytes.length); //$NON-NLS-1$
- assertEquals("1", 1, bytes[0]); //$NON-NLS-1$
- assertEquals("2", 2, bytes[1]); //$NON-NLS-1$
- assertEquals("3", 3, bytes[2]); //$NON-NLS-1$
+ private void removeUser2() {
+ assertTrue(userAdmin.removeRole("testUserCreate2")); //$NON-NLS-1$
+ }
+ private void removeUser2Silently() {
try {
- Role[] roles = userAdmin.getRoles("(test3=1)"); //$NON-NLS-1$
- assertNotNull(roles);
- assertEquals("number of roles", 1, roles.length); //$NON-NLS-1$
- } catch (InvalidSyntaxException e) {
- fail(e.getMessage());
+ removeUser2();
+ } catch (Exception e) {
+ // Ignore.
+ } catch (AssertionFailedError e) {
+ // Ignore.
}
- userAdmin.removeRole(user.getName());
- }
-
- public void testRemovedUser02() {
- assertNull(userAdmin.getRole("testUserCreate2")); //$NON-NLS-1$
}
-
- public void testUserCreateAndRemove() throws Exception {
- User user = (User) userAdmin.createRole("testUserCreateAndRemove", Role.USER); //$NON-NLS-1$
- assertNotNull(user);
- assertEquals("testUserCreateAndRemove", user.getName()); //$NON-NLS-1$
- assertTrue(user.getType() == Role.USER);
- assertTrue(userAdmin.removeRole("testUserCreateAndRemove")); //$NON-NLS-1$
- assertNull(userAdmin.getRole("testUserCreateAndRemove")); //$NON-NLS-1$
- }
-
}