Search in sources :

Example 1 with PropertiesBuilder

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]);
}
Also used : JAASRealm(org.apache.catalina.realm.JAASRealm) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) Test(org.junit.Test)

Example 2 with PropertiesBuilder

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());
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) SecurityService(org.apache.openejb.spi.SecurityService) Properties(java.util.Properties) ContainerProperties(org.apache.openejb.testing.ContainerProperties) Map(java.util.Map) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 3 with PropertiesBuilder

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));
}
Also used : File(java.io.File) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder)

Example 4 with PropertiesBuilder

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();
}
Also used : Path(java.nio.file.Path) File(java.io.File) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder) Configuration(org.apache.openejb.testing.Configuration)

Example 5 with PropertiesBuilder

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());
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) Callable(java.util.concurrent.Callable) InitialContext(javax.naming.InitialContext) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder) DataSource(javax.sql.DataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Aggregations

PropertiesBuilder (org.apache.openejb.testng.PropertiesBuilder)9 Test (org.junit.Test)5 Properties (java.util.Properties)4 Context (javax.naming.Context)3 InitialContext (javax.naming.InitialContext)3 File (java.io.File)2 EjbJar (org.apache.openejb.jee.EjbJar)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 EJBException (javax.ejb.EJBException)1 LoginException (javax.security.auth.login.LoginException)1 DataSource (javax.sql.DataSource)1 JAASRealm (org.apache.catalina.realm.JAASRealm)1 Assembler (org.apache.openejb.assembler.classic.Assembler)1 JNDIContext (org.apache.openejb.client.JNDIContext)1 RemoteInitialContextFactory (org.apache.openejb.client.RemoteInitialContextFactory)1