Search in sources :

Example 1 with SingletonAssembler

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

the class OperatorsTest method testOperators.

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

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            new EntityTestAssembler().assemble(module);
            module.entities(TestEntity.class);
            module.values(TestValue.class);
            module.forMixin(TestEntity.class).declareDefaults().foo().set("Bar");
            module.forMixin(TestValue.class).declareDefaults().bar().set("Xyz");
        }
    };
    UnitOfWork uow = assembler.module().newUnitOfWork();
    try {
        EntityBuilder<TestEntity> entityBuilder = uow.newEntityBuilder(TestEntity.class, "123");
        entityBuilder.instance().value().set(assembler.module().newValue(TestValue.class));
        TestEntity testEntity = entityBuilder.newInstance();
        uow.complete();
        uow = assembler.module().newUnitOfWork();
        Iterable<TestEntity> entities = Iterables.iterable(testEntity = uow.get(testEntity));
        QueryBuilder<TestEntity> builder = assembler.module().newQueryBuilder(TestEntity.class);
        {
            Specification<Composite> where = QueryExpressions.eq(QueryExpressions.templateFor(TestEntity.class).foo(), "Bar");
            Assert.assertTrue(where.satisfiedBy(testEntity));
            System.out.println(where);
        }
        {
            Specification<Composite> where = QueryExpressions.eq(QueryExpressions.templateFor(TestEntity.class).value().get().bar(), "Xyz");
            Assert.assertTrue(where.satisfiedBy(testEntity));
            System.out.println(where);
            Assert.assertTrue(builder.where(where).newQuery(entities).find().equals(testEntity));
        }
    } finally {
        uow.discard();
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) Specification(org.qi4j.functional.Specification) Test(org.junit.Test)

Example 2 with SingletonAssembler

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

the class ApplicationActivationTest method testApplicationActivator.

@Test
public void testApplicationActivator() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.layer().application().withActivators(TestedActivator.class);
        }
    };
    // Activate
    Application application = assembly.application();
    // Assert activated
    Assert.assertEquals("Activation Level", 2, activationLevel);
    // Passivate
    application.passivate();
    // Assert passivated
    Assert.assertEquals("Passivation Level", 2, passivationLevel);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Application(org.qi4j.api.structure.Application) Test(org.junit.Test)

Example 3 with SingletonAssembler

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

the class ImportedServiceActivationTest method testServiceImporterImportedServiceActivators.

@Test
public void testServiceImporterImportedServiceActivators() throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.importedServices(TestedService.class).importedBy(ImportedServiceDeclaration.SERVICE_IMPORTER).setMetaInfo("testimporter").withActivators(TestedActivator.class).importOnStartup();
            module.services(TestedServiceImporterService.class).identifiedBy("testimporter");
        }
    };
    Application application = assembler.application();
    assertEquals("Activation Level", 2, activationLevel);
    application.passivate();
    assertEquals("Passivation Level", 2, passivationLevel);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Application(org.qi4j.api.structure.Application) Test(org.junit.Test)

Example 4 with SingletonAssembler

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

the class InvocationInjectionTest method whenInvocationInjectionWithMethodWhenInjectedThenInjectMethod.

@Test
public void whenInvocationInjectionWithMethodWhenInjectedThenInjectMethod() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(MyComposite.class);
        }
    };
    MyComposite composite = assembly.module().newTransient(MyComposite.class);
    composite.doStuff();
    composite.doStuff();
    composite.doStuff2();
    composite.doStuff3();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 5 with SingletonAssembler

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

the class ServiceInjectionTest method testInjectService.

@Test
public void testInjectService() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.services(MyServiceComposite.class).identifiedBy("Foo").setMetaInfo(new ServiceName("Foo"));
            module.services(MyServiceComposite2.class).identifiedBy("Bar").setMetaInfo(new ServiceName("Bar"));
            module.services(StringService.class, LongService.class);
            module.objects(ServiceUser.class);
        }
    };
    testInjection(assembly);
}
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