Repository: zest-java Updated Branches: refs/heads/develop 6dc286da4 -> 5e718da0a
AggregatedTest: minor fixes and added tests Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/5e718da0 Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/5e718da0 Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/5e718da0 Branch: refs/heads/develop Commit: 5e718da0adc094ade648bf54187f8b77e3db8afa Parents: 6dc286d Author: Paul Merlin <[email protected]> Authored: Sun Sep 6 18:02:38 2015 +0200 Committer: Paul Merlin <[email protected]> Committed: Sun Sep 6 18:02:38 2015 +0200 ---------------------------------------------------------------------- .../zest/runtime/entity/EntityInstance.java | 7 +- .../zest/runtime/entity/AggregatedTest.java | 136 ++++++++----------- 2 files changed, 63 insertions(+), 80 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-java/blob/5e718da0/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java index 573af9a..d30ff3f 100755 --- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java @@ -18,6 +18,7 @@ package org.apache.zest.runtime.entity; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.zest.api.association.AssociationDescriptor; @@ -272,13 +273,13 @@ public final class EntityInstance stateDescriptor.associations() .filter( AssociationDescriptor::isAggregated ) .map( association -> state.associationFor( association.accessor() ).get() ) - .filter( entity -> entity != null ), + .filter( Objects::nonNull ), Stream.concat( stateDescriptor.manyAssociations() .filter( AssociationDescriptor::isAggregated ) .flatMap( association -> state.manyAssociationFor( association.accessor() ).toList().stream() ) - .filter( entity -> entity != null ), + .filter( Objects::nonNull ), stateDescriptor.namedAssociations() .filter( AssociationDescriptor::isAggregated ) @@ -286,7 +287,7 @@ public final class EntityInstance .toMap() .values() .stream() ) - .filter( entity -> entity != null ) + .filter( Objects::nonNull ) ) ).distinct().collect( Collectors.toList() ).stream().forEach( unitOfWork::remove ); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/5e718da0/core/runtime/src/test/java/org/apache/zest/runtime/entity/AggregatedTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/entity/AggregatedTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/entity/AggregatedTest.java index 1ee9665..58bacd2 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/entity/AggregatedTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/entity/AggregatedTest.java @@ -23,6 +23,7 @@ import org.apache.zest.api.entity.EntityComposite; import org.apache.zest.api.property.Property; import org.apache.zest.api.unitofwork.NoSuchEntityException; import org.apache.zest.api.unitofwork.UnitOfWork; +import org.apache.zest.api.usecase.UsecaseBuilder; import org.apache.zest.bootstrap.AssemblyException; import org.apache.zest.bootstrap.ModuleAssembly; import org.apache.zest.test.AbstractZestTest; @@ -53,103 +54,84 @@ public class AggregatedTest CompanyEntity companyEntity; PersonEntity personEntity, personEntity2; EmployeeEntity employeeEntity, employeeEntity2; + try( UnitOfWork unitOfWork = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Creation" ) ) ) { - UnitOfWork unitOfWork = module.newUnitOfWork(); - try { - { - EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class ); - personEntity = builder.instance(); - personEntity.name().set( "Rickard" ); - personEntity = builder.newInstance(); - } - - { - EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class ); - personEntity2 = builder.instance(); - personEntity2.name().set( "Niclas" ); - builder.newInstance(); - } - - { - EntityBuilder<EmployeeEntity> builder = unitOfWork.newEntityBuilder( EmployeeEntity.class ); - employeeEntity = builder.instance(); - employeeEntity.person().set( personEntity ); - employeeEntity.salary().set( 50000 ); - employeeEntity.title().set( "Director" ); - employeeEntity = builder.newInstance(); - } - - { - EntityBuilder<EmployeeEntity> builder = unitOfWork.newEntityBuilder( EmployeeEntity.class ); - employeeEntity2 = builder.instance(); - employeeEntity2.person().set( personEntity ); - employeeEntity2.salary().set( 40000 ); - employeeEntity2.title().set( "Developer" ); - employeeEntity2 = builder.newInstance(); - } - - { - EntityBuilder<CompanyEntity> builder = unitOfWork.newEntityBuilder( CompanyEntity.class ); - companyEntity = builder.instance(); - companyEntity.director().set( employeeEntity ); - companyEntity.employees().add( 0, employeeEntity ); - companyEntity.employees().add( 0, employeeEntity2 ); - companyEntity = builder.newInstance(); - } - - unitOfWork.complete(); + EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class ); + personEntity = builder.instance(); + personEntity.name().set( "Rickard" ); + personEntity = builder.newInstance(); } - finally + { - unitOfWork.discard(); + EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class ); + personEntity2 = builder.instance(); + personEntity2.name().set( "Niclas" ); + builder.newInstance(); } - } - { - UnitOfWork unitOfWork = module.newUnitOfWork(); - try { - companyEntity = unitOfWork.get( companyEntity ); - unitOfWork.remove( companyEntity ); + EntityBuilder<EmployeeEntity> builder = unitOfWork.newEntityBuilder( EmployeeEntity.class ); + employeeEntity = builder.instance(); + employeeEntity.person().set( personEntity ); + employeeEntity.salary().set( 50000 ); + employeeEntity.title().set( "Director" ); + employeeEntity = builder.newInstance(); + } - unitOfWork.complete(); + { + EntityBuilder<EmployeeEntity> builder = unitOfWork.newEntityBuilder( EmployeeEntity.class ); + employeeEntity2 = builder.instance(); + employeeEntity2.person().set( personEntity ); + employeeEntity2.salary().set( 40000 ); + employeeEntity2.title().set( "Developer" ); + employeeEntity2 = builder.newInstance(); } - finally + { - unitOfWork.discard(); + EntityBuilder<CompanyEntity> builder = unitOfWork.newEntityBuilder( CompanyEntity.class ); + companyEntity = builder.instance(); + companyEntity.director().set( employeeEntity ); + companyEntity.employees().add( 0, employeeEntity ); + companyEntity.employees().add( 0, employeeEntity2 ); + companyEntity = builder.newInstance(); } + + unitOfWork.complete(); } + try( UnitOfWork unitOfWork = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Removal" ) ) ) { - UnitOfWork unitOfWork = module.newUnitOfWork(); - try - { - unitOfWork.get( employeeEntity ); + companyEntity = unitOfWork.get( companyEntity ); + unitOfWork.remove( companyEntity ); - fail( "Should not work" ); + unitOfWork.complete(); + } - unitOfWork.complete(); - } - catch( NoSuchEntityException e ) - { - unitOfWork.discard(); - } + try( UnitOfWork unitOfWork = module.newUnitOfWork( UsecaseBuilder.newUsecase( "No 1st employee" ) ) ) + { + unitOfWork.get( employeeEntity ); + fail( "Should not work" ); + } + catch( NoSuchEntityException e ) + { + // Expected } + try( UnitOfWork unitOfWork = module.newUnitOfWork( UsecaseBuilder.newUsecase( "No 2nd employee" ) ) ) { - UnitOfWork unitOfWork = module.newUnitOfWork(); - try - { - unitOfWork.get( employeeEntity2 ); - fail( "Should not work" ); + unitOfWork.get( employeeEntity2 ); + fail( "Should not work" ); + } + catch( NoSuchEntityException e ) + { + // Expected + } - unitOfWork.complete(); - } - catch( NoSuchEntityException e ) - { - unitOfWork.discard(); - } + try( UnitOfWork unitOfWork = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Persons not removed" ) ) ) + { + unitOfWork.get( personEntity ); + unitOfWork.get( personEntity2 ); } }
