use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.
the class PassivationTest method givenSuccessPassivationWhenPassivatingExpectNoExceptions.
@Test
public void givenSuccessPassivationWhenPassivatingExpectNoExceptions() throws Throwable {
SingletonAssembler assembly = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
module.addServices(DataAccessService.class).withActivators(PassivationSuccessActivator.class);
}
};
Iterable<ServiceReference<DataAccess>> iterable = assembly.module().findServices(DataAccess.class);
for (ServiceReference<DataAccess> service : iterable) {
assertTrue("Service should not be Active before accessed", !service.isActive());
assertTrue(service.get().data().activated);
assertTrue("Service should be Active after access.", service.isActive());
}
assembly.application().passivate();
}
use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.
the class ServiceIdSelectorTest method givenManyServicesWhenInjectServiceThenGetSelectedOne.
@Test
public void givenManyServicesWhenInjectServiceThenGetSelectedOne() throws ActivationException, AssemblyException {
SingletonAssembler assembler = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.objects(ServiceConsumer.class);
module.services(TestServiceComposite1.class, TestServiceComposite2.class);
}
};
ObjectFactory obf = assembler.module();
ServiceConsumer consumer = obf.newObject(ServiceConsumer.class, TestServiceComposite2.class.getSimpleName());
TestService service = consumer.getService();
assertThat("service is selected one", service.test(), equalTo("mixin2"));
}
use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.
the class IterableQuerySourceTest method setUp.
@Before
public void setUp() throws UnitOfWorkCompletionException, ActivationException, AssemblyException {
SingletonAssembler assembler = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
Iterable<Class<?>> entities = ClassScanner.findClasses(DomainEntity.class);
for (Class entity : entities) {
module.entities(entity);
}
module.values(ContactsValue.class, ContactValue.class);
new EntityTestAssembler().assemble(module);
}
};
uow = assembler.module().newUnitOfWork();
Network.populate(uow, assembler.module());
uow.complete();
uow = assembler.module().newUnitOfWork();
Network.refresh(uow);
qbf = assembler.module();
}
use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.
the class ValueComposite2Test method testServiceAndStructureInjectionsAllowedInValueComposite.
@Test
public void testServiceAndStructureInjectionsAllowedInValueComposite() throws ActivationException, AssemblyException {
SingletonAssembler app = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.values(SomeValue.class);
module.services(DummyService.class);
}
};
ValueBuilder<Some> builder = app.module().newValueBuilder(Some.class);
Some prototype = builder.prototype();
Property<String> otherProperty = prototype.other();
otherProperty.set("Abc");
Some value = builder.newInstance();
Assert.assertEquals(value.other().get(), "Abc");
}
use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.
the class TypeToCompositeLookupTest method entities.
@Test
public void entities() throws UnitOfWorkCompletionException, ActivationException, AssemblyException {
Module module = new SingletonAssembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
new EntityTestAssembler().assemble(module);
module.entities(SomeOtherFoo.class);
}
}.module();
UnitOfWork uow = module.newUnitOfWork();
SomeOtherFoo someOtherFoo = uow.newEntityBuilder(SomeOtherFoo.class).newInstance();
BasicFoo basicFoo = uow.newEntityBuilder(BasicFoo.class).newInstance();
Foo foo = uow.newEntityBuilder(Foo.class).newInstance();
assertEquals(CATHEDRAL, someOtherFoo.bar());
assertEquals(CATHEDRAL, basicFoo.bar());
assertEquals(CATHEDRAL, foo.bar());
String someOtherFooIdentity = ((Identity) someOtherFoo).identity().get();
String basicFooIdentity = ((Identity) basicFoo).identity().get();
String fooIdentity = ((Identity) foo).identity().get();
uow.complete();
uow = module.newUnitOfWork();
uow.get(SomeOtherFoo.class, someOtherFooIdentity);
uow.get(BasicFoo.class, basicFooIdentity);
uow.get(Foo.class, fooIdentity);
uow.discard();
}
Aggregations