Search in sources :

Example 71 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler 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)

Example 72 with SingletonAssembler

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

the class EventRouterTest method testData.

@Before
public void testData() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.values(UnitOfWorkDomainEventsValue.class, DomainEventValue.class);
        }
    };
    list = new ArrayList<UnitOfWorkDomainEventsValue>();
    {
        ValueBuilder<UnitOfWorkDomainEventsValue> builder = assembler.module().newValueBuilder(UnitOfWorkDomainEventsValue.class);
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test1"));
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test2"));
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test3"));
        builder.prototype().version().set("1.0");
        builder.prototype().timestamp().set(System.currentTimeMillis());
        builder.prototype().usecase().set("Test");
        list.add(builder.newInstance());
    }
    {
        ValueBuilder<UnitOfWorkDomainEventsValue> builder = assembler.module().newValueBuilder(UnitOfWorkDomainEventsValue.class);
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test4"));
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test5"));
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test6"));
        builder.prototype().version().set("1.0");
        builder.prototype().timestamp().set(System.currentTimeMillis());
        builder.prototype().usecase().set("Test2");
        list.add(builder.newInstance());
    }
}
Also used : ValueBuilder(org.qi4j.api.value.ValueBuilder) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) UnitOfWorkDomainEventsValue(org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue) Before(org.junit.Before)

Example 73 with SingletonAssembler

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

the class HelloWorldCompositeTest method testEntity.

@Test
public void testEntity() throws UnitOfWorkCompletionException, IOException {
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.entities(TestEntity.class).withMixins(ScalaTraitMixin.class);
            module.services(TestService.class).withMixins(ScalaTraitMixin.class);
            new EntityTestAssembler().assemble(module);
            new RdfMemoryStoreAssembler().assemble(module);
        }
    };
    // Create and update Entity
    UnitOfWork uow = assembler.module().newUnitOfWork();
    try {
        Commands entity = uow.newEntity(Commands.class);
        entity.updateFoo("Foo");
        Data data = uow.get(Data.class, entity.toString());
        Assert.assertEquals("FooFoo", data.foo().get());
    } finally {
        uow.complete();
    }
    assembler.module().findService(IndexExporter.class).get().exportReadableToStream(System.out);
    // Find it
    uow = assembler.module().newUnitOfWork();
    try {
        Data data = uow.newQuery(assembler.module().newQueryBuilder(Data.class).where(eq(templateFor(Data.class).foo(), "FooFoo"))).find();
        Assert.assertEquals("FooFoo", data.foo().get());
    } finally {
        uow.discard();
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) RdfMemoryStoreAssembler(org.qi4j.index.rdf.assembly.RdfMemoryStoreAssembler) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) Test(org.junit.Test)

Example 74 with SingletonAssembler

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

the class HelloWorldCompositeTest method testComposite.

@Test
public void testComposite() {
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(HelloWorldComposite.class, HelloWorldComposite2.class).withMixins(ScalaTraitMixin.class).withConcerns(ExclamationGenericConcern.class);
        }
    };
    HelloWorldComposite composite = assembler.module().newTransient(HelloWorldComposite.class);
    Assert.assertEquals("Do stuff!", composite.doStuff());
    Assert.assertEquals("Hello there World!", composite.sayHello("World"));
    try {
        composite.sayHello("AReallyReallyLongName");
    } catch (ConstraintViolationException e) {
    // Ok!
    }
    HelloWorldComposite2 composite2 = assembler.module().newTransient(HelloWorldComposite2.class);
    Assert.assertEquals("Do custom stuff!", composite2.doStuff());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ScalaTraitMixin(org.qi4j.lang.scala.ScalaTraitMixin) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) ConstraintViolationException(org.qi4j.api.constraint.ConstraintViolationException) Test(org.junit.Test)

Example 75 with SingletonAssembler

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

the class FileConfigurationTest method testFileConfiguration.

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

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            // START SNIPPET: simple
            new FileConfigurationAssembler().assemble(module);
        // END SNIPPET: simple
        }
    };
    FileConfiguration config = assembler.module().findService(FileConfiguration.class).get();
    File confDir = config.configurationDirectory();
    System.out.println(confDir);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) File(java.io.File) 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