Search in sources :

Example 1 with IvmJndiFactory

use of org.apache.openejb.core.ivm.naming.IvmJndiFactory in project tomee by apache.

the class OpenEjbBrokerFactoryTest method testLookupDataSource.

public void testLookupDataSource() throws Exception {
    final Properties properties = new Properties();
    final JDBCDataSource dataSource = new JDBCDataSource();
    dataSource.setDatabase("jdbc:hsqldb:mem:testdb" + System.currentTimeMillis());
    dataSource.setUser("sa");
    dataSource.setPassword("");
    dataSource.getConnection().close();
    MockInitialContextFactory.install(Collections.singletonMap("openejb/Resource/TestDs", dataSource));
    assertSame(dataSource, new InitialContext().lookup("openejb/Resource/TestDs"));
    final CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
    containerSystem.getJNDIContext().bind("openejb/Resource/TestDs", dataSource);
    SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);
    properties.put("DataSource", "TestDs");
    properties.put("UseDatabaseLock", "false");
    properties.put("StartupTimeout", "10000");
    ActiveMQFactory.setThreadProperties(properties);
    BrokerService broker = null;
    try {
        broker = BrokerFactory.createBroker(new URI(getBrokerUri("broker:(tcp://localhost:" + brokerPort + ")?useJmx=false")));
        assertNotNull("broker is null", broker);
        final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
        assertNotNull("persistenceAdapter is null", persistenceAdapter);
        assertTrue("persistenceAdapter should be an instance of JDBCPersistenceAdapter", persistenceAdapter instanceof JDBCPersistenceAdapter);
        final JDBCPersistenceAdapter jdbcPersistenceAdapter = (JDBCPersistenceAdapter) persistenceAdapter;
        assertSame(dataSource, jdbcPersistenceAdapter.getDataSource());
    } finally {
        stopBroker(broker);
        ActiveMQFactory.setThreadProperties(null);
    }
}
Also used : JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) IvmJndiFactory(org.apache.openejb.core.ivm.naming.IvmJndiFactory) JDBCDataSource(org.hsqldb.jdbc.JDBCDataSource) CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) Properties(java.util.Properties) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) InitialContext(javax.naming.InitialContext) MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter)

Example 2 with IvmJndiFactory

use of org.apache.openejb.core.ivm.naming.IvmJndiFactory in project tomee by apache.

the class HttpResponseImplSessionTest method start.

@Before
public void start() throws Exception {
    SystemInstance.get().setComponent(ContainerSystem.class, new CoreContainerSystem(new IvmJndiFactory()));
    server = new OpenEJBHttpEjbServer();
    server.init(new Properties());
    server.start();
}
Also used : IvmJndiFactory(org.apache.openejb.core.ivm.naming.IvmJndiFactory) CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) Properties(java.util.Properties) Before(org.junit.Before)

Example 3 with IvmJndiFactory

use of org.apache.openejb.core.ivm.naming.IvmJndiFactory in project tomee by apache.

the class ReloadingLoaderTest method initContext.

@Before
public void initContext() throws LifecycleException {
    final OpenEjbConfiguration configuration = new OpenEjbConfiguration();
    configuration.facilities = new FacilitiesInfo();
    final CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
    SystemInstance.get().setComponent(OpenEjbConfiguration.class, configuration);
    SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);
    SystemInstance.get().setComponent(WebAppEnricher.class, new WebAppEnricher() {

        @Override
        public URL[] enrichment(final ClassLoader webappClassLaoder) {
            return new URL[0];
        }
    });
    parentInstance = new AtomicReference<>(ParentClassLoaderFinder.Helper.get());
    loader = new TomEEWebappClassLoader(parentInstance.get()) {

        @Override
        public ClassLoader getInternalParent() {
            return parentInstance.get();
        }

        @Override
        protected void clearReferences() {
        // no-op: this test should be reworked to support it but in real life a loader is not stopped/started
        }
    };
    loader.init();
    final StandardRoot resources = new StandardRoot();
    loader.setResources(resources);
    resources.setContext(new StandardContext() {

        @Override
        public String getDocBase() {
            final File file = new File("target/foo");
            file.mkdirs();
            return file.getAbsolutePath();
        }

        @Override
        public String getMBeanKeyProperties() {
            return "foo";
        }

        {
        }
    });
    resources.start();
    loader.start();
    info = new AppInfo();
    info.appId = "test";
    context = new AppContext(info.appId, SystemInstance.get(), loader, new IvmContext(), new IvmContext(), true);
    containerSystem.addAppContext(context);
    final WebContext webDeployment = new WebContext(context);
    webDeployment.setId(context.getId());
    webDeployment.setClassLoader(loader);
    containerSystem.addWebContext(webDeployment);
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) StandardRoot(org.apache.catalina.webresources.StandardRoot) IvmJndiFactory(org.apache.openejb.core.ivm.naming.IvmJndiFactory) TomEEWebappClassLoader(org.apache.tomee.catalina.TomEEWebappClassLoader) CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) WebAppEnricher(org.apache.openejb.classloader.WebAppEnricher) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) AppInfo(org.apache.openejb.assembler.classic.AppInfo) FacilitiesInfo(org.apache.openejb.assembler.classic.FacilitiesInfo) StandardContext(org.apache.catalina.core.StandardContext) TomEEWebappClassLoader(org.apache.tomee.catalina.TomEEWebappClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) Before(org.junit.Before)

Aggregations

CoreContainerSystem (org.apache.openejb.core.CoreContainerSystem)3 IvmJndiFactory (org.apache.openejb.core.ivm.naming.IvmJndiFactory)3 Properties (java.util.Properties)2 Before (org.junit.Before)2 File (java.io.File)1 URI (java.net.URI)1 URLClassLoader (java.net.URLClassLoader)1 InitialContext (javax.naming.InitialContext)1 BrokerService (org.apache.activemq.broker.BrokerService)1 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)1 JDBCPersistenceAdapter (org.apache.activemq.store.jdbc.JDBCPersistenceAdapter)1 MemoryPersistenceAdapter (org.apache.activemq.store.memory.MemoryPersistenceAdapter)1 StandardContext (org.apache.catalina.core.StandardContext)1 StandardRoot (org.apache.catalina.webresources.StandardRoot)1 AppContext (org.apache.openejb.AppContext)1 AppInfo (org.apache.openejb.assembler.classic.AppInfo)1 FacilitiesInfo (org.apache.openejb.assembler.classic.FacilitiesInfo)1 OpenEjbConfiguration (org.apache.openejb.assembler.classic.OpenEjbConfiguration)1 WebAppEnricher (org.apache.openejb.classloader.WebAppEnricher)1 WebContext (org.apache.openejb.core.WebContext)1