Java Code Examples for javax.ejb.embeddable.EJBContainer#close()
The following examples show how to use
javax.ejb.embeddable.EJBContainer#close() .
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: 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 2
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 3
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 4
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 5
Source File: OpenEjbContainerNoRestartTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void noRestart() throws Exception { final EJBContainer container1 = EJBContainer.createEJBContainer(new Properties() {{ put(EJBContainer.MODULES, new EjbJar()); put(OpenEjbContainer.OPENEJB_EJBCONTAINER_CLOSE, OpenEjbContainer.OPENEJB_EJBCONTAINER_CLOSE_SINGLE); }}); container1.close(); final EJBContainer container2 = EJBContainer.createEJBContainer(new Properties() {{ put(EJBContainer.MODULES, new EjbJar()); }}); container2.close(); assertTrue(SystemInstance.isInitialized()); assertSame(container1, container2); Reflections.invokeByReflection(container2, "doClose", new Class<?>[0], null); assertFalse(SystemInstance.isInitialized()); }
Example 6
Source File: EmbeddedTomEEContainerTest.java From tomee with Apache License 2.0 | 5 votes |
@Test public void containerTest() throws Exception { final File war = createWar(); final Properties p = new Properties(); p.setProperty(EJBContainer.APP_NAME, "test"); p.setProperty(EJBContainer.PROVIDER, EmbeddedTomEEContainer.class.getName()); p.put(EJBContainer.MODULES, war.getAbsolutePath()); p.setProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT, "-1"); EJBContainer container = null; try { container = EJBContainer.createEJBContainer(p); assertNotNull(container); assertNotNull(container.getContext()); final URL url = new URL("http://127.0.0.1:" + System.getProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT) + "/test/index.html"); assertEquals("true", getOk(url, 2)); } finally { if (container != null) { container.close(); } try { FileUtils.forceDelete(war); } catch (final IOException e) { FileUtils.deleteQuietly(war); } } }
Example 7
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 8
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 9
Source File: OpenEJBEmbeddedMojo.java From tomee with Apache License 2.0 | 5 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { MavenLogStreamFactory.setLogger(getLog()); final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(createClassLoader(oldCl)); EJBContainer container = null; try { container = EJBContainer.createEJBContainer(map()); if (await) { final CountDownLatch latch = new CountDownLatch(1); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { latch.countDown(); } })); try { latch.await(); } catch (final InterruptedException e) { // ignored } } } finally { if (container != null) { container.close(); } Thread.currentThread().setContextClassLoader(oldCl); } }
Example 10
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 11
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 12
Source File: MoviesTest.java From tomee with Apache License 2.0 | 4 votes |
public void test() throws Exception { final Properties p = new Properties(); p.put("movieDatabaseXA", "new://Resource?type=javax.sql.XADataSource&class-name=org.apache.derby.jdbc.EmbeddedXADataSource"); p.put("movieDatabaseXA.DatabaseName", "test"); p.put("movieDatabaseXA.CreateDatabase", "create"); p.put("movieDatabase", "new://Resource?type=DataSource"); p.put("movieDatabase.DataSourceCreator", "dbcp"); p.put("movieDatabase.XaDataSource", "movieDatabaseXA"); p.put("movieDatabase.JtaManaged", "true"); p.put("movieDatabase.UserName", "admin"); p.put("movieDatabase.Password", "admin"); p.put("movieDatabase.MaxActive", "128"); p.put("movieDatabase.MaxIdle", "25"); p.put("movieDatabase.MinIdle", "10"); p.put("movieDatabase.AccessToUnderlyingConnectionAllowed", "true"); p.put("movieDatabase.TestOnBorrow", "false"); p.put("movieDatabase.TestWhileIdle", "true"); p.put("movieDatabase.TimeBetweenEvictionRuns", "1 minute"); p.put("movieDatabase.MaxWaitTime", "0 seconds"); p.put("movieDatabase.PoolPreparedStatements", "true"); p.put("movieDatabase.MaxOpenPreparedStatements", "1024"); p.put("movieDatabase.ValidationQuery", "values 1"); p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource"); p.put("movieDatabaseUnmanaged.DataSourceCreator", "dbcp"); p.put("movieDatabaseUnmanaged.JdbcDriver", "org.apache.derby.jdbc.EmbeddedDriver"); p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:derby:test;create=true"); p.put("movieDatabaseUnmanaged.UserName", "admin"); p.put("movieDatabaseUnmanaged.Password", "admin"); p.put("movieDatabaseUnmanaged.JtaManaged", "false"); p.put("movieDatabaseUnmanaged.MaxActive", "128"); p.put("movieDatabaseUnmanaged.MaxIdle", "25"); p.put("movieDatabaseUnmanaged.MinIdle", "10"); p.put("movieDatabaseUnmanaged.AccessToUnderlyingConnectionAllowed", "true"); p.put("movieDatabaseUnmanaged.TestOnBorrow", "false"); p.put("movieDatabaseUnmanaged.TestWhileIdle", "true"); p.put("movieDatabaseUnmanaged.TimeBetweenEvictionRuns", "1 minute"); p.put("movieDatabaseUnmanaged.MaxWaitTime", "0 seconds"); p.put("movieDatabaseUnmanaged.PoolPreparedStatements", "true"); p.put("movieDatabaseUnmanaged.MaxOpenPreparedStatements", "1024"); p.put("movieDatabaseUnmanaged.ValidationQuery", "values 1"); EJBContainer container = EJBContainer.createEJBContainer(p); final Context context = container.getContext(); Movies movies = (Movies) context.lookup("java:global/xa-datasource/Movies"); MoviesDirect moviesDirect = (MoviesDirect) context.lookup("java:global/xa-datasource/MoviesDirect"); 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()); assertEquals(3, moviesDirect.count()); for (Movie movie : list) { movies.deleteMovie(movie); } assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); assertEquals(0, moviesDirect.count()); container.close(); }
Example 13
Source File: MoviesTest.java From tomee with Apache License 2.0 | 3 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(); final Movies movies = (Movies) context.lookup("java:global/jpa-enumerated/Movies"); movies.addMovie(new Movie("James Frawley", "The Muppet Movie", 1979, Rating.G)); movies.addMovie(new Movie("Jim Henson", "The Great Muppet Caper", 1981, Rating.G)); movies.addMovie(new Movie("Frank Oz", "The Muppets Take Manhattan", 1984, Rating.G)); movies.addMovie(new Movie("James Bobin", "The Muppets", 2011, Rating.PG)); assertEquals("List.size()", 4, movies.getMovies().size()); assertEquals("List.size()", 3, movies.findByRating(Rating.G).size()); assertEquals("List.size()", 1, movies.findByRating(Rating.PG).size()); assertEquals("List.size()", 0, movies.findByRating(Rating.R).size()); container.close(); }