Package javax.ejb.embeddable

Examples of javax.ejb.embeddable.EJBContainer


            "    </Engine>\n" +
            "  </Service>\n" +
            "</Server>\n");
        serverXml.close();

        EJBContainer container = null;
        try {
            container = EJBContainer.createEJBContainer(new HashMap<Object, Object>() {{
                put(EJBContainer.PROVIDER, "tomee-remote");
                put(EJBContainer.MODULES, app.getAbsolutePath());
                put("openejb.home", tomee.getAbsolutePath());
            }});
            final URL url = new URL("http://localhost:" + http + "/webapp/index.html");
            assertEquals("Hello", IO.slurp(url));
        } finally {
            if (container != null) {
                container.close();
            }
        }
    }
View Full Code Here


        this.startingStatement = startingStatement;
    }

    @Override
    protected void after() throws Exception {
        final EJBContainer container = startingStatement.getContainer();
        if (container != null) {
            container.close();
        }
    }
View Full Code Here

        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();
    }
View Full Code Here

    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 (InterruptedException e) {
                    // ignored
                }
            }
        } finally {
            if (container != null) {
                container.close();
            }
            Thread.currentThread().setContextClassLoader(oldCl);
        }
    }
View Full Code Here

        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");
        try {
            final EJBContainer 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", IO.readProperties(url).getProperty("ok"));
            container.close();
        } finally {
            try {
                FileUtils.forceDelete(war);
            } catch (final IOException e) {
                FileUtils.deleteQuietly(war);
View Full Code Here

    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");
        final EJBContainer container = EJBContainer.createEJBContainer(p);
        assertNotNull(container);
        final ABean bean = ABean.class.cast(container.getContext().lookup("java:global/tomee-embedded/ABean"));
        assertNotNull(bean);
        assertEquals("ok", bean.embedded());
        container.close();
    }
View Full Code Here

    @EJB
    private EjbWithJTASupport jtaSupport;

    @Test
    public void test() throws Exception {
        final EJBContainer container = EJBContainer.createEJBContainer(new Properties() {{
            setProperty("openejb.jul.forceReload", Boolean.TRUE.toString());
            setProperty("logging.level.OpenEJB", "OFF"); // logging will make the test failling just cause System.out takes time
        }});
        container.getContext().bind("inject", this);

        final long start = System.currentTimeMillis();

        final CountDownLatch latch = new CountDownLatch(ITERATIONS);
        try {
            final ExecutorService es = Executors.newFixedThreadPool(50);
            for (int i = 0; i < ITERATIONS; i++) {
                es.submit(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            jtaSupport.commit();
                        } catch (final Exception e) {
                            e.printStackTrace(System.out);
                        }

                        try {
                            jtaSupport.rollback();
                        } finally {
                            latch.countDown();
                        }
                    }
                });
            }
            es.shutdown();
            latch.await();

            Thread.sleep(500); // wait last measure

            final long end = System.currentTimeMillis();

            assertEquals(ITERATIONS, sum(Repository.INSTANCE.getGaugeValues(start, end, JTAGauges.JTA_COMMITED).values()), 0);
            assertEquals(ITERATIONS, sum(Repository.INSTANCE.getGaugeValues(start, end, JTAGauges.JTA_ROLLBACKED).values()), 0);

            // due to the sleep we use in commit() we only see half of the tx when checking actives
            assertEquals(ITERATIONS / 2, sum(Repository.INSTANCE.getGaugeValues(start, end, JTAGauges.JTA_ACTIVE).values()), ITERATIONS * .1);
        } finally {
            container.close();
        }
    }
View Full Code Here

import static org.junit.Assert.assertTrue;

public class OpenEjbContainerNoRestartTest {
    @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);
    }
View Full Code Here

        assertNotSame(container1, container2);
    }

    @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());
    }
View Full Code Here

    public static void main(String[] args) throws Exception {

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(EJBContainer.MODULES, new File("target/classes"));

        EJBContainer ec = EJBContainer.createEJBContainer(properties);
        Context ctx = ec.getContext();

        // Looks up for the EJB
        ItemEJB itemEJB = (ItemEJB) ctx.lookup("java:global/classes/ItemEJB");

        // Creates an instance of book
        Book book = new Book("H2G2", 12.5f, "Best IT Scifi Book", "1234-5678-5678", 247, false, Language.ENGLISH);
        // Tags
        List<String> tags = new ArrayList<String>();
        tags.add("scifi");
        tags.add("french");
        book.setTags(tags);
        // Chapters
        Chapter chapter1 = new Chapter("Arriving on earth", "blah blah blah blah blah");
        Chapter chapter2 = new Chapter("Restaurant of the universe", "Forty two");
        List<Chapter> chapters = new ArrayList<Chapter>();
        chapters.add(chapter1);
        chapters.add(chapter2);
        book.setChapters(chapters);

        // Creates an instance of CD
        CD cd = new CD("St Pepper", 12.80f, "Beatles master piece", "Apple", 1, 53.32f, "Pop");
        // Tracks
        Track track1 = new Track("Sgt Pepper Lonely Heart Club Ban", 4.53f, "Listen to the trumpet carefully, it's George Harrison playing");
        Track track2 = new Track("Fixing a Hole", 3.34f, "Beleive it or not, this song is about drugs");
        List<Track> tracks = new ArrayList<Track>();
        tracks.add(track1);
        tracks.add(track2);
        cd.setTracks(tracks);

        // Persists the book to the database
        itemEJB.createBook(book);

        // Persists the CD to the database
        itemEJB.createCD(cd);

        // Finds all the items
        logger.info("##### All items");
        List<Item> items = itemEJB.findAllItems();
        for (Item oneItem : items) {
            logger.info("# " + oneItem);
        }

        // Finds all the CDs
        logger.info("##### All CDs");
        List<CD> cds = itemEJB.findAllCDs();
        for (CD oneCD : cds) {
            logger.info("# " + oneCD);
        }

        // Finds all the Books
        logger.info("##### All Books");
        List<Book> books = itemEJB.findAllBooks();
        for (Book oneBook : books) {
            logger.info("# " + oneBook);
        }

        ec.close();
    }
View Full Code Here

TOP

Related Classes of javax.ejb.embeddable.EJBContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.