private JpaTester jpaTester;
private Cache<String, User> userCache;
private UserAdministration userAdmin;
+ private MessageDigester passwordDigester;
public UserAdministrationTester() {
persistenceUnit = new SecurityPersistenceUnit();
NameValidator passwordValidator = new RegexpNameValidator(".{5,}",
"INVALID_PASSWORD", "Password must have at least 5 characters");
- MessageDigester passwordDigester = new Md5HexMessageDigester();
+ passwordDigester = new Md5HexMessageDigester();
UserSet userset = new JpaUserSet(userCache, passwordValidator,
passwordDigester, factory.getTransactionScopedEntityManager());
GroupSet groupset = new JpaGroupSet(factory
public UserAdministration getUserAdministration() {
return userAdmin;
}
+
+ public MessageDigester getPasswordEncoder() {
+ return passwordDigester;
+ }
public void stop() throws Exception {
jpaTester.stop();
public void bind(String aName, Object aObj) throws NamingException {
bindings.put(aName, aObj);
}
+
+ @Override
+ public void unbind(String aName) throws NamingException {
+ bindings.remove(aName);
+ }
@Override
public Object lookup(String aName) throws NamingException {
}
return value;
}
+
+ @Override
+ public void bind(Name aName, Object aObj) throws NamingException {
+ bind(aName.toString(), aObj);
+ }
+
+ @Override
+ public void unbind(Name aName) throws NamingException {
+ unbind(aName.toString());
+ }
@Override
public Object lookup(Name aName) throws NamingException {
- Object value = super.lookup(aName.toString());
- if (value == null) {
- throw new NameNotFoundException(aName.toString());
- }
- return value;
+ return lookup(aName.toString());
}
}
import static junit.framework.Assert.*;
+import javax.naming.CompositeName;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
public class StubInitiaContextFactoryTest {
+ private static final String JNDI_NAME = "a/b";
+
@Before
@After
public void setUp() {
@Test(expected = NamingException.class)
public void testLookupNotRegistered() throws Exception {
InitialContext ctx = new InitialContext();
- ctx.bind("a/b", "hallo");
+ ctx.bind(JNDI_NAME, "hallo");
}
+
+ // String based lookups.
@Test
public void testLookup() throws Exception {
StubInitialContextFactory.register();
InitialContext ctx = new InitialContext();
- ctx.bind("a/b", "hallo");
+ ctx.bind(JNDI_NAME, "hallo");
ctx = new InitialContext();
- Object obj = ctx.lookup("a/b");
+ Object obj = ctx.lookup(JNDI_NAME);
assertEquals("hallo", obj);
}
+
+ @Test(expected = NameNotFoundException.class)
+ public void testUnbind() throws Exception {
+ testLookup();
+ InitialContext ctx = new InitialContext();
+ ctx.unbind(JNDI_NAME);
+ ctx = new InitialContext();
+ ctx.lookup(JNDI_NAME);
+
+ }
@Test(expected = NameNotFoundException.class)
public void testLookupFails() throws Exception {
StubInitialContextFactory.register();
InitialContext ctx = new InitialContext();
- Object obj = ctx.lookup("a/b");
+ Object obj = ctx.lookup(JNDI_NAME);
+ }
+
+ // Name based lookups
+
+ @Test
+ public void testLookupName() throws Exception {
+ StubInitialContextFactory.register();
+
+ InitialContext ctx = new InitialContext();
+ ctx.bind(new CompositeName(JNDI_NAME), "hallo");
+
+ ctx = new InitialContext();
+ Object obj = ctx.lookup(new CompositeName(JNDI_NAME));
+
+ assertEquals("hallo", obj);
+ }
+
+ @Test(expected = NameNotFoundException.class)
+ public void testUnbindName() throws Exception {
+ testLookup();
+ InitialContext ctx = new InitialContext();
+ ctx.unbind(new CompositeName(JNDI_NAME));
+ ctx = new InitialContext();
+ ctx.lookup(new CompositeName(JNDI_NAME));
+ }
+
+ @Test(expected = NameNotFoundException.class)
+ public void testLookupFailsName() throws Exception {
+ StubInitialContextFactory.register();
+
+ InitialContext ctx = new InitialContext();
+ Object obj = ctx.lookup(JNDI_NAME);
}
}