Package org.qi4j.bootstrap

Examples of org.qi4j.bootstrap.SingletonAssembler


    @Test
    public void testInjectionServiceBetweenModules()
        throws ActivationException, AssemblyException
    {
        SingletonAssembler assembly = new SingletonAssembler()
        {
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                module.services( MyServiceComposite.class )
View Full Code Here


    @Test
    public void testInjectionServiceBetweenLayers()
        throws ActivationException, AssemblyException
    {
        SingletonAssembler assembly = new SingletonAssembler()
        {
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                module.services( MyServiceComposite.class )
View Full Code Here

    @Test( expected = ConstructionException.class )
    public void testMissingServiceDependency()
        throws ActivationException, AssemblyException
    {
        // No service fulfils the dependency injection -> fail to create application
        new SingletonAssembler()
        {
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                module.objects( ServiceUser.class );
View Full Code Here

{
    @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();
View Full Code Here

{
    @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 );
    }
View Full Code Here

        final File confDir = testFile;
        final File dataDir = testFile;
        final File tempDir = testFile;
        final File cacheDir = testFile;
        final File logDir = testFile;
        SingletonAssembler assembler = new SingletonAssembler()
        {
            @Override
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                // START SNIPPET: override
                FileConfigurationOverride override = new FileConfigurationOverride().
                    withConfiguration( confDir ).
                    withData( dataDir ).
                    withTemporary( tempDir ).
                    withCache( cacheDir ).
                    withLog( logDir );
                new FileConfigurationAssembler().withOverride( override ).assemble( module );
                // END SNIPPET: override
            }
        };

        FileConfiguration config = assembler.module().findService( FileConfiguration.class ).get();

        assertEquals( testFile.getAbsolutePath(), config.configurationDirectory().getAbsolutePath() );
    }
View Full Code Here

{
    @Test
    public void testLiquibase()
        throws SQLException, IOException, ActivationException, AssemblyException
    {
        final SingletonAssembler assembler = new SingletonAssembler()
        {
            @Override
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                ModuleAssembly configModule = module;
                // Create in-memory store for configurations
                new EntityTestAssembler().assemble( configModule );

                new C3P0DataSourceServiceAssembler().
                    identifiedBy( "datasource-service" ).
                    withConfig( configModule, Visibility.layer ).
                    assemble( module );
                new DataSourceAssembler().
                    withDataSourceServiceIdentity( "datasource-service" ).
                    identifiedBy( "testds-liquibase" ).
                    withCircuitBreaker().
                    assemble( module );

                module.values( SomeValue.class );

                // Set up Liquibase service that will create the tables
                // START SNIPPET: assembly
                new LiquibaseAssembler().
                    withConfig( configModule, Visibility.layer ).
                    assemble( module );
                // END SNIPPET: assembly
                module.forMixin( LiquibaseConfiguration.class ).declareDefaults().enabled().set( true );
                module.forMixin( LiquibaseConfiguration.class ).declareDefaults().changeLog().set( "changelog.xml" );
            }

            @Override
            public void beforeActivation( Application application )
            {
                application.registerActivationEventListener( new ActivationEventListener()
                {

                    @Override
                    public void onEvent( ActivationEvent event )
                    {
                        System.out.println( event );
                    }

                } );
            }

        };

        Module module = assembler.module();

        // START SNIPPET: io
        // Look up the DataSource
        DataSource ds = module.findService( DataSource.class ).get();

        // Instanciate Databases helper
        Databases database = new Databases( ds );

        // Assert that insertion works
        assertTrue( database.update( "insert into test values ('someid', 'bar')" ) == 1 );
        // END SNIPPET: io

        database.query( "select * from test", new Databases.ResultSetVisitor()
        {
            @Override
            public boolean visit( ResultSet visited )
                throws SQLException
            {
                assertThat( visited.getString( "id" ), equalTo( "someid" ) );
                assertThat( visited.getString( "foo" ), equalTo( "bar" ) );

                return true;
            }
        } );

        Function<ResultSet, SomeValue> toValue = new Function<ResultSet, SomeValue>()
        {
            @Override
            public SomeValue map( ResultSet resultSet )
            {
                ValueBuilder<SomeValue> builder = assembler.module().newValueBuilder( SomeValue.class );
                try
                {
                    builder.prototype().id().set( resultSet.getString( "id" ) );
                    builder.prototype().foo().set( resultSet.getString( "foo" ) );
                }
View Full Code Here

{
    @Test
    public void testWhenDependentMixinsThenOrderMixins()
        throws Exception
    {
        Module module = new SingletonAssembler()
        {
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                module.transients( TestComposite1.class );
View Full Code Here

{

    public static void main( String[] args )
        throws ActivationException, AssemblyException
    {
        SingletonAssembler assembler = new SingletonAssembler()
        {

            @Override
            // START SNIPPET: jmx
            public void assemble( ModuleAssembly module )
                    throws AssemblyException
            {
                // END SNIPPET: jmx
                CircuitBreaker cb = new CircuitBreaker( 3, 250, CircuitBreakers.in( IllegalArgumentException.class ) );

                module.importedServices( TestService.class ).setMetaInfo( new TestService( cb ) );

                // START SNIPPET: jmx
                // JMX Library
                module.importedServices( MBeanServer.class ).
                    importedBy( MBeanServerImporter.class );
                // CircuitBreakers in JMX
                module.services( CircuitBreakerManagement.class ).
                    instantiateOnStartup();
            }
            // END SNIPPET: jmx

        };

        TestService service = assembler.module().<TestService>findService( TestService.class ).get();

        int interval = 1; // Seconds
        System.out.println( "CircuitBreaker JMX Support sample is now started." );
        System.out.println();
        System.out.println( "A Service that randomly output some text or fail is called through a CircuitBreaker every " + interval + " seconds." );
View Full Code Here

{
    @Test
    public void givenManyServicesWhenInjectServiceThenGetFirstOne()
        throws ActivationException, AssemblyException
    {
        SingletonAssembler assembler = new SingletonAssembler()
        {
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                module.objects( ServiceConsumer.class );
                module.services( TestServiceComposite1.class,
                                 TestServiceComposite2.class );
            }
        };

        TestService service = assembler.module().newObject( ServiceConsumer.class ).getService();

        assertThat( "service is first one", service.test(), equalTo( "mixin1" ) );
    }
View Full Code Here

TOP

Related Classes of org.qi4j.bootstrap.SingletonAssembler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.