Search in sources :

Example 1 with AmbiguousTypeException

use of org.qi4j.api.composite.AmbiguousTypeException in project qi4j-sdk by Qi4j.

the class TypeToCompositeLookupTest method transientsAmbiguousDeclaration.

@Test
public void transientsAmbiguousDeclaration() throws ActivationException, AssemblyException {
    Module module = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(SomeOtherFoo.class, BasicFoo.class);
        }
    }.module();
    assertEquals(CATHEDRAL, module.newTransientBuilder(SomeOtherFoo.class).newInstance().bar());
    assertEquals(BAZAR, module.newTransientBuilder(BasicFoo.class).newInstance().bar());
    try {
        module.newTransientBuilder(Foo.class);
        fail("Ambiguous type exception not detected for Transients");
    } 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 2 with AmbiguousTypeException

use of org.qi4j.api.composite.AmbiguousTypeException in project qi4j-sdk by Qi4j.

the class TypeToCompositeLookupTest method objectsAmbiguousDeclaration.

@Test
public void objectsAmbiguousDeclaration() throws ActivationException, AssemblyException {
    Module module = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(SomeOtherFooImpl.class, BasicFooImpl.class);
        }
    }.module();
    assertEquals(CATHEDRAL, module.newObject(SomeOtherFooImpl.class).bar());
    assertEquals(BAZAR, module.newObject(BasicFooImpl.class).bar());
    try {
        module.newObject(Foo.class);
        fail("Ambiguous type exception not detected for Objects");
    } 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 3 with AmbiguousTypeException

use of org.qi4j.api.composite.AmbiguousTypeException 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 4 with AmbiguousTypeException

use of org.qi4j.api.composite.AmbiguousTypeException 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)

Aggregations

Test (org.junit.Test)4 AmbiguousTypeException (org.qi4j.api.composite.AmbiguousTypeException)4 Module (org.qi4j.api.structure.Module)4 AssemblyException (org.qi4j.bootstrap.AssemblyException)4 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)4 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)4 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)1 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)1