Search in sources :

Example 96 with SeContainer

use of jakarta.enterprise.inject.se.SeContainer in project helidon by oracle.

the class HelidonDeployableContainer method startServer.

void startServer(RunContext context, Path[] classPath) throws ReflectiveOperationException {
    try {
        Optional.of((SeContainer) CDI.current()).ifPresent(SeContainer::close);
        stopAll();
    } catch (IllegalStateException ignored) {
    // there is no server running
    }
    URLClassLoader urlClassloader;
    ClassLoader parent;
    if (containerConfig.getUserParentClassloader()) {
        urlClassloader = new URLClassLoader(toUrls(classPath));
        parent = urlClassloader;
    } else {
        urlClassloader = new URLClassLoader(toUrls(classPath), null);
        parent = Thread.currentThread().getContextClassLoader();
    }
    context.classLoader = new HelidonContainerClassloader(parent, urlClassloader, excludedLibrariesPattern, containerConfig.getUserParentClassloader());
    context.oldClassLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(context.classLoader);
    context.runnerClass = context.classLoader.loadClass("io.helidon.microprofile.arquillian.ServerRunner");
    context.runner = context.runnerClass.getDeclaredConstructor().newInstance();
    STOP_RUNNABLES.add(() -> {
        try {
            context.runnerClass.getDeclaredMethod("stop").invoke(context.runner);
        } catch (ReflectiveOperationException e) {
            LOGGER.log(Level.WARNING, "Can't stop embedded Helidon", e);
        }
    });
    // Configuration needs to be explicit, as some TCK libraries contain an unfortunate
    // META-INF/microprofile-config.properties (such as JWT-Auth)
    ConfigBuilder builder = ConfigProviderResolver.instance().getBuilder();
    // we must use the default configuration to support profiles (and test them correctly in config TCK)
    // we may need to have a custom configuration for TCKs that do require workarounds
    /*
        Config config =
                containerConfig.useBuilder(builder.withSources(findMpConfigSources(classPath)))
                .addDiscoveredConverters()
                // will read application.yaml
                .addDiscoveredSources()
                .build();

        if (config.getOptionalValue("mp.config.profile", Boolean.class).orElse(false)) {
            // there is a configuration profile, we must add correct sources
        }
        */
    Config config;
    if (containerConfig.hasCustomConfig()) {
        config = containerConfig.useBuilder(builder).build();
    } else {
        config = ConfigProvider.getConfig();
    }
    context.runnerClass.getDeclaredMethod("start", Config.class, Integer.TYPE).invoke(context.runner, config, containerConfig.getPort());
}
Also used : Config(org.eclipse.microprofile.config.Config) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ConfigBuilder(org.eclipse.microprofile.config.spi.ConfigBuilder) SeContainer(jakarta.enterprise.inject.se.SeContainer)

Example 97 with SeContainer

use of jakarta.enterprise.inject.se.SeContainer in project helidon by oracle.

the class HelidonContainerInitializerTest method testRestart.

@Test
void testRestart() {
    // this is a reproducer for bug 1554
    Config config = ConfigProviderResolver.instance().getBuilder().withSources(MpConfigSources.create(Map.of(HelidonContainerInitializer.CONFIG_ALLOW_INITIALIZER, "true"))).build();
    configResolver.registerConfig((org.eclipse.microprofile.config.Config) config, cl);
    // now we can start using SeContainerInitializer
    SeContainer container = SeContainerInitializer.newInstance().disableDiscovery().addBeanClasses(TestBean.class).initialize();
    container.close();
    try {
        Main.main(new String[0]);
    } finally {
        Main.shutdown();
    }
}
Also used : Config(org.eclipse.microprofile.config.Config) SeContainer(jakarta.enterprise.inject.se.SeContainer) Test(org.junit.jupiter.api.Test)

Example 98 with SeContainer

use of jakarta.enterprise.inject.se.SeContainer in project helidon by oracle.

the class InvalidStateTest method assertDeploymentException.

@SuppressWarnings("unchecked")
void assertDeploymentException(Class<? extends Throwable> expected, Map<String, String> configMap, Class<?>... beans) {
    Config config = ConfigProviderResolver.instance().getBuilder().withSources(MpConfigSources.create(configMap), MpConfigSources.create(Map.of("mp.initializer.allow", "true"))).build();
    ConfigProviderResolver.instance().registerConfig(config, Thread.currentThread().getContextClassLoader());
    SeContainerInitializer initializer = SeContainerInitializer.newInstance();
    initializer.addExtensions(SchedulingCdiExtension.class);
    initializer.addBeanClasses(beans);
    try (SeContainer c = initializer.initialize()) {
        fail("Expected " + expected.getName());
    } catch (AssertionFailedError e) {
        throw e;
    } catch (Throwable e) {
        assertEquals(expected, e.getClass());
    }
}
Also used : Config(org.eclipse.microprofile.config.Config) SeContainer(jakarta.enterprise.inject.se.SeContainer) AssertionFailedError(org.opentest4j.AssertionFailedError) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer)

Example 99 with SeContainer

use of jakarta.enterprise.inject.se.SeContainer in project helidon by oracle.

the class AsyncClient method main.

/**
 * Program entry point.
 *
 * @param args  the program arguments
 *
 * @throws Exception if an error occurs
 */
public static void main(String[] args) throws Exception {
    SeContainerInitializer initializer = SeContainerInitializer.newInstance();
    SeContainer container = initializer.initialize();
    AsyncClient client = container.select(AsyncClient.class).get();
    client.asyncUnary();
}
Also used : SeContainer(jakarta.enterprise.inject.se.SeContainer) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer)

Example 100 with SeContainer

use of jakarta.enterprise.inject.se.SeContainer in project helidon by oracle.

the class Client method main.

/**
 * Program entry point.
 *
 * @param args  the program arguments
 *
 * @throws Exception if an error occurs
 */
public static void main(String[] args) throws Exception {
    SeContainerInitializer initializer = SeContainerInitializer.newInstance();
    SeContainer container = initializer.initialize();
    Client client = container.select(Client.class).get();
    client.unary();
    client.serverStreaming();
    client.clientStreaming();
    client.bidirectional();
}
Also used : SeContainer(jakarta.enterprise.inject.se.SeContainer) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer)

Aggregations

SeContainer (jakarta.enterprise.inject.se.SeContainer)103 Test (org.testng.annotations.Test)66 SeContainerInitializer (jakarta.enterprise.inject.se.SeContainerInitializer)61 SpecAssertions (org.jboss.test.audit.annotations.SpecAssertions)38 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)30 Test (org.junit.jupiter.api.Test)14 BeanManager (jakarta.enterprise.inject.spi.BeanManager)11 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)10 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)10 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)10 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)9 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)9 Test (org.junit.Test)9 MetadataSources (org.hibernate.boot.MetadataSources)7 ContextNotActiveException (jakarta.enterprise.context.ContextNotActiveException)6 Apple (org.jboss.cdi.tck.tests.se.container.testPackage.Apple)6 Pear (org.jboss.cdi.tck.tests.se.container.testPackage.nestedPackage.Pear)6 Config (org.eclipse.microprofile.config.Config)5 ServerCdiExtension (io.helidon.microprofile.server.ServerCdiExtension)3 Bean (jakarta.enterprise.inject.spi.Bean)3