You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2016/08/19 12:18:43 UTC
[09/25] zest-java git commit: ZEST-151 : Removed Conversion Library
http://git-wip-us.apache.org/repos/asf/zest-java/blob/5229303a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityService.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityService.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityService.java
deleted file mode 100644
index 07eb026..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityService.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.library.conversion.values;
-
-import org.apache.zest.api.entity.Identity;
-import org.apache.zest.api.mixin.Mixins;
-
-/**
- * Service that creates or updates Entities from matching Values.
- * @deprecated Please use {@link org.apache.zest.api.unitofwork.UnitOfWork#toEntity(Class, Identity)} instead.
- */
-@Mixins( ValueToEntityMixin.class )
-public interface ValueToEntityService
- extends ValueToEntity
-{
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/5229303a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/package.html
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/package.html b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/package.html
deleted file mode 100644
index 8e3482c..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/package.html
+++ /dev/null
@@ -1,24 +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.
- ~
- ~
- -->
-<html>
- <body>
- <h2>Entities to Values Conversion.</h2>
- </body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/5229303a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/EntityToValueTest.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/EntityToValueTest.java b/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/EntityToValueTest.java
deleted file mode 100644
index 13c1868..0000000
--- a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/EntityToValueTest.java
+++ /dev/null
@@ -1,232 +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.library.conversion.values;
-
-import java.time.Instant;
-import java.time.LocalDate;
-import java.util.function.Function;
-import org.junit.Test;
-import org.apache.zest.api.constraint.ConstraintViolationException;
-import org.apache.zest.api.service.ServiceReference;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.library.conversion.values.TestModel.PersonEntity;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue2;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue3;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue4;
-import org.apache.zest.test.AbstractZestTest;
-import org.apache.zest.test.EntityTestAssembler;
-
-import static org.junit.Assert.assertEquals;
-import static org.apache.zest.library.conversion.values.TestModel.createBirthDate;
-import static org.apache.zest.library.conversion.values.TestModel.createPerson;
-
-public class EntityToValueTest
- extends AbstractZestTest
-{
- @Override
- public void assemble( ModuleAssembly module )
- throws AssemblyException
- {
- // START SNIPPET: assembly
- new EntityToValueAssembler().assemble( module );
- // END SNIPPET: assembly
- new EntityTestAssembler().assemble( module );
- module.entities( PersonEntity.class );
- module.values( PersonValue.class );
- module.values( PersonValue2.class );
- module.values( PersonValue3.class );
- module.values( PersonValue4.class );
- }
-
- @Test
- public void whenConvertingEntityToValueExpectCorrectValues()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- PersonEntity entity = setupPersonEntities( uow );
-
- // START SNIPPET: conversion
- EntityToValueService conversion = serviceFinder.findService( EntityToValueService.class ).get();
- PersonValue value = conversion.convert( PersonValue.class, entity );
- // END SNIPPET: conversion
- assertEquals( "Niclas", value.firstName().get() );
- assertEquals( "Hedhman", value.lastName().get() );
- assertEquals( "id:Lis", value.spouse().get() );
- assertEquals( "id:Eric", value.children().get().get( 0 ) );
- uow.complete();
- }
- finally
- {
- uow.discard();
- }
- }
-
- @Test
- public void givenUnqualifiedValueWhenConvertingEntityExpectCorrectMapping()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- PersonEntity niclas = setupPersonEntities( uow );
-
- ServiceReference<EntityToValueService> reference = serviceFinder.findService( EntityToValueService.class );
- EntityToValueService service = reference.get();
-
- PersonValue2 niclasValue = service.convert( PersonValue2.class, niclas );
- assertEquals( "Niclas", niclasValue.firstName().get() );
- assertEquals( "Hedhman", niclasValue.lastName().get() );
- assertEquals( "id:Lis", niclasValue.spouse().get() );
- assertEquals( "id:Eric", niclasValue.children().get().get( 0 ) );
- uow.complete();
- }
- finally
- {
- uow.discard();
- }
- }
-
- @Test
- public void givenUnqualifiedValue2WhenConvertingEntityExpectCorrectMapping()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- PersonEntity niclas = setupPersonEntities( uow );
-
- ServiceReference<EntityToValueService> reference = serviceFinder.findService( EntityToValueService.class );
- EntityToValueService service = reference.get();
-
- PersonValue3 niclasValue = service.convert( PersonValue3.class, niclas );
- assertEquals( "Niclas", niclasValue.firstName().get() );
- assertEquals( "Hedhman", niclasValue.lastName().get() );
- assertEquals( "id:Lis", niclasValue.spouse().get() );
- assertEquals( "id:Eric", niclasValue.children().get().get( 0 ) );
- uow.complete();
- }
- finally
- {
- uow.discard();
- }
- }
-
- @Test( expected = ConstraintViolationException.class )
- public void givenQualifiedValueNotFromSameInterfaceWhenConvertingEntityExpectNonOptionalException()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- PersonEntity niclas = setupPersonEntities( uow );
-
- ServiceReference<EntityToValueService> reference = serviceFinder.findService( EntityToValueService.class );
- EntityToValueService service = reference.get();
-
- PersonValue4 niclasValue = service.convert( PersonValue4.class, niclas );
- uow.complete();
- }
- finally
- {
- uow.discard();
- }
- }
-
- @Test
- public void whenConvertingEntityToValueUsingPrototypeOpportunityExpectCorrectValues()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- PersonEntity entity = setupPersonEntities( uow );
-
- // START SNIPPET: prototypeOpportunity
- EntityToValueService conversion = serviceFinder.findService( EntityToValueService.class ).get();
- PersonValue value = conversion.convert( PersonValue.class, entity, new Function<PersonValue, PersonValue>()
- {
- @Override
- public PersonValue apply( PersonValue prototype )
- {
- prototype.firstName().set( "Prototype Opportunity" );
- return prototype;
- }
- } );
- // END SNIPPET: prototypeOpportunity
- assertEquals( "Prototype Opportunity", value.firstName().get() );
- assertEquals( "Hedhman", value.lastName().get() );
- assertEquals( "id:Lis", value.spouse().get() );
- assertEquals( "id:Eric", value.children().get().get( 0 ) );
- uow.complete();
- }
- finally
- {
- uow.discard();
- }
- }
-
- private static PersonEntity setupPersonEntities( UnitOfWork uow )
- {
- PersonEntity niclas = createNiclas( uow );
- PersonEntity lis = createLis( uow );
- PersonEntity eric = createEric( uow );
- niclas.spouse().set( lis );
- niclas.children().add( eric );
- lis.spouse().set( niclas );
- lis.children().add( eric );
- assertEquals( "Niclas", niclas.firstName() );
- assertEquals( "Hedhman", niclas.lastName() );
- assertEquals( "Lis", lis.firstName() );
- assertEquals( "Gazi", lis.lastName() );
- assertEquals( "Eric", eric.firstName() );
- assertEquals( "Hedman", eric.lastName() );
- return niclas;
- }
-
- private static PersonEntity createNiclas( UnitOfWork uow )
- {
- String firstName = "Niclas";
- String lastName = "Hedhman";
- LocalDate birthTime = createBirthDate( 1964, 9, 25 );
- return createPerson( uow, firstName, lastName, birthTime );
- }
-
- private static PersonEntity createLis( UnitOfWork uow )
- {
- String firstName = "Lis";
- String lastName = "Gazi";
- LocalDate birthTime = createBirthDate( 1976, 2, 19 );
- return createPerson( uow, firstName, lastName, birthTime );
- }
-
- private static PersonEntity createEric( UnitOfWork uow )
- {
- String firstName = "Eric";
- String lastName = "Hedman";
- LocalDate birthTime = createBirthDate( 2004, 4, 8 );
- return createPerson( uow, firstName, lastName, birthTime );
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/5229303a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/NestedValuesConversionTest.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/NestedValuesConversionTest.java b/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/NestedValuesConversionTest.java
deleted file mode 100644
index e049c30..0000000
--- a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/NestedValuesConversionTest.java
+++ /dev/null
@@ -1,130 +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.library.conversion.values;
-
-import java.util.Arrays;
-import java.util.List;
-import org.junit.Test;
-import org.apache.zest.api.entity.EntityBuilder;
-import org.apache.zest.api.entity.EntityComposite;
-import org.apache.zest.api.property.Property;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
-import org.apache.zest.api.value.ValueBuilder;
-import org.apache.zest.api.value.ValueComposite;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.test.AbstractZestTest;
-import org.apache.zest.test.EntityTestAssembler;
-
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
-
-public class NestedValuesConversionTest
- extends AbstractZestTest
-{
-
- @Override
- public void assemble( ModuleAssembly ma )
- throws AssemblyException
- {
- new EntityToValueAssembler().assemble( ma );
- new EntityTestAssembler().assemble( ma );
-
- ma.entities( FooEntity.class );
- ma.values( FooValue.class, BarValue.class );
- }
-
- @Test
- public void testNestedValuesConversion()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- FooEntity fooEntity = createFooEntity( uow, "Test nested values conversion" );
- EntityToValueService conversion = serviceFinder.findService( EntityToValueService.class ).get();
- FooValue fooValue = conversion.convert( FooValue.class, fooEntity );
- assertThat( fooValue.name().get(), equalTo( "Test nested values conversion" ) );
- assertThat( fooValue.bar().get().bazar().get(), equalTo( "single" ) );
- List<BarValue> barList = fooValue.barList().get();
- assertThat( barList.size(), equalTo( 3 ) );
- assertThat( barList.get( 0 ).bazar().get(), equalTo( "multi-one" ) );
- assertThat( barList.get( 1 ).bazar().get(), equalTo( "multi-two" ) );
- assertThat( barList.get( 2 ).bazar().get(), equalTo( "multi-three" ) );
- uow.complete();
- uow = null;
- }
- finally
- {
- if( uow != null )
- {
- uow.discard();
- }
- }
- }
-
- private FooEntity createFooEntity( UnitOfWork uow, String name )
- {
- EntityBuilder<FooEntity> builder = uow.newEntityBuilder( FooEntity.class );
- builder.instance().name().set( name );
- builder.instance().bar().set( createBarValue( "single" ) );
- List<BarValue> bars = Arrays.asList( createBarValue( "multi-one" ),
- createBarValue( "multi-two" ),
- createBarValue( "multi-three" ) );
- builder.instance().barList().set( bars );
- return builder.newInstance();
- }
-
- private BarValue createBarValue( String bazar )
- {
- ValueBuilder<BarValue> builder = valueBuilderFactory.newValueBuilder( BarValue.class );
- builder.prototype().bazar().set( bazar );
- return builder.newInstance();
- }
-
- public interface FooState
- {
-
- Property<String> name();
-
- Property<BarValue> bar();
-
- Property<List<BarValue>> barList();
- }
-
- public interface FooValue
- extends FooState, ValueComposite
- {
- }
-
- public interface FooEntity
- extends FooState, EntityComposite
- {
- }
-
- public interface BarValue
- extends ValueComposite
- {
-
- Property<String> bazar();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/5229303a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java b/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java
deleted file mode 100644
index 54fe910..0000000
--- a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java
+++ /dev/null
@@ -1,202 +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.library.conversion.values;
-
-import java.time.Duration;
-import java.time.Instant;
-import java.time.LocalDate;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.util.List;
-import org.apache.zest.api.association.Association;
-import org.apache.zest.api.association.ManyAssociation;
-import org.apache.zest.api.common.Optional;
-import org.apache.zest.api.entity.EntityBuilder;
-import org.apache.zest.api.entity.EntityComposite;
-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.unitofwork.UnitOfWork;
-import org.apache.zest.api.value.ValueComposite;
-
-import static java.time.ZoneOffset.UTC;
-
-/**
- * Test Model.
- */
-final class TestModel
-{
- static PersonEntity createPerson( UnitOfWork uow, String firstName, String lastName, LocalDate birthDate )
- {
- EntityBuilder<PersonEntity> builder = uow.newEntityBuilder( PersonEntity.class, "id:" + firstName );
- PersonState state = builder.instanceFor( PersonState.class );
- state.firstName().set( firstName );
- state.lastName().set( lastName );
- state.dateOfBirth().set( birthDate );
- return builder.newInstance();
- }
-
- static LocalDate createBirthDate( int year, int month, int day )
- {
- return LocalDate.of( year, month, day);
- }
-
- // START SNIPPET: state
- public interface PersonState
- {
-
- Property<String> firstName();
-
- Property<String> lastName();
-
- Property<LocalDate> dateOfBirth();
-
- }
- // END SNIPPET: state
-
- // START SNIPPET: value
- public interface PersonValue
- extends PersonState, ValueComposite
- {
-
- @Optional
- Property<String> spouse();
-
- @Optional
- Property<List<String>> children();
-
- }
- // END SNIPPET: value
-
- // START SNIPPET: entity
- @Mixins( PersonMixin.class )
- public interface PersonEntity
- extends EntityComposite
- {
-
- String firstName();
-
- String lastName();
-
- Integer age();
-
- @Optional
- Association<PersonEntity> spouse();
-
- ManyAssociation<PersonEntity> children();
-
- }
- // END SNIPPET: entity
-
- // START SNIPPET: entity
- public static abstract class PersonMixin
- implements PersonEntity
- {
-
- @This
- private PersonState state;
- // END SNIPPET: entity
-
- @Override
- public String firstName()
- {
- return state.firstName().get();
- }
-
- @Override
- public String lastName()
- {
- return state.lastName().get();
- }
-
- @Override
- public Integer age()
- {
- Duration age = Duration.between( state.dateOfBirth().get(), Instant.now() );
- return (int) age.toDays()/365;
- }
-
- // START SNIPPET: entity
- }
- // END SNIPPET: entity
-
- // START SNIPPET: unqualified
- @Unqualified
- public interface PersonValue2
- extends ValueComposite
- {
-
- Property<String> firstName();
-
- Property<String> lastName();
-
- Property<LocalDate> dateOfBirth();
-
- @Optional
- Property<String> spouse();
-
- @Optional
- Property<List<String>> children();
-
- }
- // END SNIPPET: unqualified
-
- @Unqualified( true )
- public interface PersonValue3
- extends ValueComposite
- {
-
- Property<String> firstName();
-
- Property<String> lastName();
-
- Property<LocalDate> dateOfBirth();
-
- @Optional
- Property<String> spouse();
-
- @Optional
- Property<List<String>> children();
-
- }
-
- @Unqualified( false )
- public interface PersonValue4
- extends ValueComposite
- {
-
- Property<String> firstName();
-
- Property<String> lastName();
-
- Property<LocalDate> dateOfBirth();
-
- @Optional
- Property<String> spouse();
-
- @Optional
- Property<List<String>> children();
-
- }
-
- private TestModel()
- {
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/5229303a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java b/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java
deleted file mode 100644
index c0f8eea..0000000
--- a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java
+++ /dev/null
@@ -1,355 +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.library.conversion.values;
-
-import java.time.LocalDate;
-import java.util.Arrays;
-import java.util.function.Predicate;
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.zest.api.constraint.ConstraintViolationException;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
-import org.apache.zest.api.value.ValueBuilder;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.functional.Iterables;
-import org.apache.zest.library.conversion.values.TestModel.PersonEntity;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue2;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue3;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue4;
-import org.apache.zest.test.AbstractZestTest;
-import org.apache.zest.test.EntityTestAssembler;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
-import static org.apache.zest.api.usecase.UsecaseBuilder.newUsecase;
-import static org.apache.zest.library.conversion.values.TestModel.createBirthDate;
-import static org.apache.zest.library.conversion.values.TestModel.createPerson;
-
-/**
- * ValueToEntity Service Test.
- */
-public class ValueToEntityTest
- extends AbstractZestTest
-{
- @Override
- public void assemble( ModuleAssembly module )
- throws AssemblyException
- {
- // START SNIPPET: assembly
- new ValueToEntityAssembler().assemble( module );
- // END SNIPPET: assembly
- new EntityTestAssembler().assemble( module );
- module.entities( PersonEntity.class );
- module.values( PersonValue.class );
- module.values( PersonValue2.class );
- module.values( PersonValue3.class );
- module.values( PersonValue4.class );
- }
-
- private LocalDate someBirthDate;
- private String ednaIdentity;
- private String zekeIdentity;
- private String fredIdentity;
-
- @Before
- public void setupInitialData()
- throws UnitOfWorkCompletionException
- {
- // See http://en.wikipedia.org/wiki/Template:Flintstones_family_tree
- someBirthDate = createBirthDate( 1, 1, 1 );
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "InitialData" ) ) )
- {
- ednaIdentity = createPerson( uow, "Edna", "Flintstone", someBirthDate ).identity().get();
- zekeIdentity = createPerson( uow, "Zeke", "Flintstone", someBirthDate ).identity().get();
- fredIdentity = createPerson( uow, "Fred", "Flintstone", someBirthDate ).identity().get();
- uow.complete();
- }
- }
-
- @Test
- public void givenQualifiedValueWhenCreatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- ValueBuilder<PersonValue> builder = valueBuilderFactory.newValueBuilder( PersonValue.class );
- builder.prototype().firstName().set( "Ed" );
- builder.prototype().lastName().set( "Flintstone" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- builder.prototype().spouse().set( ednaIdentity );
- builder.prototype().children().set( Arrays.asList( zekeIdentity, fredIdentity ) );
- PersonValue edValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreatingEntityFromQualifiedValue" ) ) )
- {
- // START SNIPPET: creation
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
- PersonEntity edEntity = conversion.create( PersonEntity.class, edValue );
- // END SNIPPET: creation
- assertThat( edEntity.firstName(), equalTo( "Ed" ) );
- assertThat( edEntity.lastName(), equalTo( "Flintstone" ) );
- assertThat( edEntity.spouse().get().firstName(), equalTo( "Edna" ) );
- assertThat( Iterables.count( Iterables.filter( new Predicate<PersonEntity>()
- {
- @Override
- public boolean test( PersonEntity child )
- {
- return "Zeke".equals( child.firstName() ) || "Fred".equals( child.firstName() );
- }
- }, edEntity.children() ) ), is( 2L ) );
-
- uow.complete();
- }
- }
-
- @Test
- public void givenUnqualifiedValueWhenCreatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- ValueBuilder<PersonValue2> builder = valueBuilderFactory.newValueBuilder( PersonValue2.class );
- builder.prototype().firstName().set( "Ed" );
- builder.prototype().lastName().set( "Flintstone" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- builder.prototype().spouse().set( ednaIdentity );
- builder.prototype().children().set( Arrays.asList( zekeIdentity, fredIdentity ) );
- PersonValue2 edValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreatingEntityFromUnqualifiedValue" ) ) )
- {
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
-
- PersonEntity edEntity = conversion.create( PersonEntity.class, "id:Ed", edValue );
-
- assertThat( edEntity.identity().get(), equalTo( "id:Ed" ) );
- assertThat( edEntity.firstName(), equalTo( "Ed" ) );
- assertThat( edEntity.lastName(), equalTo( "Flintstone" ) );
- assertThat( edEntity.spouse().get().firstName(), equalTo( "Edna" ) );
- assertThat( Iterables.count( Iterables.filter( new Predicate<PersonEntity>()
- {
- @Override
- public boolean test( PersonEntity child )
- {
- return "Zeke".equals( child.firstName() ) || "Fred".equals( child.firstName() );
- }
- }, edEntity.children() ) ), is( 2L ) );
-
- uow.complete();
- }
- }
-
- @Test
- public void givenUnqualifiedValue2WhenCreatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- ValueBuilder<PersonValue3> builder = valueBuilderFactory.newValueBuilder( PersonValue3.class );
- builder.prototype().firstName().set( "Ed" );
- builder.prototype().lastName().set( "Flintstone" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- builder.prototype().spouse().set( ednaIdentity );
- builder.prototype().children().set( Arrays.asList( zekeIdentity, fredIdentity ) );
- PersonValue3 edValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreatingEntityFromUnqualifiedValue" ) ) )
- {
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
-
- PersonEntity edEntity = conversion.create( PersonEntity.class, "id:Ed", edValue );
-
- assertThat( edEntity.identity().get(), equalTo( "id:Ed" ) );
- assertThat( edEntity.firstName(), equalTo( "Ed" ) );
- assertThat( edEntity.lastName(), equalTo( "Flintstone" ) );
- assertThat( edEntity.spouse().get().firstName(), equalTo( "Edna" ) );
- assertThat( Iterables.count( Iterables.filter( new Predicate<PersonEntity>()
- {
- @Override
- public boolean test( PersonEntity child )
- {
- return "Zeke".equals( child.firstName() ) || "Fred".equals( child.firstName() );
- }
- }, edEntity.children() ) ), is( 2L ) );
-
- uow.complete();
- }
- }
-
- @Test( expected = ConstraintViolationException.class )
- public void givenQualifiedValueNotFromSameInterfaceWhenCreatingEntityExpectNonOptionalException()
- throws UnitOfWorkCompletionException
- {
- ValueBuilder<PersonValue4> builder = valueBuilderFactory.newValueBuilder( PersonValue4.class );
- builder.prototype().firstName().set( "Ed" );
- builder.prototype().lastName().set( "Flintstone" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- builder.prototype().spouse().set( ednaIdentity );
- builder.prototype().children().set( Arrays.asList( zekeIdentity, fredIdentity ) );
- PersonValue4 edValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreatingEntityFromUnqualifiedValue" ) ) )
- {
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
-
- PersonEntity edEntity = conversion.create( PersonEntity.class, "id:Ed", edValue );
-
- uow.complete();
- }
-
- }
-
- @Test
- public void givenQualifiedValueWhenUpdatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- String rickyIdentity;
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreateRickySlaghoopleWithTypo" ) ) )
- {
- PersonEntity ricky = createPerson( uow, "Ricky", "Slaghople", someBirthDate );
- ricky.spouse().set( uow.get( PersonEntity.class, ednaIdentity ) );
- ricky.children().add( uow.get( PersonEntity.class, zekeIdentity ) );
- rickyIdentity = ricky.identity().get();
- assertThat( ricky.spouse().get(), notNullValue() );
- assertThat( ricky.children().count(), is( 1 ) );
- uow.complete();
- }
- ValueBuilder<PersonValue> builder = valueBuilderFactory.newValueBuilder( PersonValue.class );
- builder.prototype().firstName().set( "Ricky" );
- builder.prototype().lastName().set( "Slaghoople" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- PersonValue rickyNewStateValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "UpdateRickySlaghoople" ) ) )
- {
- PersonEntity rickyEntity = uow.get( PersonEntity.class, rickyIdentity );
- // START SNIPPET: update
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
- conversion.update( rickyEntity, rickyNewStateValue );
- // END SNIPPET: update
-
- assertThat( rickyEntity.lastName(), equalTo( "Slaghoople" ) );
- assertThat( rickyEntity.spouse().get(), nullValue() );
- assertThat( rickyEntity.children().count(), is( 0 ) );
-
- uow.complete();
- }
- }
-
- @Test
- public void givenUnqualifiedValueWhenUpdatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- String rickyIdentity;
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreateRickySlaghoopleWithTypo" ) ) )
- {
- PersonEntity ricky = createPerson( uow, "Ricky", "Slaghople", someBirthDate );
- ricky.spouse().set( uow.get( PersonEntity.class, ednaIdentity ) );
- ricky.children().add( uow.get( PersonEntity.class, zekeIdentity ) );
- rickyIdentity = ricky.identity().get();
- assertThat( ricky.spouse().get(), notNullValue() );
- assertThat( ricky.children().count(), is( 1 ) );
- uow.complete();
- }
- ValueBuilder<PersonValue2> builder = valueBuilderFactory.newValueBuilder( PersonValue2.class );
- builder.prototype().firstName().set( "Ricky" );
- builder.prototype().lastName().set( "Slaghoople" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- PersonValue2 newStateValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "UpdateRickySlaghoople" ) ) )
- {
- PersonEntity ricky = uow.get( PersonEntity.class, rickyIdentity );
-
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
- conversion.update( ricky, newStateValue );
-
- assertThat( ricky.lastName(), equalTo( "Slaghoople" ) );
- assertThat( ricky.spouse().get(), nullValue() );
- assertThat( ricky.children().count(), is( 0 ) );
-
- uow.complete();
- }
- }
-
- @Test
- public void givenUnqualifiedValue2WhenUpdatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- String rickyIdentity;
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreateRickySlaghoopleWithTypo" ) ) )
- {
- PersonEntity ricky = createPerson( uow, "Ricky", "Slaghople", someBirthDate );
- ricky.spouse().set( uow.get( PersonEntity.class, ednaIdentity ) );
- ricky.children().add( uow.get( PersonEntity.class, zekeIdentity ) );
- rickyIdentity = ricky.identity().get();
- assertThat( ricky.spouse().get(), notNullValue() );
- assertThat( ricky.children().count(), is( 1 ) );
- uow.complete();
- }
- ValueBuilder<PersonValue3> builder = valueBuilderFactory.newValueBuilder( PersonValue3.class );
- builder.prototype().firstName().set( "Ricky" );
- builder.prototype().lastName().set( "Slaghoople" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- PersonValue3 newStateValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "UpdateRickySlaghoople" ) ) )
- {
- PersonEntity ricky = uow.get( PersonEntity.class, rickyIdentity );
-
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
- conversion.update( ricky, newStateValue );
-
- assertThat( ricky.lastName(), equalTo( "Slaghoople" ) );
- assertThat( ricky.spouse().get(), nullValue() );
- assertThat( ricky.children().count(), is( 0 ) );
-
- uow.complete();
- }
- }
-
- @Test
- public void givenQualifiedValueNotFromSameInterfaceWhenUpdatingEntityExpectPropsNotUpdated()
- throws UnitOfWorkCompletionException
- {
- String rickyIdentity;
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreateRickySlaghoopleWithTypo" ) ) )
- {
- PersonEntity ricky = createPerson( uow, "Ricky", "Slaghople", someBirthDate );
- ricky.spouse().set( uow.get( PersonEntity.class, ednaIdentity ) );
- ricky.children().add( uow.get( PersonEntity.class, zekeIdentity ) );
- rickyIdentity = ricky.identity().get();
- assertThat( ricky.spouse().get(), notNullValue() );
- assertThat( ricky.children().count(), is( 1 ) );
- uow.complete();
- }
- ValueBuilder<PersonValue4> builder = valueBuilderFactory.newValueBuilder( PersonValue4.class );
- builder.prototype().firstName().set( "Ricky" );
- builder.prototype().lastName().set( "Slaghoople" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- PersonValue4 newStateValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "UpdateRickySlaghoopleWontWork" ) ) )
- {
- PersonEntity ricky = uow.get( PersonEntity.class, rickyIdentity );
-
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
- conversion.update( ricky, newStateValue );
-
- assertThat( ricky.lastName(), equalTo( "Slaghople" ) );
- assertThat( ricky.spouse().get(), nullValue() );
- assertThat( ricky.children().count(), is( 0 ) );
-
- uow.complete();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/5229303a/settings.gradle
----------------------------------------------------------------------
diff --git a/settings.gradle b/settings.gradle
index 16a0615..058f616 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -28,7 +28,6 @@ include 'core:functional',
'libraries:alarm',
'libraries:circuitbreaker',
'libraries:constraints',
- 'libraries:conversion',
'libraries:eventsourcing',
'libraries:eventsourcing-jdbm',
'libraries:eventsourcing-rest',