@Test public void entityStatesSPI() { EntityStore entityStore = serviceFinder.findService( EntityStore.class ).get(); try( Stream<EntityState> states = entityStore.entityStates( module ) ) { assertThat( states.count(), is( 0L ) ); } UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork(); TestEntity newInstance = createEntity( unitOfWork ); unitOfWork.complete(); try( Stream<EntityState> states = entityStore.entityStates( module ) ) { assertThat( states.count(), is( 1L ) ); } unitOfWork = unitOfWorkFactory.newUnitOfWork(); TestEntity instance = unitOfWork.get( newInstance ); unitOfWork.remove( instance ); unitOfWork.complete(); try( Stream<EntityState> states = entityStore.entityStates( module ) ) { assertThat( states.count(), is( 0L ) ); } }
@Test public void entityStatesSPI() { EntityStore entityStore = serviceFinder.findService( EntityStore.class ).get(); try( Stream<EntityState> states = entityStore.entityStates( module ) ) { assertThat( states.count(), is( 0L ) ); } UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork(); TestEntity newInstance = createEntity( unitOfWork ); unitOfWork.complete(); try( Stream<EntityState> states = entityStore.entityStates( module ) ) { assertThat( states.count(), is( 1L ) ); } unitOfWork = unitOfWorkFactory.newUnitOfWork(); TestEntity instance = unitOfWork.get( newInstance ); unitOfWork.remove( instance ); unitOfWork.complete(); try( Stream<EntityState> states = entityStore.entityStates( module ) ) { assertThat( states.count(), is( 0L ) ); } }
try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() ) instance = createEntity( unitOfWork ); unitOfWork.complete();
@Test public void givenEntityStoredLoadedChangedWhenUnitOfWorkDiscardsThenDontStoreState() throws UnitOfWorkCompletionException { UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork(); try { Identity identity = createEntity( unitOfWork ).identity().get(); unitOfWork.complete(); unitOfWork = unitOfWorkFactory.newUnitOfWork(); TestEntity entity = unitOfWork.get( TestEntity.class, identity ); assertThat( entity.intValue().get(), is( 42 ) ); entity.intValue().set( 23 ); unitOfWork.discard(); unitOfWork = unitOfWorkFactory.newUnitOfWork(); entity = unitOfWork.get( TestEntity.class, identity ); assertThat( entity.intValue().get(), is( 42 ) ); } finally { unitOfWork.discard(); } }
@Test public void givenEntityStoredLoadedChangedWhenUnitOfWorkDiscardsThenDontStoreState() throws UnitOfWorkCompletionException { UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork(); try { Identity identity = createEntity( unitOfWork ).identity().get(); unitOfWork.complete(); unitOfWork = unitOfWorkFactory.newUnitOfWork(); TestEntity entity = unitOfWork.get( TestEntity.class, identity ); assertThat( entity.intValue().get(), is( 42 ) ); entity.intValue().set( 23 ); unitOfWork.discard(); unitOfWork = unitOfWorkFactory.newUnitOfWork(); entity = unitOfWork.get( TestEntity.class, identity ); assertThat( entity.intValue().get(), is( 42 ) ); } finally { unitOfWork.discard(); } }
try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() ) instance = createEntity( unitOfWork ); unitOfWork.complete();
@Test public void whenRemovedEntityThenCannotFindEntity() throws Exception { TestEntity newInstance; Identity identity; try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() ) { newInstance = createEntity( unitOfWork ); identity = newInstance.identity().get(); unitOfWork.complete(); } // Remove entity try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() ) { TestEntity instance = unitOfWork.get( newInstance ); unitOfWork.remove( instance ); unitOfWork.complete(); } // Find entity try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() ) { unitOfWork.get( TestEntity.class, identity ); fail( "Should not be able to find entity" ); } catch( NoSuchEntityException e ) { // Ok! } }
@Test public void whenRemovedEntityThenCannotFindEntity() throws Exception { TestEntity newInstance; Identity identity; try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() ) { newInstance = createEntity( unitOfWork ); identity = newInstance.identity().get(); unitOfWork.complete(); } // Remove entity try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() ) { TestEntity instance = unitOfWork.get( newInstance ); unitOfWork.remove( instance ); unitOfWork.complete(); } // Find entity try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() ) { unitOfWork.get( TestEntity.class, identity ); fail( "Should not be able to find entity" ); } catch( NoSuchEntityException e ) { // Ok! } }