use of org.apache.openejb.testng.PropertiesBuilder in project tomee by apache.
the class ConfigurationTest method autoConfig.
@Test
public void autoConfig() {
final Configuration configuration = new Configuration();
configuration.loadFromProperties(new PropertiesBuilder().p("http", "1234").p("stop", "1235").p("host", "here").p("dir", "target/dirtmp").p("quickSession", "false").p("webResourceCached", "false").p("withEjbRemote", "true").p("deployOpenEjbApp", "true").p("users.u1", "p1").p("users.u2", "p2").p("roles.admin", "u1,u2").p("roles.simple", "u1").p("realm", "org.apache.catalina.realm.JAASRealm").p("realm.appName", "app").p("realm.configFile", "configuration.jaas").p("login", "").p("login.realmName", "app").p("login.authMethod", "BASIC").p("securityConstraint", "").p("securityConstraint.authConstraint", "true").p("securityConstraint.authRole", "**").p("securityConstraint.collection", "api:/api/*").build());
assertEquals(1234, configuration.getHttpPort());
assertEquals(1235, configuration.getStopPort());
assertEquals("target/dirtmp", configuration.getDir());
assertFalse(configuration.isQuickSession());
assertTrue(configuration.isWithEjbRemote());
assertTrue(configuration.isDeployOpenEjbApp());
assertEquals(new HashMap<String, String>() {
{
put("u1", "p1");
put("u2", "p2");
}
}, configuration.getUsers());
assertEquals(new HashMap<String, String>() {
{
put("admin", "u1,u2");
put("simple", "u1");
}
}, configuration.getRoles());
assertNotNull(configuration.getRealm());
assertTrue(JAASRealm.class.isInstance(configuration.getRealm()));
final JAASRealm realm = JAASRealm.class.cast(configuration.getRealm());
assertEquals("app", realm.getAppName());
assertEquals("configuration.jaas", realm.getConfigFile());
assertNotNull(configuration.getLoginConfig());
final LoginConfig loginConfig = configuration.getLoginConfig().build();
assertEquals("app", loginConfig.getRealmName());
assertEquals("BASIC", loginConfig.getAuthMethod());
final Collection<SecurityConstaintBuilder> securityConstraints = configuration.getSecurityConstraints();
assertNotNull(securityConstraints);
assertEquals(1, securityConstraints.size());
final SecurityConstraint constraint = securityConstraints.iterator().next().build();
assertTrue(constraint.getAuthConstraint());
assertTrue(constraint.getAuthenticatedUsers());
assertEquals("/api/*", constraint.findCollection("api").findPatterns()[0]);
}
use of org.apache.openejb.testng.PropertiesBuilder in project tomee by apache.
the class SecurityServiceDoesntLeakTest method run.
@Test
public void run() throws NamingException {
final SecurityService ss = SystemInstance.get().getComponent(SecurityService.class);
assertNotNull(ss);
final Map<Object, Object> identities = (Map<Object, Object>) Reflections.get(ss, "identities");
assertEquals(0, identities.size());
final Properties p = new PropertiesBuilder().p("java.naming.factory.initial", RemoteInitialContextFactory.class.getName()).p("java.naming.provider.url", "ejbd://localhost:" + port).p("java.naming.security.principal", "foo").p("java.naming.security.credentials", "bar").p("openejb.authentication.realmName", "PropertiesLogin").build();
final Context ctx = new InitialContext(p);
final CallMeRemotely handle = CallMeRemotely.class.cast(ctx.lookup("java:global/openejb/CallMe!org.apache.openejb.SecurityServiceDoesntLeakTest$CallMeRemotely"));
assertNotNull(handle);
assertEquals("remote!", handle.remote());
assertEquals(1, identities.size());
ctx.close();
assertEquals(0, identities.size());
}
use of org.apache.openejb.testng.PropertiesBuilder in project tomee by apache.
the class SetupTest method replaceTest.
private void replaceTest(int http1, int stop1, int ajp1, int http2, int stop2, int ajp2) throws IOException {
final File target = write("target/setup1.xml", serverXml(http1, stop1, ajp1));
Setup.replace(new PropertiesBuilder().p(Integer.toString(http1), Integer.toString(http2)).p(Integer.toString(stop1), Integer.toString(stop2)).p(Integer.toString(ajp1), Integer.toString(ajp2)).asMap(), target, true);
assertEquals(serverXml(http2, stop2, ajp2), IO.slurp(target));
}
use of org.apache.openejb.testng.PropertiesBuilder in project tomee by apache.
the class ClasspathAPITest method config.
@Configuration
public Properties config() {
// using relative path avoids issue between IDE/surefire (. = target for surefire) and URI format
final Path here = new File(".").getAbsoluteFile().toPath();
final Path classes = jarLocation(ClasspathAPITest.class).getAbsoluteFile().toPath();
return new PropertiesBuilder().p("r", "new://Resource?class-name=org.apache.openejb.resource.ClasspathAPITest$MyImpl&" + "classpath-api=java.util.concurrent.Callable&" + "classpath=" + classes.relativize(here).toString().replace(File.separator, "/")).build();
}
use of org.apache.openejb.testng.PropertiesBuilder in project tomee by apache.
the class OpenEJBInitialContextFactoryTest method run.
@Test
public void run() throws Exception {
final Callable<Boolean> innerTest = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
final Context ctx = new InitialContext(new PropertiesBuilder().p(Context.INITIAL_CONTEXT_FACTORY, OpenEJBInitialContextFactory.class.getName()).build());
// ejbs
assertEquals("ejb", SomeEjb.class.cast(ctx.lookup("java:global/openejb/SomeEjb")).from());
assertEquals("ejb", SomeEjb.class.cast(ctx.lookup("global/openejb/SomeEjb")).from());
assertEquals("ejb", SomeEjb.class.cast(ctx.lookup("java:openejb/local/SomeEjbLocalBean")).from());
assertEquals("ejb", SomeEjb.class.cast(ctx.lookup("openejb/local/SomeEjbLocalBean")).from());
assertEquals("ejb", SomeEjb.class.cast(ctx.lookup("openejb:local/SomeEjbLocalBean")).from());
assertEquals("ejb", SomeEjb.class.cast(ctx.lookup("SomeEjbLocalBean")).from());
// resources (hibernate use case for instance)
assertTrue(DataSource.class.isInstance(ctx.lookup("openejb:Resource/db")));
assertTrue(DataSource.class.isInstance(ctx.lookup("java:openejb/Resource/db")));
assertTrue(DataSource.class.isInstance(ctx.lookup("openejb/Resource/db")));
assertTrue(DataSource.class.isInstance(ctx.lookup("db")));
return true;
}
};
// in an unmanaged thread
final AtomicBoolean result = new AtomicBoolean(false);
final Thread outOfContext = new Thread(new Runnable() {
@Override
public void run() {
try {
result.set(innerTest.call());
} catch (final Exception e) {
result.set(false);
}
}
});
outOfContext.start();
outOfContext.join();
assertTrue(result.get());
// and in a managed thread
assertTrue(innerTest.call());
}
Aggregations