Package javax.ejb.embeddable

Examples of javax.ejb.embeddable.EJBContainer


        final Map<String, Object> p = new HashMap<String, Object>();
        p.put("MySTATEFUL", "new://Container?type=STATEFUL");
        p.put("MySTATEFUL.Capacity", "2"); //How many instances of Stateful beans can our server hold in memory?
        p.put("MySTATEFUL.Frequency", "1"); //Interval in seconds between checks
        p.put("MySTATEFUL.BulkPassivate", "0"); //No bulkPassivate - just passivate entities whenever it is needed
        final EJBContainer container = EJBContainer.createEJBContainer(p);

        //this is going to track the execution
        ExecutionChannel.getInstance().addObserver(this);

        {
            final Context context = getContext();

            CallbackCounter counterA = (CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter");
            Assert.assertNotNull(counterA);
            Assert.assertEquals("postConstruct", this.received.remove(0));

            Assert.assertEquals(0, counterA.count());
            Assert.assertEquals("count", this.received.remove(0));

            Assert.assertEquals(1, counterA.increment());
            Assert.assertEquals("increment", this.received.remove(0));

            Assert.assertEquals(0, counterA.reset());
            Assert.assertEquals("reset", this.received.remove(0));

            Assert.assertEquals(1, counterA.increment());
            Assert.assertEquals("increment", this.received.remove(0));

            System.out.println("Waiting 2 seconds...");
            Thread.sleep(2000);

            Assert.assertEquals("preDestroy", this.received.remove(0));

            try {
                counterA.increment();
                Assert.fail("The ejb is not supposed to be there.");
            } catch (javax.ejb.NoSuchEJBException e) {
                //excepted
            }

            context.close();
        }

        {
            final Context context = getContext();

            CallbackCounter counterA = (CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter");
            Assert.assertEquals("postConstruct", this.received.remove(0));

            Assert.assertEquals(1, counterA.increment());
            Assert.assertEquals("increment", this.received.remove(0));

            ((CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter")).count();
            Assert.assertEquals("postConstruct", this.received.remove(0));
            Assert.assertEquals("count", this.received.remove(0));

            ((CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter")).count();
            Assert.assertEquals("postConstruct", this.received.remove(0));
            Assert.assertEquals("count", this.received.remove(0));

            System.out.println("Waiting 2 seconds...");
            Thread.sleep(2000);
            Assert.assertEquals("prePassivate", this.received.remove(0));

            context.close();
        }
        container.close();

        Assert.assertEquals("preDestroy", this.received.remove(0));
        Assert.assertEquals("preDestroy", this.received.remove(0));

        Assert.assertTrue(this.received.toString(), this.received.isEmpty());
View Full Code Here


    private static final String OBJECT_NAME = "openejb.user.mbeans:group=org.superbiz.mbean,application=mbean-auto-registration,name=GuessHowManyMBean";

    @Test
    public void play() throws Exception {
        Properties properties = new Properties();
        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();
    }
View Full Code Here

    @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();
    }
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 Map<String, Object> p = new HashMap<String, Object>();
        p.put("MySTATEFUL", "new://Container?type=STATEFUL");
        p.put("MySTATEFUL.Capacity", "2"); //How many instances of Stateful beans can our server hold in memory?
        p.put("MySTATEFUL.Frequency", "1"); //Interval in seconds between checks
        p.put("MySTATEFUL.BulkPassivate", "0"); //No bulkPassivate - just passivate entities whenever it is needed
        final EJBContainer container = EJBContainer.createEJBContainer(p);

        //this is going to track the execution
        ExecutionChannel.getInstance().addObserver(this);

        {
            final Context context = getContext();

            CallbackCounter counterA = (CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter");
            Assert.assertNotNull(counterA);
            Assert.assertEquals("postConstruct", this.received.remove(0));

            Assert.assertEquals(0, counterA.count());
            Assert.assertEquals("count", this.received.remove(0));

            Assert.assertEquals(1, counterA.increment());
            Assert.assertEquals("increment", this.received.remove(0));

            Assert.assertEquals(0, counterA.reset());
            Assert.assertEquals("reset", this.received.remove(0));

            Assert.assertEquals(1, counterA.increment());
            Assert.assertEquals("increment", this.received.remove(0));

            System.out.println("Waiting 2 seconds...");
            Thread.sleep(2000);

            Assert.assertEquals("preDestroy", this.received.remove(0));

            try {
                counterA.increment();
                Assert.fail("The ejb is not supposed to be there.");
            } catch (javax.ejb.NoSuchEJBException e) {
                //excepted
            }

            context.close();
        }

        {
            final Context context = getContext();

            CallbackCounter counterA = (CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter");
            Assert.assertEquals("postConstruct", this.received.remove(0));

            Assert.assertEquals(1, counterA.increment());
            Assert.assertEquals("increment", this.received.remove(0));

            ((CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter")).count();
            Assert.assertEquals("postConstruct", this.received.remove(0));
            Assert.assertEquals("count", this.received.remove(0));

            ((CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter")).count();
            Assert.assertEquals("postConstruct", this.received.remove(0));
            Assert.assertEquals("count", this.received.remove(0));

            System.out.println("Waiting 2 seconds...");
            Thread.sleep(2000);
            Assert.assertEquals("prePassivate", this.received.remove(0));

            context.close();
        }
        container.close();

        Assert.assertEquals("preDestroy", this.received.remove(0));
        Assert.assertEquals("preDestroy", this.received.remove(0));

        Assert.assertTrue(this.received.toString(), this.received.isEmpty());
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

    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

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

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

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