diff --git a/docs/modules/onecx-help-svc/pages/index.adoc b/docs/modules/onecx-help-svc/pages/index.adoc index b5754f4..b54a828 100644 --- a/docs/modules/onecx-help-svc/pages/index.adoc +++ b/docs/modules/onecx-help-svc/pages/index.adoc @@ -4,5 +4,7 @@ include::onecx-help-svc-attributes.adoc[opts=optional] include::docs.adoc[opts=optional] +=== Configuration +include::onecx-help-svc.adoc[opts=optional] include::onecx-help-svc-docs.adoc[opts=optional] diff --git a/docs/modules/onecx-help-svc/pages/onecx-help-svc-extensions.adoc b/docs/modules/onecx-help-svc/pages/onecx-help-svc-extensions.adoc index 5d8ac5b..932813f 100644 --- a/docs/modules/onecx-help-svc/pages/onecx-help-svc-extensions.adoc +++ b/docs/modules/onecx-help-svc/pages/onecx-help-svc-extensions.adoc @@ -12,13 +12,13 @@ h| Version | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link] | -| 0.22.0 +| 0.24.0 | onecx-tenant | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-tenant.html[Link] -| https://github.com/onecx/onecx-quarkus/blob/0.22.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link] -| 0.22.0 +| https://github.com/onecx/onecx-quarkus/blob/0.24.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link] +| 0.24.0 | quarkus-oidc @@ -29,50 +29,50 @@ h| Version | 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.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link] +| 2.28.0 | tkit-quarkus-jpa-tenant | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-jpa-tenant.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa-tenant.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa-tenant.adoc[Link] +| 2.28.0 | tkit-quarkus-data-import | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-data-import.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link] +| 2.28.0 | tkit-quarkus-jpa | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-jpa.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link] +| 2.28.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.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link] +| 2.28.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.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link] +| 2.28.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.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link] +| 2.28.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.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link] +| 2.28.0 | quarkus-arc @@ -143,8 +143,8 @@ h| Version | 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.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link] +| 2.28.0 | quarkus-container-image-docker @@ -157,7 +157,7 @@ h| Version | | -| 0.22.0 +| 0.24.0 | quarkus-smallrye-context-propagation diff --git a/docs/modules/onecx-help-svc/pages/onecx-help-svc.adoc b/docs/modules/onecx-help-svc/pages/onecx-help-svc.adoc new file mode 100644 index 0000000..01401f4 --- /dev/null +++ b/docs/modules/onecx-help-svc/pages/onecx-help-svc.adoc @@ -0,0 +1,63 @@ + +:summaryTableId: onecx-help-svc +[.configuration-legend] +icon:lock[title=Fixed at build time] Configuration property fixed at build time - All other configuration properties are overridable at runtime +[.configuration-reference.searchable, cols="80,.^10,.^10"] +|=== + +h|[[onecx-help-svc_configuration]]link:#onecx-help-svc_configuration[Configuration property] + +h|Type +h|Default + +a| [[onecx-help-svc_onecx-help-default-enabled]]`link:#onecx-help-svc_onecx-help-default-enabled[onecx.help.default.enabled]` + + +[.description] +-- +Enable or disable default help + +ifdef::add-copy-button-to-env-var[] +Environment variable: env_var_with_copy_button:+++ONECX_HELP_DEFAULT_ENABLED+++[] +endif::add-copy-button-to-env-var[] +ifndef::add-copy-button-to-env-var[] +Environment variable: `+++ONECX_HELP_DEFAULT_ENABLED+++` +endif::add-copy-button-to-env-var[] +--|boolean +|`false` + + +a| [[onecx-help-svc_onecx-help-default-url]]`link:#onecx-help-svc_onecx-help-default-url[onecx.help.default.url]` + + +[.description] +-- +Default help URL + +ifdef::add-copy-button-to-env-var[] +Environment variable: env_var_with_copy_button:+++ONECX_HELP_DEFAULT_URL+++[] +endif::add-copy-button-to-env-var[] +ifndef::add-copy-button-to-env-var[] +Environment variable: `+++ONECX_HELP_DEFAULT_URL+++` +endif::add-copy-button-to-env-var[] +--|string +|`https://github.com/onecx` + + +a| [[onecx-help-svc_onecx-help-product-item-id]]`link:#onecx-help-svc_onecx-help-product-item-id[onecx.help.product-item-id]` + + +[.description] +-- +Default help URL + +ifdef::add-copy-button-to-env-var[] +Environment variable: env_var_with_copy_button:+++ONECX_HELP_PRODUCT_ITEM_ID+++[] +endif::add-copy-button-to-env-var[] +ifndef::add-copy-button-to-env-var[] +Environment variable: `+++ONECX_HELP_PRODUCT_ITEM_ID+++` +endif::add-copy-button-to-env-var[] +--|string +|`PRODUCT_BASE_DOC_URL` + +|=== \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3c7bf15..d13ae71 100644 --- a/pom.xml +++ b/pom.xml @@ -220,18 +220,6 @@ DTO - - v1 - - generate - - - src/main/openapi/onecx-help-v1-openapi.yaml - gen.org.tkit.onecx.help.rs.v1 - gen.org.tkit.onecx.help.rs.v1.model - DTOV1 - - di-help-v1 diff --git a/src/main/java/org/tkit/onecx/help/domain/config/HelpConfig.java b/src/main/java/org/tkit/onecx/help/domain/config/HelpConfig.java new file mode 100644 index 0000000..eb107be --- /dev/null +++ b/src/main/java/org/tkit/onecx/help/domain/config/HelpConfig.java @@ -0,0 +1,35 @@ +package org.tkit.onecx.help.domain.config; + +import io.quarkus.runtime.annotations.ConfigDocFilename; +import io.quarkus.runtime.annotations.ConfigPhase; +import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; + +@ConfigDocFilename("onecx-help-svc.adoc") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +@ConfigMapping(prefix = "onecx.help") +public interface HelpConfig { + + /** + * Enable or disable default help + */ + @WithName("default.enabled") + @WithDefault("false") + boolean defaultHelpEnabled(); + + /** + * Default help URL + */ + @WithName("default.url") + @WithDefault("https://github.com/onecx") + String defaultHelpUrl(); + + /** + * Default help URL + */ + @WithName("product-item-id") + @WithDefault("PRODUCT_BASE_DOC_URL") + String productItemId(); +} diff --git a/src/main/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestController.java b/src/main/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestController.java index eb7096b..be5896d 100644 --- a/src/main/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestController.java +++ b/src/main/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestController.java @@ -13,6 +13,7 @@ import org.jboss.resteasy.reactive.RestResponse; import org.jboss.resteasy.reactive.server.ServerExceptionMapper; +import org.tkit.onecx.help.domain.config.HelpConfig; import org.tkit.onecx.help.domain.daos.HelpDAO; import org.tkit.onecx.help.rs.internal.mappers.ExceptionMapper; import org.tkit.onecx.help.rs.internal.mappers.HelpMapper; @@ -41,6 +42,9 @@ public class HelpsRestController implements HelpsInternalApi { @Context UriInfo uriInfo; + @Inject + HelpConfig config; + @Override @Transactional public Response createNewHelp(CreateHelpDTO createHelpDTO) { @@ -96,6 +100,25 @@ public Response updateHelp(String id, UpdateHelpDTO updateHelpDTO) { return Response.noContent().build(); } + @Override + public Response getHelpByProductNameItemId(String productName, String helpItemId) { + var help = dao.findByProductNameAndItemId(productName, helpItemId); + if (help != null) { + return Response.ok(mapper.map(help)).build(); + } + + help = dao.findByProductNameAndItemId(productName, config.productItemId()); + if (help != null) { + return Response.ok(mapper.map(help)).build(); + } + + if (config.defaultHelpEnabled()) { + return Response.ok(mapper.createDefault(productName, helpItemId, config.defaultHelpUrl())).build(); + } + + return Response.status(Response.Status.NOT_FOUND).build(); + } + @ServerExceptionMapper public RestResponse exception(ConstraintException ex) { return exceptionMapper.exception(ex); diff --git a/src/main/java/org/tkit/onecx/help/rs/internal/mappers/HelpMapper.java b/src/main/java/org/tkit/onecx/help/rs/internal/mappers/HelpMapper.java index 7bbd7ea..5dcc084 100644 --- a/src/main/java/org/tkit/onecx/help/rs/internal/mappers/HelpMapper.java +++ b/src/main/java/org/tkit/onecx/help/rs/internal/mappers/HelpMapper.java @@ -36,6 +36,16 @@ public interface HelpMapper { HelpDTO map(Help help); + @Mapping(target = "id", ignore = true) + @Mapping(target = "creationDate", ignore = true) + @Mapping(target = "creationUser", ignore = true) + @Mapping(target = "modificationDate", ignore = true) + @Mapping(target = "modificationUser", ignore = true) + @Mapping(target = "modificationCount", ignore = true) + @Mapping(target = "context", ignore = true) + @Mapping(target = "resourceUrl", ignore = true) + HelpDTO createDefault(String productName, String itemId, String baseUrl); + @Mapping(target = "id", ignore = true) @Mapping(target = "creationDate", ignore = true) @Mapping(target = "creationUser", ignore = true) diff --git a/src/main/java/org/tkit/onecx/help/rs/v1/controllers/HelpsV1RestController.java b/src/main/java/org/tkit/onecx/help/rs/v1/controllers/HelpsV1RestController.java deleted file mode 100644 index 6c62037..0000000 --- a/src/main/java/org/tkit/onecx/help/rs/v1/controllers/HelpsV1RestController.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.tkit.onecx.help.rs.v1.controllers; - -import static jakarta.transaction.Transactional.TxType.NOT_SUPPORTED; - -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; -import jakarta.transaction.Transactional; -import jakarta.ws.rs.core.Response; - -import org.tkit.onecx.help.domain.daos.HelpDAO; -import org.tkit.onecx.help.rs.v1.mappers.ExternalV1Mapper; -import org.tkit.quarkus.log.cdi.LogService; - -import gen.org.tkit.onecx.help.rs.v1.HelpsV1Api; - -@LogService -@ApplicationScoped -@Transactional(value = NOT_SUPPORTED) -public class HelpsV1RestController implements HelpsV1Api { - @Inject - HelpDAO dao; - - @Inject - ExternalV1Mapper mapper; - - @Override - public Response searchHelpItem(String productName, String helpItemId) { - var help = dao.findByProductNameAndItemId(productName, helpItemId); - if (help == null) { - return Response.status(Response.Status.NOT_FOUND).build(); - } - return Response.ok(mapper.map(help)).build(); - } -} diff --git a/src/main/java/org/tkit/onecx/help/rs/v1/mappers/ExternalV1Mapper.java b/src/main/java/org/tkit/onecx/help/rs/v1/mappers/ExternalV1Mapper.java deleted file mode 100644 index bc43308..0000000 --- a/src/main/java/org/tkit/onecx/help/rs/v1/mappers/ExternalV1Mapper.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.tkit.onecx.help.rs.v1.mappers; - -import org.mapstruct.Mapper; -import org.tkit.onecx.help.domain.models.Help; -import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; - -import gen.org.tkit.onecx.help.rs.v1.model.HelpDTOV1; - -@Mapper(uses = { OffsetDateTimeMapper.class }) -public interface ExternalV1Mapper { - - HelpDTOV1 map(Help data); -} diff --git a/src/main/openapi/onecx-help-internal-openapi.yaml b/src/main/openapi/onecx-help-internal-openapi.yaml index 03a11e1..8c08603 100644 --- a/src/main/openapi/onecx-help-internal-openapi.yaml +++ b/src/main/openapi/onecx-help-internal-openapi.yaml @@ -8,6 +8,36 @@ servers: tags: - name: helpsInternal paths: + /internal/helps/{productName}/{helpItemId}: + get: + security: + - oauth2: [ ocx-hp:all, ocx-hp:read ] + tags: + - helpsInternal + description: search help item by product name and item id + operationId: getHelpByProductNameItemId + parameters: + - name: productName + in: path + required: true + description: product name + schema: + type: string + - name: helpItemId + in: path + required: true + description: help item ID + schema: + type: string + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Help' + 404: + description: Help not found /internal/helps: post: security: diff --git a/src/main/openapi/onecx-help-v1-openapi.yaml b/src/main/openapi/onecx-help-v1-openapi.yaml deleted file mode 100644 index 7773a4e..0000000 --- a/src/main/openapi/onecx-help-v1-openapi.yaml +++ /dev/null @@ -1,65 +0,0 @@ ---- -openapi: 3.0.3 -info: - title: onecx-help v1 service - version: 1.0.0 -servers: - - url: "http://onecx-help-svc:8080" -tags: - - name: helpsV1 -paths: - /v1/helps/{productName}/{helpItemId}: - get: - security: - - oauth2: [ ocx-hp:read ] - tags: - - helpsV1 - description: search help item by criteria - operationId: searchHelpItem - parameters: - - name: productName - in: path - required: true - description: product name - schema: - type: string - - name: helpItemId - in: path - required: true - description: help item ID - schema: - type: string - responses: - 200: - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/Help' - 404: - description: Help not found -components: - securitySchemes: - oauth2: - type: oauth2 - flows: - clientCredentials: - tokenUrl: https://oauth.simple.api/token - scopes: - ocx-hp:read: Grants read access - schemas: - Help: - required: - - itemId - type: object - properties: - itemId: - type: string - context: - type: string - baseUrl: - type: string - resourceUrl: - type: string - productName: - type: string diff --git a/src/test/java/org/tkit/onecx/help/domain/di/HelpDataImportServiceTest.java b/src/test/java/org/tkit/onecx/help/domain/di/HelpDataImportServiceTest.java index 1d2b44f..645c61d 100644 --- a/src/test/java/org/tkit/onecx/help/domain/di/HelpDataImportServiceTest.java +++ b/src/test/java/org/tkit/onecx/help/domain/di/HelpDataImportServiceTest.java @@ -49,7 +49,7 @@ public Map getMetadata() { service.importData(config); List data = dao.findAll().toList(); - assertThat(data).isNotNull().hasSize(3); + assertThat(data).isNotNull().hasSize(4); } diff --git a/src/test/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestControllerConfigTest.java b/src/test/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestControllerConfigTest.java new file mode 100644 index 0000000..2cff9f8 --- /dev/null +++ b/src/test/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestControllerConfigTest.java @@ -0,0 +1,66 @@ +package org.tkit.onecx.help.rs.internal.controllers; + +import static io.restassured.RestAssured.given; +import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; +import static jakarta.ws.rs.core.Response.Status.OK; +import static org.assertj.core.api.Assertions.assertThat; +import static org.tkit.quarkus.security.test.SecurityTestUtils.getKeycloakClientToken; + +import jakarta.inject.Inject; + +import org.eclipse.microprofile.config.Config; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.tkit.onecx.help.domain.config.HelpConfig; +import org.tkit.onecx.help.test.AbstractTest; +import org.tkit.quarkus.security.test.GenerateKeycloakClient; +import org.tkit.quarkus.test.WithDBData; + +import gen.org.tkit.onecx.help.rs.internal.model.HelpDTO; +import io.quarkus.test.InjectMock; +import io.quarkus.test.common.http.TestHTTPEndpoint; +import io.quarkus.test.junit.QuarkusTest; +import io.smallrye.config.SmallRyeConfig; + +@QuarkusTest +@TestHTTPEndpoint(HelpsRestController.class) +@WithDBData(value = "data/test-internal.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true) +@GenerateKeycloakClient(clientName = "testClient", scopes = "ocx-hp:all") +class HelpsRestControllerConfigTest extends AbstractTest { + + @InjectMock + HelpConfig helpConfig; + + @Inject + Config config; + + @BeforeEach + void beforeEach() { + var tmp = config.unwrap(SmallRyeConfig.class).getConfigMapping(HelpConfig.class); + Mockito.when(helpConfig.defaultHelpEnabled()).thenReturn(true); + Mockito.when(helpConfig.defaultHelpUrl()).thenReturn(tmp.defaultHelpUrl()); + Mockito.when(helpConfig.productItemId()).thenReturn(tmp.productItemId()); + } + + @Test + void searchByProductNameAndItemIdNoFoundTest() { + + var data = given() + .contentType(APPLICATION_JSON) + .auth().oauth2(getKeycloakClientToken("testClient")) + .get("does-not-exists/cg") + .then() + .statusCode(OK.getStatusCode()) + .contentType(APPLICATION_JSON) + .extract() + .as(HelpDTO.class); + + assertThat(data).isNotNull(); + Assertions.assertEquals("does-not-exists", data.getProductName()); + Assertions.assertEquals("cg", data.getItemId()); + Assertions.assertEquals(helpConfig.defaultHelpUrl(), data.getBaseUrl()); + } + +} diff --git a/src/test/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestControllerTest.java b/src/test/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestControllerTest.java index 4f96e17..9c45a3f 100644 --- a/src/test/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/help/rs/internal/controllers/HelpsRestControllerTest.java @@ -178,8 +178,8 @@ void searchHelpsTest() { .as(HelpPageResultDTO.class); assertThat(data).isNotNull(); - assertThat(data.getTotalElements()).isEqualTo(3); - assertThat(data.getStream()).isNotNull().hasSize(3); + assertThat(data.getTotalElements()).isEqualTo(4); + assertThat(data.getStream()).isNotNull().hasSize(4); criteria.setItemId(""); criteria.setResourceUrl(" "); @@ -198,8 +198,8 @@ void searchHelpsTest() { .as(HelpPageResultDTO.class); assertThat(data).isNotNull(); - assertThat(data.getTotalElements()).isEqualTo(3); - assertThat(data.getStream()).isNotNull().hasSize(3); + assertThat(data.getTotalElements()).isEqualTo(4); + assertThat(data.getStream()).isNotNull().hasSize(4); criteria.setItemId("cg"); criteria.setResourceUrl("test1"); @@ -343,7 +343,54 @@ void getAllAppsWithHelpItemsTest() { .statusCode(OK.getStatusCode()) .extract().as(HelpProductNamesDTO.class); Assertions.assertNotNull(output); - Assertions.assertEquals(2, output.getProductNames().size()); - Assertions.assertEquals("productName", output.getProductNames().get(0)); + Assertions.assertEquals(3, output.getProductNames().size()); + assertThat(output.getProductNames()).contains("productName"); + } + + @Test + void searchHelpItemByProductNameAndItemIdTest() { + + var data = given() + .contentType(APPLICATION_JSON) + .auth().oauth2(getKeycloakClientToken("testClient")) + .get("productName1/cg") + .then() + .statusCode(OK.getStatusCode()) + .contentType(APPLICATION_JSON) + .extract() + .as(HelpDTO.class); + + assertThat(data).isNotNull(); + Assertions.assertEquals("productName1", data.getProductName()); + Assertions.assertEquals("cg", data.getItemId()); + } + + @Test + void searchByProductNameAndItemIdNoFoundTest() { + + given() + .contentType(APPLICATION_JSON) + .auth().oauth2(getKeycloakClientToken("testClient")) + .get("does-not-exists/cg") + .then() + .statusCode(NOT_FOUND.getStatusCode()); + } + + @Test + void searchHelpItemByProductNameAndItemIdProductUrlTest() { + + var data = given() + .contentType(APPLICATION_JSON) + .auth().oauth2(getKeycloakClientToken("testClient")) + .get("no-page-product/cg") + .then() + .statusCode(OK.getStatusCode()) + .contentType(APPLICATION_JSON) + .extract() + .as(HelpDTO.class); + + assertThat(data).isNotNull(); + Assertions.assertEquals("no-page-product", data.getProductName()); + Assertions.assertEquals("PRODUCT_BASE_DOC_URL", data.getItemId()); } } diff --git a/src/test/java/org/tkit/onecx/help/rs/v1/controllers/HelpsV1RestControllerTest.java b/src/test/java/org/tkit/onecx/help/rs/v1/controllers/HelpsV1RestControllerTest.java deleted file mode 100644 index 054a8c9..0000000 --- a/src/test/java/org/tkit/onecx/help/rs/v1/controllers/HelpsV1RestControllerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.tkit.onecx.help.rs.v1.controllers; - -import static io.restassured.RestAssured.given; -import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; -import static jakarta.ws.rs.core.Response.Status.*; -import static org.assertj.core.api.Assertions.assertThat; -import static org.tkit.quarkus.security.test.SecurityTestUtils.getKeycloakClientToken; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.tkit.onecx.help.test.AbstractTest; -import org.tkit.quarkus.security.test.GenerateKeycloakClient; -import org.tkit.quarkus.test.WithDBData; - -import gen.org.tkit.onecx.help.rs.v1.model.HelpDTOV1; -import io.quarkus.test.common.http.TestHTTPEndpoint; -import io.quarkus.test.junit.QuarkusTest; - -@QuarkusTest -@TestHTTPEndpoint(HelpsV1RestController.class) -@WithDBData(value = "data/test-v1.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true) -@GenerateKeycloakClient(clientName = "testClient", scopes = { "ocx-hp:read", "ocx-hp:write" }) -class HelpsV1RestControllerTest extends AbstractTest { - - @Test - void searchHelpItemByProductNameAndItemIdTest() { - - var data = given() - .contentType(APPLICATION_JSON) - .auth().oauth2(getKeycloakClientToken("testClient")) - .pathParam("productName", "productName") - .pathParam("helpItemId", "cg") - .get() - .then() - .statusCode(OK.getStatusCode()) - .contentType(APPLICATION_JSON) - .extract() - .as(HelpDTOV1.class); - - assertThat(data).isNotNull(); - Assertions.assertEquals("productName", data.getProductName()); - Assertions.assertEquals("cg", data.getItemId()); - } - - @Test - void searchByProductNameAndItemIdNoFoundTest() { - - given() - .contentType(APPLICATION_JSON) - .auth().oauth2(getKeycloakClientToken("testClient")) - .pathParam("productName", "does-not-exists") - .pathParam("helpItemId", "cg") - .get() - .then() - .statusCode(NOT_FOUND.getStatusCode()); - } - -} diff --git a/src/test/java/org/tkit/onecx/help/rs/v1/controllers/HelpsV1RestControllerTestIT.java b/src/test/java/org/tkit/onecx/help/rs/v1/controllers/HelpsV1RestControllerTestIT.java deleted file mode 100644 index 8272d59..0000000 --- a/src/test/java/org/tkit/onecx/help/rs/v1/controllers/HelpsV1RestControllerTestIT.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.tkit.onecx.help.rs.v1.controllers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -class HelpsV1RestControllerTestIT extends HelpsV1RestControllerTest { -} diff --git a/src/test/java/org/tkit/onecx/help/test/AbstractTest.java b/src/test/java/org/tkit/onecx/help/test/AbstractTest.java index a4f013f..496aac7 100644 --- a/src/test/java/org/tkit/onecx/help/test/AbstractTest.java +++ b/src/test/java/org/tkit/onecx/help/test/AbstractTest.java @@ -6,15 +6,22 @@ import java.security.PrivateKey; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Inject; import jakarta.json.Json; import jakarta.json.JsonObjectBuilder; +import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.jwt.Claims; +import org.tkit.onecx.help.domain.config.HelpConfig; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import io.quarkus.test.Mock; import io.restassured.config.RestAssuredConfig; +import io.smallrye.config.SmallRyeConfig; import io.smallrye.jwt.build.Jwt; import io.smallrye.jwt.util.KeyUtils; @@ -48,4 +55,17 @@ protected static String createToken(String organizationId) { } } + public static class ConfigProducer { + + @Inject + Config config; + + @Produces + @ApplicationScoped + @Mock + HelpConfig config() { + return config.unwrap(SmallRyeConfig.class).getConfigMapping(HelpConfig.class); + } + } + } diff --git a/src/test/resources/data/test-internal.xml b/src/test/resources/data/test-internal.xml index 3c7b22f..9591f88 100644 --- a/src/test/resources/data/test-internal.xml +++ b/src/test/resources/data/test-internal.xml @@ -6,6 +6,10 @@ + + + + diff --git a/src/test/resources/data/test-v1.xml b/src/test/resources/data/test-v1.xml deleted file mode 100644 index c9906b0..0000000 --- a/src/test/resources/data/test-v1.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - -