Search in sources :

Example 26 with AssemblyException

use of org.qi4j.bootstrap.AssemblyException 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 27 with AssemblyException

use of org.qi4j.bootstrap.AssemblyException 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 28 with AssemblyException

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

the class AbstractQi4jBaseTest method newApplication.

protected ApplicationDescriptor newApplication() throws AssemblyException {
    ApplicationAssembler assembler = new ApplicationAssembler() {

        @Override
        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            ApplicationAssembly applicationAssembly = applicationFactory.newApplicationAssembly();
            applicationAssembly.setMode(Application.Mode.test);
            defineApplication(applicationAssembly);
            return applicationAssembly;
        }
    };
    try {
        return qi4j.newApplicationModel(assembler);
    } catch (AssemblyException e) {
        assemblyException(e);
        return null;
    }
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly)

Example 29 with AssemblyException

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

the class AbstractQi4jScenarioTest method newApplication.

protected static ApplicationDescriptor newApplication() throws AssemblyException {
    final Assembler asm = assembler;
    ApplicationAssembler assembler = new ApplicationAssembler() {

        @Override
        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            return applicationFactory.newApplicationAssembly(asm);
        }
    };
    try {
        return qi4j.newApplicationModel(assembler);
    } catch (AssemblyException e) {
        assemblyException(e);
        return null;
    }
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Assembler(org.qi4j.bootstrap.Assembler)

Example 30 with AssemblyException

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

the class MigrationTest method testMigration.

@Test
public void testMigration() throws UnitOfWorkCompletionException, IOException, ActivationException, AssemblyException {
    // Set up version 1
    String id;
    StringInputOutput data_v1 = new StringInputOutput();
    {
        SingletonAssembler v1 = new SingletonAssembler() {

            @Override
            public void assemble(ModuleAssembly module) throws AssemblyException {
                MigrationTest.this.assemble(module);
                module.layer().application().setVersion("1.0");
            }
        };
        UnitOfWork uow = v1.module().newUnitOfWork();
        TestEntity1_0 entity = uow.newEntity(TestEntity1_0.class);
        entity.foo().set("Some value");
        entity.fooManyAssoc().add(entity);
        entity.fooAssoc().set(entity);
        id = entity.identity().get();
        uow.complete();
        BackupRestore backupRestore = v1.module().findService(BackupRestore.class).get();
        backupRestore.backup().transferTo(data_v1);
    }
    // Set up version 1.1
    StringInputOutput data_v1_1 = new StringInputOutput();
    {
        SingletonAssembler v1_1 = new SingletonAssembler() {

            @Override
            public void assemble(ModuleAssembly module) throws AssemblyException {
                MigrationTest.this.assemble(module);
                module.layer().application().setVersion("1.1");
            }
        };
        BackupRestore testData = v1_1.module().findService(BackupRestore.class).get();
        data_v1.transferTo(testData.restore());
        UnitOfWork uow = v1_1.module().newUnitOfWork();
        TestEntity1_1 entity = uow.get(TestEntity1_1.class, id);
        assertThat("Property has been renamed", entity.newFoo().get(), CoreMatchers.equalTo("Some value"));
        assertThat("ManyAssociation has been renamed", entity.newFooManyAssoc().count(), CoreMatchers.equalTo(1));
        assertThat("Association has been renamed", entity.newFooAssoc().get(), CoreMatchers.equalTo(entity));
        uow.complete();
        testData.backup().transferTo(data_v1_1);
    }
    // Set up version 2.0
    {
        SingletonAssembler v2_0 = new SingletonAssembler() {

            @Override
            public void assemble(ModuleAssembly module) throws AssemblyException {
                MigrationTest.this.assemble(module);
                module.layer().application().setVersion("2.0");
            }
        };
        BackupRestore testData = v2_0.module().findService(BackupRestore.class).get();
        // Test migration from 1.0 -> 2.0
        {
            data_v1.transferTo(testData.restore());
            UnitOfWork uow = v2_0.module().newUnitOfWork();
            TestEntity2_0 entity = uow.get(TestEntity2_0.class, id);
            assertThat("Property has been created", entity.bar().get(), CoreMatchers.equalTo("Some value"));
            assertThat("Custom Property has been created", entity.customBar().get(), CoreMatchers.equalTo("Hello Some value"));
            assertThat("ManyAssociation has been renamed", entity.newFooManyAssoc().count(), CoreMatchers.equalTo(1));
            assertThat("Association has been renamed", entity.newFooAssoc().get(), CoreMatchers.equalTo(entity));
            uow.complete();
        }
    }
    // Set up version 3.0
    {
        SingletonAssembler v3_0 = new SingletonAssembler() {

            @Override
            public void assemble(ModuleAssembly module) throws AssemblyException {
                MigrationTest.this.assemble(module);
                module.layer().application().setVersion("3.0");
            }
        };
        BackupRestore testData = v3_0.module().findService(BackupRestore.class).get();
        data_v1_1.transferTo(testData.restore());
        // Test migration from 1.0 -> 3.0
        {
            data_v1.transferTo(testData.restore());
            UnitOfWork uow = v3_0.module().newUnitOfWork();
            org.qi4j.migration.moved.TestEntity2_0 entity = uow.get(org.qi4j.migration.moved.TestEntity2_0.class, id);
            uow.complete();
        }
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) BackupRestore(org.qi4j.spi.entitystore.BackupRestore) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Aggregations

AssemblyException (org.qi4j.bootstrap.AssemblyException)38 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)27 Test (org.junit.Test)23 Module (org.qi4j.api.structure.Module)14 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)14 IOException (java.io.IOException)10 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)10 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)10 Assembler (org.qi4j.bootstrap.Assembler)10 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)9 Application (org.qi4j.api.structure.Application)8 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)8 Energy4Java (org.qi4j.bootstrap.Energy4Java)8 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)5 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)5 AmbiguousTypeException (org.qi4j.api.composite.AmbiguousTypeException)4 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JettyConfiguration (org.qi4j.library.http.JettyConfiguration)2