Package javax.ejb.embeddable

Examples of javax.ejb.embeddable.EJBContainer


import static org.junit.matchers.JUnitMatchers.containsString;

public class CalculatorTest {
    @Test
    public void call() throws MalformedURLException {
        final EJBContainer container = EJBContainer.createEJBContainer(new Properties() {{
            setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
        }});

        // normal call

        final Service service = Service.create(
                new URL("http://127.0.0.1:4204/webservice-ws-with-resources-config/CalculatorBean?wsdl"),
                new QName("http://security.ws.superbiz.org/", "CalculatorBeanService"));

        final Calculator calculator = service.getPort(Calculator.class);
        ClientProxy.getClient(calculator).getOutInterceptors().add(
                new WSS4JOutInterceptor(new HashMap<String, Object>() {{
                    put("action", "UsernameToken");
                    put("user", "openejb");
                    put("passwordType", "PasswordText");
                    put("passwordCallbackRef", new CallbackHandler() {
                        @Override
                        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                            final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
                            pc.setPassword("tomee");
                        }
                    });
                }}));

        assertEquals(5, calculator.add(2, 3));

        // bad auth

        final Calculator calculator2 = service.getPort(Calculator.class);
        ClientProxy.getClient(calculator2).getOutInterceptors().add(
                new WSS4JOutInterceptor(new HashMap<String, Object>() {{
                    put("action", "UsernameToken");
                    put("user", "openejb");
                    put("passwordType", "PasswordText");
                    put("passwordCallbackRef", new CallbackHandler() {
                        @Override
                        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                            final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
                            pc.setPassword("wrong");
                        }
                    });
                }}));

        try {
            assertEquals(5, calculator2.add(2, 3));
        } catch (SOAPFaultException sfe) {
            assertThat(sfe.getMessage(), containsString("The security token could not be authenticated or authorized"));
        }

        container.close();

        // valid it passed because all was fine and not because the server config was not here
        assertTrue(PasswordCallbackHandler.wasCalled());
    }
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");

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

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

    public static void main(String[] args) throws Exception {
        final Properties properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
        properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, Boolean.TRUE.toString());
        final EJBContainer container = EJBContainer.createEJBContainer(properties);
        final CountDownLatch latch = new CountDownLatch(1);

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                latch.countDown();
                container.close();
            }
        });

        latch.await();
    }
View Full Code Here

    @Test
    public void test() throws Exception {
        ExecutionChannel.getInstance().addObserver(this);

        final EJBContainer container = EJBContainer.createEJBContainer();

        {
            final CalculatorBean calculator = (CalculatorBean) getContext().lookup(JNDI);

            Assert.assertEquals(10, calculator.add(4, 6));

            //the bean is constructed only when it is used for the first time
            Assert.assertEquals("postConstruct", this.received.remove(0));
            Assert.assertEquals("add", this.received.remove(0));

            Assert.assertEquals(-2, calculator.subtract(4, 6));
            Assert.assertEquals("subtract", this.received.remove(0));

            Assert.assertEquals(24, calculator.multiply(4, 6));
            Assert.assertEquals("multiply", this.received.remove(0));

            Assert.assertEquals(2, calculator.divide(12, 6));
            Assert.assertEquals("divide", this.received.remove(0));

            Assert.assertEquals(4, calculator.remainder(46, 6));
            Assert.assertEquals("remainder", this.received.remove(0));
        }

        {
            final CalculatorBean calculator = (CalculatorBean) getContext().lookup(JNDI);

            Assert.assertEquals(10, calculator.add(4, 6));
            Assert.assertEquals("add", this.received.remove(0));

        }

        container.close();
        Assert.assertEquals("preDestroy", this.received.remove(0));
        Assert.assertTrue(this.received.isEmpty());
    }
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 class CalculatorTest {

    @Test
    public void call() throws MalformedURLException {
        final EJBContainer container = EJBContainer.createEJBContainer(new Properties() {{
            setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
        }});

        // normal call

        final Service service = Service.create(
                                                  new URL("http://127.0.0.1:4204/webservice-ws-with-resources-config/CalculatorBean?wsdl"),
                                                  new QName("http://security.ws.superbiz.org/", "CalculatorBeanService"));

        final Calculator calculator = service.getPort(Calculator.class);
        ClientProxy.getClient(calculator).getOutInterceptors().add(
                                                                      new WSS4JOutInterceptor(new HashMap<String, Object>() {{
                                                                          put("action", "UsernameToken");
                                                                          put("user", "openejb");
                                                                          put("passwordType", "PasswordText");
                                                                          put("passwordCallbackRef", new CallbackHandler() {
                                                                              @Override
                                                                              public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                                                                                  final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
                                                                                  pc.setPassword("tomee");
                                                                              }
                                                                          });
                                                                      }}));

        assertEquals(5, calculator.add(2, 3));

        // bad auth

        final Calculator calculator2 = service.getPort(Calculator.class);
        ClientProxy.getClient(calculator2).getOutInterceptors().add(
                                                                       new WSS4JOutInterceptor(new HashMap<String, Object>() {{
                                                                           put("action", "UsernameToken");
                                                                           put("user", "openejb");
                                                                           put("passwordType", "PasswordText");
                                                                           put("passwordCallbackRef", new CallbackHandler() {
                                                                               @Override
                                                                               public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                                                                                   final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
                                                                                   pc.setPassword("wrong");
                                                                               }
                                                                           });
                                                                       }}));

        try {
            assertEquals(5, calculator2.add(2, 3));
        } catch (SOAPFaultException sfe) {
            assertThat(sfe.getMessage(), containsString("The security token could not be authenticated or authorized"));
        }

        container.close();

        // valid it passed because all was fine and not because the server config was not here
        assertTrue(PasswordCallbackHandler.wasCalled());
    }
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");

        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) {
View Full Code Here

        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();
            }
        }
    }
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", 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.