From 80a2b152bf989173a05a6ad303a7ec0a886b40b1 Mon Sep 17 00:00:00 2001 From: Pere Miquel Brull Date: Thu, 4 Jan 2024 19:47:45 +0100 Subject: [PATCH] Fix tests --- .../exception/IncidentManagerException.java | 8 + .../service/jdbi3/CollectionDAO.java | 3 +- .../service/jdbi3/TestCaseRepository.java | 9 +- .../TestCaseResolutionStatusRepository.java | 52 +++- .../dqtests/TestCaseResourceTest.java | 279 +++++++----------- 5 files changed, 174 insertions(+), 177 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/exception/IncidentManagerException.java b/openmetadata-service/src/main/java/org/openmetadata/service/exception/IncidentManagerException.java index 0df21c3366d3..500d7cf795fb 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/exception/IncidentManagerException.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/exception/IncidentManagerException.java @@ -1,6 +1,7 @@ package org.openmetadata.service.exception; import javax.ws.rs.core.Response; +import org.openmetadata.schema.tests.type.TestCaseResolutionStatusTypes; import org.openmetadata.sdk.exception.WebServiceException; public class IncidentManagerException extends WebServiceException { @@ -12,4 +13,11 @@ protected IncidentManagerException(Response.Status status, String message) { public IncidentManagerException(String message) { super(Response.Status.INTERNAL_SERVER_ERROR, message); } + + public static IncidentManagerException invalidStatus( + TestCaseResolutionStatusTypes lastStatus, TestCaseResolutionStatusTypes newStatus) { + return new IncidentManagerException( + Response.Status.BAD_REQUEST, + String.format("Incident with status [%s] cannot be moved to [%s]", lastStatus, newStatus)); + } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java index cc524675daed..f338202ee828 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java @@ -3615,7 +3615,8 @@ default String getTimeSeriesTableName() { "SELECT json FROM data_quality_data_time_series where entityFQNHash = :entityFQNHash " + "AND json ->> 'incidentId' IS NOT NULL", connectionType = POSTGRES) - void cleanTestCaseIncidents(@Bind("entityFQNHash") String entityFQNHash, @Bind("stateId") String stateId); + void cleanTestCaseIncidents( + @Bind("entityFQNHash") String entityFQNHash, @Bind("stateId") String stateId); } interface TestCaseResolutionStatusTimeSeriesDAO extends EntityTimeSeriesDAO { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java index 1123a0c735dd..7b457fe98538 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java @@ -516,10 +516,15 @@ private List getIncidentIds(TestCase test) { JsonUtils.readObjects( daoCollection .dataQualityDataTimeSeriesDao() - .getResultsWithIncidents(FullyQualifiedName.buildHash(test.getFullyQualifiedName())), + .getResultsWithIncidents( + FullyQualifiedName.buildHash(test.getFullyQualifiedName())), TestCaseResult.class); - return testCaseResults.stream().map(TestCaseResult::getIncidentId).collect(Collectors.toSet()).stream().toList(); + return testCaseResults.stream() + .map(TestCaseResult::getIncidentId) + .collect(Collectors.toSet()) + .stream() + .toList(); } public int getTestCaseCount(List testCaseIds) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseResolutionStatusRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseResolutionStatusRepository.java index 4a8fa841b13f..a67a026c3dc0 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseResolutionStatusRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseResolutionStatusRepository.java @@ -111,6 +111,34 @@ private Thread getIncidentTask(TestCaseResolutionStatus incident) { return JsonUtils.readValue(jsonThread, Thread.class); } + /** + * Ensure we are following the correct status flow + */ + private void validateStatus( + TestCaseResolutionStatusTypes lastStatus, TestCaseResolutionStatusTypes newStatus) { + switch (lastStatus) { + case New -> { + /* New can go to any status */ + } + case Ack -> { + if (newStatus.equals(TestCaseResolutionStatusTypes.New)) { + throw IncidentManagerException.invalidStatus(lastStatus, newStatus); + } + } + case Assigned -> { + if (List.of(TestCaseResolutionStatusTypes.New, TestCaseResolutionStatusTypes.Ack) + .contains(newStatus)) { + throw IncidentManagerException.invalidStatus(lastStatus, newStatus); + } + } + case Resolved -> { + if (!newStatus.equals(TestCaseResolutionStatusTypes.Resolved)) { + throw IncidentManagerException.invalidStatus(lastStatus, newStatus); + } + } + } + } + @Override @Transaction public TestCaseResolutionStatus createNewRecord( @@ -119,18 +147,33 @@ public TestCaseResolutionStatus createNewRecord( TestCaseResolutionStatus lastIncident = getLatestRecord(recordEntity.getTestCaseReference().getFullyQualifiedName()); + if (recordEntity.getStateId() == null) { + recordEntity.setStateId(UUID.randomUUID()); + } + if (lastIncident != null) { // if we have an ongoing incident, set the stateId if the new record to be created recordEntity.setStateId( Boolean.TRUE.equals(unresolvedIncident(recordEntity)) ? lastIncident.getStateId() : recordEntity.getStateId()); + + validateStatus( + lastIncident.getTestCaseResolutionStatusType(), + recordEntity.getTestCaseResolutionStatusType()); } switch (recordEntity.getTestCaseResolutionStatusType()) { // When we create a NEW incident, we need to open a task with the test case owner as the // assignee. We don't need to check any past history - case New -> openNewTask(recordEntity, lastIncident); + case New -> { + // If there is already an unresolved incident, return it without doing any + // further logic. + if (lastIncident != null) { + return getLatestRecord(lastIncident.getTestCaseReference().getFullyQualifiedName()); + } + openNewTask(recordEntity); + } case Ack -> { /* nothing to do for ACK. The Owner already has the task open. It will close it when reassigning it */ } @@ -149,12 +192,7 @@ public TestCaseResolutionStatus createNewRecord( return super.createNewRecord(recordEntity, extension, recordFQN); } - private void openNewTask( - TestCaseResolutionStatus incidentStatus, TestCaseResolutionStatus lastIncidentStatus) { - - if (lastIncidentStatus != null) { - throw new IllegalArgumentException("An existing incident cannot be moved to NEW"); - } + private void openNewTask(TestCaseResolutionStatus incidentStatus) { List owners = EntityUtil.getEntityReferences( diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java index ed2e9be540fd..78921f471085 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java @@ -1089,54 +1089,41 @@ void test_listTestCaseByExecutionTimePagination_200(TestInfo test) paginate(maxEntities, allEntities, logicalTestSuite); } - // Test Case Failure Status Tests @Test - void post_createTestCaseResultFailure(TestInfo test) throws HttpResponseException { - TestCase testCaseEntity = createEntity(createRequest(getEntityName(test)), ADMIN_AUTH_HEADERS); + void post_createTestCaseResultFailure(TestInfo test) + throws HttpResponseException, ParseException { + // We're going to check how each test only has a single open stateID + // and 2 tests have their own flow + Long startTs = System.currentTimeMillis(); + TestCase testCaseEntity1 = createEntity(createRequest(getEntityName(test)), ADMIN_AUTH_HEADERS); + TestCase testCaseEntity2 = + createEntity(createRequest(getEntityName(test) + "2"), ADMIN_AUTH_HEADERS); - // Create a test case failure status for each status type - List testCaseFailureStatuses = new ArrayList<>(); - List resolvedTestCaseFailureStatus = new ArrayList<>(); - for (TestCaseResolutionStatusTypes statusType : TestCaseResolutionStatusTypes.values()) { - CreateTestCaseResolutionStatus createTestCaseFailureStatus = + // Add a failed result, which will create a NEW incident and add a new status + for (TestCase testCase : List.of(testCaseEntity1, testCaseEntity2)) { + putTestCaseResult( + testCase.getFullyQualifiedName(), + new TestCaseResult() + .withResult("result") + .withTestCaseStatus(TestCaseStatus.Failed) + .withTimestamp(TestUtils.dateToTimestamp("2024-01-01")), + ADMIN_AUTH_HEADERS); + + CreateTestCaseResolutionStatus createAckIncident = new CreateTestCaseResolutionStatus() - .withTestCaseReference(testCaseEntity.getFullyQualifiedName()) - .withTestCaseResolutionStatusType(statusType) + .withTestCaseReference(testCase.getFullyQualifiedName()) + .withTestCaseResolutionStatusType(TestCaseResolutionStatusTypes.Ack) .withTestCaseResolutionStatusDetails(null); - if (statusType.equals(TestCaseResolutionStatusTypes.Assigned)) { - createTestCaseFailureStatus.setTestCaseResolutionStatusDetails( - new Assigned().withAssignee(USER1_REF)); - } - if (statusType.equals(TestCaseResolutionStatusTypes.Resolved)) { - createTestCaseFailureStatus.setTestCaseResolutionStatusDetails( - new Resolved() - .withTestCaseFailureComment("resolved") - .withTestCaseFailureReason(TestCaseFailureReasonType.MissingData) - .withResolvedBy(USER1_REF)); - resolvedTestCaseFailureStatus.add(createTestCaseFailureStatus); - continue; - } - testCaseFailureStatuses.add(createTestCaseFailureStatus); + createTestCaseFailureStatus(createAckIncident); } - // Create 2 the test case failure statuses with all stages - // this should generate 2 sequence IDs - Long startTs = System.currentTimeMillis(); - createTestCaseResolutionStatus(testCaseFailureStatuses); - // create resolved test case failure status last - createTestCaseResolutionStatus(resolvedTestCaseFailureStatus); - - // Start a new sequence ID - createTestCaseResolutionStatus(testCaseFailureStatuses); - // create resolved test case failure status last - createTestCaseResolutionStatus(resolvedTestCaseFailureStatus); Long endTs = System.currentTimeMillis(); // Get the test case failure statuses ResultList testCaseFailureStatusResultList = getTestCaseFailureStatus(startTs, endTs, null, null); - assertEquals(8, testCaseFailureStatusResultList.getData().size()); + assertEquals(4, testCaseFailureStatusResultList.getData().size()); - // check we have only 2 distinct sequence IDs + // check we have only 2 distinct sequence IDs, one for each test case List stateIds = testCaseFailureStatusResultList.getData().stream() .map(TestCaseResolutionStatus::getStateId) @@ -1156,58 +1143,38 @@ void post_createTestCaseResultFailure(TestInfo test) throws HttpResponseExceptio // Get the test case failure statuses by sequence ID ResultList storedTestCaseResolutions = getTestCaseFailureStatusByStateId(stateId); - assertEquals(4, storedTestCaseResolutions.getData().size()); + assertEquals(2, storedTestCaseResolutions.getData().size()); assertEquals(stateId, storedTestCaseResolutions.getData().get(0).getStateId()); // Get the test case resolution statuses by status type storedTestCaseResolutions = - getTestCaseFailureStatus(startTs, endTs, null, TestCaseResolutionStatusTypes.Assigned); + getTestCaseFailureStatus(startTs, endTs, null, TestCaseResolutionStatusTypes.Ack); assertEquals(2, storedTestCaseResolutions.getData().size()); assertEquals( - TestCaseResolutionStatusTypes.Assigned, + TestCaseResolutionStatusTypes.Ack, storedTestCaseResolutions.getData().get(0).getTestCaseResolutionStatusType()); - - // Get test case resolution statuses by assignee name - storedTestCaseResolutions = getTestCaseFailureStatus(startTs, endTs, USER1.getName(), null); - assertEquals(2, storedTestCaseResolutions.getData().size()); } @Test - void test_listTestCaseFailureStatusPagination(TestInfo test) throws IOException { + void test_listTestCaseFailureStatusPagination(TestInfo test) throws IOException, ParseException { // Create a number of entities between 5 and 20 inclusive Random rand = new Random(); int maxEntities = rand.nextInt(16) + 5; - TestCase testCaseEntity = createEntity(createRequest(getEntityName(test)), ADMIN_AUTH_HEADERS); - TestCaseResolutionStatusTypes[] testCaseFailureStatusTypes = - TestCaseResolutionStatusTypes.values(); - List testCaseFailureStatuses = new ArrayList<>(); - + Long startTs = System.currentTimeMillis() - 1000; for (int i = 0; i < maxEntities; i++) { - // randomly pick a status type - TestCaseResolutionStatusTypes testCaseFailureStatusType = - testCaseFailureStatusTypes[i % testCaseFailureStatusTypes.length]; - - CreateTestCaseResolutionStatus createTestCaseFailureStatus = - new CreateTestCaseResolutionStatus() - .withTestCaseReference(testCaseEntity.getFullyQualifiedName()) - .withTestCaseResolutionStatusType(testCaseFailureStatusType) - .withTestCaseResolutionStatusDetails(null); - if (testCaseFailureStatusType.equals(TestCaseResolutionStatusTypes.Assigned)) { - createTestCaseFailureStatus.setTestCaseResolutionStatusDetails( - new Assigned().withAssignee(USER1_REF)); - } - if (testCaseFailureStatusType.equals(TestCaseResolutionStatusTypes.Resolved)) { - createTestCaseFailureStatus.setTestCaseResolutionStatusDetails( - new Resolved() - .withTestCaseFailureComment("resolved") - .withTestCaseFailureReason(TestCaseFailureReasonType.MissingData) - .withResolvedBy(USER1_REF)); - } - testCaseFailureStatuses.add(createTestCaseFailureStatus); + // We'll create random test cases + TestCase testCaseEntity = + createEntity(createRequest(getEntityName(test) + i), ADMIN_AUTH_HEADERS); + // Adding failed test case, which will create a NEW incident + putTestCaseResult( + testCaseEntity.getFullyQualifiedName(), + new TestCaseResult() + .withResult("result") + .withTestCaseStatus(TestCaseStatus.Failed) + .withTimestamp(TestUtils.dateToTimestamp("2024-01-01")), + ADMIN_AUTH_HEADERS); } - Long startTs = System.currentTimeMillis() - 1000; - createTestCaseResolutionStatus(testCaseFailureStatuses); Long endTs = System.currentTimeMillis() + 1000; // List all entities and use it for checking pagination @@ -1217,57 +1184,6 @@ void test_listTestCaseFailureStatusPagination(TestInfo test) throws IOException paginateTestCaseFailureStatus(maxEntities, allEntities, null, startTs, endTs); } - @Test - void test_listTestCaseFailureStatusLatestPagination(TestInfo test) throws IOException { - // Create a number of entities between 5 and 20 inclusive - Random rand = new Random(); - TestCase testCaseEntity; - int maxEntities = rand.nextInt(16) + 5; - - TestCaseResolutionStatusTypes[] testCaseFailureStatusTypes = - TestCaseResolutionStatusTypes.values(); - List testCaseFailureStatuses = new ArrayList<>(); - - for (int i = 0; i < maxEntities; i++) { - // create `maxEntities` number of test cases - testCaseEntity = createEntity(createRequest(getEntityName(test) + i), ADMIN_AUTH_HEADERS); - - for (int j = 0; j < 5; j++) { - // create 5 test case failure statuses for each test case - // randomly pick a status type - TestCaseResolutionStatusTypes testCaseFailureStatusType = - testCaseFailureStatusTypes[j % TestCaseResolutionStatusTypes.values().length]; - - CreateTestCaseResolutionStatus createTestCaseFailureStatus = - new CreateTestCaseResolutionStatus() - .withTestCaseReference(testCaseEntity.getFullyQualifiedName()) - .withTestCaseResolutionStatusType(testCaseFailureStatusType) - .withTestCaseResolutionStatusDetails(null); - if (testCaseFailureStatusType.equals(TestCaseResolutionStatusTypes.Assigned)) { - createTestCaseFailureStatus.setTestCaseResolutionStatusDetails( - new Assigned().withAssignee(USER1_REF)); - } - if (testCaseFailureStatusType.equals(TestCaseResolutionStatusTypes.Resolved)) { - createTestCaseFailureStatus.setTestCaseResolutionStatusDetails( - new Resolved() - .withTestCaseFailureComment("resolved") - .withTestCaseFailureReason(TestCaseFailureReasonType.MissingData) - .withResolvedBy(USER1_REF)); - } - testCaseFailureStatuses.add(createTestCaseFailureStatus); - } - } - Long startTs = System.currentTimeMillis() - 1000; - createTestCaseResolutionStatus(testCaseFailureStatuses); - Long endTs = System.currentTimeMillis() + 1000; - - // List all entities and use it for checking pagination - ResultList allEntities = - getTestCaseFailureStatus(1000000, null, true, startTs, endTs, null); - - paginateTestCaseFailureStatus(maxEntities, allEntities, true, startTs, endTs); - } - @Test void patch_TestCaseResultFailure(TestInfo test) throws HttpResponseException { TestCase testCaseEntity = createEntity(createRequest(getEntityName(test)), ADMIN_AUTH_HEADERS); @@ -1326,24 +1242,34 @@ void patch_TestCaseResultFailureUnauthorizedFields(TestInfo test) throws HttpRes @Test public void test_testCaseResolutionTaskResolveWorkflowThruFeed(TestInfo test) - throws HttpResponseException { + throws HttpResponseException, ParseException { Long startTs = System.currentTimeMillis(); FeedResourceTest feedResourceTest = new FeedResourceTest(); TestCase testCaseEntity = createEntity(createRequest(getEntityName(test)), ADMIN_AUTH_HEADERS); - CreateTestCaseResolutionStatus createTestCaseFailureStatus = + + // Add failed test case, which will create a NEW incident + putTestCaseResult( + testCaseEntity.getFullyQualifiedName(), + new TestCaseResult() + .withResult("result") + .withTestCaseStatus(TestCaseStatus.Failed) + .withTimestamp(TestUtils.dateToTimestamp("2024-01-01")), + ADMIN_AUTH_HEADERS); + + // Now, we should be good to create an ASSIGNED status + CreateTestCaseResolutionStatus createAssignedIncident = new CreateTestCaseResolutionStatus() .withTestCaseReference(testCaseEntity.getFullyQualifiedName()) .withTestCaseResolutionStatusType(TestCaseResolutionStatusTypes.Assigned) .withTestCaseResolutionStatusDetails(new Assigned().withAssignee(USER1_REF)); - TestCaseResolutionStatus testCaseFailureStatus = - createTestCaseFailureStatus(createTestCaseFailureStatus); + TestCaseResolutionStatus assignedIncident = createTestCaseFailureStatus(createAssignedIncident); String jsonThread = Entity.getCollectionDAO() .feedDAO() - .fetchThreadByTestCaseResolutionStatusId(testCaseFailureStatus.getId()); + .fetchThreadByTestCaseResolutionStatusId(assignedIncident.getStateId()); Thread thread = JsonUtils.readValue(jsonThread, Thread.class); - assertEquals(testCaseFailureStatus.getId(), thread.getTask().getTestCaseResolutionStatusId()); + assertEquals(assignedIncident.getStateId(), thread.getTask().getTestCaseResolutionStatusId()); assertEquals(TaskStatus.Open, thread.getTask().getStatus()); // resolve the task. The old task should be closed and the latest test case resolution status @@ -1358,7 +1284,7 @@ public void test_testCaseResolutionTaskResolveWorkflowThruFeed(TestInfo test) jsonThread = Entity.getCollectionDAO() .feedDAO() - .fetchThreadByTestCaseResolutionStatusId(testCaseFailureStatus.getId()); + .fetchThreadByTestCaseResolutionStatusId(assignedIncident.getStateId()); thread = JsonUtils.readValue(jsonThread, Thread.class); // Confirm that the task is closed assertEquals(TaskStatus.Closed, thread.getTask().getStatus()); @@ -1380,7 +1306,7 @@ public void test_testCaseResolutionTaskResolveWorkflowThruFeed(TestInfo test) TestCaseResolutionStatusTypes.Resolved, mostRecentTestCaseResolutionStatusData.getTestCaseResolutionStatusType()); assertEquals( - testCaseFailureStatus.getStateId(), mostRecentTestCaseResolutionStatusData.getStateId()); + assignedIncident.getStateId(), mostRecentTestCaseResolutionStatusData.getStateId()); Resolved resolved = JsonUtils.convertValue( mostRecentTestCaseResolutionStatusData.getTestCaseResolutionStatusDetails(), @@ -1391,31 +1317,40 @@ public void test_testCaseResolutionTaskResolveWorkflowThruFeed(TestInfo test) @Test public void test_testCaseResolutionTaskCloseWorkflowThruFeed(TestInfo test) - throws HttpResponseException { + throws HttpResponseException, ParseException { Long startTs = System.currentTimeMillis(); FeedResourceTest feedResourceTest = new FeedResourceTest(); TestCase testCaseEntity = createEntity(createRequest(getEntityName(test)), ADMIN_AUTH_HEADERS); - CreateTestCaseResolutionStatus createTestCaseFailureStatus = + + // Add failed test case, which will create a NEW incident + putTestCaseResult( + testCaseEntity.getFullyQualifiedName(), + new TestCaseResult() + .withResult("result") + .withTestCaseStatus(TestCaseStatus.Failed) + .withTimestamp(TestUtils.dateToTimestamp("2024-01-01")), + ADMIN_AUTH_HEADERS); + + // Now, we should be good to create an ASSIGNED status + CreateTestCaseResolutionStatus createAssignedIncident = new CreateTestCaseResolutionStatus() .withTestCaseReference(testCaseEntity.getFullyQualifiedName()) .withTestCaseResolutionStatusType(TestCaseResolutionStatusTypes.Assigned) .withTestCaseResolutionStatusDetails(new Assigned().withAssignee(USER1_REF)); - TestCaseResolutionStatus testCaseFailureStatus = - createTestCaseFailureStatus(createTestCaseFailureStatus); + TestCaseResolutionStatus assignedIncident = createTestCaseFailureStatus(createAssignedIncident); // Assert that the task is open String jsonThread = Entity.getCollectionDAO() .feedDAO() - .fetchThreadByTestCaseResolutionStatusId(testCaseFailureStatus.getId()); + .fetchThreadByTestCaseResolutionStatusId(assignedIncident.getStateId()); Thread thread = JsonUtils.readValue(jsonThread, Thread.class); - assertEquals(testCaseFailureStatus.getId(), thread.getTask().getTestCaseResolutionStatusId()); + assertEquals(assignedIncident.getStateId(), thread.getTask().getTestCaseResolutionStatusId()); assertEquals(TaskStatus.Open, thread.getTask().getStatus()); // close the task. The old task should be closed and the latest test case resolution status - // should be updated (assigned) with the same state ID and a new task should be opened - + // should be updated (resolved) with the same state ID. CloseTask closeTask = new CloseTask() .withComment(USER1.getFullyQualifiedName()) @@ -1424,7 +1359,7 @@ public void test_testCaseResolutionTaskCloseWorkflowThruFeed(TestInfo test) jsonThread = Entity.getCollectionDAO() .feedDAO() - .fetchThreadByTestCaseResolutionStatusId(testCaseFailureStatus.getId()); + .fetchThreadByTestCaseResolutionStatusId(assignedIncident.getStateId()); thread = JsonUtils.readValue(jsonThread, Thread.class); assertEquals(TaskStatus.Closed, thread.getTask().getStatus()); @@ -1442,49 +1377,48 @@ public void test_testCaseResolutionTaskCloseWorkflowThruFeed(TestInfo test) TestCaseResolutionStatus mostRecentTestCaseResolutionStatusData = mostRecentTestCaseResolutionStatus.getData().get(0); assertEquals( - TestCaseResolutionStatusTypes.Assigned, + TestCaseResolutionStatusTypes.Resolved, mostRecentTestCaseResolutionStatusData.getTestCaseResolutionStatusType()); assertEquals( - testCaseFailureStatus.getStateId(), mostRecentTestCaseResolutionStatusData.getStateId()); - Assigned assigned = - JsonUtils.convertValue( - mostRecentTestCaseResolutionStatusData.getTestCaseResolutionStatusDetails(), - Assigned.class); - assertEquals(USER1.getFullyQualifiedName(), assigned.getAssignee().getFullyQualifiedName()); + assignedIncident.getStateId(), mostRecentTestCaseResolutionStatusData.getStateId()); } @Test public void test_testCaseResolutionTaskWorkflowThruAPI(TestInfo test) - throws HttpResponseException { + throws HttpResponseException, ParseException { TestCase testCaseEntity = createEntity(createRequest(getEntityName(test)), ADMIN_AUTH_HEADERS); - CreateTestCaseResolutionStatus createTestCaseFailureStatus = + // Add failed test case, which will create a NEW incident + putTestCaseResult( + testCaseEntity.getFullyQualifiedName(), + new TestCaseResult() + .withResult("result") + .withTestCaseStatus(TestCaseStatus.Failed) + .withTimestamp(TestUtils.dateToTimestamp("2024-01-01")), + ADMIN_AUTH_HEADERS); + + // Now, we should be good to create an ASSIGNED status + CreateTestCaseResolutionStatus createAssignedIncident = new CreateTestCaseResolutionStatus() .withTestCaseReference(testCaseEntity.getFullyQualifiedName()) - .withTestCaseResolutionStatusType(TestCaseResolutionStatusTypes.New) - .withTestCaseResolutionStatusDetails(null); + .withTestCaseResolutionStatusType(TestCaseResolutionStatusTypes.Assigned) + .withTestCaseResolutionStatusDetails(new Assigned().withAssignee(USER1_REF)); - createTestCaseFailureStatus(createTestCaseFailureStatus); - TestCaseResolutionStatus testCaseFailureStatusAssigned = - createTestCaseFailureStatus( - createTestCaseFailureStatus - .withTestCaseResolutionStatusType(TestCaseResolutionStatusTypes.Assigned) - .withTestCaseResolutionStatusDetails(new Assigned().withAssignee(USER1_REF))); + TestCaseResolutionStatus assignedIncident = createTestCaseFailureStatus(createAssignedIncident); // Confirm that the task is open String jsonThread = Entity.getCollectionDAO() .feedDAO() - .fetchThreadByTestCaseResolutionStatusId(testCaseFailureStatusAssigned.getId()); + .fetchThreadByTestCaseResolutionStatusId(assignedIncident.getStateId()); Thread thread = JsonUtils.readValue(jsonThread, Thread.class); assertEquals(TaskStatus.Open, thread.getTask().getStatus()); - assertEquals( - testCaseFailureStatusAssigned.getId(), thread.getTask().getTestCaseResolutionStatusId()); + assertEquals(assignedIncident.getStateId(), thread.getTask().getTestCaseResolutionStatusId()); // Create a new test case resolution status with type Resolved // and confirm the task is closed CreateTestCaseResolutionStatus createTestCaseFailureStatusResolved = - createTestCaseFailureStatus + createAssignedIncident .withTestCaseResolutionStatusType(TestCaseResolutionStatusTypes.Resolved) .withTestCaseResolutionStatusDetails( new Resolved() @@ -1499,22 +1433,33 @@ public void test_testCaseResolutionTaskWorkflowThruAPI(TestInfo test) } @Test - public void unauthorizedTestCaseResolutionFlow(TestInfo test) throws HttpResponseException { + public void unauthorizedTestCaseResolutionFlow(TestInfo test) + throws HttpResponseException, ParseException { TestCase testCaseEntity = createEntity(createRequest(getEntityName(test)), ADMIN_AUTH_HEADERS); - CreateTestCaseResolutionStatus createTestCaseFailureStatus = + // Add failed test case, which will create a NEW incident + putTestCaseResult( + testCaseEntity.getFullyQualifiedName(), + new TestCaseResult() + .withResult("result") + .withTestCaseStatus(TestCaseStatus.Failed) + .withTimestamp(TestUtils.dateToTimestamp("2024-01-01")), + ADMIN_AUTH_HEADERS); + + // Now, we should be good to create an ASSIGNED status + CreateTestCaseResolutionStatus createAssignedIncident = new CreateTestCaseResolutionStatus() .withTestCaseReference(testCaseEntity.getFullyQualifiedName()) .withTestCaseResolutionStatusType(TestCaseResolutionStatusTypes.Assigned) .withTestCaseResolutionStatusDetails(new Assigned().withAssignee(USER1_REF)); - createTestCaseFailureStatus(createTestCaseFailureStatus); + createTestCaseFailureStatus(createAssignedIncident); assertResponseContains( () -> createTestCaseFailureStatus( - createTestCaseFailureStatus.withTestCaseResolutionStatusType( + createAssignedIncident.withTestCaseResolutionStatusType( TestCaseResolutionStatusTypes.Ack)), BAD_REQUEST, - "with type `Assigned` cannot be moved to `New` or `Ack`. You can `Assign` or `Resolve` the test case failure."); + "Incident with status [Assigned] cannot be moved to [Ack]"); } public void deleteTestCaseResult(String fqn, Long timestamp, Map authHeaders)