javax.ejb.embeddable.EJBContainer Java Examples
The following examples show how to use
javax.ejb.embeddable.EJBContainer.
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: GuessHowManyMBeanTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void play() throws Exception { Properties properties = new Properties(); properties.setProperty(LocalMBeanServer.OPENEJB_JMX_ACTIVE, Boolean.TRUE.toString()); EJBContainer container = EJBContainer.createEJBContainer(properties); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName(OBJECT_NAME); assertEquals(0, server.getAttribute(objectName, "value")); server.setAttribute(objectName, new Attribute("value", 3)); assertEquals(3, server.getAttribute(objectName, "value")); assertEquals("winner", server.invoke(objectName, "tryValue", new Object[]{3}, null)); assertEquals("not the correct value, please have another try", server.invoke(objectName, "tryValue", new Object[]{2}, null)); container.close(); }
Example #2
Source File: DynamicUserDaoTest.java From tomee with Apache License 2.0 | 6 votes |
@BeforeClass public static void start() throws Exception { final Properties p = new Properties(); p.setProperty("openejb.deployments.classpath.include", "spring-data-proxy"); p.setProperty("openejb.exclude-include.order", "exclude-include"); p.setProperty("jdbc/DynamicUserDaoTest", "new://Resource?type=DataSource"); p.setProperty("jdbc/DynamicUserDaoTest", "new://Resource?type=DataSource"); p.setProperty("jdbc/DynamicUserDaoTest.JdbcDriver", "org.hsqldb.jdbcDriver"); p.setProperty("jdbc/DynamicUserDaoTest.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); p.setProperty("jdbc/DynamicUserDaoTest.UserName", "sa"); p.setProperty("jdbc/DynamicUserDaoTest.Password", ""); container = EJBContainer.createEJBContainer(p); }
Example #3
Source File: MoviesTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void testMe() throws Exception { final Properties p = new Properties(); p.put("movieDatabase", "new://Resource?type=DataSource"); p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); EJBContainer.createEJBContainer(p).getContext().bind("inject", this); movies.addMovie(new Movie("Asif Kapadia", "Senna", 2010)); movies.addMovie(new Movie("José Padilha", "Tropa de Elite", 2007)); movies.addMovie(new Movie("Andy Wachowski/Lana Wachowski", "The Matrix", 1999)); movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); Assert.assertEquals(5L, movies.countMovies().longValue()); }
Example #4
Source File: MoviesTest.java From tomee with Apache License 2.0 | 6 votes |
public void test() throws Exception { System.setProperty("hsqldb.reconfig_logging", "false"); System.setProperty("tomee.jpa.factory.lazy", "true"); final Properties p = new Properties(); p.put("movieDatabase", "new://Resource?type=DataSource"); p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); final Context context = EJBContainer.createEJBContainer(p).getContext(); Movies movies = (Movies) context.lookup("java:global/jpa-hibernate/Movies"); movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); List<Movie> list = movies.getMovies(); assertEquals("List.size()", 3, list.size()); for (Movie movie : list) { movies.deleteMovie(movie); } assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); }
Example #5
Source File: DataSourceCipheredExampleTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void accessDatasourceWithMyImplementation() throws Exception { // define the datasource Properties properties = new Properties(); properties.setProperty("ProtectedDatasource", "new://Resource?type=DataSource"); properties.setProperty("ProtectedDatasource.JdbcDriver", "org.hsqldb.jdbcDriver"); properties.setProperty("ProtectedDatasource.JdbcUrl", "jdbc:hsqldb:mem:protected"); properties.setProperty("ProtectedDatasource.UserName", USER); properties.setProperty("ProtectedDatasource.Password", "3MdniFr3v3NLLuoY"); properties.setProperty("ProtectedDatasource.PasswordCipher", "reverse"); properties.setProperty("ProtectedDatasource.JtaManaged", "true"); // start the context and makes junit test injections EJBContainer container = EJBContainer.createEJBContainer(properties); Context context = container.getContext(); context.bind("inject", this); // test the datasource assertNotNull(dataSource); assertNotNull(dataSource.getConnection()); // closing the context container.close(); }
Example #6
Source File: DataSourceCipheredExampleTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void accessDatasource() throws Exception { // define the datasource Properties properties = new Properties(); properties.setProperty("ProtectedDatasource", "new://Resource?type=DataSource"); properties.setProperty("ProtectedDatasource.JdbcDriver", "org.hsqldb.jdbcDriver"); properties.setProperty("ProtectedDatasource.JdbcUrl", DATASOURCE_URL); properties.setProperty("ProtectedDatasource.UserName", USER); properties.setProperty("ProtectedDatasource.Password", "fEroTNXjaL5SOTyRQ92x3DNVS/ksbtgs"); properties.setProperty("ProtectedDatasource.PasswordCipher", "Static3DES"); properties.setProperty("ProtectedDatasource.JtaManaged", "true"); // start the context and makes junit test injections EJBContainer container = EJBContainer.createEJBContainer(properties); Context context = container.getContext(); context.bind("inject", this); // test the datasource assertNotNull(dataSource); assertNotNull(dataSource.getConnection()); // closing the context container.close(); }
Example #7
Source File: StratocasterTest.java From tomee with Apache License 2.0 | 6 votes |
public void test() throws Exception { EJBContainer.createEJBContainer().getContext().bind("inject", this); Date date = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).parse("Mar 1, 1962"); assertEquals("Strat.getDateCreated()", date, strat.getDateCreated()); List<Pickup> pickups = asList(Pickup.SINGLE_COIL, Pickup.SINGLE_COIL, Pickup.SINGLE_COIL); assertEquals("Strat.getPickups()", pickups, strat.getPickups()); assertEquals("Strat.getStyle()", Style.VINTAGE, strat.getStyle()); assertEquals("Strat.getStringGuage(\"E1\")", 0.052F, strat.getStringGuage("E1"), 1e-15); assertEquals("Strat.getStringGuage(\"A\")", 0.042F, strat.getStringGuage("A"), 1e-15); assertEquals("Strat.getStringGuage(\"D\")", 0.030F, strat.getStringGuage("D"), 1e-15); assertEquals("Strat.getStringGuage(\"G\")", 0.017F, strat.getStringGuage("G"), 1e-15); assertEquals("Strat.getStringGuage(\"B\")", 0.013F, strat.getStringGuage("B"), 1e-15); assertEquals("Strat.getStringGuage(\"E\")", 0.010F, strat.getStringGuage("E"), 1e-15); File file = new File("/tmp/strat-certificate.txt"); assertEquals("Strat.getCertificateOfAuthenticity()", file, strat.getCertificateOfAuthenticity()); }
Example #8
Source File: MoviesTest.java From tomee with Apache License 2.0 | 6 votes |
public void test() throws Exception { Properties p = new Properties(); p.put("movieDatabase", "new://Resource?type=DataSource"); p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); Context context = EJBContainer.createEJBContainer(p).getContext(); Movies movies = (Movies) context.lookup("java:global/injection-of-datasource/Movies"); movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); List<Movie> list = movies.getMovies(); assertEquals("List.size()", 3, list.size()); for (Movie movie : list) { movies.deleteMovie(movie); } assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); }
Example #9
Source File: EmbeddedTomEEContainerTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void classpath() throws Exception { final Properties p = new Properties(); p.setProperty(EJBContainer.PROVIDER, EmbeddedTomEEContainer.class.getName()); p.setProperty(DeploymentsResolver.CLASSPATH_INCLUDE, ".*tomee-embedded.*"); p.setProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT, "-1"); EJBContainer container = null; try { container = EJBContainer.createEJBContainer(p); assertNotNull(container); assertNotNull(container.getContext()); final ABean bean = ABean.class.cast(container.getContext().lookup("java:global/tomee-embedded/ABean")); assertNotNull(bean); assertEquals("ok", bean.embedded()); } finally { if (container != null) { container.close(); } } }
Example #10
Source File: MovieTest.java From tomee with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { final ClassLoader ctxCl = Thread.currentThread().getContextClassLoader(); System.setProperty("openejb.ScriptLoginModule.scriptURI", ctxCl.getResource("loginscript.js").toExternalForm()); Properties p = new Properties(); p.put("movieDatabase", "new://Resource?type=DataSource"); p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); this.container = EJBContainer.createEJBContainer(p); this.container.getContext().bind("inject", this); }
Example #11
Source File: DynamicUserDaoTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void start() throws Exception { final Properties p = new Properties(); p.setProperty("openejb.deployments.classpath.include", "spring-data-proxy-meta"); p.setProperty("openejb.exclude-include.order", "exclude-include"); p.setProperty("jdbc/DynamicUserDaoTest", "new://Resource?type=DataSource"); p.setProperty("jdbc/DynamicUserDaoTest.JdbcDriver", "org.hsqldb.jdbcDriver"); p.setProperty("jdbc/DynamicUserDaoTest.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); p.setProperty("jdbc/DynamicUserDaoTest.UserName", "sa"); p.setProperty("jdbc/DynamicUserDaoTest.Password", ""); container = EJBContainer.createEJBContainer(p); }
Example #12
Source File: CustomProviderWithConfigTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void start() throws Exception { port = NetworkUtil.getNextAvailablePort(); final Properties properties = new Properties(); properties.setProperty(DeploymentFilterable.CLASSPATH_INCLUDE, ".*openejb-cxf-rs.*"); properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true"); properties.setProperty(DeploymentLoader.OPENEJB_ALTDD_PREFIX, "custom-config"); properties.setProperty("httpejbd.port", Integer.toString(port)); // cxf.jaxrs.properties = faultStackTraceEnabled=true container = EJBContainer.createEJBContainer(properties); }
Example #13
Source File: Ch01SecurityTest.java From javaee8-cookbook with Apache License 2.0 | 5 votes |
@Before public void setUp() throws NamingException { Properties p = new Properties(); p.put("userDb", "new://Resource?type=DataSource"); p.put("userDb.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("userDb.JdbcUrl", "jdbc:hsqldb:mem:userdatabase"); this.ejbContainer = EJBContainer.createEJBContainer(p); this.ejbContainer.getContext().bind("inject", this); }
Example #14
Source File: MoviesTest.java From tomee with Apache License 2.0 | 5 votes |
public void test() throws Exception { final Properties p = new Properties(); p.put("movieDatabase", "new://Resource?type=DataSource"); p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); EJBContainer container = EJBContainer.createEJBContainer(p); final Context context = container.getContext(); Movies movies = (Movies) context.lookup("java:global/injection-of-entitymanager/Movies"); movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); List<Movie> list = movies.getMovies(); assertEquals("List.size()", 3, list.size()); for (Movie movie : list) { movies.deleteMovie(movie); } assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); container.close(); }
Example #15
Source File: InjectStatement.java From tomee with Apache License 2.0 | 5 votes |
@Override public void evaluate() throws Throwable { if (startingStatement != null) { Class<?> clazz = this.clazz; while (!Object.class.equals(clazz)) { for (final Field field : clazz.getDeclaredFields()) { final TestResource resource = field.getAnnotation(TestResource.class); if (resource != null) { if (Context.class.isAssignableFrom(field.getType())) { field.setAccessible(true); field.set(Modifier.isStatic(field.getModifiers()) ? null : test, startingStatement.getContainer().getContext()); } else if (Hashtable.class.isAssignableFrom(field.getType())) { field.setAccessible(true); field.set(Modifier.isStatic(field.getModifiers()) ? null : test, startingStatement.getProperties()); } else if (EJBContainer.class.isAssignableFrom(field.getType())) { field.setAccessible(true); field.set(Modifier.isStatic(field.getModifiers()) ? null : test, startingStatement.getContainer()); } else { throw new OpenEJBException("can't inject field '" + field.getName() + "'"); } } } clazz = clazz.getSuperclass(); } } if (test != null) { SystemInstance.get().setComponent(TestInstance.class, new TestInstance(test.getClass(), test)); SystemInstance.get().getComponent(FallbackPropertyInjector.class); // force eager init (MockitoInjector initialize eveything in its constructor) Injector.inject(test); } if (statement != null) { statement.evaluate(); } }
Example #16
Source File: DynamicSubclassEjbDeploymentTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void start() throws Exception { port = NetworkUtil.getNextAvailablePort(); final Properties properties = new Properties(); properties.setProperty("cxf.jaxrs.skip-provider-scanning", "true"); properties.setProperty("httpejbd.port", Integer.toString(port)); properties.setProperty(DeploymentFilterable.CLASSPATH_INCLUDE, ".*openejb-cxf-rs.*"); properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true"); container = EJBContainer.createEJBContainer(properties); service = (RESTIsVeryCool) container.getContext().lookup("java:/global/openejb-cxf-rs/RESTIsVeryCool"); }
Example #17
Source File: MoviesTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { final Properties props = new Properties(); props.setProperty(DeploymentFilterable.CLASSPATH_INCLUDE, ".*arquillian-tomee-moviefun-example.*"); // arquillian-tomee excluded by default ejbContainer = EJBContainer.createEJBContainer(props); final Object object = ejbContainer.getContext().lookup("java:global/arquillian-tomee-moviefun-example/Movies!org.superbiz.moviefun.MoviesRemote"); assertTrue(MoviesRemote.class.isInstance(object)); movies = MoviesRemote.class.cast(object); }
Example #18
Source File: MoviesTest.java From tomee with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { final Properties p = new Properties(); p.put("movieDatabase", "new://Resource?type=DataSource"); p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); final EJBContainer container = EJBContainer.createEJBContainer(p); final Context context = container.getContext(); context.bind("inject", this); assertTrue(((ReloadableEntityManagerFactory) emf).getManagedClasses().contains(Movie.class.getName())); container.close(); }
Example #19
Source File: CalculatorTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { final Properties properties = new Properties(); properties.setProperty("openejb.embedded.remotable", "true"); //Just for this test we change the default port from 4204 to avoid conflicts properties.setProperty("httpejbd.port", "" + port); container = EJBContainer.createEJBContainer(properties); }
Example #20
Source File: DynamicUserDaoTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void init() throws Exception { final Properties p = new Properties(); p.put("jdbc/dynamicDB", "new://Resource?type=DataSource"); p.put("jdbc/dynamicDB.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("jdbc/dynamicDB.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); p.put("jdbc/dynamicDB.UserName", "sa"); p.put("jdbc/dynamicDB.Password", ""); final Context context = EJBContainer.createEJBContainer(p).getContext(); dao = (UserDao) context.lookup("java:global/dynamic-dao-implementation/UserDao"); util = (Util) context.lookup("java:global/dynamic-dao-implementation/Util"); util.init(); // init database }
Example #21
Source File: CalculatorTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { Properties properties = new Properties(); properties.setProperty("openejb.embedded.remotable", "true"); //Just for this test we change the default port from 4204 to avoid conflicts properties.setProperty("httpejbd.port", "" + port); // properties.setProperty("httpejbd.print", "true"); // properties.setProperty("httpejbd.indent.xml", "true"); // properties.setProperty("logging.level.OpenEJB.server.http", "FINE"); EJBContainer.createEJBContainer(properties); }
Example #22
Source File: UserServiceTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void start() throws IOException { final File webApp = Archive.archive().copyTo("WEB-INF/classes", jarLocation(UserDAO.class)).asDir(); final Properties p = new Properties(); p.setProperty(EJBContainer.APP_NAME, "rest-example"); p.setProperty(EJBContainer.PROVIDER, "tomee-embedded"); // need web feature p.setProperty(EJBContainer.MODULES, webApp.getAbsolutePath()); p.setProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT, "-1"); // random port container = EJBContainer.createEJBContainer(p); }
Example #23
Source File: OpenEjbContainer.java From tomee with Apache License 2.0 | 5 votes |
private InvalidModulesPropertyException invalidModulesValue(final Object value) { final String[] spec = {"java.lang.String", "java.lang.String[]", "java.io.File", "java.io.File[]"}; // TODO // String[] vendor = {"java.lang.Class","java.lang.Class[]", "java.net.URL", "java.io.URL[]"}; final String type = value == null ? null : value.getClass().getName(); return new InvalidModulesPropertyException(String.format("Invalid '%s' value '%s'. Valid values are: %s", EJBContainer.MODULES, type, Join.join(", ", spec))); }
Example #24
Source File: JndiBuilder.java From tomee with Apache License 2.0 | 5 votes |
public JndiBuilder(final Context openejbContext) { this.openejbContext = openejbContext; final Options options = SystemInstance.get().getOptions(); failOnCollision = options.get(JNDINAME_FAILONCOLLISION, true); embeddedEjbContainerApi = options.get(EJBContainer.class.getName(), false); }
Example #25
Source File: SSHServerTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void start() { System.setProperty("openejb.server.ssh.key", "src/test/key/ssh-key"); System.setProperty("openejb.logger.external", "true"); container = EJBContainer.createEJBContainer(new HashMap<Object, Object>() {{ put(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true"); put(DeploymentFilterable.CLASSPATH_FILTER_SYSTEMAPPS, "false"); }}); }
Example #26
Source File: Ch02JtaTest.java From javaee8-cookbook with Apache License 2.0 | 5 votes |
@Before public void setUp() throws NamingException { Properties p = new Properties(); p.put("userDb", "new://Resource?type=DataSource"); p.put("userDb.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("userDb.JdbcUrl", "jdbc:hsqldb:mem:userdatabase"); ejbContainer = EJBContainer.createEJBContainer(p); ejbContainer.getContext().bind("inject", this); }
Example #27
Source File: OpenEjbContainerNoRestartTest.java From tomee with Apache License 2.0 | 5 votes |
@Test public void normalRestart() throws Exception { final EJBContainer container1 = EJBContainer.createEJBContainer(new Properties() {{ put(EJBContainer.MODULES, new EjbJar()); }}); container1.close(); final EJBContainer container2 = EJBContainer.createEJBContainer(new Properties() {{ put(EJBContainer.MODULES, new EjbJar()); }}); container2.close(); assertNotSame(container1, container2); }
Example #28
Source File: ExtraJCacheExtensionTest.java From jcache-cdi with Apache License 2.0 | 5 votes |
@Before public void setUp() { try { container = EJBContainer.createEJBContainer(); container.getContext().bind("inject", this); } catch (Exception e) { e.printStackTrace(); } }
Example #29
Source File: ShutingDownStatement.java From tomee with Apache License 2.0 | 5 votes |
@Override protected void after() throws Exception { final EJBContainer container = startingStatement.getContainer(); if (container != null) { container.close(); } }
Example #30
Source File: DiscoverCustomProviderTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void start() throws Exception { port = NetworkUtil.getNextAvailablePort(); final Properties properties = new Properties(); properties.setProperty("httpejbd.port", Integer.toString(port)); properties.setProperty(DeploymentFilterable.CLASSPATH_INCLUDE, ".*openejb-cxf-rs.*"); properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true"); properties.setProperty(RESTService.OPENEJB_JAXRS_PROVIDERS_AUTO_PROP, "true"); properties.setProperty(CxfRsHttpListener.CXF_JAXRS_PREFIX + "debug", "true"); container = EJBContainer.createEJBContainer(properties); }