| | |
| | | import static org.mockito.Mockito.doAnswer; |
| | | import static org.mockito.Mockito.never; |
| | | import static org.mockito.Mockito.verify; |
| | | import static org.mockito.Mockito.verifyNoInteractions; |
| | | import static org.mockito.Mockito.when; |
| | | import static org.mockito.Mockito.times; |
| | | |
| | |
| | | { |
| | | TTest test = validTest(); |
| | | mockEnabledOptions(); |
| | | mockGroupSnapshot(); |
| | | when(testMapper.insertTest(any(TTest.class))).thenAnswer(invocation -> { |
| | | invocation.<TTest>getArgument(0).setTestId(10L); |
| | | return 1; |
| | |
| | | assertEquals("WAITING", test.getTestStatus()); |
| | | assertEquals("NOT_STARTED", test.getReceptionStatus()); |
| | | assertEquals(7L, test.getCreatorId()); |
| | | verify(testMapper).insertTestPlanStep(any(TTestPlanStep.class)); |
| | | verify(testMapper, never()).insertTestPlanStep(any(TTestPlanStep.class)); |
| | | verify(testMapper).insertTestChannelBinding(any(TTestChannelBinding.class)); |
| | | verify(testMapper, times(3)).insertTestCollectorChannel(any(TTestCollectorChannel.class)); |
| | | verify(sharedFieldSnapshotService).saveForTest(eq(10L), any()); |
| | | verify(sharedFieldSnapshotService, never()).saveForTest(anyLong(), any()); |
| | | verify(testMapper).insertTestThreshold(any(TTestWarningThreshold.class)); |
| | | verify(testMapper).insertTestAudit(anyLong(), any(), anyLong(), any(), isNull(), any()); |
| | | verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), isNull(), any()); |
| | | } |
| | | |
| | | @Test |
| | |
| | | TTest test = validTest(); |
| | | test.setPlanSteps(Collections.emptyList()); |
| | | mockEnabledOptions(); |
| | | mockGroupSnapshot(); |
| | | when(testMapper.insertTest(any(TTest.class))).thenAnswer(invocation -> { |
| | | invocation.<TTest>getArgument(0).setTestId(10L); |
| | | return 1; |
| | |
| | | current.setMonitorTimeoutMinutes(30); |
| | | when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current); |
| | | when(testMapper.selectTestBatteries(10L)).thenReturn(current.getBatteries()); |
| | | when(sharedFieldSnapshotService.selectByTestId(10L)).thenReturn(java.util.List.of()); |
| | | when(sharedFieldSnapshotService.resolveForUpdate(1L, 1L, java.util.List.of())) |
| | | .thenReturn(java.util.List.of()); |
| | | mockEnabledOptions(); |
| | | when(testMapper.updateTest(request)).thenReturn(1); |
| | | doAnswer(invocation -> { |
| | |
| | | assertEquals(1, testService.updateTest(request)); |
| | | assertEquals(45, request.getMonitorTimeoutMinutes()); |
| | | verify(testMapper).deleteTestBindingsByTestId(10L); |
| | | verify(testMapper).deleteTestPlanStepsByTestId(10L); |
| | | verify(testMapper).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any()); |
| | | verify(testMapper, never()).deleteTestPlanStepsByTestId(10L); |
| | | verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any()); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current); |
| | | when(testMapper.selectTestBatteries(10L)).thenReturn(current.getBatteries()); |
| | | when(sharedFieldSnapshotService.selectByTestId(10L)).thenReturn(java.util.List.of(originalSnapshot)); |
| | | when(sharedFieldSnapshotService.resolveForUpdate(1L, 1L, java.util.List.of(originalSnapshot))) |
| | | .thenReturn(java.util.List.of(originalSnapshot)); |
| | | mockEnabledOptions(); |
| | | when(testMapper.updateTest(request)).thenReturn(1); |
| | | doAnswer(invocation -> { |
| | |
| | | |
| | | assertEquals(1, testService.updateTest(request)); |
| | | |
| | | verify(sharedFieldSnapshotService).resolveForUpdate(1L, 1L, java.util.List.of(originalSnapshot)); |
| | | verify(sharedFieldSnapshotService).saveForTest(eq(10L), org.mockito.ArgumentMatchers.argThat(snapshots -> |
| | | snapshots.size() == 1 && "72".equals(snapshots.get(0).getFieldValue()))); |
| | | verifyNoInteractions(sharedFieldSnapshotService); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | assertEquals(1, testService.deleteTestByIds(new Long[] { 10L }, 7L, "operator")); |
| | | |
| | | verify(testMapper).insertTestAudit(eq(10L), eq("TEST_DELETED"), eq(7L), eq("operator"), any(), isNull()); |
| | | verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any()); |
| | | } |
| | | |
| | | @Test |