The reason that these tests didn't work, is because my commit/push was overwritten somehow. No problem with runtime added mixins.
Signed-off-by: niclas <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/26e216db Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/26e216db Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/26e216db Branch: refs/heads/develop Commit: 26e216db897c3fd0460829b49922e36114f3686e Parents: 33d4309 Author: niclas <[email protected]> Authored: Mon May 15 15:00:20 2017 +0800 Committer: niclas <[email protected]> Committed: Mon May 15 15:00:20 2017 +0800 ---------------------------------------------------------------------- .../polygene/bootstrap/SingletonAssembler.java | 45 ++++++++- .../polygene/bootstrap/RuntimeMixinsTest.java | 96 ++++++++++---------- 2 files changed, 90 insertions(+), 51 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/26e216db/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/SingletonAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/SingletonAssembler.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/SingletonAssembler.java index 051c8d5..01673f8 100644 --- a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/SingletonAssembler.java +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/SingletonAssembler.java @@ -47,11 +47,25 @@ public class SingletonAssembler private final Module moduleInstance; private Consumer<ModuleAssembly> assemble; + /** + * Creates a Polygene Runtime instance containing one Layer with one Module. + * The Layer will be named "Layer 1" and the Module will be named "Module 1". It is possible to add + * additional layers and modules via the Assembler interface that must be implemented in the subclass of this + * class. + * + * @param assemble An Assembler lambda containing the module assembly. + * @throws AssemblyException Either if the model can not be created from the disk, or some inconsistency in + * the programming model makes it impossible to create it. + * @throws ActivationException If the automatic {@code activate()} method is throwing this Exception.. + */ public SingletonAssembler( Consumer<ModuleAssembly> assemble ) throws ActivationException { - this(); this.assemble = assemble; + polygene = new Energy4Java(); + applicationInstance = createApplicationInstance(); + activateApplication(); + moduleInstance = applicationInstance.findModule( layerName(), moduleName() ); } /** @@ -69,10 +83,23 @@ public class SingletonAssembler { // START SNIPPET: actual polygene = new Energy4Java(); - applicationInstance = polygene.newApplication( + applicationInstance = createApplicationInstance(); + activateApplication(); +// END SNIPPET: actual + moduleInstance = applicationInstance.findModule( layerName(), moduleName() ); + } + + // START SNIPPET: actual + private Application createApplicationInstance() + { + return polygene.newApplication( applicationFactory -> applicationFactory.newApplicationAssembly( SingletonAssembler.this ) ); + } + private void activateApplication() + throws ActivationException + { try { beforeActivation( applicationInstance ); @@ -86,10 +113,8 @@ public class SingletonAssembler } throw new ActivationException( "Could not activate application", e ); } -// START SNIPPET: actual - - moduleInstance = applicationInstance.findModule( "Layer 1", "Module 1" ); } +// END SNIPPET: actual public final PolygeneAPI runtime() { @@ -106,6 +131,16 @@ public class SingletonAssembler return moduleInstance; } + protected String layerName() + { + return "Layer 1"; + } + + protected String moduleName() + { + return "Module 1"; + } + protected void beforeActivation( Application application ) throws Exception { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/26e216db/core/runtime/src/test/java/org/apache/polygene/bootstrap/RuntimeMixinsTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/bootstrap/RuntimeMixinsTest.java b/core/runtime/src/test/java/org/apache/polygene/bootstrap/RuntimeMixinsTest.java index c8aa70a..cdf8ead 100644 --- a/core/runtime/src/test/java/org/apache/polygene/bootstrap/RuntimeMixinsTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/bootstrap/RuntimeMixinsTest.java @@ -22,33 +22,28 @@ package org.apache.polygene.bootstrap; import org.apache.polygene.api.activation.ActivationException; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.mixin.NoopMixin; -import org.junit.Ignore; import org.junit.Test; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNull.nullValue; import static org.junit.Assert.assertThat; -@Ignore public class RuntimeMixinsTest { @Test public void givenValueWithRuntimeMixinsWhenAssembledExpectCorrectComposition() throws ActivationException { - SingletonAssembler singletonAssembler = new SingletonAssembler() - { - - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException + SingletonAssembler singletonAssembler = new SingletonAssembler( + module -> { - module.values( TestType1.class ).withMixins( DoThisMixin.class, DoThatMixin.class ); + module.values( SayWhat.class ).withMixins( SayThisMixin.class, SayThatMixin.class ); } - }; - TestType1 value = singletonAssembler.valueBuilderFactory().newValue( TestType1.class ); - assertThat( value.doThis(), equalTo( "this" ) ); - assertThat( value.doThat(), equalTo( "that" ) ); + ); + + SayWhat value = singletonAssembler.valueBuilderFactory().newValue( SayWhat.class ); + assertThat( value.sayThis(), equalTo( "this" ) ); + assertThat( value.sayThat(), equalTo( "that" ) ); } @Test @@ -57,17 +52,16 @@ public class RuntimeMixinsTest { SingletonAssembler singletonAssembler = new SingletonAssembler() { - @Override public void assemble( ModuleAssembly module ) throws AssemblyException { - module.values( TestType2.class ).withMixins( DoThisMixin.class ); + module.values( SayWhere.class ).withMixins( SayHereMixin.class ); } }; - TestType2 value = singletonAssembler.valueBuilderFactory().newValue( TestType2.class ); - assertThat( value.doThis(), equalTo( "this" ) ); - assertThat( value.doThat(), nullValue() ); + SayWhere value = singletonAssembler.valueBuilderFactory().newValue( SayWhere.class ); + assertThat( value.sayHere(), equalTo( "here" ) ); + assertThat( value.sayThere(), nullValue() ); } @Test @@ -81,12 +75,12 @@ public class RuntimeMixinsTest public void assemble( ModuleAssembly module ) throws AssemblyException { - module.transients( TestType1.class ).withMixins( DoThisMixin.class, DoThatMixin.class ); + module.transients( SayWhat.class ).withMixins( SayThisMixin.class, SayThatMixin.class ); } }; - TestType1 value = singletonAssembler.transientBuilderFactory().newTransient( TestType1.class ); - assertThat( value.doThis(), equalTo( "this" ) ); - assertThat( value.doThat(), equalTo( "that" ) ); + SayWhat value = singletonAssembler.transientBuilderFactory().newTransient( SayWhat.class ); + assertThat( value.sayThis(), equalTo( "this" ) ); + assertThat( value.sayThat(), equalTo( "that" ) ); } @Test @@ -100,12 +94,12 @@ public class RuntimeMixinsTest public void assemble( ModuleAssembly module ) throws AssemblyException { - module.transients( TestType2.class ).withMixins( DoThisMixin.class ); + module.transients( SayWhere.class ).withMixins( SayHereMixin.class ); } }; - TestType2 value = singletonAssembler.transientBuilderFactory().newTransient( TestType2.class ); - assertThat( value.doThis(), equalTo( "this" ) ); - assertThat( value.doThat(), nullValue() ); + SayWhere value = singletonAssembler.transientBuilderFactory().newTransient( SayWhere.class ); + assertThat( value.sayHere(), equalTo( "here" ) ); + assertThat( value.sayThere(), nullValue() ); } @Test @@ -119,12 +113,12 @@ public class RuntimeMixinsTest public void assemble( ModuleAssembly module ) throws AssemblyException { - module.services( TestType1.class ).withMixins( DoThisMixin.class, DoThatMixin.class ); + module.services( SayWhat.class ).withMixins( SayThisMixin.class, SayThatMixin.class ); } }; - TestType1 value = singletonAssembler.serviceFinder().findService( TestType1.class ).get(); - assertThat( value.doThis(), equalTo( "this" ) ); - assertThat( value.doThat(), equalTo( "that" ) ); + SayWhat value = singletonAssembler.serviceFinder().findService( SayWhat.class ).get(); + assertThat( value.sayThis(), equalTo( "this" ) ); + assertThat( value.sayThat(), equalTo( "that" ) ); } @Test @@ -138,46 +132,56 @@ public class RuntimeMixinsTest public void assemble( ModuleAssembly module ) throws AssemblyException { - module.services( TestType2.class ).withMixins( DoThisMixin.class ); + module.services( SayWhere.class ).withMixins( SayHereMixin.class ); } }; - TestType2 value = singletonAssembler.serviceFinder().findService( TestType2.class ).get(); - assertThat( value.doThis(), equalTo( "this" ) ); - assertThat( value.doThat(), nullValue() ); + SayWhere value = singletonAssembler.serviceFinder().findService( SayWhere.class ).get(); + assertThat( value.sayHere(), equalTo( "here" ) ); + assertThat( value.sayThere(), nullValue() ); } - public interface TestType1 + public interface SayWhat { - String doThis(); + String sayThis(); - String doThat(); + String sayThat(); } @Mixins( NoopMixin.class ) - public interface TestType2 + public interface SayWhere { - String doThis(); + String sayHere(); - String doThat(); + String sayThere(); } - protected abstract static class DoThisMixin - implements TestType1 + protected abstract static class SayThisMixin + implements SayWhat { @Override - public String doThis() + public String sayThis() { return "this"; } } - protected abstract static class DoThatMixin - implements TestType1 + protected abstract static class SayThatMixin + implements SayWhat { @Override - public String doThat() + public String sayThat() { return "that"; } } + + protected abstract static class SayHereMixin + implements SayWhere + { + @Override + public String sayHere() + { + return "here"; + } + } }
