@Test(dataProvider = "state_and_events") public void testIdempotency(EntityState.STATE state, EntityState.EVENT event) throws Exception { Process mockEntity = new Process(); mockEntity.setName("test"); storeEntity(EntityType.PROCESS, "test"); EntityState entityState = new EntityState(mockEntity).setCurrentState(state); entityState.nextTransition(event); Assert.assertEquals(entityState.getCurrentState(), state); }
// Tests a schedulable entity's lifecycle : Submit -> run -> suspend -> resume @Test public void testLifeCycle() throws Exception { Process mockEntity = new Process(); mockEntity.setName("test"); storeEntity(EntityType.PROCESS, "test"); StateService.get().handleStateChange(mockEntity, EntityState.EVENT.SUBMIT, listener); EntityState entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next(); Mockito.verify(listener).onSubmit(mockEntity); Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SUBMITTED)); StateService.get().handleStateChange(mockEntity, EntityState.EVENT.SCHEDULE, listener); Mockito.verify(listener).onSchedule(mockEntity); entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next(); Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SCHEDULED)); StateService.get().handleStateChange(mockEntity, EntityState.EVENT.SUSPEND, listener); Mockito.verify(listener).onSuspend(mockEntity); entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next(); Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SUSPENDED)); StateService.get().handleStateChange(mockEntity, EntityState.EVENT.RESUME, listener); Mockito.verify(listener).onResume(mockEntity); entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next(); Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SCHEDULED)); }