http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/polygene/api/value/DocumentationSupport.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/polygene/api/value/DocumentationSupport.java b/core/api/src/test/java/org/apache/polygene/api/value/DocumentationSupport.java new file mode 100644 index 0000000..67abae9 --- /dev/null +++ b/core/api/src/test/java/org/apache/polygene/api/value/DocumentationSupport.java @@ -0,0 +1,277 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.api.value; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Stream; +import org.apache.polygene.api.injection.scope.Service; +import org.apache.polygene.api.property.Property; +import org.apache.polygene.api.structure.Application; +import org.apache.polygene.api.structure.Module; +import org.apache.polygene.api.type.CollectionType; +import org.apache.polygene.bootstrap.Assembler; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.Energy4Java; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; +import org.apache.polygene.test.AbstractPolygeneTest; +import org.apache.polygene.valueserialization.orgjson.OrgJsonValueSerializationAssembler; +import org.junit.Test; + +import static java.util.stream.Collectors.toList; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +/** + * Snippets: + * - default : default ValueSerialization + * - service : assembled service ValueSerialization + * - lookup : ValueSerialization values module finder + */ +public class DocumentationSupport + extends AbstractPolygeneTest +{ + + // START SNIPPET: default + // START SNIPPET: service + public interface SomeValue // (1) + { + + Property<String> foo(); + } + + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.values( SomeValue.class ); // (2) + // END SNIPPET: default + new OrgJsonValueSerializationAssembler().assemble( module ); // (3) + new DefaultUnitOfWorkAssembler().assemble( module ); + // START SNIPPET: default + } + // END SNIPPET: default + // END SNIPPET: service + + @Test + // START SNIPPET: default + public void defaultValueSerialization() + { + SomeValue someValue = someNewValueInstance(); // (3) + String json = someValue.toString(); // (4) + SomeValue someNewValue = valueBuilderFactory.newValueFromSerializedState( SomeValue.class, json ); // (5) + // END SNIPPET: default + + assertThat( json, equalTo( "{\"foo\":\"bar\"}" ) ); + assertThat( someNewValue, equalTo( someValue ) ); + + // START SNIPPET: default + } + + // END SNIPPET: default + // START SNIPPET: service + @Service + private ValueSerializer valueSerializer; // (4) + @Service + private ValueDeserializer valueDeserializer; // (4) + + // END SNIPPET: service + @Test + // START SNIPPET: service + public void assembledDefaultServiceSerialization() + { + SomeValue someValue = someNewValueInstance(); // (5) + String json = valueSerializer.serialize( someValue ); // (6) + SomeValue someNewValue = valueDeserializer.deserialize( module, SomeValue.class, json ); // (7) + // END SNIPPET: service + + assertThat( json, equalTo( "{\"foo\":\"bar\"}" ) ); + assertThat( someNewValue, equalTo( someValue ) ); + + // START SNIPPET: service + } + // END SNIPPET: service + + static enum AcmeValue + { + + foo, bar + } + + @Test + // START SNIPPET: stream + public void assembledServiceStreamingSerialization() + { + // END SNIPPET: stream + + List<AcmeValue> dataSource = Arrays.asList( AcmeValue.values() ); + ByteArrayOutputStream targetStream = new ByteArrayOutputStream(); + + // START SNIPPET: stream + // (1) + Iterable<AcmeValue> data = dataSource; // Eg. Entities converted to Values + OutputStream output = targetStream; // Eg. streaming JSON over HTTP + + // (2) + valueSerializer.serialize( data, output ); + // END SNIPPET: stream + + byte[] serialized = targetStream.toByteArray(); + ByteArrayInputStream sourceStream = new ByteArrayInputStream( serialized ); + + // START SNIPPET: stream + // (3) + InputStream input = sourceStream; // Eg. reading incoming JSON + + // (4) + List<AcmeValue> values = valueDeserializer.deserialize( module, CollectionType.listOf( AcmeValue.class ), input ); + // END SNIPPET: stream + + assertThat( values, equalTo( dataSource ) ); + + // START SNIPPET: stream + } + // END SNIPPET: stream + + @Test + // START SNIPPET: io + public void assembledServiceIOSerialization() + throws IOException + { + // END SNIPPET: io + + List<AcmeValue> dataSource = Arrays.asList( AcmeValue.values() ); + StringWriter stringOutput = new StringWriter(); + PrintWriter output = new PrintWriter( stringOutput ); + + + // START SNIPPET: io + // (1) + // Eg. Entities converted to Values + Stream<AcmeValue> queryResult = dataSource.stream(); + + // (2) + Function<AcmeValue, String> serialize = valueSerializer.serialize(); + + // (3) + // Eg. pipe data to another process or to a file + queryResult.map( serialize ).forEach( output::println ); + // END SNIPPET: io + + output.flush(); + String string = stringOutput.toString(); + List<String> input = Arrays.asList( string.split( System.lineSeparator() ) ); + + // START SNIPPET: io + // (4) + Stream<String> lines = input.stream(); + + // (5) + Function<String, AcmeValue> deserialize = valueDeserializer.deserialize( module, AcmeValue.class ); + + // Deserialization of a collection of AcmeValue from a String. + // One serialized AcmeValue per line. + // (6) + List<AcmeValue> values = lines.map( deserialize ).collect( toList() ); + // END SNIPPET: io + + assertThat( dataSource, equalTo( values ) ); + + // START SNIPPET: io + } + // END SNIPPET: io + + @Test + // TODO Move to SPI ! + // TODO Include in each ValueSerialization extensions documentation + public void assembledWithValuesModuleSerialization() + throws Exception + { + Application app = new Energy4Java().newApplication( applicationFactory -> { + Assembler[][][] pancakes = new Assembler[][][] + { + { + { + valuesModule -> { + valuesModule.layer().setName( "SINGLE-Layer" ); + valuesModule.setName( "VALUES-Module" ); + + valuesModule.values( SomeValue.class ); + new DefaultUnitOfWorkAssembler().assemble( valuesModule ); + } + }, + { + servicesModule -> { + servicesModule.setName( "SERVICES-Module" ); + + Function<Application, Module> valuesModuleFinder = new Function<Application, Module>() + { + @Override + public Module apply( Application app1 ) + { + return app1.findModule( "SINGLE-Layer", "VALUES-Module" ); + } + }; + new OrgJsonValueSerializationAssembler(). + withValuesModuleFinder( valuesModuleFinder ). + assemble( servicesModule ); + } + } + } + }; + return applicationFactory.newApplicationAssembly( pancakes ); + } ); + app.activate(); + try + { + Module valuesModule = app.findModule( "SINGLE-Layer", "VALUES-Module" ); + SomeValue someValue = someNewValueInstance(); + + Module servicesModule = app.findModule( "SINGLE-Layer", "SERVICES-Module" ); + ValueSerialization valueSerialization = servicesModule.findService( ValueSerialization.class ).get(); + + String json = valueSerialization.serialize( someValue ); + assertThat( json, equalTo( "{\"foo\":\"bar\"}" ) ); + + SomeValue someNewValue = valueSerialization.deserialize( module, SomeValue.class, json ); + assertThat( someNewValue, equalTo( someValue ) ); + } + finally + { + app.passivate(); + } + } + + private SomeValue someNewValueInstance( ) + { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + builder.prototype().foo().set( "bar" ); + return builder.newInstance(); + } +}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/polygene/api/value/ValueBuilderTemplateTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/polygene/api/value/ValueBuilderTemplateTest.java b/core/api/src/test/java/org/apache/polygene/api/value/ValueBuilderTemplateTest.java new file mode 100644 index 0000000..f52d103 --- /dev/null +++ b/core/api/src/test/java/org/apache/polygene/api/value/ValueBuilderTemplateTest.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.api.value; + +import org.junit.Test; +import org.apache.polygene.api.property.Property; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.test.AbstractPolygeneTest; + +/** + * TODO + */ +public class ValueBuilderTemplateTest + extends AbstractPolygeneTest +{ + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.values( TestValue.class ); + } + + @Test + public void testTemplate() + { + new TestBuilder( "Rickard" ).newInstance( module ); + } + + @Test + public void testAnonymousTemplate() + { + new ValueBuilderTemplate<TestValue>( TestValue.class ) + { + @Override + protected void build( TestValue prototype ) + { + prototype.name().set( "Rickard" ); + } + }.newInstance( module ); + } + + interface TestValue + extends ValueComposite + { + Property<String> name(); + } + + class TestBuilder + extends ValueBuilderTemplate<TestValue> + { + String name; + + TestBuilder( String name ) + { + super( TestValue.class ); + this.name = name; + } + + @Override + protected void build( TestValue prototype ) + { + prototype.name().set( name ); + } + } + + ; +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/polygene/api/value/ValueCompositeTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/polygene/api/value/ValueCompositeTest.java b/core/api/src/test/java/org/apache/polygene/api/value/ValueCompositeTest.java new file mode 100644 index 0000000..ffe500c --- /dev/null +++ b/core/api/src/test/java/org/apache/polygene/api/value/ValueCompositeTest.java @@ -0,0 +1,314 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ + +package org.apache.polygene.api.value; + +import java.util.List; +import org.junit.Assert; +import org.junit.Test; +import org.apache.polygene.api.association.Association; +import org.apache.polygene.api.association.ManyAssociation; +import org.apache.polygene.api.common.Optional; +import org.apache.polygene.api.common.UseDefaults; +import org.apache.polygene.api.constraint.ConstraintViolationException; +import org.apache.polygene.api.entity.EntityBuilder; +import org.apache.polygene.api.entity.EntityComposite; +import org.apache.polygene.api.property.Property; +import org.apache.polygene.api.unitofwork.UnitOfWork; +import org.apache.polygene.api.unitofwork.UnitOfWorkCompletionException; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.library.constraints.annotation.MaxLength; +import org.apache.polygene.test.AbstractPolygeneTest; +import org.apache.polygene.test.EntityTestAssembler; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +/** + * Tests for ValueComposites + */ +public class ValueCompositeTest + extends AbstractPolygeneTest +{ + + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.values( SomeValue.class, AnotherValue.class, AssociationValue.class ); + module.entities( SomeEntity.class ); + new EntityTestAssembler().assemble( module ); + } + + @Test( expected = IllegalStateException.class ) + public void testImmutabilityOfValueComposite() + { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + SomeValue some = builder.prototype(); + some.other().set( "test" ); + some = builder.newInstance(); + some.other().set( "test2" ); + } + + @Test + public void testCreationOfValueComposite() + { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + SomeValue some = builder.prototype(); + some.other().set( "test" ); + builder.newInstance(); + + // Check that @UseDefaults works for ValueComposites + assertEquals( "{\"val1\":\"\"}", some.another().get().toString() ); + } + + @Test + public void testEqualityOfValueComposite() + { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + SomeValue prototype = builder.prototype(); + prototype.other().set( "test" ); + SomeValue instance = builder.newInstance(); + SomeValue other = builder.newInstance(); + Assert.assertFalse( "Instances should not be the same.", instance == other ); + Assert.assertEquals( "Equal values.", instance, other ); + } + + @Test + public void testHashcodeOfValueComposite() + { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + SomeValue prototype = builder.prototype(); + prototype.other().set( "test" ); + SomeValue instance = builder.newInstance(); + SomeValue other = builder.newInstance(); + Assert.assertFalse( "Instances should not be the same.", instance == other ); + Assert.assertEquals( "Equal values.", instance.hashCode(), other.hashCode() ); + } + + @Test + public void testModifyValue() + { + ValueBuilder<AnotherValue> anotherBuilder = valueBuilderFactory.newValueBuilder( AnotherValue.class ); + anotherBuilder.prototype().val1().set( "Val1" ); + AnotherValue anotherValue = anotherBuilder.newInstance(); + + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + SomeValue prototype = builder.prototype(); + prototype.some().set( "foo" ); + prototype.other().set( "test" ); + prototype.xyzzyList().get().add( "blah" ); + prototype.another().set( anotherValue ); + SomeValue instance = builder.newInstance(); + + assertThat( "List has value blah", instance.xyzzyList().get().get( 0 ), equalTo( "blah" ) ); + + // Modify value + builder = valueBuilderFactory.newValueBuilderWithPrototype( instance ); + builder.prototype().some().set( "bar" ); + instance = builder.newInstance(); + + assertThat( "Other is set to test", instance.other().get(), equalTo( "test" ) ); + assertThat( "List has value blah", instance.xyzzyList().get().get( 0 ), equalTo( "blah" ) ); + assertThat( "AnotherValue.val1 has value Val1", instance.another().get().val1().get(), equalTo( "Val1" ) ); + + // Modify value again using method 2 + builder = valueBuilderFactory.newValueBuilderWithPrototype( instance ); + builder.prototype().other().set( "test2" ); + instance = builder.newInstance(); + + assertThat( "Other is set to test2", instance.other().get(), equalTo( "test2" ) ); + assertThat( "Some is set to bar", instance.some().get(), equalTo( "bar" ) ); + } + + @Test( expected = ConstraintViolationException.class ) + public void givenValueWhenModifyToIncorrectValueThenThrowConstraintException() + { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + SomeValue prototype = builder.prototype(); + prototype.some().set( "foo" ); + SomeValue instance = builder.newInstance(); + + builder = valueBuilderFactory.newValueBuilderWithPrototype( instance ); + builder.prototype().some().set( "123456" ); + } + + @Test + public void givenValueWithListOfValueWhenPrototypeThenListedValuesAreEditable() + { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + builder.prototype().anotherList().get().add( valueBuilderFactory.newValue( AnotherValue.class ) ); + SomeValue some = builder.newInstance(); + + builder = valueBuilderFactory.newValueBuilderWithPrototype( some ); + builder.prototype().anotherList().get().get( 0 ).val1().set( "Foo" ); + builder.prototype().anotherList().get().add( valueBuilderFactory.newValue( AnotherValue.class ) ); + some = builder.newInstance(); + + assertThat( "Val1 has been set", some.anotherList().get().get( 0 ).val1().get(), equalTo( "Foo" ) ); + + try + { + some.anotherList().get().get( 0 ).val1().set( "Bar" ); + Assert.fail( "Should not be allowed to modify value" ); + } + catch( IllegalStateException e ) + { + // Ok + } + } + + @Test + public void givenEntityWhenUpdateValueThenValueIsSet() + throws UnitOfWorkCompletionException + { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + builder.prototype().anotherList().get().add( valueBuilderFactory.newValue( AnotherValue.class ) ); + ValueBuilder<AnotherValue> valueBuilder = valueBuilderFactory.newValueBuilder( AnotherValue.class ); + valueBuilder.prototype().val1().set( "Foo" ); + builder.prototype().another().set( valueBuilder.newInstance() ); + builder.prototype().number().set( 42L ); + SomeValue some = builder.newInstance(); + + UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork(); + try + { + EntityBuilder<SomeEntity> entityBuilder = unitOfWork.newEntityBuilder( SomeEntity.class ); + entityBuilder.instance().someValue().set( some ); + SomeEntity entity = entityBuilder.newInstance(); + + assertThat( "Value has been set", entity.someValue().get().another().get().val1().get(), equalTo( "Foo" ) ); + + unitOfWork.complete(); + } + finally + { + unitOfWork.discard(); + } + } + + @Test + public void givenValueWithAssociationsWhenNewUoWThenCanRead() + throws UnitOfWorkCompletionException + { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + builder.prototype().anotherList().get().add( valueBuilderFactory.newValue( AnotherValue.class ) ); + ValueBuilder<AnotherValue> valueBuilder = valueBuilderFactory.newValueBuilder( AnotherValue.class ); + valueBuilder.prototype().val1().set( "Foo" ); + builder.prototype().another().set( valueBuilder.newInstance() ); + builder.prototype().number().set( 42L ); + SomeValue some = builder.newInstance(); + + UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork(); + AssociationValue associationValue; + try + { + EntityBuilder<SomeEntity> entityBuilder = unitOfWork.newEntityBuilder( SomeEntity.class ); + entityBuilder.instance().someValue().set( some ); + SomeEntity entity = entityBuilder.newInstance(); + + ValueBuilder<AssociationValue> associationBuilder = valueBuilderFactory.newValueBuilder( AssociationValue.class ); + associationBuilder.prototype().some().set( entity ); + associationValue = associationBuilder.newInstance(); + + String json = associationValue.toString(); + + unitOfWork.complete(); + + unitOfWork = unitOfWorkFactory.newUnitOfWork(); + + AssociationValue newAssociationValue = valueBuilderFactory.newValueFromSerializedState( AssociationValue.class, json ); + + Assert.assertEquals( associationValue.some().get(), newAssociationValue.some().get() ); + } + finally + { + unitOfWork.discard(); + } + + // Should allow the toString() to print the entityRefs. + System.out.println( associationValue.toString() ); + try + { + associationValue.some().get(); + fail( "Should have thrown an exception" ); + } + catch( Exception e ) + { + // Ok + } + } + + public enum TestEnum + { + somevalue, anothervalue + } + + public interface SomeValue + extends ValueComposite + { + @UseDefaults + @MaxLength( 5 ) + Property<String> some(); + + @UseDefaults + Property<String> other(); + + @UseDefaults + Property<Long> number(); + + @UseDefaults + Property<List<String>> xyzzyList(); + + @UseDefaults + Property<AnotherValue> another(); + + @UseDefaults + Property<List<AnotherValue>> anotherList(); + + @UseDefaults + Property<TestEnum> testEnum(); + } + + public interface AnotherValue + extends ValueComposite + { + @UseDefaults + Property<String> val1(); + } + + public interface AssociationValue + extends ValueComposite + { + @Optional + Association<SomeEntity> some(); + + ManyAssociation<SomeEntity> manySome(); + } + + public interface SomeEntity + extends EntityComposite + { + Property<SomeValue> someValue(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java b/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java deleted file mode 100644 index 86151a0..0000000 --- a/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api; - -import java.util.Collections; -import java.util.function.Predicate; -import org.apache.zest.api.activation.ActivationException; -import org.apache.zest.api.composite.Composite; -import org.apache.zest.api.entity.EntityBuilder; -import org.apache.zest.api.entity.EntityComposite; -import org.apache.zest.api.identity.StringIdentity; -import org.apache.zest.api.property.Property; -import org.apache.zest.api.query.QueryBuilder; -import org.apache.zest.api.query.QueryExpressions; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException; -import org.apache.zest.api.unitofwork.UnitOfWorkFactory; -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.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; -import org.apache.zest.test.EntityTestAssembler; -import org.junit.Assert; -import org.junit.Test; - -/** - * TODO - */ -public class OperatorsTest -{ - @Test - public void testOperators() - throws UnitOfWorkCompletionException, ActivationException, AssemblyException - { - SingletonAssembler assembler = new SingletonAssembler() - { - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - new EntityTestAssembler().assemble( module ); - - module.entities( TestEntity.class ); - module.values( TestValue.class ); - module.forMixin( TestEntity.class ).declareDefaults().foo().set( "Bar" ); - module.forMixin( TestValue.class ).declareDefaults().bar().set( "Xyz" ); - new DefaultUnitOfWorkAssembler().assemble( module ); - } - }; - - UnitOfWorkFactory uowf = assembler.module().unitOfWorkFactory(); - UnitOfWork uow = uowf.newUnitOfWork(); - - try - { - EntityBuilder<TestEntity> entityBuilder = uow.newEntityBuilder( TestEntity.class, new StringIdentity( "123" ) ); - entityBuilder.instance().value().set( assembler.module().newValue( TestValue.class ) ); - TestEntity testEntity = entityBuilder.newInstance(); - - uow.complete(); - uow = uowf.newUnitOfWork(); - - Iterable<TestEntity> entities = Collections.singleton( testEntity = uow.get( testEntity ) ); - - QueryBuilder<TestEntity> builder = assembler.module().newQueryBuilder( TestEntity.class ); - - { - Predicate<Composite> where = QueryExpressions.eq( QueryExpressions.templateFor( TestEntity.class ) - .foo(), "Bar" ); - Assert.assertTrue( where.test( testEntity ) ); - System.out.println( where ); - } - { - Predicate<Composite> where = QueryExpressions.eq( QueryExpressions.templateFor( TestEntity.class ) - .value() - .get() - .bar(), "Xyz" ); - Assert.assertTrue( where.test( testEntity ) ); - System.out.println( where ); - - Assert.assertTrue( builder.where( where ).newQuery( entities ).find().equals( testEntity ) ); - } - } - finally - { - uow.discard(); - } - } - - public interface TestEntity - extends EntityComposite - { - Property<String> foo(); - - Property<TestValue> value(); - } - - public interface TestValue - extends ValueComposite - { - Property<String> bar(); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/activation/ActivationEventsTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/activation/ActivationEventsTest.java b/core/api/src/test/java/org/apache/zest/api/activation/ActivationEventsTest.java deleted file mode 100644 index a9ce44a..0000000 --- a/core/api/src/test/java/org/apache/zest/api/activation/ActivationEventsTest.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.activation; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import org.junit.Test; -import org.apache.zest.api.activation.ActivationEvent.EventType; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.service.ServiceComposite; -import org.apache.zest.api.structure.Application; -import org.apache.zest.api.structure.Module; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.bootstrap.SingletonAssembler; - -import static org.junit.Assert.*; -import static org.apache.zest.api.activation.ActivationEvent.EventType.*; - -public class ActivationEventsTest -{ - - public static interface TestService - { - void test(); - } - - public static class TestServiceInstance - implements TestService - { - - @Override - public void test() - { - } - - } - - @Mixins( TestServiceInstance.class ) - public static interface TestServiceComposite - extends TestService, ServiceComposite - { - } - - @Test - public void testSingleModuleSingleService() - throws Exception - { - final List<ActivationEvent> events = new ArrayList<>(); - - new SingletonAssembler() - { - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.services( TestServiceComposite.class ).instantiateOnStartup(); - } - - @Override - protected void beforeActivation( Application application ) - { - application.registerActivationEventListener( new EventsRecorder( events ) ); - } - - - }.application().passivate(); - - Iterator<ActivationEvent> it = events.iterator(); - - // Activation - assertEvent( it.next(), ACTIVATING, "Application" ); - assertEvent( it.next(), ACTIVATING, "Layer" ); - assertEvent( it.next(), ACTIVATING, "Module" ); - assertEvent( it.next(), ACTIVATING, "TestService" ); - assertEvent( it.next(), ACTIVATED, "TestService" ); - assertEvent( it.next(), ACTIVATED, "Module" ); - assertEvent( it.next(), ACTIVATED, "Layer" ); - assertEvent( it.next(), ACTIVATED, "Application" ); - - // Passivation - assertEvent( it.next(), PASSIVATING, "Application" ); - assertEvent( it.next(), PASSIVATING, "Layer" ); - assertEvent( it.next(), PASSIVATING, "Module" ); - assertEvent( it.next(), PASSIVATING, "TestService" ); - assertEvent( it.next(), PASSIVATED, "TestService" ); - assertEvent( it.next(), PASSIVATED, "Module" ); - assertEvent( it.next(), PASSIVATED, "Layer" ); - assertEvent( it.next(), PASSIVATED, "Application" ); - - assertFalse( it.hasNext() ); - } - - @Test - public void testSingleModuleSingleImportedService() - throws Exception - { - final List<ActivationEvent> events = new ArrayList<>(); - - new SingletonAssembler() - { - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.importedServices( TestService.class ). - setMetaInfo( new TestServiceInstance() ). - importOnStartup(); - } - - @Override - protected void beforeActivation( Application application ) - { - application.registerActivationEventListener( new EventsRecorder( events ) ); - } - - - }.application().passivate(); - - Iterator<ActivationEvent> it = events.iterator(); - - // Activation - assertEvent( it.next(), ACTIVATING, "Application" ); - assertEvent( it.next(), ACTIVATING, "Layer" ); - assertEvent( it.next(), ACTIVATING, "Module" ); - assertEvent( it.next(), ACTIVATING, "TestService" ); - assertEvent( it.next(), ACTIVATED, "TestService" ); - assertEvent( it.next(), ACTIVATED, "Module" ); - assertEvent( it.next(), ACTIVATED, "Layer" ); - assertEvent( it.next(), ACTIVATED, "Application" ); - - // Passivation - assertEvent( it.next(), PASSIVATING, "Application" ); - assertEvent( it.next(), PASSIVATING, "Layer" ); - assertEvent( it.next(), PASSIVATING, "Module" ); - assertEvent( it.next(), PASSIVATING, "TestService" ); - assertEvent( it.next(), PASSIVATED, "TestService" ); - assertEvent( it.next(), PASSIVATED, "Module" ); - assertEvent( it.next(), PASSIVATED, "Layer" ); - assertEvent( it.next(), PASSIVATED, "Application" ); - - assertFalse( it.hasNext() ); - } - - @Test - public void testSingleModuleSingleLazyService() - throws Exception - { - final List<ActivationEvent> events = new ArrayList<>(); - - SingletonAssembler assembler = new SingletonAssembler() - { - - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.services( TestServiceComposite.class ); - } - - @Override - protected void beforeActivation( Application application ) - { - application.registerActivationEventListener( new EventsRecorder( events ) ); - } - - }; - Application application = assembler.application(); - application.passivate(); - - Iterator<ActivationEvent> it = events.iterator(); - - // Activation - assertEvent( it.next(), ACTIVATING, "Application" ); - assertEvent( it.next(), ACTIVATING, "Layer" ); - assertEvent( it.next(), ACTIVATING, "Module" ); - // Lazy Service NOT activated - assertEvent( it.next(), ACTIVATED, "Module" ); - assertEvent( it.next(), ACTIVATED, "Layer" ); - assertEvent( it.next(), ACTIVATED, "Application" ); - - // Passivation - assertEvent( it.next(), PASSIVATING, "Application" ); - assertEvent( it.next(), PASSIVATING, "Layer" ); - assertEvent( it.next(), PASSIVATING, "Module" ); - // Lazy Service NOT passivated - assertEvent( it.next(), PASSIVATED, "Module" ); - assertEvent( it.next(), PASSIVATED, "Layer" ); - assertEvent( it.next(), PASSIVATED, "Application" ); - - assertFalse( it.hasNext() ); - - events.clear(); - application.activate(); - Module module = assembler.module(); - module.findService( TestService.class ).get().test(); - application.passivate(); - - for( ActivationEvent event : events ) { - System.out.println( event ); - } - - it = events.iterator(); - - // Activation - assertEvent( it.next(), ACTIVATING, "Application" ); - assertEvent( it.next(), ACTIVATING, "Layer" ); - assertEvent( it.next(), ACTIVATING, "Module" ); - assertEvent( it.next(), ACTIVATED, "Module" ); - assertEvent( it.next(), ACTIVATED, "Layer" ); - assertEvent( it.next(), ACTIVATED, "Application" ); - - // Lazy Service Activation - assertEvent( it.next(), ACTIVATING, "TestService" ); - assertEvent( it.next(), ACTIVATED, "TestService" ); - - // Passivation - assertEvent( it.next(), PASSIVATING, "Application" ); - assertEvent( it.next(), PASSIVATING, "Layer" ); - assertEvent( it.next(), PASSIVATING, "Module" ); - assertEvent( it.next(), PASSIVATING, "TestService" ); - assertEvent( it.next(), PASSIVATED, "TestService" ); - assertEvent( it.next(), PASSIVATED, "Module" ); - assertEvent( it.next(), PASSIVATED, "Layer" ); - assertEvent( it.next(), PASSIVATED, "Application" ); - - assertFalse( it.hasNext() ); - } - - private static class EventsRecorder - implements ActivationEventListener - { - - private final List<ActivationEvent> events; - - private EventsRecorder( List<ActivationEvent> events ) - { - this.events = events; - } - - @Override - public void onEvent( ActivationEvent event ) - { - events.add( event ); - } - - } - - // WARN This assertion depends on ApplicationInstance, LayerInstance, ModuleInstance and ServiceReferenceInstance toString() method. - private static void assertEvent( ActivationEvent event, EventType expectedType, String expected ) - { - boolean wrongEvent = expectedType != event.type(); - boolean wrongMessage = ! event.message().contains( expected ); - if( wrongEvent || wrongMessage ) - { - StringBuilder sb = new StringBuilder(); - sb.append("Event (").append( event ).append( ") has"); - if( wrongEvent ) - { - sb.append( " wrong type (expected:'" ).append( expectedType ). - append( "' but was:'" ).append( event.type() ).append( "')" ); - if( wrongMessage ) - { - sb.append( ";" ); - } - } - if( wrongMessage ) - { - sb.append( " wrong message (expected:'" ).append( expected ). - append( "' but was:'" ).append( event.message() ).append( "')" ); - } - fail( sb.toString() ); - } - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/activation/PassivationExceptionTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/activation/PassivationExceptionTest.java b/core/api/src/test/java/org/apache/zest/api/activation/PassivationExceptionTest.java deleted file mode 100644 index 079ea58..0000000 --- a/core/api/src/test/java/org/apache/zest/api/activation/PassivationExceptionTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.activation; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.Arrays; -import java.util.Collections; -import org.junit.Test; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.service.ServiceReference; -import org.apache.zest.api.structure.Application; -import org.apache.zest.api.structure.Layer; -import org.apache.zest.api.structure.Module; -import org.apache.zest.bootstrap.Assembler; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.bootstrap.builder.ApplicationBuilder; - -import static org.hamcrest.core.StringContains.containsString; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -public class PassivationExceptionTest -{ - private static String stack( Exception ex ) - { - StringWriter writer = new StringWriter(); - ex.printStackTrace( new PrintWriter( writer ) ); - return writer.toString(); - } - - @Test - public void testEmptyPassivationException() - { - PassivationException empty = new PassivationException( Collections.<Exception>emptyList() ); - assertThat( empty.getMessage(), containsString( "has 0 cause" ) ); - } - - @Test - public void testSinglePassivationException() - { - PassivationException single = new PassivationException( Collections.singletonList( new Exception( "single" ) ) ); - String stack = stack( single ); - assertThat( single.getMessage(), containsString( "has 1 cause" ) ); - assertThat( stack, containsString( "Suppressed: java.lang.Exception: single" ) ); - } - - @Test - public void testMultiplePassivationException() - { - PassivationException multi = new PassivationException( Arrays.asList( new Exception( "one" ), - new Exception( "two" ), - new Exception( "three" ) ) ); - String stack = stack( multi ); - assertThat( multi.getMessage(), containsString( "has 3 cause(s)" ) ); - assertThat( stack, containsString( "Suppressed: java.lang.Exception: one" ) ); - assertThat( stack, containsString( "Suppressed: java.lang.Exception: two" ) ); - assertThat( stack, containsString( "Suppressed: java.lang.Exception: three" ) ); - } - - @Test - public void testPassivationExceptionsAccrossStructure() - throws AssemblyException, ActivationException - { - ApplicationBuilder appBuilder = new ApplicationBuilder( "TestApplication" ); - appBuilder.withLayer( "Layer 1" ).withModule( "Module A" ).withAssembler( new Assembler() - { - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.services( TestService.class ). - identifiedBy( "TestService_Module.A" ). - withActivators( FailBeforePassivationServiceActivator.class ). - instantiateOnStartup(); - } - } ); - appBuilder.withLayer( "Layer 2" ).withModule( "Module B" ).withAssembler( new Assembler() - { - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.services( TestService.class ). - identifiedBy( "TestService_Module.B" ). - withActivators( FailAfterPassivationServiceActivator.class ). - instantiateOnStartup(); - } - } ); - appBuilder.registerActivationEventListener( new TestActivationEventListener() ); - - Application app = appBuilder.newApplication(); - - try - { - Module moduleA = app.findModule( "Layer 1", "Module A" ); - TestService service = moduleA.findService( TestService.class ).get(); - assertThat( service.hello(), equalTo( "Hello Polygene!" ) ); - } - finally - { - try - { - app.passivate(); - fail( "No PassivationException" ); - } - catch( PassivationException ex ) - { - ex.printStackTrace(); - String stack = stack( ex ); - assertThat( ex.getMessage(), containsString( "has 12 cause(s)" ) ); - assertThat( stack, containsString( "EVENT: FAIL BEFORE PASSIVATION for TestApplication" ) ); - assertThat( stack, containsString( "EVENT: FAIL BEFORE PASSIVATION for Layer 2" ) ); - assertThat( stack, containsString( "EVENT: FAIL BEFORE PASSIVATION for Module B" ) ); - assertThat( stack, containsString( "ACTIVATOR: FAIL AFTER PASSIVATION for TestService_Module.B(active=false,module='Module B')" ) ); - assertThat( stack, containsString( "EVENT: FAIL AFTER PASSIVATION for Module B" ) ); - assertThat( stack, containsString( "EVENT: FAIL AFTER PASSIVATION for Layer 2" ) ); - assertThat( stack, containsString( "EVENT: FAIL BEFORE PASSIVATION for Layer 1" ) ); - assertThat( stack, containsString( "EVENT: FAIL BEFORE PASSIVATION for Module A" ) ); - assertThat( stack, containsString( "ACTIVATOR: FAIL BEFORE PASSIVATION for TestService_Module.A(active=true,module='Module A')" ) ); - assertThat( stack, containsString( "EVENT: FAIL AFTER PASSIVATION for Module A" ) ); - assertThat( stack, containsString( "EVENT: FAIL AFTER PASSIVATION for Layer 1" ) ); - assertThat( stack, containsString( "EVENT: FAIL AFTER PASSIVATION for TestApplication" ) ); - } - } - } - - @Mixins( TestService.Mixin.class ) - public interface TestService - { - String hello(); - - static class Mixin - implements TestService - { - @Structure - private Module module; - - @Override - public String hello() - { - module.name(); - return "Hello Polygene!"; - } - } - - } - - public static class FailBeforePassivationServiceActivator - extends ActivatorAdapter<ServiceReference<TestService>> - { - @Override - public void beforePassivation( ServiceReference<TestService> passivated ) - throws Exception - { - throw new Exception( "ACTIVATOR: FAIL BEFORE PASSIVATION for " + passivated ); - } - } - - public static class FailAfterPassivationServiceActivator - extends ActivatorAdapter<ServiceReference<TestService>> - { - @Override - public void afterPassivation( ServiceReference<TestService> passivated ) - throws Exception - { - throw new Exception( "ACTIVATOR: FAIL AFTER PASSIVATION for " + passivated ); - } - } - - public static class TestActivationEventListener - implements ActivationEventListener - { - @Override - public void onEvent( ActivationEvent event ) - throws Exception - { - if( !( event.source() instanceof Application ) - && !( event.source() instanceof Layer ) - && !( event.source() instanceof Module ) ) - { - return; - } - switch( event.type() ) - { - case PASSIVATING: - throw new Exception( "EVENT: FAIL BEFORE PASSIVATION for " + event.source() ); - case PASSIVATED: - throw new Exception( "EVENT: FAIL AFTER PASSIVATION for " + event.source() ); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/annotation/MixinsTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/annotation/MixinsTest.java b/core/api/src/test/java/org/apache/zest/api/annotation/MixinsTest.java deleted file mode 100644 index f274697..0000000 --- a/core/api/src/test/java/org/apache/zest/api/annotation/MixinsTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.annotation; - -import java.lang.annotation.Annotation; -import org.junit.Test; -import org.apache.zest.api.mixin.Mixins; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Tests public api exposed by Mixins annotation. - * This will ensure that the public api does not get changed by mistake. - */ -public class MixinsTest -{ - - @Test - public void retention() - { - Annotation[] annotations = Annotated.class.getDeclaredAnnotations(); - assertNotNull( "annotations should not be null", annotations ); - assertEquals( "number of annotations", 1, annotations.length ); - assertEquals( "annotation type", Mixins.class, annotations[ 0 ].annotationType() ); - } - - @Mixins( Object.class ) - private static class Annotated - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/annotation/ModifiedByTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/annotation/ModifiedByTest.java b/core/api/src/test/java/org/apache/zest/api/annotation/ModifiedByTest.java deleted file mode 100644 index b886121..0000000 --- a/core/api/src/test/java/org/apache/zest/api/annotation/ModifiedByTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.annotation; - -import java.lang.annotation.Annotation; -import org.junit.Test; -import org.apache.zest.api.concern.Concerns; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Tests public api exposed by Concerns annotation. - * This will ensure that the public api does not get changed by mistake. - */ -public class ModifiedByTest -{ - - @Test - public void retention() - { - Annotation[] annotations = Annotated.class.getDeclaredAnnotations(); - assertNotNull( "annotations should not be null", annotations ); - assertEquals( "number of annotations", 1, annotations.length ); - assertEquals( "annotation type", Concerns.class, annotations[ 0 ].annotationType() ); - } - - @Concerns( Object.class ) - private static class Annotated - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/annotation/scope/ModifiesTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/annotation/scope/ModifiesTest.java b/core/api/src/test/java/org/apache/zest/api/annotation/scope/ModifiesTest.java deleted file mode 100644 index 1a2170c..0000000 --- a/core/api/src/test/java/org/apache/zest/api/annotation/scope/ModifiesTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.annotation.scope; - -import java.lang.annotation.Annotation; -import org.junit.Test; -import org.apache.zest.api.concern.internal.ConcernFor; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Tests public api exposed by Modified annotation. - * This will ensure that the public api does not get changed by mistake. - */ -public class ModifiesTest -{ - - @Test - public void retention() - throws NoSuchFieldException - { - Annotation[] annotations = Annotated.class.getDeclaredField( "modified" ).getDeclaredAnnotations(); - assertNotNull( "annotations should not be null", annotations ); - assertEquals( "number of annotations", 1, annotations.length ); - assertEquals( "annotation type", ConcernFor.class, annotations[ 0 ].annotationType() ); - } - - private static class Annotated - { - @ConcernFor - String modified; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/common/AppliesToTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/common/AppliesToTest.java b/core/api/src/test/java/org/apache/zest/api/common/AppliesToTest.java deleted file mode 100644 index 8a3755a..0000000 --- a/core/api/src/test/java/org/apache/zest/api/common/AppliesToTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.common; - -import java.lang.annotation.Annotation; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Tests public api exposed by AppliesTo annotation. - * This will ensure that the public api does not get changed by mistake. - */ -public class AppliesToTest -{ - - @Test - public void retention() - { - Annotation[] annotations = Annotated.class.getDeclaredAnnotations(); - assertNotNull( "annotations should not be null", annotations ); - assertEquals( "number of annotations", 1, annotations.length ); - assertEquals( "annotation type", AppliesTo.class, annotations[ 0 ].annotationType() ); - } - - @AppliesTo( Object.class ) - private static class Annotated - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/common/QualifiedNameTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/common/QualifiedNameTest.java b/core/api/src/test/java/org/apache/zest/api/common/QualifiedNameTest.java deleted file mode 100644 index 85e2106..0000000 --- a/core/api/src/test/java/org/apache/zest/api/common/QualifiedNameTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.common; - -import org.junit.Test; -import org.apache.zest.api.util.NullArgumentException; - -import static org.junit.Assert.assertEquals; - -public class QualifiedNameTest -{ - @Test - public void testQualifiedNameWithDollar() - { - assertEquals( "Name containing dollar is modified", "Test-Test", - new QualifiedName( TypeName.nameOf( "Test$Test" ), "satisfiedBy" ).type() ); - } - - @Test - public void testQualifiedNameFromQNWithDollar() - { - assertEquals( "Name containing dollar is cleaned up", "Test-Test", - QualifiedName.fromFQN( "Test$Test:satisfiedBy" ).type() ); - } - - @Test( expected = NullArgumentException.class ) - public void nonNullArguments1() - { - new QualifiedName( TypeName.nameOf( "Test" ), null ); - } - - @Test( expected = NullArgumentException.class ) - public void nonNullArguments2() - { - new QualifiedName( null, "satisfiedBy" ); - } - - @Test( expected = NullArgumentException.class ) - public void nonNullArguments3() - { - new QualifiedName( null, null ); - } - - @Test( expected = NullArgumentException.class ) - public void nonNullArguments4() - { - QualifiedName.fromFQN( null ); - } - - @Test( expected = NullArgumentException.class ) - public void nonNullArguments5() - { - QualifiedName.fromAccessor( null ); - } - - @Test( expected = NullArgumentException.class ) - public void nonNullArguments6() - { - QualifiedName.fromClass( null, "satisfiedBy" ); - } - - @Test( expected = NullArgumentException.class ) - public void nonNullArguments7() - { - QualifiedName.fromClass( null, null ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/composite/PropertyMapperTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/composite/PropertyMapperTest.java b/core/api/src/test/java/org/apache/zest/api/composite/PropertyMapperTest.java deleted file mode 100644 index 22464b1..0000000 --- a/core/api/src/test/java/org/apache/zest/api/composite/PropertyMapperTest.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.zest.api.composite; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class PropertyMapperTest -{ - private final static Method MAP_TO_TYPE; - - static - { - try - { - MAP_TO_TYPE = PropertyMapper.class.getDeclaredMethod( "mapToType", Composite.class, Type.class, Object.class ); - MAP_TO_TYPE.setAccessible( true ); - } - catch( NoSuchMethodException e ) - { - InternalError error = new InternalError(); - error.initCause( e ); - throw error; - } - } - - @Test - public void testMappingOfInteger() - throws Exception - { - assertEquals( 5, mapToType( null, Integer.class, "5" ) ); - assertEquals( -5, mapToType( null, Integer.class, "-5" ) ); - assertEquals( Integer.class, mapToType( null, Integer.class, "5" ).getClass() ); - } - - @Test - public void testMappingOfLong() - throws Exception - { - assertEquals( 5L, mapToType( null, Long.class, "5" ) ); - assertEquals( 5876328476238746238L, mapToType( null, Long.class, "5876328476238746238" ) ); - assertEquals( Long.class, mapToType( null, Long.class, "5" ).getClass() ); - } - - @Test - public void testMappingOfBoolean() - throws Exception - { - assertEquals( false, mapToType( null, Boolean.class, "false" ) ); - assertEquals( true, mapToType( null, Boolean.class, "true" ) ); - assertEquals( Boolean.class, mapToType( null, Boolean.class, "false" ).getClass() ); - } - - @Test - public void testMappingOfFloat() - throws Exception - { - assertEquals( 5.1234f, mapToType( null, Float.class, "5.1234" ) ); - assertEquals( 5876328476.6238f, mapToType( null, Float.class, "5876328476.6238" ) ); - assertEquals( Float.class, mapToType( null, Float.class, "5" ).getClass() ); - } - - @Test - public void testMappingOfDouble() - throws Exception - { - assertEquals( 5.1234, mapToType( null, Double.class, "5.1234" ) ); - assertEquals( 5876328476.623823, mapToType( null, Double.class, "5876328476.623823" ) ); - assertEquals( Double.class, mapToType( null, Double.class, "5" ).getClass() ); - } - - @Test - public void testMappingOfBigDecimal() - throws Exception - { - assertEquals( new BigDecimal( 3 ), mapToType( null, BigDecimal.class, "3" ) ); - assertEquals( new BigDecimal( "12345.67891011" ), mapToType( null, BigDecimal.class, "12345.67891011" ) ); - assertEquals( BigDecimal.class, mapToType( null, BigDecimal.class, "5" ).getClass() ); - } - - @Test - public void testMappingOfBigInteger() - throws Exception - { - assertEquals( new BigInteger( "20", 16 ), mapToType( null, BigInteger.class, "32" ) ); - assertEquals( new BigInteger( "1234567891011" ), mapToType( null, BigInteger.class, "1234567891011" ) ); - assertEquals( BigInteger.class, mapToType( null, BigInteger.class, "5" ).getClass() ); - } - - @Test - public void testMappingOfEnum() - throws Exception - { - assertEquals( TestEnum.FIRST, mapToType( null, TestEnum.class, "FIRST" ) ); - assertEquals( TestEnum.SECOND, mapToType( null, TestEnum.class, "SECOND" ) ); - assertEquals( TestEnum.class, mapToType( null, TestEnum.class, "SECOND" ).getClass() ); - } - - @Test - public void testMappingOfIntegerArray() - throws Exception - { - Object[] value = (Object[]) mapToType( null, Integer[].class, "5,4 , 3 ,2,1" ); - assertEquals( 5, value.length ); - assertEquals( 5, value[ 0 ] ); - assertEquals( 4, value[ 1 ] ); - assertEquals( 3, value[ 2 ] ); - assertEquals( 2, value[ 3 ] ); - assertEquals( 1, value[ 4 ] ); - } - - @Test - public void testMappingOfStringArray() - throws Exception - { - { - Object[] value = (Object[]) mapToType( null, String[].class, "5,4 , 3 ,2,1" ); - assertEquals( 5, value.length ); - assertEquals( "5", value[ 0 ] ); - assertEquals( "4 ", value[ 1 ] ); - assertEquals( " 3 ", value[ 2 ] ); - assertEquals( "2", value[ 3 ] ); - assertEquals( "1", value[ 4 ] ); - } - { - Object[] value = (Object[]) mapToType( null, String[].class, "5,4 ,\" 3, \", \" 2\" ,1" ); - assertEquals( "5", value[ 0 ] ); - assertEquals( "4 ", value[ 1 ] ); - assertEquals( " 3, ", value[ 2 ] ); - assertEquals( " 2", value[ 3 ] ); - assertEquals( "1", value[ 4 ] ); - assertEquals( 5, value.length ); - } - } - - @Test - public void testMappingOfBooleanArray() - throws Exception - { - Object[] value = (Object[]) mapToType( null, Boolean[].class, " true,false, false, true ,true,false" ); - assertEquals( true, value[ 0 ] ); - assertEquals( false, value[ 1 ] ); - assertEquals( false, value[ 2 ] ); - assertEquals( true, value[ 3 ] ); - assertEquals( true, value[ 4 ] ); - assertEquals( false, value[ 5 ] ); - assertEquals( 6, value.length ); - } - - @Test - public void testMappingOfList() - throws Exception - { - Type type = Testing.class.getDeclaredMethod( "list" ).getGenericReturnType(); - List<String> value = (List<String>) mapToType( null, type, "5,4 ,\" 3, \", \" 2\" ,1" ); - assertEquals( "5", value.get( 0 ) ); - assertEquals( "4 ", value.get( 1 ) ); - assertEquals( " 3, ", value.get( 2 ) ); - assertEquals( " 2", value.get( 3 ) ); - assertEquals( "1", value.get( 4 ) ); - assertEquals( 5, value.size() ); - } - - @Test - public void testMappingOfSet() - throws Exception - { - Type type = Testing.class.getDeclaredMethod( "set" ).getGenericReturnType(); - Set<String> value = (Set<String>) mapToType( null, type, "5,4 ,\" 3, \", \" 2\" ,1" ); - assertTrue( value.contains( "5" ) ); - assertTrue( value.contains( "4 " ) ); - assertTrue( value.contains( " 3, " ) ); - assertTrue( value.contains( " 2" ) ); - assertTrue( value.contains( "1" ) ); - assertEquals( 5, value.size() ); - } - - @Test - public void testMappingOfMap() - throws Exception - { - Type type = Testing.class.getDeclaredMethod( "map" ).getGenericReturnType(); - Map<String, String> value = (Map<String, String>) mapToType( null, type, "first:5,second:4 , third:\" 3, \", fourth: \" 2\" ,fifth : 1" ); - assertEquals( "5", value.get( "first" ) ); - assertEquals( "4 ", value.get( "second" ) ); - assertEquals( " 3, ", value.get( " third" ) ); - assertEquals( " 2", value.get( " fourth" ) ); - assertEquals( " 1", value.get( "fifth " ) ); - assertEquals( 5, value.size() ); - } - - private Object mapToType( Composite composite, Type propertyType, Object value ) - throws IllegalAccessException, InvocationTargetException - { - return MAP_TO_TYPE.invoke( null, composite, propertyType, value ); - } - - interface Testing - { - List<String> list(); - - Set<String> set(); - - Map<String, String> map(); - } - - enum TestEnum - { - FIRST, - SECOND - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/concern/DocumentationSupport.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/concern/DocumentationSupport.java b/core/api/src/test/java/org/apache/zest/api/concern/DocumentationSupport.java deleted file mode 100644 index 1a46b2c..0000000 --- a/core/api/src/test/java/org/apache/zest/api/concern/DocumentationSupport.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.concern; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import org.apache.zest.api.common.AppliesTo; -import org.apache.zest.api.common.AppliesToFilter; -import org.apache.zest.api.injection.InjectionScope; - -public class DocumentationSupport -{ -// START SNIPPET: class - @AppliesTo( java.sql.Connection.class ) - public class CacheConcern extends GenericConcern - implements InvocationHandler - { -// END SNIPPET: class - @Override - public Object invoke( Object proxy, Method method, Object[] args ) - throws Throwable - { - return null; - } - } - -// START SNIPPET: filter - @AppliesTo( BusinessAppliesToFilter.class ) - public class BusinessConcern extends GenericConcern - implements InvocationHandler - { -// END SNIPPET: filter - @Override - public Object invoke( Object proxy, Method method, Object[] args ) - throws Throwable - { - return null; - } - } - -// START SNIPPET: filter - public class BusinessAppliesToFilter - implements AppliesToFilter - { - - @Override - public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass - ) - { - return true; // Some criteria for when a method is wrapped with the concern. - } - } -// END SNIPPET: filter - - -// START SNIPPET: annotation - @AppliesTo( Audited.class ) - public class AuditConcern extends GenericConcern - implements InvocationHandler - { -// START SNIPPET: annotation - @Override - public Object invoke( Object proxy, Method method, Object[] args ) - throws Throwable - { - return null; - } - } - -// START SNIPPET: annotation - @Retention( RetentionPolicy.RUNTIME ) - @Target( { ElementType.METHOD } ) - @Documented - @InjectionScope - public @interface Audited - { - } -// END SNIPPET: annotation -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/configuration/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/configuration/ConfigurationTest.java b/core/api/src/test/java/org/apache/zest/api/configuration/ConfigurationTest.java deleted file mode 100644 index 4d29164..0000000 --- a/core/api/src/test/java/org/apache/zest/api/configuration/ConfigurationTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.configuration; - -import org.junit.Test; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.property.Property; -import org.apache.zest.api.service.ServiceComposite; -import org.apache.zest.api.value.ValueComposite; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.test.AbstractPolygeneTest; -import org.apache.zest.test.EntityTestAssembler; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -public class ConfigurationTest extends AbstractPolygeneTest -{ - - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.services( MyService.class ).instantiateOnStartup(); - module.entities( MyConfig.class ); - module.values( PersonDetails.class, Address.class, City.class, Country.class ); - new EntityTestAssembler().assemble( module ); - } - - @Test - public void testConfiguration() - throws Exception - { - MyService service = serviceFinder.findService( MyService.class ).get(); - PersonDetails details = service.details(); - assertThat(details.name().get(), equalTo( "Niclas" ) ); - assertThat(details.address().get().street1().get(), equalTo( "Henan Lu 555" ) ); - assertThat(details.address().get().street2().get(), equalTo( "Block 15" ) ); - assertThat(details.address().get().city().get().cityName().get(), equalTo( "Shanghai" ) ); - assertThat(details.address().get().city().get().country().get().countryName().get(), equalTo( "China" ) ); - } - - @Mixins(MyServiceMixin.class) - public interface MyService extends ServiceComposite - { - PersonDetails details(); - } - - public abstract class MyServiceMixin - implements MyService - { - @This - Configuration<MyConfig> myconf; - - @Override - public PersonDetails details() - { - return myconf.get().me().get(); - } - } - - public interface MyConfig extends ConfigurationComposite - { - Property<PersonDetails> me(); - } - - public interface PersonDetails extends ValueComposite - { - Property<String> name(); - Property<Address> address(); - - } - - public interface Address extends ValueComposite - { - Property<String> street1(); - Property<String> street2(); - Property<City> city(); - } - - public interface City extends ValueComposite - { - Property<String> cityName(); - Property<Country> country(); - } - - public interface Country extends ValueComposite - { - Property<String> countryName(); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/configuration/DeclareConfigurationDefaultsTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/configuration/DeclareConfigurationDefaultsTest.java b/core/api/src/test/java/org/apache/zest/api/configuration/DeclareConfigurationDefaultsTest.java deleted file mode 100644 index cf6217c..0000000 --- a/core/api/src/test/java/org/apache/zest/api/configuration/DeclareConfigurationDefaultsTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.configuration; - -import org.junit.Assert; -import org.junit.Test; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.property.Property; -import org.apache.zest.api.service.ServiceComposite; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.test.AbstractPolygeneTest; -import org.apache.zest.test.EntityTestAssembler; - -public class DeclareConfigurationDefaultsTest - extends AbstractPolygeneTest -{ - - @Mixins( FooServiceMixin.class ) - public static interface FooServiceComposite - extends ServiceComposite - { - - String configuredFoo(); - - } - - public static abstract class FooServiceMixin - implements FooServiceComposite - { - - @This - private Configuration<FooConfigurationComposite> config; - - public String configuredFoo() - { - return config.get().foo().get(); - } - - } - - public static interface FooConfigurationComposite - extends ConfigurationComposite - { - - Property<String> foo(); - - } - - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.services( FooServiceComposite.class ).identifiedBy( "bazar" ); - module.entities( FooConfigurationComposite.class ); - new EntityTestAssembler().assemble( module ); - FooConfigurationComposite config = module.forMixin( FooConfigurationComposite.class ).declareDefaults(); - config.foo().set( "bar" ); - } - - @Test - public void testConfigurationDefaults() - { - FooServiceComposite fooService = serviceFinder.findService( FooServiceComposite.class ).get(); - Assert.assertEquals( "bar", fooService.configuredFoo() ); - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/configuration/MailService.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/configuration/MailService.java b/core/api/src/test/java/org/apache/zest/api/configuration/MailService.java deleted file mode 100644 index 7392be5..0000000 --- a/core/api/src/test/java/org/apache/zest/api/configuration/MailService.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.zest.api.configuration; - -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.library.constraints.annotation.Email; -import org.apache.zest.library.constraints.annotation.MinLength; - -// Documentation Support -@Mixins( MailService.MailServiceMixin.class ) -public interface MailService -{ - void sendMail( @Email String to, @MinLength( 8 ) String subject, String body ); - - // START SNIPPET: write - void changeExternalMailService( String hostName, int port ); - // END SNIPPET: write - - public class MailServiceMixin - implements MailService - { - // START SNIPPET: read - @This - private Configuration<MailServiceConfiguration> config; - - @Override - public void sendMail( @Email String to, @MinLength( 8 ) String subject, String body ) - { - config.refresh(); - MailServiceConfiguration conf = config.get(); - String hostName = conf.hostName().get(); - int port = conf.port().get(); - // END SNIPPET: read - - // START SNIPPET: read - } - // END SNIPPET: read - - // START SNIPPET: write - @Override - public void changeExternalMailService( String hostName, int port ) - { - MailServiceConfiguration conf = config.get(); - conf.hostName().set( hostName ); - conf.port().set( port ); - config.save(); - } - // START SNIPPET: write - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/api/src/test/java/org/apache/zest/api/configuration/MailServiceConfiguration.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/configuration/MailServiceConfiguration.java b/core/api/src/test/java/org/apache/zest/api/configuration/MailServiceConfiguration.java deleted file mode 100644 index 8da6b69..0000000 --- a/core/api/src/test/java/org/apache/zest/api/configuration/MailServiceConfiguration.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.zest.api.configuration; - -import org.apache.zest.api.property.Property; - -// Documentation Support class -// START SNIPPET: configuration -public interface MailServiceConfiguration extends ConfigurationComposite -{ - Property<String> hostName(); - - Property<Integer> port(); -} -// END SNIPPET: configuration
