Java Code Examples for javax.ejb.embeddable.EJBContainer#createEJBContainer()

The following examples show how to use javax.ejb.embeddable.EJBContainer#createEJBContainer() . 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: MoviesHtmlUnitTest.java    From tomee with Apache License 2.0 8 votes vote down vote up
@BeforeClass
public static void start() throws IOException {

    // get a random unused port to use for http requests
    ServerSocket server = new ServerSocket(0);
    port = server.getLocalPort();
    server.close();

    webApp = createWebApp();
    Properties p = new Properties();
    p.setProperty(EJBContainer.APP_NAME, "moviefun");
    p.setProperty(EJBContainer.PROVIDER, "tomee-embedded"); // need web feature
    p.setProperty(EJBContainer.MODULES, webApp.getAbsolutePath());
    p.setProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT, String.valueOf(port));
    container = EJBContainer.createEJBContainer(p);
}
 
Example 2
Source File: MovieTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@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 3
Source File: SSHServerTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: CustomExceptionMapperTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@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, "em");
    properties.setProperty("httpejbd.port", Integer.toString(port));
    properties.setProperty("cxf.jaxrs.skip-provider-scanning", "true");
    container = EJBContainer.createEJBContainer(properties);
}
 
Example 5
Source File: Ch01SecurityTest.java    From javaee8-cookbook with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: SubjectServiceTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void start() {
    final Properties properties = new Properties();
    properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
    properties.setProperty(EJBContainer.APP_NAME, "polling/api");
    properties.setProperty(EJBContainer.PROVIDER, "openejb");
    container = EJBContainer.createEJBContainer(properties);
}
 
Example 7
Source File: CalculatorTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: ContainersImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
    public boolean deploy(final InputStream archive, final String name) {
        if (!OpenEJB.isInitialized()) stuck = name;
        else System.out.println("STUCK " + stuck);

        exception = null;

        final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);

        ThreadSingletonServiceImpl.exit(null);
        if (assembler != null) {
            assembler.destroy();
        }
        try {
            final File file = writeToFile(archive, name);
            final Map<String, Object> map = new HashMap<String, Object>();
            map.put(EJBContainer.MODULES, file);
            map.put(EJBContainer.APP_NAME, name);

            originalClassLoader = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[]{file.toURI().toURL()}, originalClassLoader));
            container = EJBContainer.createEJBContainer(map);

//            final WebBeansContext webBeansContext = ThreadSingletonServiceImpl.get();
//            dump(webBeansContext.getBeanManagerImpl());
        } catch (Exception e) {
            if (e instanceof EJBException && e.getCause() instanceof ValidationException) {
                exception = ValidationException.class.cast(e.getCause());
            } else {
                exception = e;
            }
            return false;
        }

        return true;
    }
 
Example 9
Source File: ExtraJCacheExtensionTest.java    From jcache-cdi with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    try {
        container = EJBContainer.createEJBContainer();
        container.getContext().bind("inject", this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 10
Source File: Ch02JtaTest.java    From javaee8-cookbook with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: DynamicUserDaoTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@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: PaymentTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void start() {
    container = EJBContainer.createEJBContainer();
}
 
Example 13
Source File: RemoteTomEEEJBContainerIT.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 300000)
public void run() throws IOException {
    final File app = new File("target/mock/webapp");
    Files.mkdirs(app);

    final FileWriter writer = new FileWriter(new File(app, "index.html"));
    writer.write("Hello");
    writer.close();

    File work = new File("target/webprofile-work-dir/").getAbsoluteFile();
    if (!work.exists()) {
        //May be running from root
        work = new File("apache-tomee/target/webprofile-work-dir/").getAbsoluteFile();
    }

    final File[] files = work.listFiles(new FileFilter() {
        @Override
        public boolean accept(final File pathname) {
            return pathname.isDirectory() && pathname.getName().startsWith("apache-tomcat-");
        }
    });

    final File tomee = (null != files ? files[0] : null);
    if (tomee == null) {
        fail("Failed to find Tomcat directory required for this test - Ensure you have run at least the maven phase: mvn process-resources");
    }

    final FileWriter serverXml = new FileWriter(new File(tomee, "conf/server.xml"));
    final int http = NetworkUtil.getNextAvailablePort();
    serverXml.write("<?xml version='1.0' encoding='utf-8'?>\n" +
        "<Server port=\"" + NetworkUtil.getNextAvailablePort() + "\" shutdown=\"SHUTDOWN\">\n" +
        "  <!-- TomEE plugin for Tomcat -->\n" +
        "  <Listener className=\"org.apache.tomee.catalina.ServerListener\" />\n" +
        "  <Service name=\"Catalina\">\n" +
        "    <Connector port=\"" + http + "\" protocol=\"HTTP/1.1\" xpoweredBy=\"false\" server=\"Apache TomEE\" />\n" +
        "    <Engine name=\"Catalina\" defaultHost=\"localhost\">\n" +
        "      <Host name=\"localhost\"  appBase=\"webapps\"\n" +
        "            unpackWARs=\"true\" autoDeploy=\"true\">\n" +
        "      </Host>\n" +
        "    </Engine>\n" +
        "  </Service>\n" +
        "</Server>\n");
    serverXml.close();

    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());
            put("retries", "120");
            put("debug", System.getProperty("RemoteTomEEEJBContainerIT.debug", "false"));
        }});
        final URL url = new URL("http://localhost:" + http + "/webapp/index.html");
        assertEquals("Hello", IO.slurp(url));
    } finally {
        if (container != null) {
            container.close();
            container = null;
        }
    }
}
 
Example 14
Source File: MoviesTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    ejbContainer = EJBContainer.createEJBContainer();
}
 
Example 15
Source File: MoviesTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    ejbContainer = EJBContainer.createEJBContainer();
}
 
Example 16
Source File: OpenEjbContainerTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void startTheContainer() throws Exception {
    final Map<String, Object> map = new HashMap<>();


    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(Widget.class));
    map.put(EJBContainer.MODULES, ejbJar);

    try (OpenEjbContainer openEjbContainer = (OpenEjbContainer) EJBContainer.createEJBContainer(map)) {
        Injector.inject(this);

        assertNotNull(widget);

        widget = null;

        openEjbContainer.getContext().bind("inject", this);
    }

}
 
Example 17
Source File: StereotypeTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void start() throws NamingException {
    container = EJBContainer.createEJBContainer();
    journey = (Journey) container.getContext().lookup("java:global/cdi-alternative-and-stereotypes/Journey");
}
 
Example 18
Source File: EventTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void start() throws NamingException {
    initialLogProperty = System.getProperty("openejb.logger.external");
    System.setProperty("openejb.logger.external", "true");
    container = EJBContainer.createEJBContainer();
}
 
Example 19
Source File: CalculatorTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void startTheContainer() {
    ejbContainer = EJBContainer.createEJBContainer();
}
 
Example 20
Source File: RestaurantTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Before
public void startContainer() throws Exception {
    container = EJBContainer.createEJBContainer();
    container.getContext().bind("inject", this);
}