Commit 42160b89 authored by Aalekh Jain's avatar Aalekh Jain
Browse files

Added ITs for system workflow

parent b9d67ca8
package org.opengroup.osdu.azure.workflow.workflow;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.opengroup.osdu.azure.workflow.utils.HTTPClientAzure;
import org.opengroup.osdu.workflow.workflow.v3.DeleteSystemWorkflowV3IntegrationTests;
import java.util.ArrayList;
import static org.opengroup.osdu.workflow.consts.TestConstants.CREATE_WORKFLOW_WORKFLOW_NAME;
public class TestDeleteSystemWorkflowV3Integration extends DeleteSystemWorkflowV3IntegrationTests {
@BeforeEach
@Override
public void setup() {
this.client = new HTTPClientAzure();
this.headers = client.getCommonHeaderWithoutPartition();
try {
deleteTestSystemWorkflows(CREATE_WORKFLOW_WORKFLOW_NAME);
} catch (Exception e) {
e.printStackTrace();
}
}
@AfterEach
@Override
public void tearDown() {
deleteAllTestWorkflowRecords();
this.client = null;
this.headers = null;
this.createdWorkflows = new ArrayList<>();
}
private void deleteAllTestWorkflowRecords() {
createdWorkflows.stream().forEach(c -> {
try {
deleteTestSystemWorkflows(c.get(WORKFLOW_NAME_FIELD));
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
package org.opengroup.osdu.azure.workflow.workflow;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.opengroup.osdu.azure.workflow.utils.HTTPClientAzure;
import org.opengroup.osdu.workflow.workflow.v3.PostCreateSystemWorkflowV3IntegrationTests;
import java.util.ArrayList;
import static org.opengroup.osdu.workflow.consts.TestConstants.CREATE_WORKFLOW_WORKFLOW_NAME;
public class TestPostCreateSystemWorkflowV3Integration extends PostCreateSystemWorkflowV3IntegrationTests {
@BeforeEach
@Override
public void setup() {
this.client = new HTTPClientAzure();
this.headers = client.getCommonHeaderWithoutPartition();
try {
deleteTestSystemWorkflows(CREATE_WORKFLOW_WORKFLOW_NAME);
} catch (Exception e) {
e.printStackTrace();
}
}
@AfterEach
@Override
public void tearDown() {
deleteAllTestWorkflowRecords();
this.client = null;
this.headers = null;
this.createdWorkflows = new ArrayList<>();
}
private void deleteAllTestWorkflowRecords() {
createdWorkflows.stream().forEach(c -> {
try {
deleteTestSystemWorkflows(c.get(WORKFLOW_NAME_FIELD));
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
package org.opengroup.osdu.workflow.workflow.v3;
import com.sun.jersey.api.client.ClientResponse;
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;
import org.opengroup.osdu.workflow.util.v3.TestBase;
import javax.ws.rs.HttpMethod;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opengroup.osdu.workflow.consts.TestConstants.CREATE_WORKFLOW_WORKFLOW_NAME;
import static org.opengroup.osdu.workflow.consts.TestConstants.GET_SYSTEM_WORKFLOW_BY_ID_URL;
public abstract class DeleteSystemWorkflowV3IntegrationTests extends TestBase {
@Test
public void should_delete_when_givenValidWorkflowName() throws Exception {
String responseBody = createSystemWorkflow();
Map<String, String> workflowInfo = getWorkflowInfoFromCreateWorkflowResponseBody(responseBody);
createdWorkflows.add(workflowInfo);
ClientResponse deleteResponse = client.send(
HttpMethod.DELETE,
String.format(GET_SYSTEM_WORKFLOW_BY_ID_URL, CREATE_WORKFLOW_WORKFLOW_NAME),
null,
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.SC_NO_CONTENT, deleteResponse.getStatus());
}
@Test
public void should_ReturnNotFound_when_givenInvalidWorkflowName() throws Exception {
String responseBody = createSystemWorkflow();
Map<String, String> workflowInfo = getWorkflowInfoFromCreateWorkflowResponseBody(responseBody);
createdWorkflows.add(workflowInfo);
ClientResponse deleteResponse = client.send(
HttpMethod.DELETE,
String.format(GET_SYSTEM_WORKFLOW_BY_ID_URL, INVALID_WORKFLOW_NAME),
null,
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.SC_NOT_FOUND, deleteResponse.getStatus());
}
@Test
public void should_returnForbidden_when_notGivenAccessToken() throws Exception {
String responseBody = createSystemWorkflow();
Map<String, String> workflowInfo = getWorkflowInfoFromCreateWorkflowResponseBody(responseBody);
createdWorkflows.add(workflowInfo);
ClientResponse response = client.send(
HttpMethod.DELETE,
String.format(GET_SYSTEM_WORKFLOW_BY_ID_URL, CREATE_WORKFLOW_WORKFLOW_NAME),
null,
headers,
null
);
assertTrue(HttpStatus.SC_FORBIDDEN == response.getStatus() || HttpStatus.SC_UNAUTHORIZED == response.getStatus());
}
}
package org.opengroup.osdu.workflow.workflow.v3;
import com.sun.jersey.api.client.ClientResponse;
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;
import org.opengroup.osdu.workflow.util.v3.TestBase;
import javax.ws.rs.HttpMethod;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opengroup.osdu.workflow.consts.TestConstants.CREATE_SYSTEM_WORKFLOW_URL;
import static org.opengroup.osdu.workflow.util.PayloadBuilder.buildCreateWorkflowPayloadWithIncorrectWorkflowName;
import static org.opengroup.osdu.workflow.util.PayloadBuilder.buildCreateWorkflowPayloadWithNoWorkflowName;
import static org.opengroup.osdu.workflow.util.PayloadBuilder.buildCreateWorkflowValidPayload;
public abstract class PostCreateSystemWorkflowV3IntegrationTests extends TestBase {
@Test
public void should_returnWorkflowExists_when_givenDuplicateCreateWorkflowRequest() throws Exception{
String responseBody = createSystemWorkflow();
Map<String, String> workflowInfo = getWorkflowInfoFromCreateWorkflowResponseBody(responseBody);
createdWorkflows.add(workflowInfo);
ClientResponse duplicateResponse = client.send(
HttpMethod.POST,
CREATE_SYSTEM_WORKFLOW_URL,
buildCreateWorkflowValidPayload(),
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.SC_CONFLICT, duplicateResponse.getStatus());
}
@Test
public void should_returnBadRequest_when_givenInvalidRequestWithNoWorkflowName() throws Exception{
ClientResponse response = client.send(
HttpMethod.POST,
CREATE_SYSTEM_WORKFLOW_URL,
buildCreateWorkflowPayloadWithNoWorkflowName(),
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
}
@Test
public void should_returnBadRequest_when_givenInvalidRequestWithIncorrectWorkflowName() throws Exception{
ClientResponse response = client.send(
HttpMethod.POST,
CREATE_SYSTEM_WORKFLOW_URL,
buildCreateWorkflowPayloadWithIncorrectWorkflowName(),
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
}
@Test
public void should_returnForbidden_when_notGivenAccessToken() throws Exception {
ClientResponse response = client.send(
HttpMethod.POST,
CREATE_SYSTEM_WORKFLOW_URL,
buildCreateWorkflowValidPayload(),
headers,
null
);
assertTrue(HttpStatus.SC_FORBIDDEN == response.getStatus() || HttpStatus.SC_UNAUTHORIZED == response.getStatus());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment