org.apache.openejb.core.LocalInitialContextFactory Java Examples
The following examples show how to use
org.apache.openejb.core.LocalInitialContextFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TckContextFactory.java From incubator-batchee with Apache License 2.0 | 6 votes |
@Override public Context getInitialContext(final Hashtable<?, ?> environment) throws NamingException { final InitialContext delegate = new InitialContext(new Properties() {{ setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); }}); return Context.class.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[]{Context.class}, new InvocationHandler() { @Override // convert jdbc/foo to openejb:Resource/jdbc/foo since jdbc/xxx is not standard - useful for ee tests public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { if ("lookup".equals(method.getName()) && String.class.isInstance(args[0]) && String.class.cast(args[0]).startsWith("jdbc")) { return method.invoke(delegate, "openejb:Resource/" + args[0]); } return method.invoke(delegate, args); } })); }
Example #2
Source File: EjbObjectInputStreamTest.java From tomee with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { oldWhitelist = System.getProperty("tomee.serialization.class.whitelist"); oldBlacklist = System.getProperty("tomee.serialization.class.blacklist"); System.setProperty("tomee.serialization.class.whitelist", "org.apache.openejb.,java.lang.SecurityException,java.lang.RuntimeException,java.lang.Exception," + "java.lang.Throwable,java.lang.StackTraceElement,java.util.Collections,java.util.ArrayList,java.util.Properties,java.util.Hashtable,java.util.HashSet," + "java.net.URI,java.util.TreeSet,java.util.LinkedHashSet,java.lang.String"); System.setProperty("tomee.serialization.class.blacklist", "-"); config = new ConfigurationFactory(); assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class)); final Properties props = new Properties(); props.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); context = new InitialContext(props); }
Example #3
Source File: SingletonLazyInstantiationTest.java From tomee with Apache License 2.0 | 6 votes |
@Override protected void setUp() throws Exception { exception.set(false); MySingleton.instances.set(0); System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); // containers assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class)); // Setup the descriptor information final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(new SingletonBean(MySingleton.class)); assembler.createApplication(config.configureApplication(ejbJar)); }
Example #4
Source File: ResourcesJsonTest.java From tomee with Apache License 2.0 | 6 votes |
@Before public void setUp() throws OpenEJBException, NamingException, IOException { final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final AppModule app = new AppModule(ResourcesJsonTest.class.getClassLoader(), ResourcesJsonTest.class.getSimpleName()); final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(new SingletonBean(ConfiguredThroughJSonBean.class)); app.getEjbModules().add(new EjbModule(ejbJar)); app.getEjbModules().iterator().next().getAltDDs().put("resources.json", getClass().getClassLoader().getResource("appresource.resources.json")); assembler.createApplication(config.configureApplication(app)); final Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); properties.setProperty("openejb.embedded.initialcontext.close", "destroy"); // some hack to be sure to call destroy() context = new InitialContext(properties); bean = (ConfiguredThroughJSonBean) context.lookup("ConfiguredThroughJSonBeanLocalBean"); }
Example #5
Source File: StatelessInterceptorTest.java From tomee with Apache License 2.0 | 6 votes |
public void setUp() throws Exception { final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class)); final EjbJarInfo ejbJar = config.configureApplication(buildTestApp()); assertNotNull(ejbJar); assembler.createApplication(ejbJar); final Properties properties = new Properties(System.getProperties()); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); ctx = new InitialContext(properties); }
Example #6
Source File: OpenEJBXmlByModuleTest.java From tomee with Apache License 2.0 | 6 votes |
@Before public void setUp() throws OpenEJBException, NamingException, IOException { final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final AppModule app = new AppModule(OpenEJBXmlByModuleTest.class.getClassLoader(), OpenEJBXmlByModuleTest.class.getSimpleName()); final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(new SingletonBean(UselessBean.class)); app.getEjbModules().add(new EjbModule(ejbJar)); app.getEjbModules().iterator().next().getAltDDs().put("resources.xml", getClass().getClassLoader().getResource("META-INF/resource/appresource.openejb.xml")); assembler.createApplication(config.configureApplication(app)); final Properties properties = new Properties(); properties.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); properties.setProperty("openejb.embedded.initialcontext.close", "destroy"); // some hack to be sure to call destroy() context = new InitialContext(properties); bean = (UselessBean) context.lookup("UselessBeanLocalBean"); }
Example #7
Source File: StatefulTransactionLockingTest.java From tomee with Apache License 2.0 | 6 votes |
@Override protected void setUp() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class); statefulContainerInfo.properties.setProperty("AccessTimeout", "0 milliseconds"); // containers assembler.createContainer(statefulContainerInfo); // Setup the descriptor information final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(new StatelessBean(BlueStatelessBean.class)); ejbJar.addEnterpriseBean(new StatefulBean(RedStatefulBean.class)); ejbJar.addEnterpriseBean(new StatefulBean(LegacyStatefulBean.class)); assembler.createApplication(config.configureApplication(ejbJar)); }
Example #8
Source File: AsynchInRoleTest.java From tomee with Apache License 2.0 | 5 votes |
@Before public void beforeTest() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); config = new ConfigurationFactory(); assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); }
Example #9
Source File: CrossClassLoaderProxyTest.java From tomee with Apache License 2.0 | 5 votes |
protected void setUp() throws Exception { super.setUp(); System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); // containers final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class); statelessContainerInfo.properties.setProperty("TimeOut", "10"); statelessContainerInfo.properties.setProperty("MaxSize", "0"); statelessContainerInfo.properties.setProperty("StrictPooling", "false"); assembler.createContainer(statelessContainerInfo); // Setup the descriptor information final StatelessBean bean = new StatelessBean(WidgetBean.class); bean.addBusinessLocal(Widget.class.getName()); bean.addBusinessRemote(RemoteWidget.class.getName()); bean.setHomeAndRemote(WidgetHome.class, WidgetRemote.class); bean.addPostConstruct("init"); bean.addPreDestroy("destroy"); final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(bean); assembler.createApplication(config.configureApplication(ejbJar)); WidgetBean.lifecycle.clear(); }
Example #10
Source File: StatelessInstanceManagerPoolingTest.java From tomee with Apache License 2.0 | 5 votes |
protected void setUp() throws Exception { super.setUp(); System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); // containers final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class); statelessContainerInfo.properties.setProperty("TimeOut", "100"); statelessContainerInfo.properties.setProperty("MaxSize", "10"); statelessContainerInfo.properties.setProperty("MinSize", "2"); statelessContainerInfo.properties.setProperty("StrictPooling", "true"); assembler.createContainer(statelessContainerInfo); // Setup the descriptor information final StatelessBean bean = new StatelessBean(CounterBean.class); bean.addBusinessLocal(Counter.class.getName()); bean.addBusinessRemote(RemoteCounter.class.getName()); bean.addPostConstruct("init"); bean.addPreDestroy("destroy"); final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(bean); instances.set(0); assembler.createApplication(config.configureApplication(ejbJar)); }
Example #11
Source File: StatefulSessionBeanTest.java From tomee with Apache License 2.0 | 5 votes |
public void test() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); // containers final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class); statefulContainerInfo.properties.setProperty("PoolSize", "0"); statefulContainerInfo.properties.setProperty("BulkPassivate", "1"); statefulContainerInfo.properties.setProperty("Frequency", "0"); assembler.createContainer(statefulContainerInfo); assembler.createApplication(config.configureApplication(buildTestApp())); StatefulSessionBeanTest.calls.clear(); final InitialContext ctx = new InitialContext(); final TargetHome home = (TargetHome) ctx.lookup("TargetBeanRemoteHome"); assertNotNull(home); final Target target = home.create("Fuzz"); assertNotNull(target); final String name = target.getName(); assertEquals("Fuzz", name); target.remove(); assertCalls(Call.values()); }
Example #12
Source File: StatefulConcurrentLookupTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static synchronized void beforeClass() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class); assembler.createContainer(statefulContainerInfo); final EjbJar ejbJar = new EjbJar(); final StatefulBean bean1 = new StatefulBean(MyLocalBeanImpl.class); final Timeout timeout1 = new Timeout(); timeout1.setTimeout(10); timeout1.setUnit(TimeUnit.SECONDS); final ConcurrentMethod method1 = new ConcurrentMethod(); method1.setMethod(new NamedMethod("*")); method1.setAccessTimeout(timeout1); bean1.getConcurrentMethod().add(method1); ejbJar.addEnterpriseBean(bean1); assembler.createApplication(config.configureApplication(ejbJar)); }
Example #13
Source File: AsynchTest.java From tomee with Apache License 2.0 | 5 votes |
@Before public void beforeTest() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); config = new ConfigurationFactory(); assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); }
Example #14
Source File: SecurityTest.java From tomee with Apache License 2.0 | 5 votes |
private Assembler configureAssembler(final String defaultUser) throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); final SecurityServiceInfo serviceInfo = new SecurityServiceInfo(); serviceInfo.service = "SecurityService"; serviceInfo.className = SecurityServiceImpl.class.getName(); serviceInfo.id = "New Security Service"; serviceInfo.properties = new Properties(); if (defaultUser != null) { // override the default user serviceInfo.properties.setProperty("DefaultUser", defaultUser); } assembler.createSecurityService(serviceInfo); // containers assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class)); final EjbJar ejbJar = new EjbJar("SecurityTest"); ejbJar.addEnterpriseBean(new StatelessBean(FooBean.class)); ejbJar.addEnterpriseBean(new StatelessBean(BarBean.class)); final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar); assembler.createApplication(ejbJarInfo); return assembler; }
Example #15
Source File: AbstractCommand.java From tomee with Apache License 2.0 | 5 votes |
public <T> T lookup(final Class<T> clazz, final String jndiName) throws NamingException { Properties p = new Properties(); p.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { return (T) new InitialContext(p).lookup(jndiName); } finally { Thread.currentThread().setContextClassLoader(oldCl); } }
Example #16
Source File: JMXDeployer.java From tomee with Apache License 2.0 | 5 votes |
private static Deployer deployer() throws NamingException { final Properties p = new Properties(); p.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(DeployerEjb.class.getClassLoader()); try { return (Deployer) new InitialContext(p).lookup("openejb/DeployerBusinessRemote"); } finally { Thread.currentThread().setContextClassLoader(oldCl); } }
Example #17
Source File: EjbSecurityRoleRefTest.java From tomee with Apache License 2.0 | 5 votes |
protected void setUp() throws Exception { config = new ConfigurationFactory(); assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class)); final Properties props = new Properties(); props.setProperty(Context.SECURITY_PRINCIPAL, "jonathan"); props.setProperty(Context.SECURITY_CREDENTIALS, "secret"); props.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); context = new InitialContext(props); }
Example #18
Source File: LocalClientNoInjectionTest.java From tomee with Apache License 2.0 | 5 votes |
public void test() throws Exception { final Properties properties = new Properties(); properties.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final InitialContext context = new InitialContext(properties); context.bind("inject", this); }
Example #19
Source File: MappedNameTest.java From tomee with Apache License 2.0 | 5 votes |
public void test() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(new StatelessBean(GreenBean.class)); ejbJar.addEnterpriseBean(new StatelessBean(RedBean.class)); final EjbModule ejbModule = new EjbModule(ejbJar, new OpenejbJar()); ejbModule.getOpenejbJar().addEjbDeployment(new EjbDeployment(null, "foo/bar/baz/Green", "GreenBean")); ejbModule.getOpenejbJar().addEjbDeployment(new EjbDeployment(null, "foo/bar/baz/Red", "RedBean")); final EjbJarInfo info = config.configureApplication(ejbModule); assembler.createApplication(info); final InitialContext initialContext = new InitialContext(); final Color green = (Color) initialContext.lookup("foo/bar/baz/GreenLocal"); final Color red = (Color) initialContext.lookup("foo/bar/baz/RedLocal"); red.test(); }
Example #20
Source File: LocalClientTest.java From tomee with Apache License 2.0 | 5 votes |
public void test() throws Exception { final Properties properties = new Properties(); properties.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final InitialContext context = new InitialContext(properties); context.bind("inject", this); assertRefs(); }
Example #21
Source File: LocalClientSubclassTest.java From tomee with Apache License 2.0 | 5 votes |
@Override public void test() throws Exception { final Properties properties = new Properties(); properties.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final InitialContext context = new InitialContext(properties); context.bind("inject", this); assertRefs(); }
Example #22
Source File: StatefulBeanManagedTest.java From tomee with Apache License 2.0 | 4 votes |
@BeforeClass public static void beforeClass() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(new StatefulBean(MyBean.class)); assembler.createApplication(config.configureApplication(ejbJar)); }
Example #23
Source File: LocalInitialContext.java From tomee with Apache License 2.0 | 4 votes |
public LocalInitialContext(final Hashtable env, final LocalInitialContextFactory factory) throws NamingException { super(env, factory); }
Example #24
Source File: DynamicDataSourceTest.java From tomee with Apache License 2.0 | 4 votes |
@Test public void route() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); // resources for (int i = 1; i <= 3; i++) { final String dbName = "database" + i; final Resource resourceDs = new Resource(dbName, "DataSource"); final Properties p = resourceDs.getProperties(); p.put("JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("JdbcUrl", "jdbc:hsqldb:mem:db" + i); p.put("UserName", "sa"); p.put("Password", ""); p.put("JtaManaged", "true"); assembler.createResource(config.configureService(resourceDs, ResourceInfo.class)); } final Resource resourceRouter = new Resource("My Router", "org.apache.openejb.router.test.DynamicDataSourceTest$DeterminedRouter", "org.router:DeterminedRouter"); resourceRouter.getProperties().setProperty("DatasourceNames", "database1 database2 database3"); resourceRouter.getProperties().setProperty("DefaultDataSourceName", "database1"); assembler.createResource(config.configureService(resourceRouter, ResourceInfo.class)); final Resource resourceRoutedDs = new Resource("Routed Datasource", "org.apache.openejb.resource.jdbc.Router", "RoutedDataSource"); resourceRoutedDs.getProperties().setProperty("Router", "My Router"); assembler.createResource(config.configureService(resourceRoutedDs, ResourceInfo.class)); // containers final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class); assembler.createContainer(statelessContainerInfo); final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(new StatelessBean(RoutedEJBBean.class)); ejbJar.addEnterpriseBean(new StatelessBean(UtilityBean.class)); final EjbModule ejbModule = new EjbModule(ejbJar); // Create an "ear" final AppModule appModule = new AppModule(ejbModule.getClassLoader(), "test-dynamic-data-source"); appModule.getEjbModules().add(ejbModule); // Create a persistence-units final PersistenceUnit unit = new PersistenceUnit("router"); unit.addClass(Person.class); unit.getProperties().put("openjpa.jdbc.SynchronizeMappings", "buildSchema"); unit.setTransactionType(TransactionType.JTA); unit.setJtaDataSource("Routed Datasource"); appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(unit))); for (int i = 1; i <= 3; i++) { final PersistenceUnit u = new PersistenceUnit("db" + i); u.addClass(Person.class); u.getProperties().put("openjpa.jdbc.SynchronizeMappings", "buildSchema"); u.setTransactionType(TransactionType.JTA); u.setJtaDataSource("database" + i); appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(u))); } assembler.createApplication(config.configureApplication(appModule)); // context final Context ctx = new InitialContext(); // running persist on all "routed" databases final List<String> databases = new ArrayList<>(); databases.add("database1"); databases.add("database2"); databases.add("database3"); // convinient bean to create tables for each persistence unit final Utility utility = (Utility) ctx.lookup("UtilityBeanLocal"); utility.initDatabase(); final RoutedEJB ejb = (RoutedEJB) ctx.lookup("RoutedEJBBeanLocal"); for (int i = 0; i < 18; i++) { final String name = "record " + i; final String db = databases.get(i % 3); ejb.persist(i, name, db); } // assert database records number using jdbc for (int i = 1; i <= 3; i++) { final Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:db" + i, "sa", ""); final Statement st = connection.createStatement(); final ResultSet rs = st.executeQuery("select count(*) from \"DynamicDataSourceTest$Person\""); rs.next(); assertEquals(6, rs.getInt(1)); st.close(); connection.close(); } }
Example #25
Source File: ManagedBeanTest.java From tomee with Apache License 2.0 | 4 votes |
@Override protected void setUp() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(new ManagedBean(MyBean.class)); assembler.createApplication(config.configureApplication(ejbJar)); }
Example #26
Source File: StatefulTimeoutTest.java From tomee with Apache License 2.0 | 4 votes |
@Override protected void setUp() throws Exception { super.setUp(); System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final StatefulSessionContainerInfo statefulContainerInfo = config .configureService(StatefulSessionContainerInfo.class); statefulContainerInfo.properties.setProperty("BulkPassivate", "1"); // clear cache every 3 seconds statefulContainerInfo.properties.setProperty("Frequency", "3"); assembler.createContainer(statefulContainerInfo); final EjbJar ejbJar = new EjbJar(); Timeout timeout; final StatefulBean bean1 = new StatefulBean("BeanNegative", MyLocalBeanImpl.class); timeout = new Timeout(); timeout.setTimeout(-1); timeout.setUnit(TimeUnit.SECONDS); bean1.setStatefulTimeout(timeout); final StatefulBean bean0 = new StatefulBean("BeanZero", MyLocalBeanImpl.class); timeout = new Timeout(); timeout.setTimeout(0); timeout.setUnit(TimeUnit.SECONDS); bean0.setStatefulTimeout(timeout); final StatefulBean bean5 = new StatefulBean("Bean", MyLocalBeanImpl.class); timeout = new Timeout(); timeout.setTimeout(5); timeout.setUnit(TimeUnit.SECONDS); bean5.setStatefulTimeout(timeout); ejbJar.addEnterpriseBean(bean1); ejbJar.addEnterpriseBean(bean0); ejbJar.addEnterpriseBean(bean5); assembler.createApplication(config.configureApplication(ejbJar)); }
Example #27
Source File: StatefulTest.java From tomee with Apache License 2.0 | 4 votes |
@Override protected void setUp() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(new StatefulBean(MyBean.class)); assembler.createApplication(config.configureApplication(ejbJar)); }
Example #28
Source File: ScheduleTest.java From tomee with Apache License 2.0 | 4 votes |
public void testSchedule() throws Exception { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final Assembler assembler = new Assembler(); final ConfigurationFactory config = new ConfigurationFactory(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final EjbJar ejbJar = new EjbJar(); //Configure schedule by deployment plan final StatelessBean subBeanA = new StatelessBean(SubBeanA.class); final Timer subBeanATimer = new Timer(); subBeanATimer.setTimeoutMethod(new NamedMethod("subBeanA", "javax.ejb.Timer")); final TimerSchedule timerScheduleA = new TimerSchedule(); timerScheduleA.setSecond("2"); timerScheduleA.setMinute("*"); timerScheduleA.setHour("*"); subBeanATimer.setSchedule(timerScheduleA); subBeanATimer.setInfo("SubBeanAInfo"); subBeanA.getTimer().add(subBeanATimer); ejbJar.addEnterpriseBean(subBeanA); //Configure schedule by annotation final StatelessBean subBeanB = new StatelessBean(SubBeanB.class); ejbJar.addEnterpriseBean(subBeanB); //Override aroundTimeout annotation by deployment plan final StatelessBean subBeanC = new StatelessBean(SubBeanC.class); final Timer subBeanCTimer = new Timer(); subBeanCTimer.setTimeoutMethod(new NamedMethod("subBeanC", "javax.ejb.Timer")); final TimerSchedule timerScheduleC = new TimerSchedule(); timerScheduleC.setSecond("2"); timerScheduleC.setMinute("*"); timerScheduleC.setHour("*"); subBeanCTimer.setSchedule(timerScheduleC); subBeanCTimer.setInfo("SubBeanCInfo"); subBeanC.getTimer().add(subBeanCTimer); ejbJar.addEnterpriseBean(subBeanC); final StatefulBean subBeanM = new StatefulBean(SubBeanM.class); ejbJar.addEnterpriseBean(subBeanM); final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar); assembler.createApplication(ejbJarInfo); countDownLatch.await(1L, TimeUnit.MINUTES); //A better way for validation ? int beforeAroundInvocationCount = 0; int afterAroundInvocationCount = 0; int timeoutInvocationCount = 0; final int size; synchronized (result) { size = result.size(); for (final Call call : result) { switch (call) { case BEAN_BEFORE_AROUNDTIMEOUT: beforeAroundInvocationCount++; break; case BEAN_AFTER_AROUNDTIMEOUT: afterAroundInvocationCount++; break; case TIMEOUT: timeoutInvocationCount++; break; } } } assertEquals(3, beforeAroundInvocationCount); assertEquals(3, afterAroundInvocationCount); assertEquals(3, timeoutInvocationCount); assertEquals(9, size); }
Example #29
Source File: StatefulConcurrencyTest.java From tomee with Apache License 2.0 | 4 votes |
@Override protected void setUp() throws Exception { super.setUp(); System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class)); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class); assembler.createContainer(statefulContainerInfo); final EjbJar ejbJar = new EjbJar(); final StatefulBean bean1 = new StatefulBean(MyLocalBeanImpl.class); final Timeout timeout1 = new Timeout(); timeout1.setTimeout(1000); timeout1.setUnit(TimeUnit.MILLISECONDS); final ConcurrentMethod method1 = new ConcurrentMethod(); method1.setMethod(new NamedMethod("*")); method1.setAccessTimeout(timeout1); bean1.getConcurrentMethod().add(method1); final StatefulBean bean2 = new StatefulBean("BeanNegative", MyLocalBeanImpl.class); final Timeout timeout2 = new Timeout(); timeout2.setTimeout(-1); timeout2.setUnit(TimeUnit.MILLISECONDS); final ConcurrentMethod method2 = new ConcurrentMethod(); method2.setMethod(new NamedMethod("*")); method2.setAccessTimeout(timeout2); bean2.getConcurrentMethod().add(method2); ejbJar.addEnterpriseBean(bean1); ejbJar.addEnterpriseBean(bean2); assembler.createApplication(config.configureApplication(ejbJar)); }
Example #30
Source File: StatefulConstructorInjectionTest.java From tomee with Apache License 2.0 | 4 votes |
protected void setUp() throws Exception { super.setUp(); System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); // Setup the descriptor information final EjbJar ejbJar = new EjbJar(); ejbJar.addEnterpriseBean(new StatelessBean(FooBean.class)); final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(WidgetBean.class)); bean.getEnvEntry().add(new EnvEntry("count", Integer.class.getName(), "10")); final EjbModule module = new EjbModule(ejbJar); module.setBeans(new Beans()); assembler.createApplication(config.configureApplication(module)); }