Search in sources :

Example 1 with LogConfig

use of io.vertigo.app.config.LogConfig in project vertigo by KleeGroup.

the class ComponentSpaceTest method testHome.

@Test
public void testHome() {
    final AppConfig appConfig = AppConfig.builder().beginBoot().withLogConfig(new LogConfig("/log4j.xml")).endBoot().addModule(ModuleConfig.builder("Bio").addComponent(BioManager.class, BioManagerImpl.class).addComponent(MathManager.class, MathManagerImpl.class, Param.of("start", "100")).addPlugin(MathPlugin.class, Param.of("factor", "20")).build()).build();
    try (AutoCloseableApp app = new AutoCloseableApp(appConfig)) {
        final BioManager bioManager = app.getComponentSpace().resolve(BioManager.class);
        final int res = bioManager.add(1, 2, 3);
        assertEquals(366, res);
        assertTrue(bioManager.isActive());
    }
}
Also used : AutoCloseableApp(io.vertigo.app.AutoCloseableApp) AppConfig(io.vertigo.app.config.AppConfig) BioManager(io.vertigo.core.spaces.component.data.BioManager) MathPlugin(io.vertigo.core.spaces.component.data.MathPlugin) BioManagerImpl(io.vertigo.core.spaces.component.data.BioManagerImpl) LogConfig(io.vertigo.app.config.LogConfig) Test(org.junit.jupiter.api.Test)

Example 2 with LogConfig

use of io.vertigo.app.config.LogConfig in project vertigo by KleeGroup.

the class ComponentSpaceTest method testHome2.

@Test
public void testHome2() {
    final AppConfig appConfig = AppConfig.builder().beginBoot().withLogConfig(new LogConfig("/log4j.xml")).endBoot().addModule(ModuleConfig.builder("Bio").addComponent(BioManager.class, BioManagerImpl.class).addPlugin(DummyPlugin.class).addComponent(MathManager.class, MathManagerImpl.class, Param.of("start", "100")).addPlugin(MathPlugin.class, Param.of("factor", "20")).build()).build();
    Assertions.assertThrows(RuntimeException.class, () -> {
        try (AutoCloseableApp app = new AutoCloseableApp(appConfig)) {
        // 
        }
    });
}
Also used : AutoCloseableApp(io.vertigo.app.AutoCloseableApp) AppConfig(io.vertigo.app.config.AppConfig) DummyPlugin(io.vertigo.core.spaces.component.data.DummyPlugin) MathPlugin(io.vertigo.core.spaces.component.data.MathPlugin) LogConfig(io.vertigo.app.config.LogConfig) Test(org.junit.jupiter.api.Test)

Example 3 with LogConfig

use of io.vertigo.app.config.LogConfig in project vertigo by KleeGroup.

the class AppServletStarter method contextInitialized.

/**
 * Initialize and start Vertigo Home.
 * @param servletContext ServletContext
 */
public void contextInitialized(final ServletContext servletContext) {
    final long start = System.currentTimeMillis();
    try {
        // Initialisation du web context de l'application (porteur des singletons applicatifs)
        ServletResourceResolverPlugin.setServletContext(servletContext);
        // Création de l'état de l'application
        // Lecture des paramètres de configuration
        final Map<String, Param> webAppConf = createWebParams(servletContext);
        WebAppContextParamPlugin.setParams(webAppConf);
        // -----
        final Properties bootConf = createBootProperties(servletContext);
        Assertion.checkArgument(bootConf.containsKey("boot.applicationConfiguration"), "Param \"boot.applicationConfiguration\" is mandatory, check your .properties or web.xml.");
        final XMLAppConfigBuilder appConfigBuilder = new XMLAppConfigBuilder();
        appConfigBuilder.beginBoot();
        // si présent on récupère le paramétrage du fichier externe de paramétrage log4j
        if (bootConf.containsKey(LOG4J_CONFIGURATION_PARAM_NAME)) {
            final String logFileName = bootConf.getProperty(LOG4J_CONFIGURATION_PARAM_NAME);
            bootConf.remove(LOG4J_CONFIGURATION_PARAM_NAME);
            // -----
            appConfigBuilder.withLogConfig(new LogConfig(logFileName));
        }
        final String xmlModulesFileNames = bootConf.getProperty("boot.applicationConfiguration");
        final String[] xmlFileNamesSplit = xmlModulesFileNames.split(";");
        bootConf.remove("boot.applicationConfiguration");
        // -----
        appConfigBuilder.withModules(getClass(), bootConf, xmlFileNamesSplit);
        // Initialisation de l'état de l'application
        app = new AutoCloseableApp(appConfigBuilder.build());
        appServletListener.onServletStart(getClass().getName());
    } catch (final Exception e) {
        LOG.error(e.getMessage(), e);
        throw WrappedException.wrap(e, "Problème d'initialisation de l'application");
    } finally {
        if (LOG.isInfoEnabled()) {
            LOG.info("Temps d'initialisation du listener " + (System.currentTimeMillis() - start));
        }
    }
}
Also used : AutoCloseableApp(io.vertigo.app.AutoCloseableApp) Param(io.vertigo.core.param.Param) Properties(java.util.Properties) IOException(java.io.IOException) WrappedException(io.vertigo.lang.WrappedException) XMLAppConfigBuilder(io.vertigo.app.config.xml.XMLAppConfigBuilder) LogConfig(io.vertigo.app.config.LogConfig)

Example 4 with LogConfig

use of io.vertigo.app.config.LogConfig in project vertigo by KleeGroup.

the class ComponentSpace4Test method testStartedComponent.

@Test
public void testStartedComponent() {
    final AppConfig appConfig = AppConfig.builder().beginBoot().withLogConfig(new LogConfig("/log4j.xml")).endBoot().addModule(ModuleConfig.builder("Started").addComponent(StartedManager.class, StartedManagerImpl.class).build()).addInitializer(StartedManagerInitializer.class).build();
    final StartedManager startedManager;
    try (AutoCloseableApp app = new AutoCloseableApp(appConfig)) {
        startedManager = app.getComponentSpace().resolve(StartedManager.class);
        assertTrue(startedManager.isInitialized(), "Component StartedManager not Initialized");
        assertTrue(startedManager.isStarted(), "Component StartedManager not Started");
        assertTrue(startedManager.isAppPreActivated(), "Component StartedManager not PostStarted");
    }
    assertFalse(startedManager.isStarted(), "Component StartedManager not Stopped");
}
Also used : StartedManager(io.vertigo.core.spaces.component.data.StartedManager) AutoCloseableApp(io.vertigo.app.AutoCloseableApp) AppConfig(io.vertigo.app.config.AppConfig) StartedManagerInitializer(io.vertigo.core.spaces.component.data.StartedManagerInitializer) LogConfig(io.vertigo.app.config.LogConfig) Test(org.junit.jupiter.api.Test)

Aggregations

AutoCloseableApp (io.vertigo.app.AutoCloseableApp)4 LogConfig (io.vertigo.app.config.LogConfig)4 AppConfig (io.vertigo.app.config.AppConfig)3 Test (org.junit.jupiter.api.Test)3 MathPlugin (io.vertigo.core.spaces.component.data.MathPlugin)2 XMLAppConfigBuilder (io.vertigo.app.config.xml.XMLAppConfigBuilder)1 Param (io.vertigo.core.param.Param)1 BioManager (io.vertigo.core.spaces.component.data.BioManager)1 BioManagerImpl (io.vertigo.core.spaces.component.data.BioManagerImpl)1 DummyPlugin (io.vertigo.core.spaces.component.data.DummyPlugin)1 StartedManager (io.vertigo.core.spaces.component.data.StartedManager)1 StartedManagerInitializer (io.vertigo.core.spaces.component.data.StartedManagerInitializer)1 WrappedException (io.vertigo.lang.WrappedException)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1