You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by pa...@apache.org on 2016/11/28 18:27:26 UTC

[2/5] zest-java git commit: remove core/io usage from tests & helpers in libraries & extensions

remove core/io usage from tests & helpers in libraries & extensions


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/a660c710
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/a660c710
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/a660c710

Branch: refs/heads/develop
Commit: a660c7106925bbe5f7ae824fa5e051c972327f1c
Parents: ebe9f8c
Author: Paul Merlin <pa...@apache.org>
Authored: Mon Nov 28 17:28:24 2016 +0100
Committer: Paul Merlin <pa...@apache.org>
Committed: Mon Nov 28 17:45:06 2016 +0100

----------------------------------------------------------------------
 .../AbstractCollectionSerializationTest.java    |  18 ---
 .../jclouds/JCloudsMapEntityStoreMixin.java     |  47 ++----
 .../apache/zest/library/groovy/GroovyMixin.java |  24 +--
 .../sql/liquibase/LiquibaseServiceTest.java     |  24 ++-
 libraries/sql/src/docs/sql.txt                  |  15 +-
 .../zest/library/sql/common/Databases.java      | 156 ++++---------------
 ...taSourceConfigurationManagerServiceTest.java | 145 ++++-------------
 7 files changed, 96 insertions(+), 333 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/a660c710/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractCollectionSerializationTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractCollectionSerializationTest.java b/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractCollectionSerializationTest.java
index d843d6f..15ad941 100644
--- a/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractCollectionSerializationTest.java
+++ b/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractCollectionSerializationTest.java
@@ -44,11 +44,6 @@ import org.apache.zest.functional.Iterables;
 import org.apache.zest.test.AbstractZestTest;
 import org.junit.Test;
 
-import static org.apache.zest.io.Inputs.iterable;
-import static org.apache.zest.io.Inputs.text;
-import static org.apache.zest.io.Outputs.collection;
-import static org.apache.zest.io.Outputs.text;
-import static org.apache.zest.io.Transforms.map;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 
@@ -72,19 +67,6 @@ public class AbstractCollectionSerializationTest
     protected ValueSerialization valueSerialization;
 
     @Test
-    public void testIOString()
-        throws Exception
-    {
-        StringBuilder sb = new StringBuilder();
-        iterable( byteCollection() ).transferTo( map( valueSerialization.serialize(), text( sb ) ) );
-        String output = sb.toString();
-
-        List<Byte> list = new ArrayList<>();
-        text( output ).transferTo( map( valueSerialization.deserialize( module, Byte.class ), collection( list ) ) );
-        assertEquals( byteCollection(), list );
-    }
-
-    @Test
     public void givenPrimitiveArrayWithIntsWhenSerializingAndDeserializingExpectEquals()
         throws Exception
     {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/a660c710/extensions/entitystore-jclouds/src/main/java/org/apache/zest/entitystore/jclouds/JCloudsMapEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jclouds/src/main/java/org/apache/zest/entitystore/jclouds/JCloudsMapEntityStoreMixin.java b/extensions/entitystore-jclouds/src/main/java/org/apache/zest/entitystore/jclouds/JCloudsMapEntityStoreMixin.java
index 37c0d0e..f8c2ac1 100644
--- a/extensions/entitystore-jclouds/src/main/java/org/apache/zest/entitystore/jclouds/JCloudsMapEntityStoreMixin.java
+++ b/extensions/entitystore-jclouds/src/main/java/org/apache/zest/entitystore/jclouds/JCloudsMapEntityStoreMixin.java
@@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 import com.google.common.io.ByteSource;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -32,33 +31,33 @@ import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Scanner;
 import java.util.Set;
-import org.jclouds.ContextBuilder;
-import org.jclouds.apis.ApiMetadata;
-import org.jclouds.apis.Apis;
-import org.jclouds.blobstore.BlobStore;
-import org.jclouds.blobstore.BlobStoreContext;
-import org.jclouds.blobstore.domain.Blob;
-import org.jclouds.blobstore.domain.StorageMetadata;
-import org.jclouds.io.Payload;
-import org.jclouds.providers.ProviderMetadata;
-import org.jclouds.providers.Providers;
 import org.apache.zest.api.configuration.Configuration;
 import org.apache.zest.api.entity.EntityDescriptor;
 import org.apache.zest.api.entity.EntityReference;
 import org.apache.zest.api.injection.scope.This;
 import org.apache.zest.api.service.ServiceActivation;
 import org.apache.zest.io.Input;
-import org.apache.zest.io.Inputs;
 import org.apache.zest.io.Output;
-import org.apache.zest.io.Outputs;
 import org.apache.zest.io.Receiver;
 import org.apache.zest.io.Sender;
 import org.apache.zest.spi.entitystore.EntityNotFoundException;
 import org.apache.zest.spi.entitystore.EntityStoreException;
 import org.apache.zest.spi.entitystore.helpers.MapEntityStore;
+import org.jclouds.ContextBuilder;
+import org.jclouds.apis.ApiMetadata;
+import org.jclouds.apis.Apis;
+import org.jclouds.blobstore.BlobStore;
+import org.jclouds.blobstore.BlobStoreContext;
+import org.jclouds.blobstore.domain.Blob;
+import org.jclouds.blobstore.domain.StorageMetadata;
+import org.jclouds.io.Payload;
+import org.jclouds.providers.ProviderMetadata;
+import org.jclouds.providers.Providers;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -179,31 +178,15 @@ public class JCloudsMapEntityStoreMixin
         {
             throw new EntityNotFoundException( entityReference );
         }
-        InputStream input = null;
-        try
+        try( InputStream input = payload.openStream() )
         {
-            input = payload.openStream();
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            Inputs.byteBuffer( input, 4096 ).transferTo( Outputs.byteBuffer( baos ) );
-            return new StringReader( baos.toString( "UTF-8" ) );
+            String state = new Scanner( input, StandardCharsets.UTF_8.name() ).useDelimiter( "\\Z" ).next();
+            return new StringReader( state );
         }
         catch( IOException ex )
         {
             throw new EntityStoreException( "Unable to read entity state for: " + entityReference, ex );
         }
-        finally
-        {
-            if( input != null )
-            {
-                try
-                {
-                    input.close();
-                }
-                catch( IOException ignored )
-                {
-                }
-            }
-        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/zest-java/blob/a660c710/libraries/lang-groovy/src/main/java/org/apache/zest/library/groovy/GroovyMixin.java
----------------------------------------------------------------------
diff --git a/libraries/lang-groovy/src/main/java/org/apache/zest/library/groovy/GroovyMixin.java b/libraries/lang-groovy/src/main/java/org/apache/zest/library/groovy/GroovyMixin.java
index 2e55911..64449c5 100644
--- a/libraries/lang-groovy/src/main/java/org/apache/zest/library/groovy/GroovyMixin.java
+++ b/libraries/lang-groovy/src/main/java/org/apache/zest/library/groovy/GroovyMixin.java
@@ -32,12 +32,11 @@ import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Scanner;
 import org.apache.zest.api.common.AppliesTo;
 import org.apache.zest.api.common.AppliesToFilter;
 import org.apache.zest.api.composite.Composite;
 import org.apache.zest.api.injection.scope.This;
-import org.apache.zest.io.Inputs;
-import org.apache.zest.io.Outputs;
 
 /**
  * Generic mixin that implements interfaces by delegating to Groovy functions
@@ -75,8 +74,7 @@ public class GroovyMixin
 
     public GroovyMixin()
     {
-
-        groovyObjects = new HashMap<Class, GroovyObject>();
+        groovyObjects = new HashMap<>();
     }
 
     @Override
@@ -104,22 +102,12 @@ public class GroovyMixin
             GroovyObject groovyObject = groovyObjects.get( declaringClass );
             if( groovyObject == null )
             {
-                InputStream is = null;
                 final Class groovyClass;
-                try
+                try( InputStream inputStream = groovySource.openStream() )
                 {
-                    is = groovySource.openStream();
-                    StringBuilder sourceBuilder = new StringBuilder();
-                    Inputs.text( groovySource ).transferTo( Outputs.text( sourceBuilder ) );
+                    String sourceText = new Scanner( inputStream ).useDelimiter( "\\Z" ).next();
                     GroovyClassLoader groovyClassLoader = new GroovyClassLoader( declaringClass.getClassLoader() );
-                    groovyClass = groovyClassLoader.parseClass( sourceBuilder.toString() );
-                }
-                finally
-                {
-                    if( is != null )
-                    {
-                        is.close();
-                    }
+                    groovyClass = groovyClassLoader.parseClass( sourceText );
                 }
                 groovyObject = (GroovyObject) groovyClass.newInstance();
                 if( hasProperty( groovyObject, "This" ) )
@@ -210,7 +198,5 @@ public class GroovyMixin
             this.script = script;
             this.url = url;
         }
-
     }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/a660c710/libraries/sql-liquibase/src/test/java/org/apache/zest/library/sql/liquibase/LiquibaseServiceTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-liquibase/src/test/java/org/apache/zest/library/sql/liquibase/LiquibaseServiceTest.java b/libraries/sql-liquibase/src/test/java/org/apache/zest/library/sql/liquibase/LiquibaseServiceTest.java
index 2a85472..83ef261 100644
--- a/libraries/sql-liquibase/src/test/java/org/apache/zest/library/sql/liquibase/LiquibaseServiceTest.java
+++ b/libraries/sql-liquibase/src/test/java/org/apache/zest/library/sql/liquibase/LiquibaseServiceTest.java
@@ -26,8 +26,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.function.Function;
 import javax.sql.DataSource;
-import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler;
-import org.junit.Test;
 import org.apache.zest.api.activation.ActivationEvent;
 import org.apache.zest.api.activation.ActivationEventListener;
 import org.apache.zest.api.activation.ActivationException;
@@ -40,18 +38,15 @@ import org.apache.zest.api.value.ValueComposite;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.ModuleAssembly;
 import org.apache.zest.bootstrap.SingletonAssembler;
-import org.apache.zest.io.Inputs;
-import org.apache.zest.io.Outputs;
 import org.apache.zest.library.sql.assembly.DataSourceAssembler;
 import org.apache.zest.library.sql.common.Databases;
 import org.apache.zest.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.zest.test.EntityTestAssembler;
+import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.apache.zest.io.Outputs.collection;
-import static org.apache.zest.io.Transforms.map;
 
 /**
  * Test DataSource and Liquibase services
@@ -92,8 +87,6 @@ public class LiquibaseServiceTest
                 // END SNIPPET: assembly
                 module.forMixin( LiquibaseConfiguration.class ).declareDefaults().enabled().set( true );
                 module.forMixin( LiquibaseConfiguration.class ).declareDefaults().changeLog().set( "changelog.xml" );
-
-                new DefaultUnitOfWorkAssembler().assemble( module );
             }
 
             @Override
@@ -159,14 +152,17 @@ public class LiquibaseServiceTest
             }
         };
 
-        // START SNIPPET: io
-        // Select rows and load them in a List
         List<SomeValue> rows = new ArrayList<SomeValue>();
-        database.query( "select * from test" ).transferTo( map( toValue, collection( rows ) ) );
+        database.query( "select * from test", new Databases.ResultSetVisitor() {
+            @Override
+            public boolean visit( final ResultSet resultSet ) throws SQLException
+            {
+                rows.add( toValue.apply( resultSet ) );
+                return true;
+            }
+        } );
 
-        // Transfer all rows to System.out
-        Inputs.iterable( rows ).transferTo( Outputs.systemOut() );
-        // END SNIPPET: io
+        rows.forEach( System.out::println );
     }
 
     interface SomeValue

http://git-wip-us.apache.org/repos/asf/zest-java/blob/a660c710/libraries/sql/src/docs/sql.txt
----------------------------------------------------------------------
diff --git a/libraries/sql/src/docs/sql.txt b/libraries/sql/src/docs/sql.txt
index 76f1e24..9f9413a 100644
--- a/libraries/sql/src/docs/sql.txt
+++ b/libraries/sql/src/docs/sql.txt
@@ -29,7 +29,7 @@ source=libraries/sql/dev-status.xml
 The SQL Library provides facilities for working with SQL databases.
 
 The center piece is the DataSource support that comes with
-<<library-circuitbreaker>> and <<library-jmx>> support. Facilities for doing SQL I/O with the <<core-io>> are provided.
+<<library-circuitbreaker>> and <<library-jmx>> support.
 
 TIP: See the <<sample-sql-support>> that demonstrate combined use of <<library-sql>>, <<extension-es-sql>> and
 <<extension-indexing-sql>>.
@@ -164,19 +164,6 @@ tag=cb-datasource
 
 
 
-
-== I/O ==
-
-Here is a simple example:
-
-[snippet,java]
-----
-source=libraries/sql-liquibase/src/test/java/org/apache/zest/library/sql/liquibase/LiquibaseServiceTest.java
-tag=io
-----
-
-
-
 == JMX ==
 
 Thanks to the <<library-jmx>> the Configuration of DataSources is exposed

http://git-wip-us.apache.org/repos/asf/zest-java/blob/a660c710/libraries/sql/src/main/java/org/apache/zest/library/sql/common/Databases.java
----------------------------------------------------------------------
diff --git a/libraries/sql/src/main/java/org/apache/zest/library/sql/common/Databases.java b/libraries/sql/src/main/java/org/apache/zest/library/sql/common/Databases.java
index 9b03a38..4d66954 100644
--- a/libraries/sql/src/main/java/org/apache/zest/library/sql/common/Databases.java
+++ b/libraries/sql/src/main/java/org/apache/zest/library/sql/common/Databases.java
@@ -25,17 +25,12 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import javax.sql.DataSource;
 import org.apache.zest.functional.Visitor;
-import org.apache.zest.io.Input;
-import org.apache.zest.io.Output;
-import org.apache.zest.io.Receiver;
-import org.apache.zest.io.Sender;
 
 /**
  * Utility methods for performing SQL calls wrapping a given DataSource.
  */
 public class Databases
 {
-
     DataSource source;
 
     /**
@@ -50,15 +45,18 @@ public class Databases
      * Perform SQL update statement.
      */
     public int update( String sql )
-            throws SQLException
+        throws SQLException
     {
         Connection connection = null;
         PreparedStatement stmt = null;
-        try {
+        try
+        {
             connection = source.getConnection();
             stmt = connection.prepareStatement( sql );
             return stmt.executeUpdate();
-        } finally {
+        }
+        finally
+        {
             SQLUtil.closeQuietly( stmt );
             SQLUtil.closeQuietly( connection );
         }
@@ -71,16 +69,19 @@ public class Databases
      * update the PreparedStatement with actual values.
      */
     public int update( String sql, StatementVisitor visitor )
-            throws SQLException
+        throws SQLException
     {
         Connection connection = null;
         PreparedStatement stmt = null;
-        try {
+        try
+        {
             connection = source.getConnection();
             stmt = connection.prepareStatement( sql );
             visitor.visit( stmt );
             return stmt.executeUpdate();
-        } finally {
+        }
+        finally
+        {
             SQLUtil.closeQuietly( stmt );
             SQLUtil.closeQuietly( connection );
         }
@@ -90,7 +91,7 @@ public class Databases
      * Perform SQL query and let visitor handle results.
      */
     public void query( String sql, ResultSetVisitor visitor )
-            throws SQLException
+        throws SQLException
     {
         query( sql, null, visitor );
     }
@@ -101,137 +102,47 @@ public class Databases
      * If the SQL string contains ? placeholders, use the StatementVisitor to
      * update the PreparedStatement with actual values.
      */
-    public void query( String sql, StatementVisitor statement, ResultSetVisitor resultsetVisitor )
-            throws SQLException
+    public void query( String sql, StatementVisitor statementVisitor, ResultSetVisitor resultSetVisitor )
+        throws SQLException
     {
         Connection connection = null;
-        PreparedStatement stmt = null;
+        PreparedStatement statement = null;
         ResultSet resultSet = null;
-        try {
+        try
+        {
             connection = source.getConnection();
-            stmt = connection.prepareStatement( sql );
-            if ( statement != null ) {
-                statement.visit( stmt );
+            statement = connection.prepareStatement( sql );
+            if( statementVisitor != null )
+            {
+                statementVisitor.visit( statement );
             }
-            resultSet = stmt.executeQuery();
-            while ( resultSet.next() ) {
-                if ( !resultsetVisitor.visit( resultSet ) ) {
+            resultSet = statement.executeQuery();
+            while( resultSet.next() )
+            {
+                if( !resultSetVisitor.visit( resultSet ) )
+                {
                     return;
                 }
             }
             resultSet.close();
-        } finally {
+        }
+        finally
+        {
             SQLUtil.closeQuietly( resultSet );
-            SQLUtil.closeQuietly( stmt );
+            SQLUtil.closeQuietly( statement );
             SQLUtil.closeQuietly( connection );
         }
     }
 
     /**
-     * Perform SQL query and provide results as an Input.
-     *
-     * This makes it possible to combine SQL data with the I/O API.
-     */
-    public Input<ResultSet, SQLException> query( final String sql )
-    {
-        return new Input<ResultSet, SQLException>()
-        {
-
-            @Override
-            public <ReceiverThrowableType extends Throwable> void transferTo( Output<? super ResultSet, ReceiverThrowableType> output )
-                    throws SQLException, ReceiverThrowableType
-            {
-                output.receiveFrom( new Sender<ResultSet, SQLException>()
-                {
-
-                    @Override
-                    public <ReceiverThrowableType extends Throwable> void sendTo( final Receiver<? super ResultSet, ReceiverThrowableType> receiver )
-                            throws ReceiverThrowableType, SQLException
-                    {
-                        query( sql, new ResultSetVisitor()
-                        {
-
-                            @Override
-                            public boolean visit( ResultSet visited )
-                                    throws SQLException
-                            {
-                                try {
-                                    receiver.receive( visited );
-                                } catch ( Throwable receiverThrowableType ) {
-                                    throw new SQLException( receiverThrowableType );
-                                }
-
-                                return true;
-                            }
-
-                        } );
-                    }
-
-                } );
-            }
-
-        };
-    }
-
-    /**
-     * Perform SQL query and provide results as an Input.
-     *
-     * This makes it possible to combine SQL data with the I/O API. If the SQL
-     * string contains ? placeholders, use the StatementVisitor to update the
-     * PreparedStatement with actual values.
-     */
-    public Input<ResultSet, SQLException> query( final String sql, final StatementVisitor visitor )
-    {
-        return new Input<ResultSet, SQLException>()
-        {
-
-            @Override
-            public <ReceiverThrowableType extends Throwable> void transferTo( Output<? super ResultSet, ReceiverThrowableType> output )
-                    throws SQLException, ReceiverThrowableType
-            {
-                output.receiveFrom( new Sender<ResultSet, SQLException>()
-                {
-
-                    @Override
-                    public <ReceiverThrowableType extends Throwable> void sendTo( final Receiver<? super ResultSet, ReceiverThrowableType> receiver )
-                            throws ReceiverThrowableType, SQLException
-                    {
-                        query( sql, visitor, new ResultSetVisitor()
-                        {
-
-                            @Override
-                            public boolean visit( ResultSet visited )
-                                    throws SQLException
-                            {
-                                try {
-                                    receiver.receive( visited );
-                                } catch ( Throwable receiverThrowableType ) {
-                                    throw new SQLException( receiverThrowableType );
-                                }
-
-                                return true;
-                            }
-
-                        } );
-                    }
-
-                } );
-            }
-
-        };
-    }
-
-    /**
      * Visitor for PreparedStatements.
      *
      * These are created when the SQL statements contain ? placeholders.
      */
     public interface StatementVisitor
     {
-
         void visit( PreparedStatement preparedStatement )
-                throws SQLException;
-
+            throws SQLException;
     }
 
     /**
@@ -241,8 +152,7 @@ public class Databases
      * by this API.
      */
     public interface ResultSetVisitor
-            extends Visitor<ResultSet, SQLException>
+        extends Visitor<ResultSet, SQLException>
     {
     }
-
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/a660c710/libraries/sql/src/test/java/org/apache/zest/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql/src/test/java/org/apache/zest/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java b/libraries/sql/src/test/java/org/apache/zest/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java
index 79dc1ad..81a2f5a 100644
--- a/libraries/sql/src/test/java/org/apache/zest/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java
+++ b/libraries/sql/src/test/java/org/apache/zest/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java
@@ -19,33 +19,21 @@
  */
 package org.apache.zest.library.sql.jmx;
 
-import java.beans.PropertyVetoException;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import javax.sql.DataSource;
-import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler;
-import org.junit.Assert;
-import org.junit.Test;
 import org.apache.zest.api.activation.ActivationException;
 import org.apache.zest.api.common.Visibility;
-import org.apache.zest.api.injection.scope.Service;
-import org.apache.zest.api.service.ServiceReference;
-import org.apache.zest.api.service.qualifier.IdentifiedBy;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.ModuleAssembly;
 import org.apache.zest.bootstrap.SingletonAssembler;
-import org.apache.zest.io.Outputs;
-import org.apache.zest.io.Receiver;
-import org.apache.zest.library.circuitbreaker.CircuitBreaker;
+import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler;
 import org.apache.zest.library.jmx.JMXAssembler;
 import org.apache.zest.library.sql.assembly.DataSourceAssembler;
 import org.apache.zest.library.sql.assembly.DataSourceJMXAssembler;
-import org.apache.zest.library.sql.common.Databases;
 import org.apache.zest.library.sql.datasource.DataSources;
 import org.apache.zest.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.zest.library.sql.liquibase.LiquibaseConfiguration;
 import org.apache.zest.library.sql.liquibase.LiquibaseService;
 import org.apache.zest.test.EntityTestAssembler;
+import org.junit.Test;
 
 /**
  * Test of export of DataSources to JMX, and some other stuff
@@ -61,10 +49,14 @@ public class DataSourceConfigurationManagerServiceTest
         instance.testDataSources();
 
         // Hang so it becomes possible to connect through VisualVM and check the JMX beans
-        synchronized( instance ) {
-            try {
+        synchronized( instance )
+        {
+            try
+            {
                 instance.wait();
-            } catch ( InterruptedException e ) {
+            }
+            catch( InterruptedException e )
+            {
                 e.printStackTrace();
             }
         }
@@ -74,11 +66,11 @@ public class DataSourceConfigurationManagerServiceTest
     public void testDataSources()
         throws ActivationException, AssemblyException
     {
-        new SingletonAssembler()
+        SingletonAssembler assembler = new SingletonAssembler()
         {
             @Override
             public void assemble( ModuleAssembly module )
-                    throws AssemblyException
+                throws AssemblyException
             {
                 new JMXAssembler().assemble( module );
 
@@ -88,24 +80,27 @@ public class DataSourceConfigurationManagerServiceTest
                 new DefaultUnitOfWorkAssembler().assemble( module );
 
                 // Set up DataSource service that will manage the connection pools
-                new DBCPDataSourceServiceAssembler().identifiedBy( "datasource-service" ).visibleIn( Visibility.layer ).assemble( module );
+                new DBCPDataSourceServiceAssembler().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 );
+                    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" );
+                    testModule.forMixin( LiquibaseConfiguration.class ).declareDefaults()
+                              .enabled().set( true );
+                    testModule.forMixin( LiquibaseConfiguration.class ).declareDefaults()
+                              .changeLog().set( "changelog.xml" );
                 }
 
                 {
@@ -113,101 +108,25 @@ public class DataSourceConfigurationManagerServiceTest
 
                     // 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 );
+                    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" );
+                    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 );
     }
-
-    public void init( @Service @IdentifiedBy( "testds" ) DataSource dataSource, @Service @IdentifiedBy( "testds2" ) ServiceReference<DataSource> dataSource2 )
-            throws SQLException, PropertyVetoException
-    {
-        Databases databases = new Databases( dataSource );
-
-        // Insert some data and print it out
-        databases.update( "insert into test values ('id1','foo')" );
-        databases.query( "select * from test" ).transferTo( Outputs.withReceiver( new Receiver<ResultSet, SQLException>()
-        {
-            @Override
-            public void receive( ResultSet item )
-                    throws SQLException
-            {
-                System.out.println( item.getString( "id" ) );
-            }
-
-        } ) );
-
-        Databases databases2 = new Databases( dataSource2.get() );
-
-        // Insert some data and print it out
-        databases2.update( "insert into test values ('id2','bar')" );
-        databases2.query( "select * from test" ).transferTo( Outputs.withReceiver( new Receiver<ResultSet, SQLException>()
-        {
-            @Override
-            public void receive( ResultSet item )
-                    throws SQLException
-            {
-                System.out.println( item.getString( "id" ) );
-            }
-
-        } ) );
-
-        // Trip the CB
-        dataSource2.metaInfo( CircuitBreaker.class ).trip();
-
-        // This should now fail
-        try {
-            databases2.query( "select * from test" ).transferTo( Outputs.withReceiver( new Receiver<ResultSet, SQLException>()
-            {
-                @Override
-                public void receive( ResultSet item )
-                        throws SQLException
-                {
-                    System.out.println( item.getString( "id" ) );
-                }
-
-            } ) );
-
-            Assert.fail();
-
-        } catch ( Throwable e ) {
-            // Correct
-        }
-
-        // Turn the CB back on
-        dataSource2.metaInfo( CircuitBreaker.class ).turnOn();
-
-        // This should now work
-        databases2.query( "select * from test" ).transferTo( Outputs.withReceiver( new Receiver<ResultSet, SQLException>()
-        {
-            @Override
-            public void receive( ResultSet item )
-                    throws SQLException
-            {
-                System.out.println( item.getString( "id" ) );
-            }
-
-        } ) );
-
-    }
-
 }