From f80f94f15b6443745ce4e79960366011d62b24ee Mon Sep 17 00:00:00 2001 From: JordenReuter <149687553+JordenReuter@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:55:22 +0200 Subject: [PATCH] feat: appId to productName and ps impl (#46) --- .../pages/onecx-announcement-bff-docs.adoc | 18 +++- .../onecx-announcement-bff-extensions.adoc | 54 +++++------ pom.xml | 15 +++ src/main/helm/values.yaml | 4 +- .../AnnouncementRestController.java | 23 ++++- .../bff/rs/mappers/AnnouncementMapper.java | 10 +- src/main/openapi/openapi-bff.yaml | 92 +++++++++++++++++-- src/main/resources/application.properties | 11 +++ .../rs/AnnouncementRestControllerTest.java | 87 +++++++++++++----- .../resources/mockserver/permissions.json | 2 + 10 files changed, 250 insertions(+), 66 deletions(-) diff --git a/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-docs.adoc b/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-docs.adoc index be707da..8857fb7 100644 --- a/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-docs.adoc +++ b/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-docs.adoc @@ -22,13 +22,22 @@ quarkus.openapi-generator.codegen.spec.onecx_announcement_svc_yaml.base-package= quarkus.openapi-generator.codegen.spec.onecx_announcement_svc_yaml.return-response=true quarkus.openapi-generator.codegen.spec.onecx_announcement_svc.additional-api-type-annotations=@org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; quarkus.openapi-generator.codegen.spec.onecx_announcement_svc.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection; +quarkus.openapi-generator.codegen.spec.onecx_announcement_svc_yaml.enable-security-generation=false quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.config-key=onecx_workspace_svc_v1 quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.base-package=gen.org.tkit.onecx.workspace.client quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.return-response=true quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.additional-api-type-annotations=@org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection; -%prod.quarkus.rest-client.onecx_announcement_svc_yaml.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter -%prod.quarkus.rest-client.onecx_workspace_svc_v1_yaml.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter +quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.enable-security-generation=false +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.config-key=onecx_product_store +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.base-package=gen.org.tkit.onecx.product.store +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.return-response=true +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.additional-api-type-annotations=@org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection; +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.enable-security-generation=false +%prod.quarkus.rest-client.onecx_announcement_svc.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter +%prod.quarkus.rest-client.onecx_workspace_svc_v1.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter +%prod.quarkus.rest-client.onecx_product_store.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter %prod.quarkus.oidc-client.client-id=${quarkus.application.name} ---- ==== @@ -65,8 +74,13 @@ app: read: permission on all GET requests and POST search write: permission on PUT, POST, PATCH requests, where objects are saved or updated delete: permission on all DELETE requests + product: + read: permission on all GET requests and POST search keycloak: client: enabled: true + spec: + kcConfig: + defaultClientScopes: [ ocx-an:all, ocx-ws:read, ocx-pm:read, ocx-ps:read ] ---- diff --git a/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-extensions.adoc b/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-extensions.adoc index e9334b3..33b158c 100644 --- a/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-extensions.adoc +++ b/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-extensions.adoc @@ -12,25 +12,25 @@ h| Version | https://quarkus.io/guides/rest[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-rest.adoc[Link] -| 3.11.1 +| 3.12.0 | quarkus-smallrye-openapi | https://quarkus.io/guides/openapi-swaggerui[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-openapi.adoc[Link] -| 3.11.1 +| 3.12.0 | quarkus-rest-jackson | https://quarkus.io/guides/rest-json[Link] | -| 3.11.1 +| 3.12.0 | quarkus-smallrye-health | https://quarkus.io/guides/smallrye-health[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-health.adoc[Link] -| 3.11.1 +| 3.12.0 | quarkus-openapi-generator @@ -42,97 +42,97 @@ h| Version | https://quarkus.io/guides/rest-client[Link] | -| 3.11.1 +| 3.12.0 | tkit-quarkus-log-cdi | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-cdi.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.25.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link] -| 2.25.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link] +| 2.27.0 | tkit-quarkus-log-rs | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-rs.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.25.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link] -| 2.25.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link] +| 2.27.0 | tkit-quarkus-log-json | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-json.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.25.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link] -| 2.25.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link] +| 2.27.0 | tkit-quarkus-rest | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.25.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link] -| 2.25.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link] +| 2.27.0 | tkit-quarkus-rest-context | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest-context.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.25.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link] -| 2.25.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link] +| 2.27.0 | quarkus-hibernate-validator | https://quarkus.io/guides/validation[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-hibernate-validator.adoc[Link] -| 3.11.1 +| 3.12.0 | quarkus-opentelemetry | https://quarkus.io/guides/opentelemetry[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-opentelemetry.adoc[Link] -| 3.11.1 +| 3.12.0 | quarkus-micrometer-registry-prometheus | https://quarkus.io/guides/telemetry-micrometer[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-micrometer-registry-prometheus.adoc[Link] -| 3.11.1 +| 3.12.0 | onecx-permissions | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-permissions.html[Link] -| https://github.com/onecx/onecx-quarkus/blob/0.20.0/docs/modules/onecx-quarkus/pages/includes/onecx-permissions.adoc[Link] -| 0.20.0 +| https://github.com/onecx/onecx-quarkus/blob/0.22.0/docs/modules/onecx-quarkus/pages/includes/onecx-permissions.adoc[Link] +| 0.22.0 | quarkus-oidc | https://quarkus.io/guides/security-oidc-bearer-token-authentication-tutorial[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-oidc.adoc[Link] -| 3.11.1 +| 3.12.0 | quarkus-oidc-client-reactive-filter | https://quarkus.io/guides/security-openid-connect-client-reference[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-oidc-client-reactive-filter.adoc[Link] -| 3.11.1 +| 3.12.0 | tkit-quarkus-security | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-security.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.25.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link] -| 2.25.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link] +| 2.27.0 | onecx-core | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link] | -| 0.20.0 +| 0.22.0 | quarkus-arc | https://quarkus.io/guides/cdi-reference[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-arc.adoc[Link] -| 3.11.1 +| 3.12.0 | quarkus-container-image-docker | https://quarkus.io/guides/container-image[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-container-image-docker.adoc[Link] -| 3.11.1 +| 3.12.0 diff --git a/pom.xml b/pom.xml index 32d0200..acea71a 100644 --- a/pom.xml +++ b/pom.xml @@ -202,6 +202,21 @@ true + + product-store-v1 + generate-resources + + wget + + + + https://raw.githubusercontent.com/onecx/onecx-product-store-svc/main/src/main/openapi/onecx-product-store-v1.yaml + + target/tmp/openapi + onecx-product-store-v1.yaml + true + + diff --git a/src/main/helm/values.yaml b/src/main/helm/values.yaml index 1c0101b..0e5a3bb 100644 --- a/src/main/helm/values.yaml +++ b/src/main/helm/values.yaml @@ -12,9 +12,11 @@ app: read: permission on all GET requests and POST search write: permission on PUT, POST, PATCH requests, where objects are saved or updated delete: permission on all DELETE requests + product: + read: permission on all GET requests and POST search keycloak: client: enabled: true spec: kcConfig: - defaultClientScopes: [ ocx-an:all, ocx-ws:read, ocx-pm:read ] \ No newline at end of file + defaultClientScopes: [ ocx-an:all, ocx-ws:read, ocx-pm:read, ocx-ps:read ] \ No newline at end of file diff --git a/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java b/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java index 8b32d99..edfd0a5 100644 --- a/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java +++ b/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java @@ -20,6 +20,8 @@ import gen.org.tkit.onecx.announcement.bff.rs.internal.model.*; import gen.org.tkit.onecx.announcement.client.api.AnnouncementInternalApi; import gen.org.tkit.onecx.announcement.client.model.*; +import gen.org.tkit.onecx.product.store.api.ProductsApi; +import gen.org.tkit.onecx.product.store.model.ProductItemPageResult; 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; @@ -37,6 +39,10 @@ public class AnnouncementRestController implements AnnouncementInternalApiServic @RestClient WorkspaceExternalApi workspaceClient; + @Inject + @RestClient + ProductsApi productStoreClient; + @Inject AnnouncementMapper announcementMapper; @@ -63,11 +69,11 @@ public Response deleteAnnouncementById(String id) { } @Override - public Response getAllAppsWithAnnouncements() { + public Response getAllProductsWithAnnouncements() { - try (Response response = client.getAllAppsWithAnnouncements()) { - AnnouncementApps announcementApps = response.readEntity(AnnouncementApps.class); - return Response.status(response.getStatus()).entity(announcementApps).build(); + try (Response response = client.getAllProductsWithAnnouncements()) { + AnnouncementProducts announcementProducts = response.readEntity(AnnouncementProducts.class); + return Response.status(response.getStatus()).entity(announcementProducts).build(); } } @@ -131,6 +137,15 @@ public Response updateAnnouncementById(String id, UpdateAnnouncementRequestDTO u } } + @Override + public Response searchProductsByCriteria(ProductsSearchCriteriaDTO productsSearchCriteriaDTO) { + try (Response response = productStoreClient + .searchProductsByCriteria(announcementMapper.map(productsSearchCriteriaDTO))) { + ProductsPageResultDTO products = announcementMapper.map(response.readEntity(ProductItemPageResult.class)); + return Response.status(response.getStatus()).entity(products).build(); + } + } + @ServerExceptionMapper public RestResponse constraint(ConstraintViolationException ex) { return exceptionMapper.constraint(ex); diff --git a/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java b/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java index f9a9043..c0ecd24 100644 --- a/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java +++ b/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java @@ -9,6 +9,8 @@ import gen.org.tkit.onecx.announcement.bff.rs.internal.model.*; import gen.org.tkit.onecx.announcement.client.model.*; +import gen.org.tkit.onecx.product.store.model.ProductItemPageResult; +import gen.org.tkit.onecx.product.store.model.ProductItemSearchCriteria; import gen.org.tkit.onecx.workspace.client.model.WorkspaceAbstract; import gen.org.tkit.onecx.workspace.client.model.WorkspacePageResult; @@ -43,7 +45,7 @@ AnnouncementPageResultDTO mapAnnouncementPageResultToAnnouncementPageResultDTO( @Mapping(target = "endDateTo", ignore = true) @Mapping(target = "endDateFrom", source = "currentDate") @Mapping(target = "content", ignore = true) - @Mapping(target = "appId", ignore = true) + @Mapping(target = "productName", ignore = true) @Mapping(target = "workspaceName", ignore = true) AnnouncementSearchCriteria mapActiveAnnouncementSearchCriteria( ActiveAnnouncementsSearchCriteriaDTO activeAnnouncementsSearchCriteriaDTO); @@ -103,4 +105,10 @@ default ActiveAnnouncementsPageResultDTO filterAndSort(ActiveAnnouncementsPageRe } return pageResult; } + + @Mapping(target = "productNames", ignore = true) + ProductItemSearchCriteria map(ProductsSearchCriteriaDTO productsSearchCriteriaDTO); + + @Mapping(target = "removeStreamItem", ignore = true) + ProductsPageResultDTO map(ProductItemPageResult productItemPageResult); } diff --git a/src/main/openapi/openapi-bff.yaml b/src/main/openapi/openapi-bff.yaml index e7409e8..f079376 100644 --- a/src/main/openapi/openapi-bff.yaml +++ b/src/main/openapi/openapi-bff.yaml @@ -101,7 +101,7 @@ paths: application/json: schema: $ref: '#/components/schemas/ProblemDetailResponse' - /announcements/appIds: + /announcements/products: get: x-onecx: permissions: @@ -109,15 +109,15 @@ paths: - read tags: - AnnouncementInternal - summary: Get all application IDs to which announcements are assigned - operationId: getAllAppsWithAnnouncements + summary: Get all product names to which announcements are assigned + operationId: getAllProductsWithAnnouncements responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/AnnouncementApps' + $ref: '#/components/schemas/AnnouncementProducts' /announcements/{id}: get: x-onecx: @@ -212,12 +212,84 @@ paths: type: array items: type: string + /announcements/products/available: + post: + x-onecx: + permissions: + product: + - read + tags: + - AnnouncementInternal + summary: Get all available products + operationId: searchProductsByCriteria + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ProductsSearchCriteria' + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ProductsPageResult' + "400": + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemDetailResponse' components: schemas: - AnnouncementApps: + ProductsPageResult: + type: object + properties: + totalElements: + format: int64 + description: The total elements in the resource. + type: integer + number: + format: int32 + type: integer + size: + format: int32 + type: integer + totalPages: + format: int64 + type: integer + stream: + type: array + items: + $ref: '#/components/schemas/Product' + ProductsSearchCriteria: + type: object + properties: + pageNumber: + format: int32 + description: The number of page. + default: 0 + type: integer + pageSize: + format: int32 + description: The size of page + default: 100 + maximum: 1000 + type: integer + Product: + type: object + required: + - name + - displayName + properties: + name: + type: string + displayName: + type: string + AnnouncementProducts: type: object properties: - appIds: + productNames: type: array items: type: string @@ -245,7 +317,7 @@ components: $ref: '#/components/schemas/OffsetDateTime' endDate: $ref: '#/components/schemas/OffsetDateTime' - appId: + productName: type: string workspaceName: type: string @@ -270,7 +342,7 @@ components: $ref: '#/components/schemas/OffsetDateTime' endDateTo: $ref: '#/components/schemas/OffsetDateTime' - appId: + productName: type: string workspaceName: type: string @@ -309,7 +381,7 @@ components: $ref: '#/components/schemas/OffsetDateTime' endDate: $ref: '#/components/schemas/OffsetDateTime' - appId: + productName: type: string workspaceName: type: string @@ -343,7 +415,7 @@ components: $ref: '#/components/schemas/OffsetDateTime' endDate: $ref: '#/components/schemas/OffsetDateTime' - appId: + productName: type: string workspaceName: type: string diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 401393a..bb13e6c 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -31,9 +31,19 @@ quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.additional-ap quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection; quarkus.openapi-generator.codegen.spec.onecx_workspace_svc_v1_yaml.enable-security-generation=false +# PRODUCT STORE V1 +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.config-key=onecx_product_store +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.base-package=gen.org.tkit.onecx.product.store +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.return-response=true +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.additional-api-type-annotations=@org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.additional-model-type-annotations=@io.quarkus.runtime.annotations.RegisterForReflection; +quarkus.openapi-generator.codegen.spec.onecx_product_store_v1_yaml.enable-security-generation=false + + # OIDC %prod.quarkus.rest-client.onecx_announcement_svc.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter %prod.quarkus.rest-client.onecx_workspace_svc_v1.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter +%prod.quarkus.rest-client.onecx_product_store.providers=io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter %prod.quarkus.oidc-client.client-id=${quarkus.application.name} @@ -54,6 +64,7 @@ quarkus.test.integration-test-profile=test %test.quarkus.mockserver.devservices.config-dir=/mockserver %test.quarkus.rest-client.onecx_announcement_svc.url=${quarkus.mockserver.endpoint} %test.quarkus.rest-client.onecx_workspace_svc_v1.url=${quarkus.mockserver.endpoint} +%test.quarkus.rest-client.onecx_product_store.url=${quarkus.mockserver.endpoint} %test.tkit.rs.context.token.header-param=apm-principal-token %test.tkit.rs.context.token.enabled=false diff --git a/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java b/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java index daf249d..5bead2b 100644 --- a/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java @@ -23,6 +23,9 @@ import gen.org.tkit.onecx.announcement.bff.rs.internal.model.*; import gen.org.tkit.onecx.announcement.client.model.*; +import gen.org.tkit.onecx.product.store.model.ProductItem; +import gen.org.tkit.onecx.product.store.model.ProductItemPageResult; +import gen.org.tkit.onecx.product.store.model.ProductItemSearchCriteria; import gen.org.tkit.onecx.workspace.client.model.WorkspaceAbstract; import gen.org.tkit.onecx.workspace.client.model.WorkspacePageResult; import io.quarkiverse.mockserver.test.InjectMockServerClient; @@ -55,7 +58,7 @@ void createAnnouncement_shouldReturnAnnouncement() { // Request data to svc Announcement data = new Announcement(); - data.setAppId("appId"); + data.setProductName("productName"); data.setContent("AnnouncmentContent"); data.setTitle("announcementTitle"); data.startDate(offsetDateTime); @@ -71,7 +74,7 @@ void createAnnouncement_shouldReturnAnnouncement() { // bff call input CreateAnnouncementRequestDTO input = new CreateAnnouncementRequestDTO(); - input.setAppId("appId1"); + input.setProductName("productName1"); input.setTitle("announcementTitle"); input.startDate(offsetDateTime); @@ -101,7 +104,7 @@ void createAnnouncement_shouldReturnAnnouncement() { // Assertions Assertions.assertNotNull(response); - Assertions.assertEquals(data.getAppId(), response.getAppId()); + Assertions.assertEquals(data.getProductName(), response.getProductName()); Assertions.assertEquals(data.getContent(), response.getContent()); } @@ -109,7 +112,7 @@ void createAnnouncement_shouldReturnAnnouncement() { void getAnnouncements_shouldReturnAnnouncementPageResults() { Announcement announcement = new Announcement(); - announcement.setAppId("appId"); + announcement.setProductName("productName"); announcement.setContent("AnnouncmentContent"); List announcements = new ArrayList<>(); announcements.add(announcement); @@ -158,7 +161,7 @@ void getAnnouncements_shouldReturnAnnouncementPageResults() { void getAnnouncementById_shouldReturnAnnouncement() { // Request data to svc Announcement data = new Announcement(); - data.setAppId("appIdTest1"); + data.setProductName("productNameTest1"); // svc call prepare mock endpoint mockServerClient @@ -186,22 +189,22 @@ void getAnnouncementById_shouldReturnAnnouncement() { // Assertions Assertions.assertNotNull(response); - Assertions.assertEquals("appIdTest1", response.getAppId()); + Assertions.assertEquals("productNameTest1", response.getProductName()); } @Test void getAllAppsWithAnnouncements_shouldReturnAnnouncementApps() { // Request data to svc - AnnouncementApps data = new AnnouncementApps(); - List appIds = new ArrayList<>(); - appIds.add("1"); - appIds.add("2"); - data.setAppIds(appIds); + AnnouncementProducts data = new AnnouncementProducts(); + List productNames = new ArrayList<>(); + productNames.add("1"); + productNames.add("2"); + data.setProductNames(productNames); // svc call prepare mock endpoint mockServerClient .when(request() - .withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/appIds") + .withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/products") .withMethod(HttpMethod.GET)) .withId(mockId) .respond( @@ -218,16 +221,16 @@ void getAllAppsWithAnnouncements_shouldReturnAnnouncementApps() { .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) .header(APM_HEADER_PARAM, ADMIN) .contentType(APPLICATION_JSON) - .get("/appIds") + .get("/products") .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) - .extract().as(AnnouncementApps.class); + .extract().as(AnnouncementProducts.class); // Assertions Assertions.assertNotNull(response); - Assertions.assertEquals(2, response.getAppIds().size()); - Assertions.assertEquals(response.getAppIds(), data.getAppIds()); + Assertions.assertEquals(2, response.getProductNames().size()); + Assertions.assertEquals(response.getProductNames(), data.getProductNames()); } @@ -295,7 +298,7 @@ void updateAnnouncementById() { String updateId = "updateId_NO_CONTENT"; Announcement data = new Announcement(); - data.setAppId("appIdTest1"); + data.setProductName("productNameTest1"); mockServerClient .when(request() @@ -424,7 +427,7 @@ void getAllWorkspaceNames() { void searchActiveAnnouncements_shouldReturnAnnouncementPageResults() { Announcement a1 = new Announcement(); - a1.setAppId("appId"); + a1.setProductName("productName"); a1.setContent("AnnouncmentContent"); a1.setPriority(AnnouncementPriorityType.IMPORTANT); a1.setTitle("A1"); @@ -432,7 +435,7 @@ void searchActiveAnnouncements_shouldReturnAnnouncementPageResults() { a1.setStartDate(OffsetDateTime.parse("2024-04-11T10:09:24-04:00")); a1.setEndDate(OffsetDateTime.parse("2024-04-25T10:09:24-04:00")); Announcement a2 = new Announcement(); - a2.setAppId("appId"); + a2.setProductName("productName"); a2.setContent("AnnouncmentContent"); a2.setPriority(AnnouncementPriorityType.NORMAL); a2.setTitle("A2"); @@ -440,7 +443,7 @@ void searchActiveAnnouncements_shouldReturnAnnouncementPageResults() { a2.setStartDate(OffsetDateTime.parse("2024-04-11T10:09:24-04:00")); a2.setEndDate(OffsetDateTime.parse("2024-04-25T10:09:24-04:00")); Announcement a3 = new Announcement(); - a3.setAppId("appId"); + a3.setProductName("productName"); a3.setContent("AnnouncmentContent"); a3.setPriority(AnnouncementPriorityType.IMPORTANT); a3.setTitle("A3"); @@ -448,7 +451,7 @@ void searchActiveAnnouncements_shouldReturnAnnouncementPageResults() { a3.setStartDate(OffsetDateTime.parse("2024-04-11T10:09:24-04:00")); a3.setEndDate(OffsetDateTime.parse("2024-04-25T10:09:24-04:00")); Announcement a4 = new Announcement(); - a4.setAppId("appId"); + a4.setProductName("productName"); a4.setContent("Shouldn't be returned"); a4.setPriority(AnnouncementPriorityType.IMPORTANT); a4.setTitle("A4"); @@ -507,4 +510,46 @@ void searchActiveAnnouncements_shouldReturnAnnouncementPageResults() { Assertions.assertEquals("w1", response.getStream().get(1).getWorkspaceName()); } + + @Test + void getAllProductsTest() { + + ProductItemSearchCriteria criteria = new ProductItemSearchCriteria(); + criteria.pageNumber(0).pageSize(1); + ProductItemPageResult result = new ProductItemPageResult(); + result.totalElements(2L).stream(List.of(new ProductItem().name("P1").displayName("Product1"), + new ProductItem().name("P2").displayName("Product2"))); + + mockServerClient + .when(request().withPath("/v1/products/search") + .withMethod(HttpMethod.POST) + .withBody(JsonBody.json(criteria))) + .withPriority(100) + .withId(mockId) + .respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode()) + .withContentType(MediaType.APPLICATION_JSON) + .withBody(JsonBody.json(result))); + + ProductsSearchCriteriaDTO criteriaDTO = new ProductsSearchCriteriaDTO(); + criteriaDTO.pageNumber(0).pageSize(1); + // bff call + var response = given() + .when() + .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) + .header(APM_HEADER_PARAM, ADMIN) + .contentType(APPLICATION_JSON) + .body(criteriaDTO) + .post("/products/available") + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .contentType(APPLICATION_JSON) + .extract().as(ProductsPageResultDTO.class); + + Assertions.assertEquals(2, response.getStream().size()); + Assertions.assertEquals("P1", response.getStream().get(0).getName()); + Assertions.assertEquals("Product1", response.getStream().get(0).getDisplayName()); + Assertions.assertEquals("P2", response.getStream().get(1).getName()); + Assertions.assertEquals("Product2", response.getStream().get(1).getDisplayName()); + mockServerClient.clear(mockId); + } } diff --git a/src/test/resources/mockserver/permissions.json b/src/test/resources/mockserver/permissions.json index 16628a7..7afa20c 100644 --- a/src/test/resources/mockserver/permissions.json +++ b/src/test/resources/mockserver/permissions.json @@ -20,6 +20,7 @@ "write", "delete" ], + "product": ["read"], "permissions": [ "admin-write", "admin-read" @@ -49,6 +50,7 @@ "announcement": [ "read" ], + "product": ["read"], "permissions": [ "admin-write", "admin-read"