use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.
the class TypeToCompositeLookupTest method entitiesAmbiguousDeclaration.
@Test
public void entitiesAmbiguousDeclaration() throws UnitOfWorkCompletionException, ActivationException, AssemblyException {
Module module = new SingletonAssembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
new EntityTestAssembler().assemble(module);
module.entities(SomeOtherFoo.class, BasicFoo.class);
}
}.module();
UnitOfWork uow = module.newUnitOfWork();
SomeOtherFoo someOtherFoo = uow.newEntityBuilder(SomeOtherFoo.class).newInstance();
BasicFoo basicFoo = uow.newEntityBuilder(BasicFoo.class).newInstance();
try {
uow.newEntityBuilder(Foo.class).newInstance();
fail("Ambiguous type exception not detected for Entities");
} catch (AmbiguousTypeException expected) {
}
// Specific Type used
assertEquals(CATHEDRAL, uow.newEntityBuilder(SomeOtherFoo.class).newInstance().bar());
// Specific Type used
assertEquals(BAZAR, uow.newEntityBuilder(BasicFoo.class).newInstance().bar());
String someOtherFooIdentity = ((Identity) someOtherFoo).identity().get();
String basicFooIdentity = ((Identity) basicFoo).identity().get();
uow.complete();
uow = module.newUnitOfWork();
assertEquals(CATHEDRAL, uow.get(SomeOtherFoo.class, someOtherFooIdentity).bar());
assertEquals(BAZAR, uow.get(BasicFoo.class, basicFooIdentity).bar());
assertEquals(CATHEDRAL, uow.get(Foo.class, someOtherFooIdentity).bar());
assertEquals(BAZAR, uow.get(Foo.class, basicFooIdentity).bar());
uow.discard();
}
use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.
the class TypeToCompositeLookupTest method valuesAmbiguousDeclaration.
@Test
public void valuesAmbiguousDeclaration() throws ActivationException, AssemblyException {
Module module = new SingletonAssembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
module.values(SomeOtherFoo.class, BasicFoo.class);
}
}.module();
assertEquals(CATHEDRAL, module.newValueBuilder(SomeOtherFoo.class).newInstance().bar());
assertEquals(BAZAR, module.newValueBuilder(BasicFoo.class).newInstance().bar());
try {
module.newValueBuilder(Foo.class);
fail("Ambiguous type exception not detected for Values");
} catch (AmbiguousTypeException expected) {
}
}
use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.
the class TypeToCompositeLookupTest method transients.
@Test
public void transients() throws ActivationException, AssemblyException {
Module module = new SingletonAssembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
module.transients(SomeOtherFoo.class);
}
}.module();
assertEquals(CATHEDRAL, module.newTransientBuilder(SomeOtherFoo.class).newInstance().bar());
assertEquals(CATHEDRAL, module.newTransientBuilder(BasicFoo.class).newInstance().bar());
assertEquals(CATHEDRAL, module.newTransientBuilder(Foo.class).newInstance().bar());
}
use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.
the class TypeToCompositeLookupTest method servicesPluralDeclaration.
@Test
public void servicesPluralDeclaration() throws ActivationException, AssemblyException {
Module module = new SingletonAssembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
module.services(SomeOtherFoo.class, BasicFoo.class);
}
}.module();
assertEquals(1, Iterables.count(module.findServices(SomeOtherFoo.class)));
assertEquals(2, Iterables.count(module.findServices(BasicFoo.class)));
assertEquals(2, Iterables.count(module.findServices(Foo.class)));
assertEquals(CATHEDRAL, module.findService(SomeOtherFoo.class).get().bar());
// Exact type match first even if it is assembled _after_ an assignable, the assignable comes after
Iterator<ServiceReference<BasicFoo>> basicFoos = module.findServices(BasicFoo.class).iterator();
assertEquals(BAZAR, basicFoos.next().get().bar());
assertEquals(CATHEDRAL, basicFoos.next().get().bar());
assertFalse(basicFoos.hasNext());
// No exact type match, all assembled are assignable, follows assembly Type order
Iterator<ServiceReference<Foo>> foos = module.findServices(Foo.class).iterator();
assertEquals(CATHEDRAL, foos.next().get().bar());
assertEquals(BAZAR, foos.next().get().bar());
assertFalse(foos.hasNext());
}
use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.
the class TransientBuilderFactoryTest method newInstanceForRegisteredComposite.
/**
* Tests that an object can be created for an registered object class.
*/
@Test
public void newInstanceForRegisteredComposite() throws ActivationException, AssemblyException {
SingletonAssembler assembler = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.transients(AnyComposite.class);
}
};
assembler.module().newTransientBuilder(AnyComposite.class);
}
Aggregations