Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public Optional<JobDetail> getWorkflowJobById(String jobId) {
.toList();

for (Integer nodeId: innerNodesList) {
// Nodes with null nodeId have not been executed in AAP. This can be due to
// reasons such as diverging paths.
if (nodeId == null) continue;

var jobDetail = jobsApi.apiJobsRead(AWX_API_VERSION, nodeId.toString());

boolean someArtifactIsAnAwxResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import org.opendevstack.component_provisioner.server.services.awx.AwxWorkflowJob;
import org.opendevstack.component_provisioner.server.services.awx.AwxWorkflowJobLaunch;
import org.opendevstack.component_provisioner.server.services.exceptions.AwxClientException;
import org.opendevstack.component_provisioner.server.services.model.AwxResultNames;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestClientException;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -186,4 +188,90 @@ void givenJobId_whenRestClientExceptionOccurs_thenThrowsAwxClientException() {
assertThrows(AwxClientException.class, () -> awxService.getWorkflowJobById(jobId));
}

@Test
void givenWorkflowNodesWithNullJobId_whenGetWorkflowJobById_thenIgnoresNullAndReturnsEmpty() {
// given
String workflowJobId = "wf-id";

WorkflowJobNodeList nodeWithNull = new WorkflowJobNodeList();
nodeWithNull.setJob(null);

var response = ApiWorkflowJobNodesList200ResponseMother.of(
List.of(nodeWithNull)
);

when(workflowJobNodesApi.apiWorkflowJobsWorkflowNodesList(
AWX_API_VERSION, workflowJobId, null, null, null))
.thenReturn(response);

// when
var result = awxService.getWorkflowJobById(workflowJobId);

// then
assertTrue(result.isEmpty());
}

@Test
void givenNullAndValidNodes_whenGetWorkflowJobById_thenSkipsNullAndReturnsValidJobDetail() {
// given
String workflowJobId = "wf-id";
String validJobId = "123";

WorkflowJobNodeList nullNode = new WorkflowJobNodeList();
nullNode.setJob(null);

WorkflowJobNodeList validNode = WorkflowJobNodeListMother.of(Integer.valueOf(validJobId));

var response = ApiWorkflowJobNodesList200ResponseMother.of(
List.of(nullNode, validNode)
);

var jobDetail = JobDetailMother.of().toBuilder()
.artifacts(Map.of(AwxResultNames.RESULT_CODE.getValue(), "value"))
.build();

when(workflowJobNodesApi.apiWorkflowJobsWorkflowNodesList(
AWX_API_VERSION, workflowJobId, null, null, null))
.thenReturn(response);

when(jobsApi.apiJobsRead(AWX_API_VERSION, validJobId))
.thenReturn(jobDetail);

// when
var result = awxService.getWorkflowJobById(workflowJobId);

// then
assertTrue(result.isPresent());
assertEquals(jobDetail, result.get());
}

@Test
void givenAllNodesNull_whenGetWorkflowJobById_thenJobsApiIsNeverCalled() {
// given
String workflowJobId = "wf-id";

WorkflowJobNodeList n1 = new WorkflowJobNodeList();
n1.setJob(null);

WorkflowJobNodeList n2 = new WorkflowJobNodeList();
n2.setJob(null);

var response = ApiWorkflowJobNodesList200ResponseMother.of(
List.of(n1, n2)
);

when(workflowJobNodesApi.apiWorkflowJobsWorkflowNodesList(
AWX_API_VERSION, workflowJobId, null, null, null))
.thenReturn(response);

// when
var result = awxService.getWorkflowJobById(workflowJobId);

// then
assertTrue(result.isEmpty());

org.mockito.Mockito.verifyNoInteractions(jobsApi);
}


}
Loading