Search in sources :

Example 76 with SingletonAssembler

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

the class Main method main.

public static void main(String[] args) throws Exception {
    SingletonAssembler singleton = new SingletonAssembler() {

        @Override
        public // START SNIPPET: assemble
        void assemble(ModuleAssembly module) throws AssemblyException {
            module.addServices(TravelPlanService.class).instantiateOnStartup().identifiedBy("ExpediaService");
            module.addServices(TravelPlanService.class).instantiateOnStartup().identifiedBy("OrbitzService");
        }
    };
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler)

Example 77 with SingletonAssembler

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

the class Qi4jImportServiceTest method givenImportedSpringServicesWhenServiceIsInjectedThenUseSpringService.

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

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(Qi4jImportServiceTest.class);
            new SpringImporterAssembler(appContext).assemble(module);
        }
    };
    assembler.module().injectTo(this);
    assertThat("service can be called", service.comment("beer"), equalTo("beer is good."));
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 78 with SingletonAssembler

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

the class Qi4jImportServiceTest method givenImportedSpringServicesWhenServicesAreFoundThenCanIdentifyByName.

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

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(Qi4jImportServiceTest.class);
            new SpringImporterAssembler(appContext).assemble(module);
        }
    };
    assembler.module().injectTo(this);
    CommentService foundService = ServiceQualifier.firstService(withId("commentService2"), finder.<CommentService>findServices(CommentService.class));
    assertThat("service with correct id has been selected", foundService.comment("pizza"), equalTo("pizza is good."));
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 79 with SingletonAssembler

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

the class Qi4jImportServiceTest method givenImportedSpringServicesWhenServicesAreInjectedThenCanIdentifyByName.

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

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(Qi4jImportServiceTest.class);
            new SpringImporterAssembler(appContext).assemble(module);
        }
    };
    assembler.module().injectTo(this);
    CommentService service = firstService(withId("commentService2"), services);
    assertThat("service with correct id has been selected", service.comment("pizza"), equalTo("pizza is good."));
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 80 with SingletonAssembler

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

the class DataSourceConfigurationManagerServiceTest method testDataSources.

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

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            new JMXAssembler().assemble(module);
            // Create in-memory store for configurations
            new EntityTestAssembler().visibleIn(Visibility.layer).assemble(module);
            // Set up DataSource service that will manage the connection pools
            new C3P0DataSourceServiceAssembler().identifiedBy("datasource-service").visibleIn(Visibility.layer).assemble(module);
            {
                ModuleAssembly testModule = module.layer().module("TestDS");
                // Create a specific DataSource that uses the "datasource" service to do the main work
                new DataSourceAssembler().withDataSourceServiceIdentity("datasource-service").identifiedBy("testds").visibleIn(Visibility.module).withCircuitBreaker(DataSources.newDataSourceCircuitBreaker()).assemble(testModule);
                // Set up Liquibase service that will create the tables
                testModule.services(LiquibaseService.class).identifiedBy("liquibase1").instantiateOnStartup();
                testModule.entities(LiquibaseConfiguration.class);
                testModule.forMixin(LiquibaseConfiguration.class).declareDefaults().enabled().set(true);
                testModule.forMixin(LiquibaseConfiguration.class).declareDefaults().changeLog().set("changelog.xml");
            }
            {
                ModuleAssembly testModule2 = module.layer().module("TestDS2");
                // Create another specific DataSource that uses the "datasource" service to do the main work
                // Use DataSourceAssembler to assemble the DataSource.
                new DataSourceAssembler().withDataSourceServiceIdentity("datasource-service").identifiedBy("testds2").visibleIn(Visibility.module).withCircuitBreaker(DataSources.newDataSourceCircuitBreaker()).assemble(testModule2);
                // Set up Liquibase service that will create the tables
                testModule2.services(LiquibaseService.class).identifiedBy("liquibase2").instantiateOnStartup();
                testModule2.entities(LiquibaseConfiguration.class);
                testModule2.forMixin(LiquibaseConfiguration.class).declareDefaults().enabled().set(true);
                testModule2.forMixin(LiquibaseConfiguration.class).declareDefaults().changeLog().set("changelog.xml");
            }
            // START SNIPPET: jmx
            new DataSourceJMXAssembler().visibleIn(Visibility.module).assemble(module);
        // END SNIPPET: jmx
        }
    };
//        assembler.application().findModule( "Layer 1","Test" ).objectBuilderFactory().newObjectBuilder( DataSourceConfigurationManagerServiceTest.class ).injectTo( this );
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) C3P0DataSourceServiceAssembler(org.qi4j.library.sql.c3p0.C3P0DataSourceServiceAssembler) DataSourceAssembler(org.qi4j.library.sql.assembly.DataSourceAssembler) DataSourceJMXAssembler(org.qi4j.library.sql.assembly.DataSourceJMXAssembler) JMXAssembler(org.qi4j.library.jmx.JMXAssembler) DataSourceJMXAssembler(org.qi4j.library.sql.assembly.DataSourceJMXAssembler) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) LiquibaseConfiguration(org.qi4j.library.sql.liquibase.LiquibaseConfiguration) LiquibaseService(org.qi4j.library.sql.liquibase.LiquibaseService) 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