Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update workspace external api #25

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.tkit.onecx.product.store.bff.rs.controllers;

import java.util.HashSet;
import java.util.Set;

import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -25,6 +24,8 @@
import gen.org.tkit.onecx.product.store.client.model.Product;
import gen.org.tkit.onecx.product.store.client.model.ProductPageResult;
import gen.org.tkit.onecx.workspace.client.api.WorkspaceExternalApi;
import gen.org.tkit.onecx.workspace.client.model.WorkspacePageResult;
import gen.org.tkit.onecx.workspace.client.model.WorkspaceSearchCriteria;

@LogService
@ApplicationScoped
Expand Down Expand Up @@ -90,8 +91,11 @@ public Response getProductByName(String name) {
try (Response response = client.getProductByName(name)) {
Product resultProduct = response.readEntity(Product.class);
Set<String> workspaceNames = null;
try (Response workspaceResponse = workspaceClient.getWorkspacesByProductName(name)) {
workspaceNames = workspaceResponse.readEntity(HashSet.class);

try (Response workspaceResponse = workspaceClient
.searchWorkspaces(new WorkspaceSearchCriteria().productName(name))) {
var result = workspaceResponse.readEntity(WorkspacePageResult.class);
workspaceNames = mapper.workspaceNames(result);
} catch (WebApplicationException ex) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@

import gen.org.tkit.onecx.product.store.bff.rs.internal.model.*;
import gen.org.tkit.onecx.product.store.client.model.*;
import gen.org.tkit.onecx.workspace.client.model.WorkspaceAbstract;
import gen.org.tkit.onecx.workspace.client.model.WorkspacePageResult;

@Mapper(uses = { OffsetDateTimeMapper.class })
public interface ProductsMapper {

default Set<String> workspaceNames(WorkspacePageResult result) {
if (result == null || result.getStream() == null) {
return Set.of();
}
return result.getStream().stream().map(WorkspaceAbstract::getName).collect(Collectors.toSet());
}

CreateProductRequest mapCreateProduct(CreateProductRequestDTO createProduct);

UpdateProductRequest mapUpdateProduct(UpdateProductRequestDTO updateProduct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockserver.client.MockServerClient;
import org.mockserver.matchers.Times;
import org.mockserver.model.JsonBody;
import org.mockserver.model.MediaType;
import org.tkit.onecx.product.store.bff.rs.controllers.ProductsRestController;
import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper;

import gen.org.tkit.onecx.product.store.bff.rs.internal.model.*;
import gen.org.tkit.onecx.product.store.client.model.*;
import gen.org.tkit.onecx.workspace.client.model.WorkspaceAbstract;
import gen.org.tkit.onecx.workspace.client.model.WorkspacePageResult;
import io.quarkiverse.mockserver.test.InjectMockServerClient;
import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
Expand Down Expand Up @@ -108,7 +111,7 @@ void getProductByName_test() {

Product data = createProduct("7a0ee705-8fd0-47b0-8205-b2a5f6540b9e", "0", offsetDateTime, null, offsetDateTime,
null, "test-appl2", "Here is some description 2", false,
"https://prod.ucwe.capgemini.com/wp-content/uploads/2023/11/world-cloud-report-banner1_2023.jpg",
"https://my-page.site.url",
"/app3", 0, "Product ABC", "Sun", "Themes, Menu");
// create mock rest endpoint
mockServerClient
Expand All @@ -118,15 +121,17 @@ void getProductByName_test() {
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(data)));

Set<String> workspaceNames = new HashSet<>();
workspaceNames.add("testWorkspace");
var result = new WorkspacePageResult().stream(
List.of(
new WorkspaceAbstract().name("testWorkspace").description("testWorkspace")));

// create mock rest endpoint
mockServerClient
.when(request().withPath("/v1/workspaces/productName/test-appl2")
.withMethod(HttpMethod.GET))
.when(request().withPath("/v1/workspaces/search")
.withMethod(HttpMethod.POST), Times.exactly(1))
.respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode())
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(workspaceNames)));
.withBody(JsonBody.json(result)));

var response = given()
.when()
Expand Down Expand Up @@ -180,8 +185,8 @@ void getProductByName_test() {

// create mock rest endpoint
mockServerClient
.when(request().withPath("/v1/workspaces/productName/test-appl50")
.withMethod(HttpMethod.GET))
.when(request().withPath("/v1/workspaces/search")
.withMethod(HttpMethod.POST), Times.exactly(1))
.respond(httpRequest -> response().withStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));

// create mock rest endpoint
Expand Down
Loading