UpdateExecutionStatus { public boolean update(Execution execution, OverviewObject overview) { ExecutionStatus oldStatus = execution.getStatus(); ExecutionStatus newStatus = selectExecutionStatus(execution, overview); if (oldStatus == newStatus) { overview.setStatus(execution.getStatus().asStr()); StatusSetter.updateOverview(execution); return false; } execution.setStatus(newStatus); overview.setStatus(execution.getStatus().asStr()); StatusSetter.updateOverview(execution); return true; }  boolean update(Execution execution, OverviewObject overview);  }
@Test public void noStateChange() { Execution execution = new Execution(); execution.setExecutorResponsive(true); execution.setExecutor(true); execution.setStatus(ExecutionStatus.RUNNING); Date lastChange = new Date(); execution.setLastChange(lastChange); execution.setOverviewJson(createOverviewJson()); OverviewObject overview = Mockito.mock(OverviewObject.class); Mockito.when(overview.getStatus()).thenReturn( ExecutionStatus.RUNNING.asStr()); boolean changed = updater.update(execution, overview); Assert.assertFalse(changed); Mockito.verify(overview, Mockito.times(1)).setStatus( ExecutionStatus.RUNNING.asStr()); Assert.assertEquals(lastChange, execution.getLastChange()); }
@Test public void cancelled() { Execution execution = new Execution(); execution.setExecutorResponsive(true); execution.setExecutor(true); execution.setStatus(ExecutionStatus.RUNNING); execution.setOverviewJson(createOverviewJson()); OverviewObject overview = Mockito.mock(OverviewObject.class); Mockito.when(overview.getStatus()).thenReturn( ExecutionStatus.CANCELLING.asStr()); boolean changed; changed = updater.update(execution, overview); Assert.assertTrue(changed); Mockito.verify(overview, Mockito.times(1)).setStatus( ExecutionStatus.CANCELLING.asStr()); Mockito.when(overview.getStatus()).thenReturn( ExecutionStatus.CANCELLED.asStr()); changed = updater.update(execution, overview); Assert.assertFalse(changed); Mockito.verify(overview, Mockito.times(2)).setStatus( ExecutionStatus.CANCELLING.asStr()); Mockito.when(overview.getFinish()).thenReturn(new Date()); changed = updater.update(execution, overview); Assert.assertTrue(changed); Mockito.verify(overview, Mockito.times(1)).setStatus( ExecutionStatus.CANCELLED.asStr()); }
@Test public void unresponsiveExecutor() { Execution execution = new Execution(); execution.setExecutorResponsive(false); execution.setExecutor(true); execution.setStatus(ExecutionStatus.RUNNING); execution.setOverviewJson(createOverviewJson()); OverviewObject overview = Mockito.mock(OverviewObject.class); Mockito.when(overview.getStatus()).thenReturn( ExecutionStatus.RUNNING.asStr()); boolean changed = updater.update(execution, overview); Assert.assertTrue(changed); Mockito.verify(overview, Mockito.times(1)).setStatus( ExecutionStatus.UNRESPONSIVE.asStr()); }
@Test public void missingExecutor() { Execution execution = new Execution(); execution.setExecutorResponsive(false); execution.setExecutor(false); execution.setStatus(ExecutionStatus.RUNNING); execution.setOverviewJson(createOverviewJson()); OverviewObject overview = Mockito.mock(OverviewObject.class); Mockito.when(overview.getStatus()).thenReturn( ExecutionStatus.RUNNING.asStr()); boolean changed = updater.update(execution, overview); Assert.assertTrue(changed); Mockito.verify(overview, Mockito.times(1)).setStatus( ExecutionStatus.DANGLING.asStr()); }