Skip to content

Commit

Permalink
Merge pull request #25 from orkes-io/tests/api-clients
Browse files Browse the repository at this point in the history
Integration test updates
  • Loading branch information
v1r3n authored Sep 15, 2022
2 parents c214730 + ba97fad commit b6505f6
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 58 deletions.
4 changes: 4 additions & 0 deletions src/main/java/io/orkes/conductor/client/MetadataClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ public interface MetadataClient {
void setTaskTags(List<TagObject> tagObjects, String taskName) throws ApiException;

void setWorkflowTags(List<TagObject> tagObjects, String name) throws ApiException;

void registerWorkflowDef(WorkflowDef workflowDef, boolean overwrite);

void updateWorkflowDefs(List<WorkflowDef> workflowDefs, boolean overwrite);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void registerWorkflowDef(WorkflowDef workflowDef) {
metadataResourceApi.create(workflowDef, true);
}

@Override
public void registerWorkflowDef(WorkflowDef workflowDef, boolean overwrite) {
metadataResourceApi.create(workflowDef, overwrite);
}
Expand All @@ -49,6 +50,7 @@ public void updateWorkflowDefs(List<WorkflowDef> workflowDefs) {
metadataResourceApi.update(workflowDefs, true);
}

@Override
public void updateWorkflowDefs(List<WorkflowDef> workflowDefs, boolean overwrite) {
metadataResourceApi.update(workflowDefs, overwrite);
}
Expand Down
107 changes: 88 additions & 19 deletions src/test/java/io/orkes/conductor/client/api/MetadataClientTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
*/
package io.orkes.conductor.client.api;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import com.netflix.conductor.common.metadata.tasks.TaskDef;
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;

import io.orkes.conductor.client.MetadataClient;
import io.orkes.conductor.client.http.ApiException;
import io.orkes.conductor.client.http.OrkesMetadataClient;
import io.orkes.conductor.client.model.TagObject;
import io.orkes.conductor.client.util.Commons;
Expand All @@ -30,30 +34,95 @@ public class MetadataClientTests extends ClientTest {
private final MetadataClient metadataClient;

public MetadataClientTests() {
this.metadataClient = super.orkesClients.getMetadataClient();
metadataClient = super.orkesClients.getMetadataClient();
}

@Test
@DisplayName("tag a workflows and task")
public void tagWorkflowsAndTasks() {
registerTask();
registerWorkflow();
TagObject tagObject = new TagObject();
tagObject.setType(TagObject.TypeEnum.METADATA);
tagObject.setKey("a");
tagObject.setValue("b");
((OrkesMetadataClient) metadataClient).addTaskTag(tagObject, Commons.TASK_NAME);
((OrkesMetadataClient) metadataClient).addWorkflowTag(tagObject, Commons.WORKFLOW_NAME);
}

void registerTask() {
TaskDef taskDef = new TaskDef();
taskDef.setName(Commons.TASK_NAME);
this.metadataClient.registerTaskDefs(List.of(taskDef));
void taskDefinition() {
try {
metadataClient.unregisterTaskDef(Commons.TASK_NAME);
} catch (ApiException e) {
if (e.getCode() != 404) {
throw e;
}
}
TaskDef taskDef = Commons.getTaskDef();
metadataClient.registerTaskDefs(List.of(taskDef));
metadataClient.updateTaskDef(taskDef);
TaskDef receivedTaskDef = metadataClient.getTaskDef(Commons.TASK_NAME);
assertTrue(taskDef.getName().equals(receivedTaskDef.getName()));
}

void registerWorkflow() {
@Test
void workflow() {
try {
metadataClient.unregisterWorkflowDef(Commons.WORKFLOW_NAME, Commons.WORKFLOW_VERSION);
} catch (ApiException e) {
if (e.getCode() != 404) {
throw e;
}
}
metadataClient.registerTaskDefs(List.of(Commons.getTaskDef()));
WorkflowDef workflowDef = WorkflowUtil.getWorkflowDef();
metadataClient.registerWorkflowDef(workflowDef);
metadataClient.updateWorkflowDefs(List.of(workflowDef));
metadataClient.updateWorkflowDefs(List.of(workflowDef), true);
metadataClient.registerWorkflowDef(workflowDef, true);
((OrkesMetadataClient) metadataClient).getWorkflowDefWithMetadata(
Commons.WORKFLOW_NAME,
Commons.WORKFLOW_VERSION);
WorkflowDef receivedWorkflowDef = metadataClient.getWorkflowDef(Commons.WORKFLOW_NAME,
Commons.WORKFLOW_VERSION);
assertTrue(receivedWorkflowDef.getName().equals(Commons.WORKFLOW_NAME));
assertEquals(receivedWorkflowDef.getVersion(), Commons.WORKFLOW_VERSION);
}

@Test
void tagTask() {
metadataClient.registerTaskDefs(List.of(Commons.getTaskDef()));
try {
metadataClient.deleteTaskTag(Commons.getTagString(), Commons.TASK_NAME);
} catch (ApiException e) {
if (e.getCode() != 404) {
throw e;
}
}
TagObject tagObject = Commons.getTagObject();
metadataClient.addTaskTag(
tagObject,
Commons.TASK_NAME);
metadataClient.setTaskTags(
List.of(tagObject),
Commons.TASK_NAME);
List<TagObject> tags = metadataClient.getTaskTags(
Commons.TASK_NAME);
assertIterableEquals(List.of(tagObject), tags);
metadataClient.deleteTaskTag(
Commons.getTagString(),
Commons.TASK_NAME);
tags = metadataClient.getTaskTags(
Commons.TASK_NAME);
assertIterableEquals(List.of(), tags);
}

@Test
void tagWorkflow() {
TagObject tagObject = Commons.getTagObject();
try {
metadataClient.deleteWorkflowTag(Commons.getTagObject(), Commons.WORKFLOW_NAME);
} catch (ApiException e) {
if (e.getCode() != 404) {
throw e;
}
}
metadataClient.addWorkflowTag(tagObject, Commons.WORKFLOW_NAME);
metadataClient.setWorkflowTags(List.of(tagObject), Commons.WORKFLOW_NAME);
List<TagObject> tags = metadataClient.getWorkflowTags(Commons.WORKFLOW_NAME);
assertIterableEquals(List.of(tagObject), tags);
}

@Test
void tag() {
metadataClient.getTags();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;

Expand All @@ -26,7 +25,6 @@
import io.orkes.conductor.client.http.ApiException;
import io.orkes.conductor.client.util.Commons;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -39,46 +37,20 @@ public WorkflowClientTests() {

@Test
public void startWorkflow() {
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest();
startWorkflowRequest.setName(Commons.WORKFLOW_NAME);
startWorkflowRequest.setVersion(Commons.WORKFLOW_VERSION);
Map<String, Object> input = new HashMap<>();
startWorkflowRequest.setInput(input);
String workflowId = workflowClient.startWorkflow(startWorkflowRequest);
String workflowId = workflowClient.startWorkflow(getStartWorkflowRequest());
Workflow workflow = workflowClient.getWorkflow(workflowId, false);
assertNotNull(workflow, "Workflow should'n be null");
assertTrue(workflow.getWorkflowName().equals(Commons.WORKFLOW_NAME));
}

@Test
public void testWorkflowMethods() {
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest();
startWorkflowRequest.setName(Commons.WORKFLOW_NAME);
startWorkflowRequest.setVersion(1);
Map<String, Object> input = new HashMap<>();
startWorkflowRequest.setInput(input);
String workflowId = workflowClient.startWorkflow(startWorkflowRequest);
Workflow workflow = workflowClient.getWorkflow(workflowId, false);
assertThrows(
UnsupportedOperationException.class,
() -> {
workflowClient.populateWorkflowOutput(workflow);
});
assertThrows(
UnsupportedOperationException.class,
() -> {
workflowClient.resetCallbacksForInProgressTasks(workflowId);
});
assertThrows(
UnsupportedOperationException.class,
() -> {
workflowClient.searchV2(Commons.WORKFLOW_NAME);
});
assertThrows(
UnsupportedOperationException.class,
() -> {
workflowClient.searchV2(0, 0, "", "", "");
});
assertNotNull(workflowClient.getWorkflows(Commons.WORKFLOW_NAME, "abc", false, false));
String workflowId = workflowClient.startWorkflow(getStartWorkflowRequest());
List<Workflow> workflows = workflowClient.getWorkflows(
Commons.WORKFLOW_NAME,
"askdjbjqhbdjqhbdjqhsbdjqhsbd",
false,
false);
assertTrue(workflows.isEmpty());
workflowClient.terminateWorkflow(workflowId, "reason");
workflowClient.retryLastFailedTask(workflowId);
workflowClient.getRunningWorkflow(Commons.WORKFLOW_NAME, Commons.WORKFLOW_VERSION);
Expand All @@ -95,15 +67,52 @@ public void testWorkflowMethods() {
workflowClient.rerunWorkflow(workflowId, new RerunWorkflowRequest());
workflowClient.pauseWorkflow(workflowId);
workflowClient.resumeWorkflow(workflowId);
workflowClient.pauseWorkflow(workflowId);
try {
workflowClient.skipTaskFromWorkflow(workflowId, Commons.TASK_NAME);
} catch (ApiException e) {
assertTrue(e.getMessage().contains("cannot be skipped"));
if (e.getCode() != 500) {
throw e;
}
}
workflowClient.pauseWorkflow(List.of(workflowId));
workflowClient.resumeWorkflow(List.of(workflowId));
workflowClient.deleteWorkflow(workflowId, false);
workflowClient.search(Commons.WORKFLOW_NAME);
workflowClient.runDecider(workflowId);
}

@Test
void testUnsupportedMethods() {
String workflowId = workflowClient.startWorkflow(getStartWorkflowRequest());
Workflow workflow = workflowClient.getWorkflow(workflowId, false);
assertThrows(
UnsupportedOperationException.class,
() -> {
workflowClient.populateWorkflowOutput(workflow);
});
assertThrows(
UnsupportedOperationException.class,
() -> {
workflowClient.resetCallbacksForInProgressTasks(workflowId);
});
assertThrows(
UnsupportedOperationException.class,
() -> {
workflowClient.searchV2(Commons.WORKFLOW_NAME);
});
assertThrows(
UnsupportedOperationException.class,
() -> {
workflowClient.searchV2(0, 0, "", "", "");
});
}

StartWorkflowRequest getStartWorkflowRequest() {
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest();
startWorkflowRequest.setName(Commons.WORKFLOW_NAME);
startWorkflowRequest.setVersion(1);
startWorkflowRequest.setInput(new HashMap<>());
return startWorkflowRequest;
}
}
29 changes: 28 additions & 1 deletion src/test/java/io/orkes/conductor/client/util/Commons.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,36 @@
*/
package io.orkes.conductor.client.util;

import com.netflix.conductor.common.metadata.tasks.TaskDef;

import io.orkes.conductor.client.model.TagObject;
import io.orkes.conductor.client.model.TagString;

public class Commons {
public static String WORKFLOW_NAME = "test-sdk-java-workflow";
public static String TASK_NAME = "test-sdk-java-workflow";
public static String TASK_NAME = "test-sdk-java-task";
public static String OWNER_EMAIL = "[email protected]";
public static int WORKFLOW_VERSION = 1;

public static TagObject getTagObject() {
TagObject tagObject = new TagObject();
tagObject.setType(TagObject.TypeEnum.METADATA);
tagObject.setKey("a");
tagObject.setValue("b");
return tagObject;
}

public static TagString getTagString() {
TagString tagString = new TagString();
tagString.setType(TagString.TypeEnum.METADATA);
tagString.setKey("a");
tagString.setValue("b");
return tagString;
}

public static TaskDef getTaskDef() {
TaskDef taskDef = new TaskDef();
taskDef.setName(Commons.TASK_NAME);
return taskDef;
}
}

0 comments on commit b6505f6

Please sign in to comment.