Search in sources :

Example 61 with SingletonAssembler

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();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) Module(org.qi4j.api.structure.Module) AmbiguousTypeException(org.qi4j.api.composite.AmbiguousTypeException) Test(org.junit.Test)

Example 62 with SingletonAssembler

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) {
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Module(org.qi4j.api.structure.Module) AmbiguousTypeException(org.qi4j.api.composite.AmbiguousTypeException) Test(org.junit.Test)

Example 63 with SingletonAssembler

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());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Module(org.qi4j.api.structure.Module) Test(org.junit.Test)

Example 64 with SingletonAssembler

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());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Module(org.qi4j.api.structure.Module) ServiceReference(org.qi4j.api.service.ServiceReference) Test(org.junit.Test)

Example 65 with SingletonAssembler

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);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Aggregations

ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)87 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)87 Test (org.junit.Test)65 Module (org.qi4j.api.structure.Module)15 AssemblyException (org.qi4j.bootstrap.AssemblyException)14 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)13 Before (org.junit.Before)11 Application (org.qi4j.api.structure.Application)10 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)5 AmbiguousTypeException (org.qi4j.api.composite.AmbiguousTypeException)4 ServiceReference (org.qi4j.api.service.ServiceReference)4 ArrayList (java.util.ArrayList)3 TransientBuilderFactory (org.qi4j.api.composite.TransientBuilderFactory)3 ObjectFactory (org.qi4j.api.object.ObjectFactory)3 ValueBuilder (org.qi4j.api.value.ValueBuilder)3 UnitOfWorkDomainEventsValue (org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue)3 File (java.io.File)2 BeforeClass (org.junit.BeforeClass)2 Ignore (org.junit.Ignore)2 ServiceDeclaration (org.qi4j.bootstrap.ServiceDeclaration)2