Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
workflow-examples cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Moti Asayag <[email protected]>
  • Loading branch information
masayag authored and openshift-merge-robot committed May 30, 2023
1 parent 1acd172 commit 74892d2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fast-build-workflow-examples: ARGS = $(FAST_BUILD_ARGS) ## Fast build workflow e
fast-build-workflow-examples: workflow-examples

coverage: mvn-checks ## Build coverage
$(MAVEN) $(ARGS) -pl coverage
$(MAVEN) $(ARGS) verify -pl coverage

fast-build-coverage: ARGS = $(FAST_BUILD_ARGS) ## Fast build coverage
fast-build-coverage: coverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public void testOutputs() {
assertThat(new Move2KubeBase().getWorkFlowTaskOutputs().size()).isEqualTo(0);
}

@Test
public void testExecute() {
// given

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@

public class Move2KubePlanTest {

private static String workspace = "workspace";
private static final String WORKSPACE = "workspace";

private static String project = "project";
private static final String PROJECT = "project";

private Move2KubePlan task;

private ProjectInputsApi projectInputsApi;

private PlanApi planApi;

@Before
public void setup() {
projectInputsApi = mock(ProjectInputsApi.class);
planApi = mock(PlanApi.class);
PlanApi planApi = mock(PlanApi.class);

task = new Move2KubePlan("http://localhost:8080", planApi, projectInputsApi);
}
Expand All @@ -67,7 +65,7 @@ public void testExecute() {
assertThat(report.getStatus()).isEqualTo(WorkStatus.COMPLETED);

assertDoesNotThrow(() -> {
verify(projectInputsApi, times(1)).createProjectInput(eq(workspace), eq(project), eq("sources"), eq("Id"),
verify(projectInputsApi, times(1)).createProjectInput(eq(WORKSPACE), eq(PROJECT), eq("sources"), eq("Id"),
anyString(), any());
});
}
Expand All @@ -76,9 +74,7 @@ WorkContext getWorkContext() {
WorkContext context = new WorkContext();
context.put("move2KubeWorkspaceID", "workspace");
context.put("move2KubeProjectID", "project");
assertDoesNotThrow(() -> {
context.put("gitArchivePath", createSampleZip().getAbsolutePath().toString());
});
assertDoesNotThrow(() -> context.put("gitArchivePath", createSampleZip().getAbsolutePath()));
return context;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
@Slf4j
public class Move2KubeRetrieveTest {

private static String move2KubeWorkspaceIDCtxKey = "move2KubeWorkspaceID";
private static final String MOVE2KUBE_WORKSPACE_ID = "move2KubeWorkspaceID";

private static String move2KubeProjectIDCtxKey = "move2KubeProjectID";
private static final String MOVE2KUBE_PROJECT_ID = "move2KubeProjectID";

private static String move2KubeTransformIDCtxKey = "move2KubeTransformID";
private static final String MOVE2KUBE_TRANSFORM_ID = "move2KubeTransformID";

private static String gitDestinationCtxKey = "gitDestination";
private static final String GIT_DESTINATION_CONTEXT_KEY = "gitDestination";

private ProjectOutputsApi output;

Expand All @@ -59,7 +59,7 @@ public void testValidExecution() {
assertThat(report.getError()).isNull();
assertThat(report.getStatus()).isEqualTo(WorkStatus.COMPLETED);

String path = (String) context.get(gitDestinationCtxKey);
String path = (String) context.get(GIT_DESTINATION_CONTEXT_KEY);
assertThat(path).isNotNull();
File gitPath = new File(path);

Expand Down Expand Up @@ -108,12 +108,10 @@ public void testWithInvalidOutputFile() {

public WorkContext getSampleWorkContext() {
WorkContext workContext = new WorkContext();
workContext.put(move2KubeTransformIDCtxKey, move2KubeProjectIDCtxKey);
workContext.put(move2KubeProjectIDCtxKey, move2KubeProjectIDCtxKey);
workContext.put(move2KubeWorkspaceIDCtxKey, move2KubeWorkspaceIDCtxKey);
assertDoesNotThrow(() -> {
workContext.put(gitDestinationCtxKey, createTempDir());
});
workContext.put(MOVE2KUBE_TRANSFORM_ID, MOVE2KUBE_PROJECT_ID);
workContext.put(MOVE2KUBE_PROJECT_ID, MOVE2KUBE_PROJECT_ID);
workContext.put(MOVE2KUBE_WORKSPACE_ID, MOVE2KUBE_WORKSPACE_ID);
assertDoesNotThrow(() -> workContext.put(GIT_DESTINATION_CONTEXT_KEY, createTempDir()));
return workContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public class Move2KubeTaskTest {

private ProjectInputsApi projectInputsApi;

private static String move2KubeWorkspaceIDCtxKey = "move2KubeWorkspaceID";
private static final String MOVE2KUBE_WORKSPACE_ID = "move2KubeWorkspaceID";

private static String move2KubeProjectIDCtxKey = "move2KubeProjectID";
private static final String MOVE2KUBE_PROJECT_ID = "move2KubeProjectID";

@Before
public void BeforeEach() {
Expand All @@ -66,7 +66,7 @@ public void testValidExecution() {
WorkContext workContext = getSampleWorkContext();
Workspace workspace = getSampleWorkspace("test");

Map<String, ProjectInputsValue> inputs = new HashMap<String, ProjectInputsValue>();
Map<String, ProjectInputsValue> inputs = new HashMap<>();
inputs.put("test1", getSampleProjectInput("test1"));
inputs.put("test2", getSampleProjectInput("test2"));
workspace.setInputs(inputs);
Expand All @@ -82,8 +82,8 @@ public void testValidExecution() {
// then
assertThat(report.getError()).isNull();
assertThat(report.getStatus()).isEqualTo(WorkStatus.COMPLETED);
assertThat(report.getWorkContext().get(move2KubeWorkspaceIDCtxKey)).isNotNull();
assertThat(report.getWorkContext().get(move2KubeProjectIDCtxKey)).isNotNull();
assertThat(report.getWorkContext().get(MOVE2KUBE_WORKSPACE_ID)).isNotNull();
assertThat(report.getWorkContext().get(MOVE2KUBE_PROJECT_ID)).isNotNull();

assertDoesNotThrow(() -> {
verify(workspacesApi, times(1)).getWorkspaces();
Expand All @@ -107,8 +107,8 @@ public void testWithoutValidWorkspace() {
// then
assertThat(report.getError()).isNotNull();
assertThat(report.getStatus()).isEqualTo(WorkStatus.FAILED);
assertThat(report.getWorkContext().get(move2KubeWorkspaceIDCtxKey)).isNull();
assertThat(report.getWorkContext().get(move2KubeProjectIDCtxKey)).isNull();
assertThat(report.getWorkContext().get(MOVE2KUBE_WORKSPACE_ID)).isNull();
assertThat(report.getWorkContext().get(MOVE2KUBE_PROJECT_ID)).isNull();

assertDoesNotThrow(() -> {
verify(workspacesApi, times(1)).getWorkspaces();
Expand All @@ -131,8 +131,8 @@ public void testWithIssuesCreatingProject() {
// then
assertThat(report.getError()).isNotNull();
assertThat(report.getStatus()).isEqualTo(WorkStatus.FAILED);
assertThat(report.getWorkContext().get(move2KubeWorkspaceIDCtxKey)).isNotNull();
assertThat(report.getWorkContext().get(move2KubeProjectIDCtxKey)).isNull();
assertThat(report.getWorkContext().get(MOVE2KUBE_WORKSPACE_ID)).isNotNull();
assertThat(report.getWorkContext().get(MOVE2KUBE_PROJECT_ID)).isNull();

assertDoesNotThrow(() -> {
verify(workspacesApi, times(1)).getWorkspaces();
Expand All @@ -149,7 +149,7 @@ public Workspace getSampleWorkspace(String workspace) {

public CreateProject201Response getSampleProject(String name) {
CreateProject201Response project = new CreateProject201Response();
project.setId(UUID.randomUUID().toString());
project.setId(name);
return project;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class Move2KubeTransformTest {

Move2KubeTransform task;

private static String move2KubeWorkspaceIDCtxKey = "move2KubeWorkspaceID";
private static final String MOVE2KUBE_WORKSPACE_ID_CONTEXT_KEY = "move2KubeWorkspaceID";

private static String move2KubeProjectIDCtxKey = "move2KubeProjectID";
private static final String MOVE2KUBE_PROJECT_ID_CONTEXT_KEY = "move2KubeProjectID";

private PlanApi planApi;

Expand All @@ -57,7 +57,6 @@ public void testValidExecution() {

// given
WorkContext context = getSampleWorkContext();
GetPlan200Response response = new GetPlan200Response();
StartTransformation202Response transformResponse = new StartTransformation202Response();
transformResponse.setId("foo");

Expand All @@ -67,8 +66,8 @@ public void testValidExecution() {
});

try (MockedStatic<RestUtils> mockedStatic = mockStatic(RestUtils.class)) {
ResponseEntity<String> responseo = ResponseEntity.ok("ok");
responseo.getStatusCode();
ResponseEntity<String> response = ResponseEntity.ok("ok");
response.getStatusCode();

mockedStatic.when((MockedStatic.Verification) RestUtils.executePost(any(), (HttpEntity<?>) any()))
.thenReturn(ResponseEntity.ok("ok"));
Expand All @@ -82,16 +81,16 @@ public void testValidExecution() {
}

assertDoesNotThrow(() -> {
verify(projectOutputsApi, times(1)).startTransformation(eq(move2KubeWorkspaceIDCtxKey),
eq(move2KubeProjectIDCtxKey), any());
verify(projectOutputsApi, times(1)).startTransformation(eq(MOVE2KUBE_WORKSPACE_ID_CONTEXT_KEY),
eq(MOVE2KUBE_PROJECT_ID_CONTEXT_KEY), any());
});

}

public WorkContext getSampleWorkContext() {
WorkContext workContext = new WorkContext();
workContext.put(move2KubeProjectIDCtxKey, move2KubeProjectIDCtxKey);
workContext.put(move2KubeWorkspaceIDCtxKey, move2KubeWorkspaceIDCtxKey);
workContext.put(MOVE2KUBE_PROJECT_ID_CONTEXT_KEY, MOVE2KUBE_PROJECT_ID_CONTEXT_KEY);
workContext.put(MOVE2KUBE_WORKSPACE_ID_CONTEXT_KEY, MOVE2KUBE_WORKSPACE_ID_CONTEXT_KEY);
WorkContextUtils.setUserId(workContext, UUID.randomUUID());
return workContext;
}
Expand Down

0 comments on commit 74892d2

Please sign in to comment.