Commit 01b5c57d authored by Mayank Saggar [Microsoft]'s avatar Mayank Saggar [Microsoft]
Browse files

GET Workfow by Id and Get WorkflowRun by Id I-Tests

parent 7696ab17
Pipeline #16734 passed with stages
in 29 minutes and 23 seconds
......@@ -46,7 +46,6 @@ public class WorkflowRunRepositoryTest {
" \"status\": \"SUBMITTED\",\n" +
" \"submittedBy\": \"user@mail.com\"\n" +
"}";
private static final String WORKFLOW_ID = "2afccfb8-1351-41c6-9127-61f2d7f22ff8";
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@Mock
......
......@@ -42,12 +42,12 @@ public class AzurePayLoadBuilder {
return new Gson().toJson(payload);
}
public static String getValidCreateWorkflowRequest() {
return new Gson().toJson(PayloadBuilder.buildCreateWorkflowRequest());
public static String getValidCreateWorkflowRequest(String dagType) {
return new Gson().toJson(PayloadBuilder.buildCreateWorkflowRequest(dagType));
}
public static String getInvalidCreateWorkflowRequest() {
Map<String, Object> payload = PayloadBuilder.buildCreateWorkflowRequest();
public static String getInvalidCreateWorkflowRequest(String dagType) {
Map<String, Object> payload = PayloadBuilder.buildCreateWorkflowRequest(dagType);
payload.remove("workflowDetailContent");
payload.put("workflowdetailcontent",WORKFLOW_DETAIL_CONTENT);
......@@ -68,38 +68,6 @@ public class AzurePayLoadBuilder {
return new Gson().toJson(payload);
}
public static String getCreateWorkflowRequestWithEmptyDetailedContent() {
Map<String, Object> payload = PayloadBuilder.buildCreateWorkflowRequest();
payload.replace("workflowDetailContent", "");
return new Gson().toJson(payload);
}
public static String getCreateWorkflowRequestWithEmptyWorkflowName() {
Map<String, Object> payload = PayloadBuilder.buildCreateWorkflowRequest();
payload.replace("workflowName", "");
return new Gson().toJson(payload);
}
public static String getCreateWorkflowRequestWithoutDetailedContent() {
Map<String, Object> payload = PayloadBuilder.buildCreateWorkflowRequest();
payload.remove("workflowDetailContent");
return new Gson().toJson(payload);
}
public static String getCreateWorkflowRequestWithoutWorkflowName() {
Map<String, Object> payload = PayloadBuilder.buildCreateWorkflowRequest();
payload.remove("workflowName");
return new Gson().toJson(payload);
}
public static String getValidWorkflowPayload(){
return PayloadBuilder.buildStartWorkflow(buildContext(), TestConstants.WORKFLOW_TYPE_INGEST);
}
......
// Copyright 2017-2019, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
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.GetWorkflowByIdIntegrationTests;
public class TestGetWorkflowByIdIntegration extends GetWorkflowByIdIntegrationTests {
@BeforeEach
@Override
public void setup() {
this.client = new HTTPClientAzure();
this.headers = client.getCommonHeader();
}
@AfterEach
@Override
public void tearDown() {
this.client = null;
this.headers = null;
}
}
// Copyright 2017-2019, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
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.GetWorkflowRunByIdIntegrationTests;
public class TestGetWorkflowRunByIdIntegration extends GetWorkflowRunByIdIntegrationTests {
@BeforeEach
@Override
public void setup() {
this.client = new HTTPClientAzure();
this.headers = client.getCommonHeader();
}
@AfterEach
@Override
public void tearDown() {
this.client = null;
this.headers = null;
}
}
......@@ -43,7 +43,8 @@ public class TestPostCreateWorkflowIntegration extends PostCreateWorkflowIntegra
@Test
@Override
public void should_returnSuccess_when_givenValidRequest() throws Exception{
String createWorkflowRequestBody = AzurePayLoadBuilder.getValidCreateWorkflowRequest();
String createWorkflowRequestBody = AzurePayLoadBuilder.getValidCreateWorkflowRequest("python");
JsonObject workflowRequest = new Gson().fromJson(createWorkflowRequestBody, JsonObject.class);
ClientResponse response = client.send(
HttpMethod.POST,
......@@ -55,7 +56,6 @@ public class TestPostCreateWorkflowIntegration extends PostCreateWorkflowIntegra
assertEquals(HttpStatus.SC_OK, response.getStatus());
JsonObject workflowRequest = new Gson().fromJson(createWorkflowRequestBody, JsonObject.class);
JsonObject workflowResponse = new Gson().fromJson(response.getEntity(String.class), JsonObject.class);
assertTrue(isNotBlank(workflowResponse.get(NEW_WORKFLOW_ID_FIELD).getAsString()));
......@@ -67,9 +67,9 @@ public class TestPostCreateWorkflowIntegration extends PostCreateWorkflowIntegra
}
@Test
@Override
public void should_returnBadRequest_when_givenInvalidRequest() throws Exception{
String createWorkflowRequestBody = AzurePayLoadBuilder.getInvalidCreateWorkflowRequest();
public void should_returnSuccess_when_givenValidRequest_httpOperator() throws Exception{
String createWorkflowRequestBody = AzurePayLoadBuilder.getValidCreateWorkflowRequest("http");
JsonObject workflowRequest = new Gson().fromJson(createWorkflowRequestBody, JsonObject.class);
ClientResponse response = client.send(
HttpMethod.POST,
......@@ -79,100 +79,91 @@ public class TestPostCreateWorkflowIntegration extends PostCreateWorkflowIntegra
client.getAccessToken()
);
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
String error = response.getEntity(String.class);
assertTrue(error.contains(CREATE_WORKFLOW_INVALID_REQUEST_MESSAGE));
}
assertEquals(HttpStatus.SC_OK, response.getStatus());
@Test
@Override
public void should_returnUnauthorized_when_notGivenAccessToken() throws Exception {
ClientResponse response = client.send(
HttpMethod.POST,
CREATE_WORKFLOW_URL,
AzurePayLoadBuilder.getValidCreateWorkflowRequest(),
headers,
null
);
JsonObject workflowResponse = new Gson().fromJson(response.getEntity(String.class), JsonObject.class);
assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatus());
assertTrue(isNotBlank(workflowResponse.get(NEW_WORKFLOW_ID_FIELD).getAsString()));
assertEquals(workflowResponse.get(WORKFLOW_NAME_FIELD).getAsString(), workflowRequest.get(WORKFLOW_NAME_FIELD).getAsString());
assertEquals(workflowResponse.get(WORKFLOW_DESCRIPTION_FIELD).getAsString(), workflowRequest.get(WORKFLOW_DESCRIPTION_FIELD).getAsString());
assertEquals(workflowResponse.get(WORKFLOW_CONCURRENT_WORKFLOW_RUN_FIELD).getAsInt(), workflowRequest.get(WORKFLOW_CONCURRENT_WORKFLOW_RUN_FIELD).getAsInt());
assertEquals(workflowResponse.get(WORKFLOW_CONCURRENT_TASK_RUN_FIELD).getAsInt(), workflowRequest.get(WORKFLOW_CONCURRENT_TASK_RUN_FIELD).getAsInt());
assertEquals(workflowResponse.get(WORKFLOW_ACTIVE_FIELD).getAsBoolean(), workflowRequest.get(WORKFLOW_ACTIVE_FIELD).getAsBoolean());
}
@Test
@Override
public void should_returnUnauthorized_when_givenNoDataAccessToken() throws Exception {
ClientResponse response = client.send(
HttpMethod.POST,
CREATE_WORKFLOW_URL,
AzurePayLoadBuilder.getValidCreateWorkflowRequest(),
headers,
client.getNoDataAccessToken()
);
assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatus());
}
public void should_returnSuccess_when_givenValidRequest_kubernetesOperator() throws Exception{
String createWorkflowRequestBody = AzurePayLoadBuilder.getValidCreateWorkflowRequest("kubernetes");
JsonObject workflowRequest = new Gson().fromJson(createWorkflowRequestBody, JsonObject.class);
@Test
public void should_return_500_when_givenEmptyDetailedContent() throws Exception {
ClientResponse response = client.send(
HttpMethod.POST,
CREATE_WORKFLOW_URL,
AzurePayLoadBuilder.getCreateWorkflowRequestWithEmptyDetailedContent(),
createWorkflowRequestBody,
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.SC_OK, response.getStatus());
String error = response.getEntity(String.class);
JsonObject workflowResponse = new Gson().fromJson(response.getEntity(String.class), JsonObject.class);
assertTrue(error.contains(WORKFLOW_EMPTY_DETAILED_CONTENT_MESSAGE));
assertTrue(isNotBlank(workflowResponse.get(NEW_WORKFLOW_ID_FIELD).getAsString()));
assertEquals(workflowResponse.get(WORKFLOW_NAME_FIELD).getAsString(), workflowRequest.get(WORKFLOW_NAME_FIELD).getAsString());
assertEquals(workflowResponse.get(WORKFLOW_DESCRIPTION_FIELD).getAsString(), workflowRequest.get(WORKFLOW_DESCRIPTION_FIELD).getAsString());
assertEquals(workflowResponse.get(WORKFLOW_CONCURRENT_WORKFLOW_RUN_FIELD).getAsInt(), workflowRequest.get(WORKFLOW_CONCURRENT_WORKFLOW_RUN_FIELD).getAsInt());
assertEquals(workflowResponse.get(WORKFLOW_CONCURRENT_TASK_RUN_FIELD).getAsInt(), workflowRequest.get(WORKFLOW_CONCURRENT_TASK_RUN_FIELD).getAsInt());
assertEquals(workflowResponse.get(WORKFLOW_ACTIVE_FIELD).getAsBoolean(), workflowRequest.get(WORKFLOW_ACTIVE_FIELD).getAsBoolean());
}
@Test
public void should_return_500_when_givenEmptyWorkflowName() throws Exception {
@Override
public void should_returnBadRequest_when_givenInvalidRequest() throws Exception{
String createWorkflowRequestBody = AzurePayLoadBuilder.getInvalidCreateWorkflowRequest("python");
ClientResponse response = client.send(
HttpMethod.POST,
CREATE_WORKFLOW_URL,
AzurePayLoadBuilder.getCreateWorkflowRequestWithEmptyWorkflowName(),
createWorkflowRequestBody,
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
String error = response.getEntity(String.class);
assertTrue(error.contains(WORKFLOW_EMPTY_WORKFLOW_NAME_MESSAGE));
assertTrue(error.contains(CREATE_WORKFLOW_INVALID_REQUEST_MESSAGE));
}
@Test
public void should_return_500_when_givenWithoutDetailContentField() throws Exception {
@Override
public void should_returnWorkflowExists_when_givenDuplicateRequest() throws Exception{
String createWorkflowRequestBody = AzurePayLoadBuilder.getValidCreateWorkflowRequest("python");
ClientResponse response = client.send(
HttpMethod.POST,
CREATE_WORKFLOW_URL,
AzurePayLoadBuilder.getCreateWorkflowRequestWithoutDetailedContent(),
createWorkflowRequestBody,
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
}
assertEquals(HttpStatus.SC_OK, response.getStatus());
@Test
public void should_return_500_when_givenWithoutWorkflowNameField() throws Exception {
ClientResponse response = client.send(
ClientResponse duplicateResponse = client.send(
HttpMethod.POST,
CREATE_WORKFLOW_URL,
AzurePayLoadBuilder.getCreateWorkflowRequestWithoutWorkflowName(),
createWorkflowRequestBody,
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.SC_CONFLICT, duplicateResponse.getStatus());
String error = duplicateResponse.getEntity(String.class);
assertTrue(error.contains(WORKFLOW_NAME_CONFLICT_MESSAGE));
}
@AfterEach
......
......@@ -32,7 +32,7 @@ public class TestPostTriggerWorkflowIntegration extends PostTriggerWorkflowInteg
ClientResponse createWorkflowResponse = client.send(
HttpMethod.POST,
CREATE_WORKFLOW_URL,
AzurePayLoadBuilder.getValidCreateWorkflowRequest(),
AzurePayLoadBuilder.getValidCreateWorkflowRequest("python"),
headers,
client.getAccessToken()
);
......@@ -40,7 +40,7 @@ public class TestPostTriggerWorkflowIntegration extends PostTriggerWorkflowInteg
JsonObject workflow = new Gson().fromJson(createWorkflowResponse.getEntity(String.class), JsonObject.class);
System.out.println(System.currentTimeMillis());
Thread.sleep(135*1000);
Thread.sleep(90*1000);
System.out.println(System.currentTimeMillis());
String triggerWorkflowRequestBody = AzurePayLoadBuilder.getValidTriggerWorkflowRequest();
......@@ -64,19 +64,22 @@ public class TestPostTriggerWorkflowIntegration extends PostTriggerWorkflowInteg
}
@Test
@Override
public void should_returnBadRequest_when_givenInvalidRequest() throws Exception{
public void should_returnSuccess_when_givenValidRequest_httpOperator() throws Exception{
ClientResponse createWorkflowResponse = client.send(
HttpMethod.POST,
CREATE_WORKFLOW_URL,
AzurePayLoadBuilder.getValidCreateWorkflowRequest(),
AzurePayLoadBuilder.getValidCreateWorkflowRequest("http"),
headers,
client.getAccessToken()
);
JsonObject workflow = new Gson().fromJson(createWorkflowResponse.getEntity(String.class), JsonObject.class);
String triggerWorkflowRequestBody = AzurePayLoadBuilder.getInvalidTriggerWorkflowRequest();
System.out.println(System.currentTimeMillis());
Thread.sleep(120*1000);
System.out.println(System.currentTimeMillis());
String triggerWorkflowRequestBody = AzurePayLoadBuilder.getValidTriggerWorkflowRequest();
ClientResponse response = client.send(
HttpMethod.POST,
......@@ -86,23 +89,31 @@ public class TestPostTriggerWorkflowIntegration extends PostTriggerWorkflowInteg
client.getAccessToken()
);
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
assertEquals(HttpStatus.SC_OK, response.getStatus());
JsonObject workflowRunRequest = new Gson().fromJson(triggerWorkflowRequestBody, JsonObject.class);
JsonObject workflowRunResponse = new Gson().fromJson(response.getEntity(String.class), JsonObject.class);
assertEquals(workflowRunResponse.get(NEW_WORKFLOW_RUN_ID_FIELD).getAsString(), workflowRunRequest.get(NEW_WORKFLOW_RUN_ID_FIELD).getAsString());
assertEquals(workflowRunResponse.get(NEW_WORKFLOW_ID_FIELD).getAsString(),workflow.get(NEW_WORKFLOW_ID_FIELD).getAsString());
assertEquals(workflowRunResponse.get(NEW_WORKFLOW_RUN_STATUS_FIELD).getAsString(), "submitted");
}
@Test
public void should_return_500_when_workflowNotReady() throws Exception{
public void should_returnSuccess_when_givenValidRequest_kubernetesOperator() throws Exception{
ClientResponse createWorkflowResponse = client.send(
HttpMethod.POST,
CREATE_WORKFLOW_URL,
AzurePayLoadBuilder.getValidCreateWorkflowRequest(),
AzurePayLoadBuilder.getValidCreateWorkflowRequest("kubernetes"),
headers,
client.getAccessToken()
);
JsonObject workflow = new Gson().fromJson(createWorkflowResponse.getEntity(String.class), JsonObject.class);
Thread.sleep(60*1000);
System.out.println(System.currentTimeMillis());
Thread.sleep(120*1000);
System.out.println(System.currentTimeMillis());
String triggerWorkflowRequestBody = AzurePayLoadBuilder.getValidTriggerWorkflowRequest();
......@@ -114,11 +125,40 @@ public class TestPostTriggerWorkflowIntegration extends PostTriggerWorkflowInteg
client.getAccessToken()
);
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.SC_OK, response.getStatus());
String error = response.getEntity(String.class);
JsonObject workflowRunRequest = new Gson().fromJson(triggerWorkflowRequestBody, JsonObject.class);
JsonObject workflowRunResponse = new Gson().fromJson(response.getEntity(String.class), JsonObject.class);
assertTrue(error.contains(WORKFLOW_RUN_TRIGGER_FAILED));
assertEquals(workflowRunResponse.get(NEW_WORKFLOW_RUN_ID_FIELD).getAsString(), workflowRunRequest.get(NEW_WORKFLOW_RUN_ID_FIELD).getAsString());
assertEquals(workflowRunResponse.get(NEW_WORKFLOW_ID_FIELD).getAsString(),workflow.get(NEW_WORKFLOW_ID_FIELD).getAsString());
assertEquals(workflowRunResponse.get(NEW_WORKFLOW_RUN_STATUS_FIELD).getAsString(), "submitted");
}
@Test
@Override
public void should_returnBadRequest_when_givenInvalidRequest() throws Exception{
ClientResponse createWorkflowResponse = client.send(
HttpMethod.POST,
CREATE_WORKFLOW_URL,
AzurePayLoadBuilder.getValidCreateWorkflowRequest("python"),
headers,
client.getAccessToken()
);
JsonObject workflow = new Gson().fromJson(createWorkflowResponse.getEntity(String.class), JsonObject.class);
String triggerWorkflowRequestBody = AzurePayLoadBuilder.getInvalidTriggerWorkflowRequest();
ClientResponse response = client.send(
HttpMethod.POST,
TRIGGER_WORKFLOW_URL.replace("{id}", workflow.get(NEW_WORKFLOW_ID_FIELD).getAsString()),
triggerWorkflowRequestBody,
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
}
@Test
......
......@@ -15,6 +15,8 @@ public class TestConstants {
public static final String START_WORKFLOW_API_ENDPOINT = "/startWorkflow";
public static final String CREATE_WORKFLOW_API_ENDPOINT = "/workflow";
public static final String TRIGGER_WORKFLOW_API_ENDPOINT = "/workflow/{id}/workflowRun";
public static final String GET_WORKFLOW_API_ENDPOINT = "/workflow/{id}";
public static final String GET_WORKFLOW_RUN_API_ENDPOINT = "/workflow/{id}/workflowRun/{runId}";
public static final String GET_STATUS_API_ENDPOINT = "/getStatus";
public static final String UPDATE_STATUS_API_ENDPOINT = "/updateStatus";
......@@ -27,6 +29,7 @@ public class TestConstants {
public static final String WORKFLOW_DETAIL_CONTENT = "{\n" +
"\"workflowDetailContent\": \"from airflow import DAG\\r\\nimport logging\\r\\nimport json\\r\\nfrom airflow.utils.dates import days_ago\\r\\nfrom datetime import timedelta\\r\\nfrom airflow.operators.http_operator import SimpleHttpOperator\\r\\n\\r\\ndefault_args = {\\r\\n 'start_date': days_ago(0),\\r\\n 'retries': 1,\\r\\n 'retry_delay': timedelta(minutes=5)\\r\\n}\\r\\n\\r\\ntoken = \\\"{{ dag_run.conf['authToken'] }}\\\"\\r\\ndata_partition_id = \\\"{{ dag_run.conf['runConfiguration']['dataPartitionId'] }}\\\"\\r\\nkind = \\\"{{ dag_run.conf['runConfiguration']['kind'] }}\\\"\\r\\nrecord_id = \\\"{{ dag_run.conf['runConfiguration']['id'] }}\\\"\\r\\n\\r\\nwith DAG(\\r\\n dag_id='{id}',\\r\\n default_args=default_args,\\r\\n schedule_interval=None,\\r\\n start_date=days_ago(2),\\r\\n tags=['csv'],\\r\\n) as dag:\\r\\n headers = {\\r\\n 'Content-Type': 'application/json',\\r\\n 'Accept': 'application/json',\\r\\n 'data-partition-id': f'{data_partition_id}',\\r\\n 'Authorization': f'{token}'\\r\\n }\\r\\n\\r\\n ingest_csv = SimpleHttpOperator(\\r\\n task_id='parse_csv',\\r\\n http_conn_id='http_csv_parser',\\r\\n endpoint='api/parser/v2/ingestion',\\r\\n method='post',\\r\\n data=json.dumps({\\\"kind\\\":kind,\\\"id\\\":record_id}),\\r\\n headers= headers,\\r\\n response_check= lambda response: response.status_code in [200,201],\\r\\n extra_options = {\\\"verify\\\":False},\\r\\n log_response= True\\r\\n )\"\n" +
"}";
public static final String DAG_FILE_PATH = "../workflow-test-core/src/main/resources/{type}_operator_dag.py";
public static final String WORKFLOW_DESCRIPTION = "This is a test workflow";
public static final int WORKFLOW_CONCURRENT_WORKFLOW_RUN = 5;
public static final int WORKFLOW_CONCURRENT_TASK_RUN = 5;
......@@ -62,6 +65,10 @@ public class TestConstants {
getEnvironmentVariableOrDefaultKey(WORKFLOW_HOST) + CREATE_WORKFLOW_API_ENDPOINT;
public static final String TRIGGER_WORKFLOW_URL =
getEnvironmentVariableOrDefaultKey(WORKFLOW_HOST) + TRIGGER_WORKFLOW_API_ENDPOINT;
public static final String GET_WORKFLOW_URL =
getEnvironmentVariableOrDefaultKey(WORKFLOW_HOST) + GET_WORKFLOW_API_ENDPOINT;
public static final String GET_WORKFLOW_RUN_URL =
getEnvironmentVariableOrDefaultKey(WORKFLOW_HOST) + GET_WORKFLOW_RUN_API_ENDPOINT;
public static final String GET_STATUS_URL =
getEnvironmentVariableOrDefaultKey(WORKFLOW_HOST) + GET_STATUS_API_ENDPOINT;
public static final String UPDATE_STATUS_URL =
......@@ -75,8 +82,8 @@ public class TestConstants {
public static final String WORKFLOW_STATUS_NOT_ALLOWED_MESSAGE = "Status: Not allowed workflow status type: SUBMITTED, Should be one of: [RUNNING, FINISHED, FAILED]";
public static final String CREATE_WORKFLOW_INVALID_REQUEST_MESSAGE = "Invalid JSON input: Unrecognized field";
public static final String WORKFLOW_NAME_CONFLICT_MESSAGE = "Resource with specified id or name already exists.";
public static final String WORKFLOW_EMPTY_DETAILED_CONTENT_MESSAGE = "ShareFileRange end must be greater than or equal to 0 if specified.";
public static final String WORKFLOW_EMPTY_WORKFLOW_NAME_MESSAGE = "The input name '' is invalid. Ensure to provide a unique non-empty string less than '1024' characters.";
public static final String WORKFLOW_NOT_FOUND_MESSAGE = "Workflow: {id} doesn't exist";
public static final String WORKFLOW_RUN_NOT_FOUND_MESSAGE = "WorkflowRun: {runId} for Workflow: {id} doesn't exist";
public static String getValidWorkflowPayload(){
return buildStartWorkflow(buildContext(), WORKFLOW_TYPE_INGEST);
......@@ -86,11 +93,11 @@ public class TestConstants {
return buildStartWorkflow(null, null);
}
public static String getValidCreateWorkflowRequest(){
return new Gson().toJson(buildCreateWorkflowRequest());
public static String getValidCreateWorkflowRequest(String dagType){
return new Gson().toJson(buildCreateWorkflowRequest(dagType));
}
public static String getInvalidCreateWorkflowRequest(){
return buildInvalidCreateWorkflowRequest();
public static String getInvalidCreateWorkflowRequest(String dagType){
return buildInvalidCreateWorkflowRequest(dagType);
}
public static String getValidTriggerWorkflowRunRequest(){
......
......@@ -3,6 +3,8 @@ package org.opengroup.osdu.workflow.util;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
......@@ -12,13 +14,21 @@ import static org.opengroup.osdu.workflow.consts.TestConstants.*;
public class PayloadBuilder {
public static Map<String, Object> buildCreateWorkflowRequest() {
Map<String, Object> payload = new HashMap<>();
public static String createDAGContentFromFile (String dagType) throws Exception{
String path = DAG_FILE_PATH.replace("{type}",dagType);
String dagContent = new String(Files.readAllBytes(Paths.get(path)));
return dagContent;
}
JsonObject workflowContent = new Gson().fromJson(WORKFLOW_DETAIL_CONTENT, JsonObject.class);
public static Map<String, Object> buildCreateWorkflowRequest(String dagType) {
Map<String, Object> payload = new HashMap<>();
payload.put("workflowName","Workflow_" + System.currentTimeMillis());
payload.put("workflowDetailContent",workflowContent.get("workflowDetailContent").getAsString().replace("{id}", (String) payload.get("workflowName")));
payload.put("workflowName","Workflow_" + dagType + "_" + System.currentTimeMillis());
try {
payload.put("workflowDetailContent",createDAGContentFromFile(dagType).replace("{dagId}", (String) payload.get("workflowName")));
} catch (Exception e) {
e.printStackTrace();
}
payload.put("description",WORKFLOW_DESCRIPTION);
payload.put("concurrentWorkflowRun",WORKFLOW_CONCURRENT_WORKFLOW_RUN);
payload.put("concurrentTaskRun",WORKFLOW_CONCURRENT_TASK_RUN);
......@@ -27,11 +37,11 @@ public class PayloadBuilder {
return payload;
}
public static String buildInvalidCreateWorkflowRequest() {
Map<String, Object> payload = buildCreateWorkflowRequest();
public static String buildInvalidCreateWorkflowRequest(String dagType) {
Map<String, Object> payload = buildCreateWorkflowRequest(dagType);
payload.remove("WorkflowName");
payload.put("workflowname","Workflow_" +