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())));
}
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;
}
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();
}
}
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);
}
}
Aggregations