use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class ApplicationDocs method createCustomerDomainModule.
private static void createCustomerDomainModule(LayerAssembly layer) {
ModuleAssembly assembly = layer.module("Customer Domain Module");
assembly.entities(CustomerEntity.class);
assembly.entities(CountryEntity.class);
assembly.transients(AddressComposite.class);
}
use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class ApplicationDocs method createPersistenceModule.
private static void createPersistenceModule(LayerAssembly layer) throws AssemblyException {
ModuleAssembly assembly = layer.module("Persistence Module");
// Someone has created an assembler for the Neo EntityStore
NeoAssembler neo = new NeoAssembler("./neostore");
neo.assemble(assembly);
}
use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class ActivationEventsTest method testSingleModuleSingleLazyService.
@Test
public void testSingleModuleSingleLazyService() throws Exception {
final List<ActivationEvent> events = new ArrayList<>();
SingletonAssembler assembler = new SingletonAssembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
module.services(TestServiceComposite.class);
}
@Override
protected void beforeActivation(Application application) {
application.registerActivationEventListener(new EventsRecorder(events));
}
};
Application application = assembler.application();
application.passivate();
Iterator<ActivationEvent> it = events.iterator();
// Activation
assertEvent(it.next(), ACTIVATING, "Application");
assertEvent(it.next(), ACTIVATING, "Layer");
assertEvent(it.next(), ACTIVATING, "Module");
// Lazy Service NOT activated
assertEvent(it.next(), ACTIVATED, "Module");
assertEvent(it.next(), ACTIVATED, "Layer");
assertEvent(it.next(), ACTIVATED, "Application");
// Passivation
assertEvent(it.next(), PASSIVATING, "Application");
assertEvent(it.next(), PASSIVATING, "Layer");
assertEvent(it.next(), PASSIVATING, "Module");
// Lazy Service NOT passivated
assertEvent(it.next(), PASSIVATED, "Module");
assertEvent(it.next(), PASSIVATED, "Layer");
assertEvent(it.next(), PASSIVATED, "Application");
assertFalse(it.hasNext());
events.clear();
application.activate();
Module module = assembler.module();
module.findService(TestService.class).get().test();
application.passivate();
for (ActivationEvent event : events) {
System.out.println(event);
}
it = events.iterator();
// Activation
assertEvent(it.next(), ACTIVATING, "Application");
assertEvent(it.next(), ACTIVATING, "Layer");
assertEvent(it.next(), ACTIVATING, "Module");
assertEvent(it.next(), ACTIVATED, "Module");
assertEvent(it.next(), ACTIVATED, "Layer");
assertEvent(it.next(), ACTIVATED, "Application");
// Lazy Service Activation
assertEvent(it.next(), ACTIVATING, "TestService");
assertEvent(it.next(), ACTIVATED, "TestService");
// Passivation
assertEvent(it.next(), PASSIVATING, "Application");
assertEvent(it.next(), PASSIVATING, "Layer");
assertEvent(it.next(), PASSIVATING, "Module");
assertEvent(it.next(), PASSIVATING, "TestService");
assertEvent(it.next(), PASSIVATED, "TestService");
assertEvent(it.next(), PASSIVATED, "Module");
assertEvent(it.next(), PASSIVATED, "Layer");
assertEvent(it.next(), PASSIVATED, "Application");
assertFalse(it.hasNext());
}
use of org.qi4j.bootstrap.ModuleAssembly 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"));
}
}
}
use of org.qi4j.bootstrap.ModuleAssembly 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();
}
}
Aggregations