Search in sources :

Example 6 with PropertiesBuilder

use of org.apache.openejb.testng.PropertiesBuilder in project tomee by apache.

the class DataSourceFactoryTest method run.

@Test
public void run() throws Exception {
    assertFalse(Boolean.class.cast(mtd.invoke(null, new Properties())));
    assertTrue(Boolean.class.cast(mtd.invoke(null, new PropertiesBuilder().p("openejb.datasource.pool", "true").build())));
    assertFalse(Boolean.class.cast(mtd.invoke(null, new PropertiesBuilder().p("openejb.datasource.pool", "false").build())));
    assertTrue(Boolean.class.cast(mtd.invoke(null, new PropertiesBuilder().p("initialPoolSize", "1").build())));
    assertTrue(Boolean.class.cast(mtd.invoke(null, new PropertiesBuilder().p("maxPoolSize", "1").build())));
    SystemInstance.get().setProperty("openejb.datasource.pool", "true");
    assertTrue(Boolean.class.cast(mtd.invoke(null, new Properties())));
    SystemInstance.get().setProperty("openejb.datasource.pool", "false");
    assertFalse(Boolean.class.cast(mtd.invoke(null, new Properties())));
}
Also used : Properties(java.util.Properties) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder) Test(org.junit.Test)

Example 7 with PropertiesBuilder

use of org.apache.openejb.testng.PropertiesBuilder in project tomee by apache.

the class QuartzPersistenceForEJBTimersTest method application.

@Module
public AppModule application() {
    final EjbModule ejbModule = new EjbModule(new EjbJar());
    ejbModule.getEjbJar().addEnterpriseBean(new SingletonBean(MyTimedEjb.class).localBean());
    final Properties quartzConfig = new PropertiesBuilder().p("org.apache.openejb.quartz.scheduler.instanceName", "TestScheduler").p("org.apache.openejb.quartz.scheduler.instanceId", "AUTO").p("org.apache.openejb.quartz.threadPool.class", SimpleThreadPool.class.getName()).p("org.apache.openejb.quartz.threadPool.threadCount", "4").p("org.apache.openejb.quartz.threadPool.threadPriority", "5").p("org.apache.openejb.quartz.jobStore.class", JobStoreCMT.class.getName()).p("org.apache.openejb.quartz.jobStore.driverDelegateClass", HSQLDBDelegate.class.getName()).p("org.apache.openejb.quartz.jobStore.dataSource", "QUARTZ").p("org.apache.openejb.quartz.jobStore.nonManagedTXDataSource", "QUARTZ_NOTX").p("org.apache.openejb.quartz.jobStore.tablePrefix", "qrtz_").p("org.apache.openejb.quartz.jobStore.isClustered", "true").p("org.apache.openejb.quartz.jobStore.clusterCheckinInterval", "60000").p("org.apache.openejb.quartz.jobStore.txIsolationLevelSerializable", "true").p("org.apache.openejb.quartz.jobStore.maxMisfiresToHandleAtATime", "100").p("org.apache.openejb.quartz.dataSource.QUARTZ.jndiURL", "openejb:Resource/QuartzPersistenceForEJBTimersDB").p("org.apache.openejb.quartz.dataSource.QUARTZ_NOTX.jndiURL", "openejb:Resource/QuartzPersistenceForEJBTimersDBNoTx").build();
    final AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), null);
    appModule.getEjbModules().add(ejbModule);
    appModule.getProperties().putAll(quartzConfig);
    return appModule;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) AppModule(org.apache.openejb.config.AppModule) HSQLDBDelegate(org.apache.openejb.quartz.impl.jdbcjobstore.HSQLDBDelegate) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder) SimpleThreadPool(org.apache.openejb.quartz.simpl.SimpleThreadPool) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) AppModule(org.apache.openejb.config.AppModule) Module(org.apache.openejb.testing.Module)

Example 8 with PropertiesBuilder

use of org.apache.openejb.testng.PropertiesBuilder in project tomee by apache.

the class AuthentWithRequestTest method invoke.

@Test
public void invoke() throws Exception {
    final EjbServer ejbServer = new EjbServer();
    OpenEJB.init(new PropertiesBuilder().p(DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY, "false").build(), new ServerFederation());
    ejbServer.init(new Properties());
    final ServiceDaemon serviceDaemon = new ServiceDaemon(ejbServer, 0, "localhost");
    serviceDaemon.start();
    final int port = serviceDaemon.getPort();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(RemoteWithSecurity.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    try {
        {
            // ok case
            final Context context = new InitialContext(new PropertiesBuilder().p(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName()).p(Context.PROVIDER_URL, "ejbd://127.0.0.1:" + port).p(JNDIContext.AUTHENTICATE_WITH_THE_REQUEST, "true").p("java.naming.security.principal", "foo").p("java.naming.security.credentials", "bar").p("openejb.authentication.realmName", "LM").build());
            final AnInterfaceRemote client = AnInterfaceRemote.class.cast(context.lookup("RemoteWithSecurityRemote"));
            assertNotNull(client);
            assertEquals("foo", client.call());
        }
        {
            // now the failing case
            final Context context = new InitialContext(new PropertiesBuilder().p(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName()).p(Context.PROVIDER_URL, "ejbd://127.0.0.1:" + port).p(JNDIContext.AUTHENTICATE_WITH_THE_REQUEST, "true").p("java.naming.security.principal", "wrong").p("java.naming.security.credentials", "wrong").p("openejb.authentication.realmName", "LM").build());
            final AnInterfaceRemote client = AnInterfaceRemote.class.cast(context.lookup("RemoteWithSecurityRemote"));
            try {
                client.call();
            } catch (final EJBException e) {
                if (!LoginException.class.isInstance(e.getCause())) {
                    e.printStackTrace();
                }
                assertTrue(LoginException.class.isInstance(e.getCause()));
            }
        }
    } finally {
        serviceDaemon.stop();
        OpenEJB.destroy();
    }
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) JNDIContext(org.apache.openejb.client.JNDIContext) ServerFederation(org.apache.openejb.core.ServerFederation) Properties(java.util.Properties) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder) InitialContext(javax.naming.InitialContext) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) EjbServer(org.apache.openejb.server.ejbd.EjbServer) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) RemoteInitialContextFactory(org.apache.openejb.client.RemoteInitialContextFactory) LoginException(javax.security.auth.login.LoginException) Assembler(org.apache.openejb.assembler.classic.Assembler) EJBException(javax.ejb.EJBException) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 9 with PropertiesBuilder

use of org.apache.openejb.testng.PropertiesBuilder in project tomee by apache.

the class HerokuDatabasePropertiesProvider method provides.

@Override
public Properties provides() {
    try {
        // let it be overridable
        final URI url = new URI(PropertyPlaceHolderHelper.simpleValue("${DATABASE_URL}"));
        final String userInfo = url.getUserInfo();
        final String jdbcUrl = "jdbc:" + (jdbcMapping.containsKey(url.getScheme()) ? jdbcMapping.get(url.getScheme()) : url.getScheme()) + "://" + url.getHost() + (url.getPort() > 0 ? ":" + url.getPort() : "") + url.getPath();
        final PropertiesBuilder builder = new PropertiesBuilder().p("JdbcUrl", jdbcUrl);
        if (userInfo != null) {
            final int sep = userInfo.indexOf(':');
            if (sep > 0) {
                builder.p("UserName", userInfo.substring(0, sep)).p("Password", userInfo.substring(sep + 1, userInfo.length()));
            } else {
                builder.p("UserName", userInfo);
            }
        }
        if (properties == null || "org.hsqldb.jdbcDriver".equals(properties.getProperty("JdbcDriver"))) {
            if ("postgres".equalsIgnoreCase(url.getScheme())) {
                builder.p("JdbcDriver", "org.postgresql.Driver");
            }
        // else TODO
        }
        return builder.build();
    } catch (final URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder)

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