Search in sources :

Example 16 with Assembler

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

the class ModuleDeclaration method withAssembler.

/**
     * Declare Assembler.
     * @param assemblerClass Assembler class
     * @return This Module declaration
     * @throws AssemblyException not an Assembler or if unable to instanciate
     */
public ModuleDeclaration withAssembler(Class<?> assemblerClass) throws AssemblyException {
    Assembler assembler = createAssemblerInstance(assemblerClass);
    assemblers.add(assembler);
    return this;
}
Also used : Assembler(org.qi4j.bootstrap.Assembler)

Example 17 with Assembler

use of org.qi4j.bootstrap.Assembler 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)

Example 18 with Assembler

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

the class DocumentationSupport method assembledWithValuesModuleSerialization.

// END SNIPPET: io
@Test
public // TODO Include in each ValueSerialization extensions documentation
void assembledWithValuesModuleSerialization() throws Exception {
    Application app = new Energy4Java().newApplication(new ApplicationAssembler() {

        @Override
        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            Assembler[][][] pancakes = new Assembler[][][] { { { new Assembler() {

                @Override
                public void assemble(ModuleAssembly valuesModule) throws AssemblyException {
                    valuesModule.layer().setName("SINGLE-Layer");
                    valuesModule.setName("VALUES-Module");
                    valuesModule.values(SomeValue.class);
                }
            } }, { new Assembler() {

                @Override
                public void assemble(ModuleAssembly servicesModule) throws AssemblyException {
                    servicesModule.setName("SERVICES-Module");
                    Function<Application, Module> valuesModuleFinder = new Function<Application, Module>() {

                        @Override
                        public Module map(Application app) {
                            return app.findModule("SINGLE-Layer", "VALUES-Module");
                        }
                    };
                    new OrgJsonValueSerializationAssembler().withValuesModuleFinder(valuesModuleFinder).assemble(servicesModule);
                }
            } } } };
            return applicationFactory.newApplicationAssembly(pancakes);
        }
    });
    app.activate();
    try {
        Module valuesModule = app.findModule("SINGLE-Layer", "VALUES-Module");
        SomeValue someValue = someNewValueInstance(valuesModule);
        Module servicesModule = app.findModule("SINGLE-Layer", "SERVICES-Module");
        ValueSerialization valueSerialization = servicesModule.findService(ValueSerialization.class).get();
        String json = valueSerialization.serialize(someValue);
        assertThat(json, equalTo("{\"foo\":\"bar\"}"));
        SomeValue someNewValue = valueSerialization.deserialize(SomeValue.class, json);
        assertThat(someNewValue, equalTo(someValue));
    } finally {
        app.passivate();
    }
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) Function(org.qi4j.functional.Function) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) Assembler(org.qi4j.bootstrap.Assembler) OrgJsonValueSerializationAssembler(org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Module(org.qi4j.api.structure.Module) Application(org.qi4j.api.structure.Application) OrgJsonValueSerializationAssembler(org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 19 with Assembler

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

the class EntityVisibilityTest method setup.

@Before
public void setup() throws Exception {
    qi4j = new Energy4Java();
    Assembler[][][] assemblers = new Assembler[][][] { { // Layer Above
    { new AboveAssembler() } }, { // Layer From
    { // From Module
    new FromAssembler() }, { // Beside Module
    new BesideAssembler() } }, { // Layer Below
    { new BelowAssembler() } } };
    app = qi4j.newApplication(new ApplicationAssemblerAdapter(assemblers) {
    });
    app.activate();
    module = app.findModule("From Layer", "From");
}
Also used : Energy4Java(org.qi4j.bootstrap.Energy4Java) Assembler(org.qi4j.bootstrap.Assembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) ApplicationAssemblerAdapter(org.qi4j.bootstrap.ApplicationAssemblerAdapter) Before(org.junit.Before)

Example 20 with Assembler

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

the class ServiceVisibilityTest method setup.

@Before
public void setup() throws Exception {
    qi4j = new Energy4Java();
    Assembler[][][] assemblers = new Assembler[][][] { { // Layer Above
    { new AboveAssembler() } }, { // Layer From
    { // From Module
    new FromAssembler() }, { // Beside Module
    new BesideAssembler() } }, { // Layer Below
    { new BelowAssembler() } } };
    app = qi4j.newApplication(new ApplicationAssemblerAdapter(assemblers) {
    });
    app.activate();
    module = app.findModule("From Layer", "From");
}
Also used : Energy4Java(org.qi4j.bootstrap.Energy4Java) Assembler(org.qi4j.bootstrap.Assembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) ApplicationAssemblerAdapter(org.qi4j.bootstrap.ApplicationAssemblerAdapter) Before(org.junit.Before)

Aggregations

Assembler (org.qi4j.bootstrap.Assembler)34 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)23 Energy4Java (org.qi4j.bootstrap.Energy4Java)19 Test (org.junit.Test)17 ApplicationAssemblerAdapter (org.qi4j.bootstrap.ApplicationAssemblerAdapter)17 Application (org.qi4j.api.structure.Application)13 AssemblyException (org.qi4j.bootstrap.AssemblyException)10 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)9 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)8 IOException (java.io.IOException)6 Before (org.junit.Before)6 Module (org.qi4j.api.structure.Module)5 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)4 OrgJsonValueSerializationAssembler (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)4 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)3 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)3 DataSourceAssembler (org.qi4j.library.sql.assembly.DataSourceAssembler)3 DBCPDataSourceServiceAssembler (org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler)3 PostgreSQLEntityStoreAssembler (org.qi4j.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler)2 Connection (java.sql.Connection)1