Search in sources :

Example 66 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class TransientBuilderFactoryTest method testClassAsTransient.

@Test(expected = ConstraintViolationException.class)
public void testClassAsTransient() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(AnyTransient.class);
        }
    };
    AnyTransient anyTransient = assembler.module().newTransient(AnyTransient.class);
    assertThat(anyTransient.hello("me"), new IsEqual<String>("Hello ME from Module 1"));
    assertThat(anyTransient.hello("World"), new IsEqual<String>("Hello WORLD from ME"));
    anyTransient.hello("Universe");
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 67 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class TransientBuilderFactoryTest method newBuilderForUnregisteredComposite.

/**
     * Tests that an transient builder cannot be created for an unregistered object.
     *
     * @throws Exception expected
     */
@Test(expected = NoSuchTransientException.class)
public void newBuilderForUnregisteredComposite() throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
        }
    };
    assembler.module().newTransientBuilder(AnyComposite.class);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 68 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class TransientBuilderFactoryTest method newBuilderForNullType.

/**
     * Tests that an transient builder cannot be created for a 'null' type.
     *
     * @throws Exception expected
     */
@Test(expected = NullArgumentException.class)
public void newBuilderForNullType() throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
        }
    };
    assembler.module().newTransientBuilder(null);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 69 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class TransientBuilderFactoryTest method newBuilderForRegisteredComposite.

/**
     * Tests that an object builder can be created for an registered object.
     */
@Test
public void newBuilderForRegisteredComposite() 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)

Example 70 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class ServiceSelectorImporterTest method givenManyServicesAndFilterWhenInjectServiceThenGetSpecifiedOne.

@Test
public void givenManyServicesAndFilterWhenInjectServiceThenGetSpecifiedOne() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(ServiceConsumer.class);
            module.importedServices(TestService.class).importedBy(SERVICE_SELECTOR).setMetaInfo(ServiceQualifier.withId(TestServiceComposite2.class.getSimpleName()));
            ModuleAssembly module2 = module.layer().module("Other module");
            module2.services(TestServiceComposite2.class, TestServiceComposite2.class).visibleIn(Visibility.layer);
        }
    };
    TestService service = assembler.module().newObject(ServiceConsumer.class).getService();
    assertThat("service is specified one", service.test(), equalTo("mixin2"));
}
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