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

Commit

Permalink
fix getIdentity result & getPath test
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardW98 authored and openshift-merge-robot committed Jun 22, 2023
1 parent c1ba174 commit 412c094
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ public WorkReport execute(WorkContext workContext) {

Identity identity = null;
if (identityName != null) {
identity = mtaClient.getIdentity(identityName);
Result<Identity> identityResult = mtaClient.getIdentity(identityName);
if (identityResult instanceof Result.Failure<Identity> failure) {
taskLogger.logErrorWithSlf4j("MTA client returned failed result to get identity: {}", identityName);
return new DefaultWorkReport(WorkStatus.FAILED, workContext, failure.t());
}
else {
identity = ((Result.Success<Identity>) identityResult).value();
}
}

Result<App> result = mtaClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface MTAApplicationClient {

Result<App> create(App app);

Identity getIdentity(String name);
Result<Identity> getIdentity(String name);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Result<App> get(String name) {
}

@Override
public Identity getIdentity(String name) {
public Result<Identity> getIdentity(String name) {
// identities in MTA have unique constraints on name.
try {
HttpResponse<String> getAll = client.send(
Expand All @@ -98,14 +98,14 @@ public Identity getIdentity(String name) {

Optional<Identity> identity = identities.stream().filter(v -> v.name().equals(name)).findFirst();
if (identity.isPresent()) {
return identity.get();
return new Result.Success<>(identity.get());
}
else {
throw new NotFoundException("failed to find identity by name " + name);
return new Result.Failure<>(new NotFoundException("failed to find identity by name " + name));
}
}
catch (IOException | InterruptedException e) {
return null;
return new Result.Failure<>(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ WorkFlowOption defaultOption() {
@Bean(name = "AnalyzeApplicationAssessment")
@Assessment(parameters = {
@Parameter(key = "repositoryURL", description = "The repository with the code to analyze",
type = WorkParameterType.TEXT, optional = false),
type = WorkParameterType.URL, optional = false),
@Parameter(key = "applicationName", description = "The name of the application to analyze",
type = WorkParameterType.TEXT, optional = false),
@Parameter(key = "branch", description = "The repository branch to analyze", type = WorkParameterType.TEXT,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.redhat.parodos.examples.move2kube.task.utils;

import java.net.URISyntaxException;

import com.redhat.parodos.examples.move2kube.utils.Move2KubeUtils;
import org.junit.jupiter.api.Test;

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

class Move2KubeUtilsTest {

private static final String WORKSPACE_ID = "workspace-id";

private static final String PROJECT_ID = "project-id";

private static final String OUTPUT_ID = "output-id";

@Test
void testGetPath() throws URISyntaxException {
String expectedResponse = "http://test.com/workspaces/workspace-id/projects/project-id/outputs/output-id";
assertEquals(expectedResponse, Move2KubeUtils.getPath("http://test.com", WORKSPACE_ID, PROJECT_ID, OUTPUT_ID));
}

}

0 comments on commit 412c094

Please sign in to comment.