Search in sources :

Example 1 with ApplicationBuilder

use of org.qi4j.bootstrap.builder.ApplicationBuilder in project qi4j-sdk by Qi4j.

the class PassivationExceptionTest method testPassivationExceptionsAccrossStructure.

@Test
public void testPassivationExceptionsAccrossStructure() throws AssemblyException, ActivationException {
    ApplicationBuilder appBuilder = new ApplicationBuilder("TestApplication");
    appBuilder.withLayer("Layer 1").withModule("Module A").withAssembler(new Assembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.services(TestService.class).identifiedBy("TestService_Module.A").withActivators(FailBeforePassivationServiceActivator.class).instantiateOnStartup();
        }
    });
    appBuilder.withLayer("Layer 2").withModule("Module B").withAssembler(new Assembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.services(TestService.class).identifiedBy("TestService_Module.B").withActivators(FailAfterPassivationServiceActivator.class).instantiateOnStartup();
        }
    });
    appBuilder.registerActivationEventListener(new TestActivationEventListener());
    Application app = appBuilder.newApplication();
    try {
        Module moduleA = app.findModule("Layer 1", "Module A");
        TestService service = moduleA.findService(TestService.class).get();
        assertThat(service.hello(), equalTo("Hello Qi4j!"));
    } finally {
        try {
            app.passivate();
            fail("No PassivationException");
        } catch (PassivationException ex) {
            ex.printStackTrace();
            String stack = stack(ex);
            assertThat(ex.getMessage(), containsString("has 12 cause(s)"));
            assertThat(stack, containsString("EVENT: FAIL BEFORE PASSIVATION for TestApplication"));
            assertThat(stack, containsString("EVENT: FAIL BEFORE PASSIVATION for Layer 2"));
            assertThat(stack, containsString("EVENT: FAIL BEFORE PASSIVATION for Module B"));
            assertThat(stack, containsString("ACTIVATOR: FAIL AFTER PASSIVATION for TestService_Module.B(active=false,module='Module B')"));
            assertThat(stack, containsString("EVENT: FAIL AFTER PASSIVATION for Module B"));
            assertThat(stack, containsString("EVENT: FAIL AFTER PASSIVATION for Layer 2"));
            assertThat(stack, containsString("EVENT: FAIL BEFORE PASSIVATION for Layer 1"));
            assertThat(stack, containsString("EVENT: FAIL BEFORE PASSIVATION for Module A"));
            assertThat(stack, containsString("ACTIVATOR: FAIL BEFORE PASSIVATION for TestService_Module.A(active=true,module='Module A')"));
            assertThat(stack, containsString("EVENT: FAIL AFTER PASSIVATION for Module A"));
            assertThat(stack, containsString("EVENT: FAIL AFTER PASSIVATION for Layer 1"));
            assertThat(stack, containsString("EVENT: FAIL AFTER PASSIVATION for TestApplication"));
        }
    }
}
Also used : ApplicationBuilder(org.qi4j.bootstrap.builder.ApplicationBuilder) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) Assembler(org.qi4j.bootstrap.Assembler) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Module(org.qi4j.api.structure.Module) Application(org.qi4j.api.structure.Application) Test(org.junit.Test)

Aggregations

StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 Test (org.junit.Test)1 Application (org.qi4j.api.structure.Application)1 Module (org.qi4j.api.structure.Module)1 Assembler (org.qi4j.bootstrap.Assembler)1 AssemblyException (org.qi4j.bootstrap.AssemblyException)1 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)1 ApplicationBuilder (org.qi4j.bootstrap.builder.ApplicationBuilder)1