From 6cd41d25a2c127e04cbe1d0e7d6ae2cadeb25139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szab=C3=B3?= Date: Mon, 22 Jan 2024 12:38:13 +0100 Subject: [PATCH 01/10] #3 - test log spcifier --- .../test/ITestQuarkusSamplerServiceRest.java | 43 +++++- qs-bom/qs-bom-all/pom.xml | 2 +- .../RequestResponseMetricsProvider.java | 3 + .../rest/TestQuarkusSamplerServiceRest.java | 9 ++ .../sampler/rest/action/SamplerPutAction.java | 87 ++++++++++++ ...kusSamplerServiceRestRegisteredClient.java | 2 +- ...kusSamplerServiceRestRegisteredClient.java | 2 +- .../sampler/rest/test/PostTestRestTest.java | 16 +++ .../sampler/rest/test/PutTestRestTest.java | 129 ++++++++++++++++++ .../src/test/resources/application.yml | 6 +- 10 files changed, 292 insertions(+), 7 deletions(-) create mode 100644 qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/action/SamplerPutAction.java create mode 100644 qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PutTestRestTest.java diff --git a/qs-api/qs-api-jakarta/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/test/ITestQuarkusSamplerServiceRest.java b/qs-api/qs-api-jakarta/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/test/ITestQuarkusSamplerServiceRest.java index 793a8a6..dd9c5e6 100644 --- a/qs-api/qs-api-jakarta/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/test/ITestQuarkusSamplerServiceRest.java +++ b/qs-api/qs-api-jakarta/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/test/ITestQuarkusSamplerServiceRest.java @@ -22,6 +22,7 @@ import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; +import jakarta.ws.rs.PUT; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.QueryParam; @@ -31,9 +32,11 @@ import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; import org.eclipse.microprofile.openapi.annotations.tags.Tag; +import hu.icellmobilsoft.coffee.cdi.annotation.xml.ValidateXML; import hu.icellmobilsoft.coffee.dto.common.commonservice.BaseRequest; import hu.icellmobilsoft.coffee.dto.exception.BaseException; -import hu.icellmobilsoft.coffee.rest.validation.xml.annotation.ValidateXML; +import hu.icellmobilsoft.coffee.rest.log.annotation.LogSpecifier; +import hu.icellmobilsoft.coffee.rest.log.annotation.enumeration.LogSpecifierTarget; import hu.icellmobilsoft.quarkus.sampler.api.jakarta.path.QuarkusSamplerPath; import hu.icellmobilsoft.quarkus.sampler.api.schema.XsdConstants; import hu.icellmobilsoft.quarkus.sampler.dto.test.post.SampleResponse; @@ -111,6 +114,8 @@ TestResponse getTest( description = "Dummy operation for testing Sampler service") @Tag(ref = ITestQuarkusSamplerServiceRest.TAG) @POST + @LogSpecifier(target = { LogSpecifierTarget.CLIENT_REQUEST }, maxEntityLogSize = 20) + @LogSpecifier(target = { LogSpecifierTarget.CLIENT_RESPONSE }, noLog = true) @Consumes(value = { MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.APPLICATION_XML }) @Produces(value = { MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.APPLICATION_XML }) SampleResponse postTest(@ValidateXML(xsdPath = XsdConstants.SUPER_XSD_PATH) BaseRequest baseRequest, @@ -123,4 +128,40 @@ SampleResponse postTest(@ValidateXML(xsdPath = XsdConstants.SUPER_XSD_PATH) Base @QueryParam(QuarkusSamplerPath.PARAM_TEST_BOOLEAN) @Parameter(name = QuarkusSamplerPath.PARAM_TEST_BOOLEAN, description = TEST_DESCRIPTION) Boolean testBoolean) throws BaseException; + + /** + * Test POST operation + * + * @param baseRequest + * base request from body + * @param testString + * {@link String} test value + * @param testInteger + * {@link Integer} test value + * @param testLong + * {@link Long} test value + * @param testBoolean + * {@link Boolean} test value + * @return {@link SampleResponse} response + * @throws BaseException + * if any error occurs + */ + @Operation(summary = "Test POST operation", // + description = "Dummy operation for testing Sampler service") + @Tag(ref = ITestQuarkusSamplerServiceRest.TAG) + @PUT + @Consumes(value = { MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.APPLICATION_XML }) + @Produces(value = { MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.APPLICATION_XML }) + @LogSpecifier(target = LogSpecifierTarget.REQUEST, maxEntityLogSize = 10) + @LogSpecifier(target = LogSpecifierTarget.RESPONSE, maxEntityLogSize = 5000) + SampleResponse putTest(@ValidateXML(xsdPath = XsdConstants.SUPER_XSD_PATH) BaseRequest baseRequest, + @QueryParam(QuarkusSamplerPath.PARAM_TEST_STRING) @Parameter(name = QuarkusSamplerPath.PARAM_TEST_STRING, + description = TEST_DESCRIPTION) String testString, + @QueryParam(QuarkusSamplerPath.PARAM_TEST_INTEGER) @Parameter(name = QuarkusSamplerPath.PARAM_TEST_INTEGER, + description = TEST_DESCRIPTION) Integer testInteger, + @QueryParam(QuarkusSamplerPath.PARAM_TEST_LONG) @Parameter(name = QuarkusSamplerPath.PARAM_TEST_LONG, + description = TEST_DESCRIPTION) Long testLong, + @QueryParam(QuarkusSamplerPath.PARAM_TEST_BOOLEAN) @Parameter(name = QuarkusSamplerPath.PARAM_TEST_BOOLEAN, + description = TEST_DESCRIPTION) Boolean testBoolean) + throws BaseException; } diff --git a/qs-bom/qs-bom-all/pom.xml b/qs-bom/qs-bom-all/pom.xml index 9276f71..66a9de3 100644 --- a/qs-bom/qs-bom-all/pom.xml +++ b/qs-bom/qs-bom-all/pom.xml @@ -13,7 +13,7 @@ pom - 2.4.0 + 2.5.0-SNAPSHOT 4.4 1.5 diff --git a/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/metrics/provider/RequestResponseMetricsProvider.java b/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/metrics/provider/RequestResponseMetricsProvider.java index 9816a1d..58afd3b 100644 --- a/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/metrics/provider/RequestResponseMetricsProvider.java +++ b/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/metrics/provider/RequestResponseMetricsProvider.java @@ -29,6 +29,8 @@ import jakarta.enterprise.context.Dependent; import jakarta.inject.Inject; import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.ConstrainedTo; +import jakarta.ws.rs.RuntimeType; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.container.ContainerRequestContext; import jakarta.ws.rs.container.ContainerRequestFilter; @@ -56,6 +58,7 @@ */ @Provider @Dependent +@ConstrainedTo(RuntimeType.SERVER) public class RequestResponseMetricsProvider implements ContainerRequestFilter, WriterInterceptor { @Inject diff --git a/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/TestQuarkusSamplerServiceRest.java b/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/TestQuarkusSamplerServiceRest.java index b938dd7..9f2670d 100644 --- a/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/TestQuarkusSamplerServiceRest.java +++ b/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/TestQuarkusSamplerServiceRest.java @@ -30,6 +30,7 @@ import hu.icellmobilsoft.quarkus.sampler.dto.test.post.SampleResponse; import hu.icellmobilsoft.quarkus.sampler.dto.test.test.TestResponse; import hu.icellmobilsoft.quarkus.sampler.rest.action.SamplerPostAction; +import hu.icellmobilsoft.quarkus.sampler.rest.action.SamplerPutAction; import hu.icellmobilsoft.quarkus.sampler.rest.action.SamplerTestAction; /** @@ -47,6 +48,8 @@ public class TestQuarkusSamplerServiceRest extends BaseRestService implements IT @Inject SamplerPostAction samplerPostAction; + @Inject + SamplerPutAction samplerPutAction; /** * Default constructor */ @@ -76,4 +79,10 @@ public SampleResponse postTest(BaseRequest baseRequest, String testString, Integ return samplerPostAction.postTest(baseRequest, testString, testInteger, testLong, testBoolean); } + @Override + @LogMethodEntryAndExit + public SampleResponse putTest(BaseRequest baseRequest, String testString, Integer testInteger, Long testLong, Boolean testBoolean) + throws BaseException { + return samplerPutAction.putTest(baseRequest, testString, testInteger, testLong, testBoolean); + } } diff --git a/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/action/SamplerPutAction.java b/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/action/SamplerPutAction.java new file mode 100644 index 0000000..5192491 --- /dev/null +++ b/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/action/SamplerPutAction.java @@ -0,0 +1,87 @@ +/*- + * #%L + * Quarkus-sampler + * %% + * Copyright (C) 2024 i-Cell Mobilsoft Zrt. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package hu.icellmobilsoft.quarkus.sampler.rest.action; + +import jakarta.enterprise.inject.Model; +import jakarta.inject.Inject; + +import org.eclipse.microprofile.rest.client.inject.RestClient; + +import hu.icellmobilsoft.coffee.dto.common.commonservice.BaseRequest; +import hu.icellmobilsoft.coffee.dto.exception.BaseException; +import hu.icellmobilsoft.quarkus.sample.common.util.string.RandomUtil; +import hu.icellmobilsoft.quarkus.sampler.common.rest.action.BaseAction; +import hu.icellmobilsoft.quarkus.sampler.dto.test.post.SampleResponse; +import hu.icellmobilsoft.quarkus.sampler.dto.test.post.SampleStatusEnumType; +import hu.icellmobilsoft.quarkus.sampler.dto.test.post.SampleType; +import hu.icellmobilsoft.quarkus.sampler.dto.test.post.SampleValueEnumType; +import hu.icellmobilsoft.quarkus.sampler.rest.restclient.ITestQuarkusSamplerServiceRestRegisteredClient; + +/** + * Sampler Put Test action + * + * @author speter555 + * @since 0.1.0 + */ +@Model +public class SamplerPutAction extends BaseAction { + + @Inject + @RestClient + ITestQuarkusSamplerServiceRestRegisteredClient testRestRegisteredClient; + + /** + * Default constructor + */ + public SamplerPutAction() { + // Default constructor for java 21 + } + + /** + * Test logic. Test LogSpecifier + * + * @param baseRequest + * base request parameter from post http call + * @param testString + * Query parameter for testing + * @param testInteger + * Query parameter for testing + * @param testLong + * Query parameter for testing + * @param testBoolean + * Query parameter for testing + * @return {@link SampleResponse} Sample response + * @throws BaseException + * asdf + */ + public SampleResponse putTest(BaseRequest baseRequest, String testString, Integer testInteger, Long testLong, Boolean testBoolean) + throws BaseException { + testRestRegisteredClient.postTest(baseRequest, testString, testInteger, testLong, testBoolean); + SampleResponse response = new SampleResponse(); + response.setSample( + new SampleType().withSampleId(RandomUtil.generateId()) + .withSampleStatus(SampleStatusEnumType.DONE) + .withColumnA("A") + .withColumnB(SampleValueEnumType.VALUE_C)); + handleSuccessResultType(response, baseRequest); + return response; + } + +} diff --git a/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/restclient/ITestQuarkusSamplerServiceRestRegisteredClient.java b/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/restclient/ITestQuarkusSamplerServiceRestRegisteredClient.java index 054a259..0d9ce92 100644 --- a/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/restclient/ITestQuarkusSamplerServiceRestRegisteredClient.java +++ b/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/restclient/ITestQuarkusSamplerServiceRestRegisteredClient.java @@ -34,5 +34,5 @@ */ @RegisterRestClient @Path(QuarkusSamplerPath.TEST_QUARKUS_SAMPLER_SERVICE) -public interface ITestQuarkusSamplerServiceRestRegisteredClient extends ITestQuarkusSamplerServiceRest { +public interface ITestQuarkusSamplerServiceRestRegisteredClient extends ITestQuarkusSamplerServiceRest, AutoCloseable { } diff --git a/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/restclient/ITestSecondQuarkusSamplerServiceRestRegisteredClient.java b/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/restclient/ITestSecondQuarkusSamplerServiceRestRegisteredClient.java index b33095f..e690173 100644 --- a/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/restclient/ITestSecondQuarkusSamplerServiceRestRegisteredClient.java +++ b/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/restclient/ITestSecondQuarkusSamplerServiceRestRegisteredClient.java @@ -34,5 +34,5 @@ */ @RegisterRestClient @Path(QuarkusSamplerPath.TEST_QUARKUS_SAMPLER_SERVICE) -public interface ITestSecondQuarkusSamplerServiceRestRegisteredClient extends ITestQuarkusSamplerServiceRest { +public interface ITestSecondQuarkusSamplerServiceRestRegisteredClient extends ITestQuarkusSamplerServiceRest, AutoCloseable { } diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java index 746daf7..a577074 100644 --- a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java @@ -23,12 +23,14 @@ import org.eclipse.microprofile.rest.client.RestClientBuilder; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import hu.icellmobilsoft.coffee.dto.common.commonservice.BaseRequest; import hu.icellmobilsoft.coffee.dto.common.commonservice.ContextType; import hu.icellmobilsoft.coffee.dto.exception.BaseException; +import hu.icellmobilsoft.coffee.dto.exception.enums.CoffeeFaultType; import hu.icellmobilsoft.coffee.tool.utils.date.DateUtil; import hu.icellmobilsoft.coffee.tool.utils.string.RandomUtil; import hu.icellmobilsoft.quarkus.sampler.api.jakarta.path.QuarkusSamplerPath; @@ -105,6 +107,20 @@ void postTestXml() throws BaseException { Assertions.assertNotNull(testResponse.getContext().getRequestId()); } + @Test + @Disabled("This is disabled while ") + @DisplayName("test post method in the service with RestClient With error (dto without ContextType") + void postTestWithoutContextType() { + try { + RestClientBuilder.newBuilder() + .baseUrl(url) + .build(XmlITestQuarkusSamplerServiceRest.class) + .postTest(new BaseRequest(), "test", 1, 1L, true); + } catch (BaseException e) { + Assertions.assertSame(CoffeeFaultType.INVALID_XML, e.getFaultTypeEnum()); + } + } + private BaseRequest createBaseRequest() { return new BaseRequest() .withContext(new ContextType().withTimestamp(DateUtil.nowUTCTruncatedToMillis()).withRequestId(RandomUtil.generateId())); diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PutTestRestTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PutTestRestTest.java new file mode 100644 index 0000000..4b1bb1b --- /dev/null +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PutTestRestTest.java @@ -0,0 +1,129 @@ +/*- + * #%L + * Quarkus-sampler + * %% + * Copyright (C) 2024 i-Cell Mobilsoft Zrt. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package hu.icellmobilsoft.quarkus.sampler.rest.test; + +import java.net.URL; + +import org.eclipse.microprofile.rest.client.RestClientBuilder; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import hu.icellmobilsoft.coffee.dto.common.commonservice.BaseRequest; +import hu.icellmobilsoft.coffee.dto.common.commonservice.ContextType; +import hu.icellmobilsoft.coffee.dto.exception.BaseException; +import hu.icellmobilsoft.coffee.dto.exception.enums.CoffeeFaultType; +import hu.icellmobilsoft.coffee.tool.utils.date.DateUtil; +import hu.icellmobilsoft.coffee.tool.utils.string.RandomUtil; +import hu.icellmobilsoft.quarkus.sampler.api.jakarta.path.QuarkusSamplerPath; +import hu.icellmobilsoft.quarkus.sampler.api.jakarta.test.ITestQuarkusSamplerServiceRest; +import hu.icellmobilsoft.quarkus.sampler.dto.test.post.SampleResponse; +import hu.icellmobilsoft.quarkus.sampler.rest.test.restclient.XmlITestQuarkusSamplerServiceRest; +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; + +/** + * Quarkus test example for ITestQuarkusSamplerServiceRest interface test. + */ +@QuarkusTest +class PutTestRestTest { + + /** + * Server url like: http://localhost:8083 + */ + @TestHTTPResource + URL url; + + @Test + @DisplayName("test post method in the service with RestAssured") + void putTestRestWithRestAssured() { + + SampleResponse sampleResponse = RestAssured.given() + .header("Accept", "application/json") + .header("Content-Type", "application/json") + .queryParam(QuarkusSamplerPath.PARAM_TEST_STRING, RandomUtil.generateId()) + .queryParam(QuarkusSamplerPath.PARAM_TEST_INTEGER, Integer.MAX_VALUE) + .queryParam(QuarkusSamplerPath.PARAM_TEST_LONG, Long.MAX_VALUE) + .queryParam(QuarkusSamplerPath.PARAM_TEST_BOOLEAN, Boolean.FALSE) + .baseUri(url.toString()) + .basePath(QuarkusSamplerPath.TEST_QUARKUS_SAMPLER_SERVICE) + .body(createBaseRequest()) + .when() + .log() + .all() + .put() + .then() + .log() + .all() + .statusCode(200) + .extract() + .response() + .as(SampleResponse.class); + Assertions.assertNotNull(sampleResponse); + Assertions.assertNotNull(sampleResponse.getContext()); + Assertions.assertNotNull(sampleResponse.getContext().getRequestId()); + } + + @Test + @DisplayName("test post method in the service with RestClient") + void putTest() throws BaseException { + SampleResponse testResponse = RestClientBuilder.newBuilder() + .baseUrl(url) + .build(ITestQuarkusSamplerServiceRest.class) + .putTest(createBaseRequest(), "test", 1, 1L, true); + Assertions.assertNotNull(testResponse); + Assertions.assertNotNull(testResponse.getContext()); + Assertions.assertNotNull(testResponse.getContext().getRequestId()); + } + + @Test + @DisplayName("test post method in the service with RestClient With xml") + void putTestXml() throws BaseException { + SampleResponse testResponse = RestClientBuilder.newBuilder() + .baseUrl(url) + .build(XmlITestQuarkusSamplerServiceRest.class) + .putTest(createBaseRequest(), "test", 1, 1L, true); + Assertions.assertNotNull(testResponse); + Assertions.assertNotNull(testResponse.getContext()); + Assertions.assertNotNull(testResponse.getContext().getRequestId()); + } + + @Test + @Disabled + @DisplayName("test post method in the service with RestClient With error (dto without ContextType") + void putTestWithoutContextType() { + try { + RestClientBuilder.newBuilder() + .baseUrl(url) + .build(XmlITestQuarkusSamplerServiceRest.class) + .putTest(new BaseRequest(), "test", 1, 1L, true); + } catch (BaseException e) { + Assertions.assertSame(CoffeeFaultType.INVALID_XML, e.getFaultTypeEnum()); + } + } + + private BaseRequest createBaseRequest() { + return new BaseRequest() + .withContext(new ContextType().withTimestamp(DateUtil.nowUTCTruncatedToMillis()).withRequestId(RandomUtil.generateId())); + } + +} diff --git a/qs-services/qs-rest-service/src/test/resources/application.yml b/qs-services/qs-rest-service/src/test/resources/application.yml index aae9f6c..5dc46ed 100644 --- a/qs-services/qs-rest-service/src/test/resources/application.yml +++ b/qs-services/qs-rest-service/src/test/resources/application.yml @@ -7,16 +7,16 @@ quarkus: rest-client: "hu.icellmobilsoft.quarkus.sampler.rest.restclient.ITestSecondQuarkusSamplerServiceRestRegisteredClient": url: http://localhost:8083 - scope: jakarta.enterprise.context.ApplicationScoped + scope: jakarta.enterprise.context.Dependent #read-timeout: 5000 #connect-timeout: 5000 "hu.icellmobilsoft.quarkus.sampler.rest.restclient.ITestQuarkusSamplerServiceRestRegisteredClient": url: http://localhost:8083 - scope: jakarta.enterprise.context.ApplicationScoped + scope: jakarta.enterprise.context.Dependent #read-timeout: 5000 #connect-timeout: 5000 "hu.icellmobilsoft.quarkus.sampler.rest.test.restclient.XmlITestQuarkusSamplerServiceRest": url: http://localhost:8083 - scope: jakarta.enterprise.context.ApplicationScoped + scope: jakarta.enterprise.context.Dependent #read-timeout: 5000 #connect-timeout: 5000 From b642604e5ebeaa649d52540d3f740b7ea467e3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szab=C3=B3?= Date: Mon, 22 Jan 2024 15:00:27 +0100 Subject: [PATCH 02/10] #4 - test localization --- pom.xml | 82 ++++++++++---- qs-common/qs-common-rest/pom.xml | 32 ++++++ .../main/resources/i18n/messages.properties | 32 +++--- .../resources/i18n/messages_hu.properties | 17 +++ .../localization/RestNotFoundErrorTest.java | 100 ++++++++++++++++++ 5 files changed, 227 insertions(+), 36 deletions(-) create mode 100644 qs-common/qs-common-rest/src/main/resources/i18n/messages_hu.properties create mode 100644 qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/localization/RestNotFoundErrorTest.java diff --git a/pom.xml b/pom.xml index a24d364..508f2f3 100644 --- a/pom.xml +++ b/pom.xml @@ -143,9 +143,51 @@ jandex + + + + + ${project.build.directory} + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.codehaus.mojo + + + native2ascii-maven-plugin + + + [1.0-beta-1,) + + + native2ascii + + + + + + + + + + + @@ -253,26 +295,26 @@ - - org.apache.maven.plugins - maven-gpg-plugin - 3.1.0 - - - sign-artifacts - verify - - sign - - - - - - --pinentry-mode - loopback - - - + + + + + + + + + + + + + + + + + + + + org.sonatype.plugins nexus-staging-maven-plugin diff --git a/qs-common/qs-common-rest/pom.xml b/qs-common/qs-common-rest/pom.xml index 9087882..7c98e5b 100644 --- a/qs-common/qs-common-rest/pom.xml +++ b/qs-common/qs-common-rest/pom.xml @@ -68,4 +68,36 @@ test + + + + + org.codehaus.mojo + native2ascii-maven-plugin + 2.1.0 + + UTF8 + i18n/**/*.properties + target/classes + + + + native2ascii-utf8 + + resources + + process-resources + + src/main/resources + UTF8 + + **/*.properties + + + + + + + + diff --git a/qs-common/qs-common-rest/src/main/resources/i18n/messages.properties b/qs-common/qs-common-rest/src/main/resources/i18n/messages.properties index 2c011cc..3e680a7 100644 --- a/qs-common/qs-common-rest/src/main/resources/i18n/messages.properties +++ b/qs-common/qs-common-rest/src/main/resources/i18n/messages.properties @@ -1,18 +1,18 @@ # classname + key = localized message -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.REST_BAD_REQUEST=The content in the request is not well-formed! -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.REST_UNAUTHORIZED=Incorrect credentials! -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.REST_FORBIDDEN=The user is not authorized to execute the operation! -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.REST_NOT_FOUND=Non-existing endpoint! -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.REST_METHOD_NOT_ALLOWED=The endpoint does not support the sent HTTP method! -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.REST_NOT_ACCEPTABLE=The endpoint does not support the expected (accept) MIME type! -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.REST_UNSUPPORTED_MEDIA_TYPE=The endpoint does not support the sent (content-type) MIME type! -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.REST_INTERNAL_SERVER_ERROR=An error occurred during the operation, please try again later! -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.REST_SERVICE_UNAVAILABLE=The service currently does not accept requests! -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.INVALID_TYPE_ERROR=Request could not be converted to target object. -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.JSON_PARSE_ERROR=The request sent could not be parsed as a valid JSON. -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.JSON_INVALID_FORMAT_ERROR=Could not deserialize JSON. -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.JSON_MAPPING_ERROR=An error occurred during JSON mapping. -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.HTTP_MESSAGE_ERROR=HTTP message cannot be processed. -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.IO_ERROR=General I/O error. -hu.icellmobilsoft.quarkus.sampler.enums.exception.hu.icellmobilsoft.quarkus.sampler.dto.FaultType.VALIDATION_ERROR=Validation error. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_BAD_REQUEST=The content in the request is not well-formed! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_UNAUTHORIZED=Incorrect credentials! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_FORBIDDEN=The user is not authorized to execute the operation! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_NOT_FOUND=Non-existing endpoint! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_METHOD_NOT_ALLOWED=The endpoint does not support the sent HTTP method! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_NOT_ACCEPTABLE=The endpoint does not support the expected (accept) MIME type! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_UNSUPPORTED_MEDIA_TYPE=The endpoint does not support the sent (content-type) MIME type! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_INTERNAL_SERVER_ERROR=An error occurred during the operation, please try again later! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_SERVICE_UNAVAILABLE=The service currently does not accept requests! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.INVALID_TYPE_ERROR=Request could not be converted to target object. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.JSON_PARSE_ERROR=The request sent could not be parsed as a valid JSON. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.JSON_INVALID_FORMAT_ERROR=Could not deserialize JSON. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.JSON_MAPPING_ERROR=An error occurred during JSON mapping. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.HTTP_MESSAGE_ERROR=HTTP message cannot be processed. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.IO_ERROR=General I/O error. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.VALIDATION_ERROR=Validation error. diff --git a/qs-common/qs-common-rest/src/main/resources/i18n/messages_hu.properties b/qs-common/qs-common-rest/src/main/resources/i18n/messages_hu.properties new file mode 100644 index 0000000..d754563 --- /dev/null +++ b/qs-common/qs-common-rest/src/main/resources/i18n/messages_hu.properties @@ -0,0 +1,17 @@ +# classname + key = lokalizált üzenet +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_BAD_REQUEST=A kérés tartalma nem jól formázott! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_UNAUTHORIZED=Hibás hitelesítő adatok! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_FORBIDDEN=A felhasználó nem jogosult a művelet végrehajtására! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_NOT_FOUND=Nem létező végpont! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_METHOD_NOT_ALLOWED=A végpont nem támogatja az elküldött HTTP módszert! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_NOT_ACCEPTABLE=A végpont nem támogatja az elvárt (accept) MIME típust! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_UNSUPPORTED_MEDIA_TYPE=A végpont nem támogatja a küldött (content-type) MIME típust! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_INTERNAL_SERVER_ERROR=A művelet során hiba történt, kérjük, próbálja meg később újra! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.REST_SERVICE_UNAVAILABLE=A szolgáltatás jelenleg nem fogad kéréseket! +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.INVALID_TYPE_ERROR=A kérést nem sikerült célobjektummá alakítani. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.JSON_PARSE_ERROR=A küldött kérést nem lehetett érvényes JSON-ként elemezni. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.JSON_INVALID_FORMAT_ERROR=A JSON nem tudott deserializálni. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.JSON_MAPPING_ERROR=Hiba történt a JSON leképezés során. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.HTTP_MESSAGE_ERROR=HTTP üzenet feldolgozása nem lehetséges. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.IO_ERROR=Általános I/O hiba. +hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType.VALIDATION_ERROR=Validációs hiba. diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/localization/RestNotFoundErrorTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/localization/RestNotFoundErrorTest.java new file mode 100644 index 0000000..4fc05e9 --- /dev/null +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/localization/RestNotFoundErrorTest.java @@ -0,0 +1,100 @@ +/*- + * #%L + * Quarkus-sampler + * %% + * Copyright (C) 2024 i-Cell Mobilsoft Zrt. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package hu.icellmobilsoft.quarkus.sampler.rest.test.localization; + +import java.net.URL; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import hu.icellmobilsoft.coffee.dto.common.commonservice.TechnicalFault; +import hu.icellmobilsoft.coffee.tool.utils.marshalling.MarshallingUtil; +import hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums.FaultType; +import hu.icellmobilsoft.quarkus.sampler.api.jakarta.path.ServicePath; +import hu.icellmobilsoft.quarkus.sampler.common.rest.header.ProjectHeader; +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; + +@QuarkusTest +@DisplayName("Testing Rest not found error") +class RestNotFoundErrorTest { + + private static final String errorMsgHu = "Nem létező végpont!"; + private static final String errorMsgDefault = "Non-existing endpoint!"; + + /** + * Server url + */ + @TestHTTPResource + URL url; + + @Test + @DisplayName("Testing /versionInfo1111 what is not alive endpoint Without Language header") + void versionInfo11111RestAssuredWithoutLanguageHeader() { + TechnicalFault technicalFault = RestAssured.given() // + .header("Accept", "application/json") + .baseUri(url.toString()) + .when() + .log() + .all() // + .request() + .accept("application/xml") + .get(ServicePath.VERSION_INFO + "1111") // + .then() + .log() + .all() // + .statusCode(404) // + .extract() + .as(TechnicalFault.class); + Assertions.assertNotNull(technicalFault); + Assertions.assertEquals(errorMsgDefault, technicalFault.getMessage()); + Assertions.assertEquals(FaultType.REST_NOT_FOUND.name(), technicalFault.getFaultType()); + + } + + @Test + @DisplayName("Testing /versionInfo1111 what is not alive endpoint with HU header") + void versionInfo11111RestAssuredWithHULanguageHeader() throws Exception { + String responseText = RestAssured.given() // + .header("Accept", "application/json") + .header(ProjectHeader.HEADER_LANGUAGE, "HU") + .baseUri(url.toString()) + .when() + .log() + .all() // + .request() + .accept("application/xml") + .get(ServicePath.VERSION_INFO + "1111") // + .then() + .log() + .all() // + .statusCode(404) // + .extract() + .asString(); + Assertions.assertNotNull(responseText); + TechnicalFault technicalFault = MarshallingUtil.unmarshall(responseText, TechnicalFault.class); + Assertions.assertNotNull(technicalFault); + Assertions.assertEquals(errorMsgHu, technicalFault.getMessage()); + Assertions.assertEquals(FaultType.REST_NOT_FOUND.name(), technicalFault.getFaultType()); + + } +} From 5720818e49411ba78d656bf08c2bb3fe99e8c5d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szab=C3=B3?= Date: Mon, 22 Jan 2024 15:01:58 +0100 Subject: [PATCH 03/10] #4 - fix pom.xml --- pom.xml | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 508f2f3..96634d6 100644 --- a/pom.xml +++ b/pom.xml @@ -295,26 +295,26 @@ - - - - - - - - - - - - - - - - - - - - + + org.apache.maven.plugins + maven-gpg-plugin + 3.1.0 + + + sign-artifacts + verify + + sign + + + + + + --pinentry-mode + loopback + + + org.sonatype.plugins nexus-staging-maven-plugin From f66b364124c38b7b4030a75c6bc2e0fd9716e9a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szab=C3=B3?= Date: Wed, 24 Jan 2024 08:35:39 +0100 Subject: [PATCH 04/10] #4 - gelf logging config --- docs/configs.adoc | 7 +++++++ .../docker-compose.local.qs-rest-service.yml | 6 ++++++ .../qs-rest-service/src/main/resources/application-dev.yml | 3 +++ .../qs-rest-service/src/main/resources/application.yml | 6 +++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/configs.adoc b/docs/configs.adoc index 63b9581..3144ecf 100644 --- a/docs/configs.adoc +++ b/docs/configs.adoc @@ -26,6 +26,13 @@ Fontosabb elemek, melyek alapból már definiálva vannak a projekttel: | quarkus.log.handler.gelf.additional-field."moduleId".value | Gelf log - *moduleId* additional-field value | SAMPLER_LOGSTASH_MODULE_ID | unknown | quarkus.log.handler.gelf.additional-field."K8S_NAMESPACE".value | Gelf log - *K8S_NAMESPACE* additional-field value | SAMPLER_LOGSTASH_K8S_NAMESPACE | unknown | quarkus.handler.gelf.include-full-mdc | Gelf log - Whether to include all fields from the MDC. | SAMPLER_LOGSTASH_K8S_NAMESPACE | false + +| quarkus.handler.gelf.enabled | Gelf log - Enable it | SAMPLER_LOGSTASH_ENABLED | false +| quarkus.handler.gelf.host | Gelf log - tcp host link of logstasth | SAMPLER_LOGSTASTH_HOST | tcp:localhost +| quarkus.handler.gelf.port | Gelf log - port of logstasth | SAMPLER_LOGSTASTH_PORT | 12201 +| quarkus.handler.gelf.version | Gelf log - version of logstasth's communication | SAMPLER_LOGSTASTH_VERSION | 1.1 + + | quarkus.log.level | Quarkus log level: https://quarkus.io/version/3.2/guides/all-config#quarkus-core_quarkus.log.level[Link] | SAMPLER_LOG_LEVEL | INFO | quarkus.log.min-level | Quarkus min log level: https://quarkus.io/version/3.2/guides/all-config#quarkus-core_quarkus.log.min-level[Link] | SAMPLER_LOG_MIN_LEVEL | ALL diff --git a/etc/docker-compose/docker-compose.local.qs-rest-service.yml b/etc/docker-compose/docker-compose.local.qs-rest-service.yml index 0fac0d0..c00814b 100644 --- a/etc/docker-compose/docker-compose.local.qs-rest-service.yml +++ b/etc/docker-compose/docker-compose.local.qs-rest-service.yml @@ -24,6 +24,12 @@ services: environment: # With this config, service use application-dev.yml! - MP_CONFIG_PROFILE=dev + #- SAMPLER_LOGSTASH_MODULE_VERSION=1.0.0-SNAPSHOT + #- SAMPLER_LOGSTASH_MODULE_ID=qs-rest-service-dev + #- SAMPLER_LOGSTASH_K8S_NAMESPACE=test + #- SAMPLER_LOGSTASH_ENABLED=true + #- SAMPLER_LOGSTASTH_HOST=tcp:graylog + #- SAMPLER_LOGSTASTH_PORT=12201 ports: - '8081:8080' # REST - '5006:5005' # Debug diff --git a/qs-services/qs-rest-service/src/main/resources/application-dev.yml b/qs-services/qs-rest-service/src/main/resources/application-dev.yml index 4769898..69d3da1 100644 --- a/qs-services/qs-rest-service/src/main/resources/application-dev.yml +++ b/qs-services/qs-rest-service/src/main/resources/application-dev.yml @@ -8,6 +8,9 @@ quarkus: log: level: INFO min-level: ALL + # handler: + # gelf: + # enabled: ${SAMPLER_LOGSTASH_ENABLED:true} swagger-ui: enable: true # jaeger: diff --git a/qs-services/qs-rest-service/src/main/resources/application.yml b/qs-services/qs-rest-service/src/main/resources/application.yml index 3faa812..015b4b8 100644 --- a/qs-services/qs-rest-service/src/main/resources/application.yml +++ b/qs-services/qs-rest-service/src/main/resources/application.yml @@ -6,7 +6,7 @@ coffee: name: ${quarkus.application.name} config: resource: - bundles: i18n.common-messages,i18n.messages + bundles: i18n.messages xml: catalog: path: xsd/hu/icellmobilsoft/quarkus/sampler/dto/super.catalog.xml @@ -38,6 +38,10 @@ quarkus: "K8S_NAMESPACE": value: ${SAMPLER_LOGSTASH_K8S_NAMESPACE:unknown} include-full-mdc: false + enabled: ${SAMPLER_LOGSTASH_ENABLED:false} + host: ${SAMPLER_LOGSTASTH_HOST:tcp:localhost} + port: ${SAMPLER_LOGSTASTH_PORT:12201} + version: ${SAMPLER_LOGSTASTH_VERSION:1.1} level: ${SAMPLER_LOG_LEVEL:INFO} min-level: ${SAMPLER_LOG_MIN_LEVEL:ALL} jaeger: From 7e4ea1c3a674bd4eab4717d1798340bc567914e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szab=C3=B3?= Date: Wed, 24 Jan 2024 09:36:40 +0100 Subject: [PATCH 05/10] #4 - maven fix --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 96634d6..f449df9 100644 --- a/pom.xml +++ b/pom.xml @@ -173,7 +173,7 @@ native2ascii-maven-plugin - [1.0-beta-1,) + [2.1.0,) native2ascii From edbdd3fc7fe80bdacce0c352c4b206e97e1d23f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szab=C3=B3?= Date: Fri, 2 Feb 2024 15:04:48 +0100 Subject: [PATCH 06/10] #4 - FaultType fix --- pom.xml | 66 ++++++++++++------- .../dto/exception/enums/FaultType.java | 5 +- .../test/ITestQuarkusSamplerServiceRest.java | 5 ++ qs-bom/qs-bom-all/pom.xml | 3 +- qs-common/qs-common-metrics/pom.xml | 7 ++ qs-common/qs-common-rest/pom.xml | 3 +- qs-services/qs-rest-service/pom.xml | 13 ++++ .../rest/action/SamplerTestAction.java | 13 +++- .../sampler/rest/test/PostTestRestTest.java | 2 - 9 files changed, 84 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index f449df9..8c9bbde 100644 --- a/pom.xml +++ b/pom.xml @@ -107,8 +107,16 @@ org.jboss.logmanager.LogManager - ${project.build.directory}/${project.build.finalName}-runner + ${maven.home} + ${settings.localRepository} + ${session.request.userSettingsFile.path} + + ${project.version} + ${project.groupId} + + -Djava.io.tmpdir="${project.build.directory}" + MAVEN_OPTS @@ -116,9 +124,17 @@ maven-surefire-plugin 3.1.2 - + org.jboss.logmanager.LogManager + ${maven.home} + ${settings.localRepository} + ${session.request.userSettingsFile.path} + + ${project.version} + ${project.groupId} + -Xmx1500m -XX:MaxMetaspaceSize=1500m -Djava.io.tmpdir="${project.build.directory}" + MAVEN_OPTS @@ -191,6 +207,10 @@ + + org.apache.maven.plugins + maven-compiler-plugin + org.codehaus.mojo buildnumber-maven-plugin @@ -271,7 +291,7 @@ check-javadoc - true + false @@ -295,26 +315,26 @@ - - org.apache.maven.plugins - maven-gpg-plugin - 3.1.0 - - - sign-artifacts - verify - - sign - - - - - - --pinentry-mode - loopback - - - + + + + + + + + + + + + + + + + + + + + org.sonatype.plugins nexus-staging-maven-plugin diff --git a/qs-api/qs-api-dto/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/dto/exception/enums/FaultType.java b/qs-api/qs-api-dto/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/dto/exception/enums/FaultType.java index df2ed62..d062957 100644 --- a/qs-api/qs-api-dto/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/dto/exception/enums/FaultType.java +++ b/qs-api/qs-api-dto/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/dto/exception/enums/FaultType.java @@ -19,7 +19,7 @@ */ package hu.icellmobilsoft.quarkus.sampler.api.jakarta.dto.exception.enums; -import hu.icellmobilsoft.coffee.dto.error.IFaultType; +import hu.icellmobilsoft.coffee.cdi.annotation.FaultTypeCode; /** * Project specific faults @@ -28,7 +28,8 @@ * @since 0.1.0 * */ -public enum FaultType implements IFaultType { +@FaultTypeCode +public enum FaultType { /** * HTTP 400 Response.Status.BAD_REQUEST
diff --git a/qs-api/qs-api-jakarta/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/test/ITestQuarkusSamplerServiceRest.java b/qs-api/qs-api-jakarta/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/test/ITestQuarkusSamplerServiceRest.java index dd9c5e6..69ceb87 100644 --- a/qs-api/qs-api-jakarta/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/test/ITestQuarkusSamplerServiceRest.java +++ b/qs-api/qs-api-jakarta/src/main/java/hu/icellmobilsoft/quarkus/sampler/api/jakarta/test/ITestQuarkusSamplerServiceRest.java @@ -36,6 +36,7 @@ import hu.icellmobilsoft.coffee.dto.common.commonservice.BaseRequest; import hu.icellmobilsoft.coffee.dto.exception.BaseException; import hu.icellmobilsoft.coffee.rest.log.annotation.LogSpecifier; +import hu.icellmobilsoft.coffee.rest.log.annotation.LogSpecifiers; import hu.icellmobilsoft.coffee.rest.log.annotation.enumeration.LogSpecifierTarget; import hu.icellmobilsoft.quarkus.sampler.api.jakarta.path.QuarkusSamplerPath; import hu.icellmobilsoft.quarkus.sampler.api.schema.XsdConstants; @@ -81,6 +82,10 @@ public interface ITestQuarkusSamplerServiceRest { description = "Dummy operation for testing Sampler service") @Tag(ref = ITestQuarkusSamplerServiceRest.TAG) @GET + @LogSpecifiers(value = { + @LogSpecifier(target = { LogSpecifierTarget.CLIENT_REQUEST }, maxEntityLogSize = 10000), + @LogSpecifier(target = { LogSpecifierTarget.CLIENT_RESPONSE }, maxEntityLogSize = 1000) + }) @Produces(value = { MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.APPLICATION_XML }) TestResponse getTest( @QueryParam(QuarkusSamplerPath.PARAM_TEST_STRING) @Parameter(name = QuarkusSamplerPath.PARAM_TEST_STRING, diff --git a/qs-bom/qs-bom-all/pom.xml b/qs-bom/qs-bom-all/pom.xml index 66a9de3..8340ad7 100644 --- a/qs-bom/qs-bom-all/pom.xml +++ b/qs-bom/qs-bom-all/pom.xml @@ -13,7 +13,7 @@ pom - 2.5.0-SNAPSHOT + 2.6.0-SNAPSHOT 4.4 1.5 @@ -71,7 +71,6 @@ commons-csv ${version.apache.commons-csv} - diff --git a/qs-common/qs-common-metrics/pom.xml b/qs-common/qs-common-metrics/pom.xml index 335e10c..649c075 100644 --- a/qs-common/qs-common-metrics/pom.xml +++ b/qs-common/qs-common-metrics/pom.xml @@ -25,6 +25,13 @@ commons-collections + + + + hu.icellmobilsoft.coffee + coffee-module-mp-metrics + + diff --git a/qs-common/qs-common-rest/pom.xml b/qs-common/qs-common-rest/pom.xml index 7c98e5b..dabbd59 100644 --- a/qs-common/qs-common-rest/pom.xml +++ b/qs-common/qs-common-rest/pom.xml @@ -39,7 +39,7 @@ hu.icellmobilsoft.coffee - coffee-module-mp-restclient + coffee-module-mp-restclient-extension @@ -78,7 +78,6 @@ UTF8 i18n/**/*.properties - target/classes diff --git a/qs-services/qs-rest-service/pom.xml b/qs-services/qs-rest-service/pom.xml index 836fed4..d9d8fdb 100644 --- a/qs-services/qs-rest-service/pom.xml +++ b/qs-services/qs-rest-service/pom.xml @@ -129,6 +129,19 @@ io.quarkus.platform quarkus-maven-plugin
+ + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.platform.version} + + + +
diff --git a/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/action/SamplerTestAction.java b/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/action/SamplerTestAction.java index c6ef901..d88c4ba 100644 --- a/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/action/SamplerTestAction.java +++ b/qs-services/qs-rest-service/src/main/java/hu/icellmobilsoft/quarkus/sampler/rest/action/SamplerTestAction.java @@ -27,6 +27,9 @@ import hu.icellmobilsoft.coffee.cdi.logger.AppLogger; import hu.icellmobilsoft.coffee.cdi.logger.ThisLogger; import hu.icellmobilsoft.coffee.dto.common.commonservice.FunctionCodeType; +import hu.icellmobilsoft.coffee.dto.exception.BaseException; +import hu.icellmobilsoft.coffee.dto.exception.enums.CoffeeFaultType; +import hu.icellmobilsoft.coffee.rest.projectstage.ProjectStage; import hu.icellmobilsoft.quarkus.sampler.common.rest.action.BaseAction; import hu.icellmobilsoft.quarkus.sampler.dto.test.test.TestResponse; @@ -43,6 +46,9 @@ public class SamplerTestAction extends BaseAction { @ThisLogger AppLogger log; + @Inject + ProjectStage projectStage; + /** * Default constructor */ @@ -63,10 +69,13 @@ public SamplerTestAction() { * Query parameter for testing * @return {@link TestResponse} Test response */ - public TestResponse getTest(String testString, Integer testInteger, Long testLong, Boolean testBoolean) { - + public TestResponse getTest(String testString, Integer testInteger, Long testLong, Boolean testBoolean) throws BaseException { log.info(MessageFormat.format("Query parameters: [{0}], [{1}], [{2}], [{3}]", testString, testInteger, testLong, testBoolean)); + + if (!projectStage.isProductionStage()) { + throw new BaseException(CoffeeFaultType.FORBIDDEN,"asdf"); + } TestResponse response = new TestResponse(); response.setFuncCode(FunctionCodeType.OK); handleSuccessResultType(response); diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java index a577074..2d1daf2 100644 --- a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java @@ -23,7 +23,6 @@ import org.eclipse.microprofile.rest.client.RestClientBuilder; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -108,7 +107,6 @@ void postTestXml() throws BaseException { } @Test - @Disabled("This is disabled while ") @DisplayName("test post method in the service with RestClient With error (dto without ContextType") void postTestWithoutContextType() { try { From 6ae8ed2c4245949e1fe690685edb1c7f9398800c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szab=C3=B3?= Date: Mon, 12 Feb 2024 13:20:54 +0100 Subject: [PATCH 07/10] =?UTF-8?q?#4=20-=20Etcd=20bek=C3=B6t=C3=A9se?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docker-compose.local.etcd.yml | 38 +++++++++++ qs-bom/qs-bom-all/pom.xml | 8 ++- qs-common/qs-common-etcd/pom.xml | 5 ++ .../sampler/etcd/EnableRuntimeEtcdConfig.java | 63 ++++++++++++++++++ ...lipse.microprofile.config.spi.ConfigSource | 1 + qs-common/qs-common-rest/pom.xml | 4 -- .../common/rest/jsonb/CustomJsonbConfig.java | 63 ------------------ .../rest/validation/catalog/Starter.java | 8 +-- qs-services/qs-rest-service/pom.xml | 8 +++ .../rest/test/EtcdResourceProfile.java | 65 +++++++++++++++++++ .../quarkus/sampler/rest/test/EtcdTest.java | 43 ++++++++++++ .../sampler/rest/test/GetTestRestTest.java | 5 +- .../{HealthTest.java => MPHealthTest.java} | 7 +- .../sampler/rest/test/PostTestRestTest.java | 4 +- .../sampler/rest/test/PutTestRestTest.java | 6 +- .../sampler/rest/test/VersionInfoTest.java | 5 +- 16 files changed, 250 insertions(+), 83 deletions(-) create mode 100644 etc/docker-compose/docker-compose.local.etcd.yml create mode 100644 qs-common/qs-common-etcd/src/main/java/hu/icellmobilsoft/quarkus/sampler/etcd/EnableRuntimeEtcdConfig.java create mode 100644 qs-common/qs-common-etcd/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource delete mode 100644 qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/jsonb/CustomJsonbConfig.java create mode 100644 qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdResourceProfile.java create mode 100644 qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdTest.java rename qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/{HealthTest.java => MPHealthTest.java} (96%) diff --git a/etc/docker-compose/docker-compose.local.etcd.yml b/etc/docker-compose/docker-compose.local.etcd.yml new file mode 100644 index 0000000..6337ba1 --- /dev/null +++ b/etc/docker-compose/docker-compose.local.etcd.yml @@ -0,0 +1,38 @@ +# futtatas: +# docker compose -f /etc/docker-compose/docker-compose.local.etcd.yml up +# +# belemaszas: +# docker exec -it qs-etcd /bin/bash +version: "3.8" + +services: + qs-etcd: + container_name: qs-etcd + image: 'bitnami/etcd:3' + ports: + - '2379:2379' + environment: + - ALLOW_NONE_AUTHENTICATION=yes + deploy: + resources: + limits: + memory: 128M + cpus: '.5' + reservations: + memory: 32M + cpus: '.5' + healthcheck: + test: etcdctl endpoint health + interval: 1s + timeout: 3s + retries: 5 + etcdsetup: + image: 'bitnami/etcd:3' + depends_on: + qs-etcd: + condition: service_healthy + command: ["sh", "-c", "etcdctl --endpoints=http://qs-etcd:2379 put hello world"] +networks: + default: + external: + name: quarkus-sampler-local-network diff --git a/qs-bom/qs-bom-all/pom.xml b/qs-bom/qs-bom-all/pom.xml index 8340ad7..646f153 100644 --- a/qs-bom/qs-bom-all/pom.xml +++ b/qs-bom/qs-bom-all/pom.xml @@ -15,6 +15,7 @@ 2.6.0-SNAPSHOT 4.4 + 3.2.2 1.5 @@ -45,11 +46,16 @@ hu.icellmobilsoft.coffee - coffee-bom + coffee-bom-project ${version.coffee} pom import + + commons-collections + commons-collections + ${version.commons-collections} + org.apache.commons commons-collections4 diff --git a/qs-common/qs-common-etcd/pom.xml b/qs-common/qs-common-etcd/pom.xml index 35417c8..15fe542 100644 --- a/qs-common/qs-common-etcd/pom.xml +++ b/qs-common/qs-common-etcd/pom.xml @@ -28,6 +28,11 @@ coffee-module-configdoc + + + io.quarkus + quarkus-core + diff --git a/qs-common/qs-common-etcd/src/main/java/hu/icellmobilsoft/quarkus/sampler/etcd/EnableRuntimeEtcdConfig.java b/qs-common/qs-common-etcd/src/main/java/hu/icellmobilsoft/quarkus/sampler/etcd/EnableRuntimeEtcdConfig.java new file mode 100644 index 0000000..0151fed --- /dev/null +++ b/qs-common/qs-common-etcd/src/main/java/hu/icellmobilsoft/quarkus/sampler/etcd/EnableRuntimeEtcdConfig.java @@ -0,0 +1,63 @@ +/*- + * #%L + * Quarkus-sampler + * %% + * Copyright (C) 2024 i-Cell Mobilsoft Zrt. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package hu.icellmobilsoft.quarkus.sampler.etcd; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.event.Observes; + +import org.jboss.logging.Logger; + +import hu.icellmobilsoft.coffee.module.etcd.producer.RuntimeEtcdConfigSource; +import io.quarkus.runtime.ShutdownEvent; +import io.quarkus.runtime.StartupEvent; + +/** + * Enable Runtime Etcd config + * + * @since 0.1.0 + * @author speter555 + */ +@ApplicationScoped +public class EnableRuntimeEtcdConfig { + + private final Logger LOGGER = Logger.getLogger(EnableRuntimeEtcdConfig.class); + + /** + * Startup event where etcd config is enabled + * + * @param ev + * startup event + */ + void onStart(@Observes StartupEvent ev) { + LOGGER.info("The application is starting..."); + RuntimeEtcdConfigSource.setActive(true); + } + + /** + * Shutdown event where etcd config is disabled + * + * @param ev + * shutdown event + */ + void onStop(@Observes ShutdownEvent ev) { + LOGGER.info("The application is stopping..."); + RuntimeEtcdConfigSource.setActive(false); + } +} diff --git a/qs-common/qs-common-etcd/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource b/qs-common/qs-common-etcd/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource new file mode 100644 index 0000000..888b993 --- /dev/null +++ b/qs-common/qs-common-etcd/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource @@ -0,0 +1 @@ +hu.icellmobilsoft.coffee.module.etcd.producer.RuntimeEtcdConfigSource diff --git a/qs-common/qs-common-rest/pom.xml b/qs-common/qs-common-rest/pom.xml index dabbd59..39641f8 100644 --- a/qs-common/qs-common-rest/pom.xml +++ b/qs-common/qs-common-rest/pom.xml @@ -43,10 +43,6 @@ - - io.quarkus - quarkus-resteasy-jsonb - diff --git a/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/jsonb/CustomJsonbConfig.java b/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/jsonb/CustomJsonbConfig.java deleted file mode 100644 index 95310e2..0000000 --- a/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/jsonb/CustomJsonbConfig.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * #%L - * Quarkus-sampler - * %% - * Copyright (C) 2024 i-Cell Mobilsoft Zrt. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ -package hu.icellmobilsoft.quarkus.sampler.common.rest.jsonb; - -import jakarta.enterprise.context.Dependent; -import jakarta.enterprise.inject.Instance; -import jakarta.json.bind.JsonbConfig; -import jakarta.json.bind.config.BinaryDataStrategy; - -import org.eclipse.yasson.FieldAccessStrategy; - -import io.quarkus.jsonb.JsonbConfigCustomizer; - -/** - * Jsonb Config customize - * - * @since 0.1.0 - * @author speter555 - */ -public class CustomJsonbConfig { - - /** - * Default constructor - */ - public CustomJsonbConfig() { - // Default constructor for java 21 - } - - // Replaces the CDI producer for JsonbConfig built into Quarkus - @Dependent - JsonbConfig jsonConfig(Instance customizers) { - - JsonbConfig config = new JsonbConfig() - // property visibility strategy setting - .withPropertyVisibilityStrategy(new FieldAccessStrategy()) - .withBinaryDataStrategy(BinaryDataStrategy.BASE_64); - // Apply all JsonbConfigCustomizer beans (incl. Quarkus) - // Default customizer in quarkus: io.quarkus.jsonb.customizer.RegisterSerializersAndDeserializersCustomizer (it is a virtual class) - for (JsonbConfigCustomizer customizer : customizers) { - customizer.customize(config); - } - - return config; - } - -} diff --git a/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/validation/catalog/Starter.java b/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/validation/catalog/Starter.java index 3ba7e9e..c6d2ed0 100644 --- a/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/validation/catalog/Starter.java +++ b/qs-common/qs-common-rest/src/main/java/hu/icellmobilsoft/quarkus/sampler/common/rest/validation/catalog/Starter.java @@ -25,12 +25,12 @@ import java.text.MessageFormat; import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.context.Initialized; import jakarta.enterprise.event.Observes; import org.jboss.logging.Logger; import hu.icellmobilsoft.coffee.rest.validation.catalog.MavenURLStreamHandlerProvider; +import io.quarkus.runtime.StartupEvent; /** * Common application starter. Starting on {@code StartupEvent} event @@ -53,10 +53,10 @@ public Starter() { /** * Must be set maven url resolver into URL factory * - * @param init - * cdi init ibject + * @param ev + * Startup event */ - public void init(@Observes @Initialized(ApplicationScoped.class) Object init) { + public void init(@Observes StartupEvent ev) { String pkgs = System.getProperty("java.protocol.handler.pkgs", ""); LOGGER.debug(MessageFormat.format("\n\nStarter\n\npkgs: [{0}]\n\n", pkgs)); diff --git a/qs-services/qs-rest-service/pom.xml b/qs-services/qs-rest-service/pom.xml index d9d8fdb..0d43d73 100644 --- a/qs-services/qs-rest-service/pom.xml +++ b/qs-services/qs-rest-service/pom.xml @@ -11,6 +11,9 @@ qs-rest-service + + --add-opens java.base/java.lang=ALL-UNNAMED + @@ -120,6 +123,11 @@ rest-assured test + + + org.testcontainers + testcontainers + diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdResourceProfile.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdResourceProfile.java new file mode 100644 index 0000000..531d093 --- /dev/null +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdResourceProfile.java @@ -0,0 +1,65 @@ +/*- + * #%L + * Quarkus-sampler + * %% + * Copyright (C) 2024 i-Cell Mobilsoft Zrt. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package hu.icellmobilsoft.quarkus.sampler.rest.test; + +import java.time.Duration; +import java.util.HashMap; +import java.util.Map; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.wait.strategy.Wait; + +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; + +public class EtcdResourceProfile implements QuarkusTestResourceLifecycleManager { + + private static final String ETCD_DOCKER_IMAGE = "dockerhub-dockerio.icellmobilsoft.hu/bitnami/etcd:3"; + protected static GenericContainer etcd; + public static Network network = Network.newNetwork(); + + static { + etcd = new GenericContainer(ETCD_DOCKER_IMAGE).withEnv("ALLOW_NONE_AUTHENTICATION", "yes") + .waitingFor(Wait.forSuccessfulCommand("etcdctl endpoint health").withStartupTimeout(Duration.ofSeconds(10))) + .withExposedPorts(2379) + .withNetwork(network) + .withNetworkAliases("qs-etcd"); + etcd.start(); + String command = "etcdctl --endpoints=http://qs-etcd:2379 put hello world"; + + GenericContainer etcdSetup = new GenericContainer(ETCD_DOCKER_IMAGE).dependsOn(etcd).withCommand(command).withNetwork(network); + etcdSetup.start(); + etcdSetup.stop(); + } + + public Map start() { + Map conf = new HashMap<>(); + conf.put("coffee.etcd.default.url", "http://localhost:" + etcd.getMappedPort(2379)); + System.setProperty("coffee.etcd.default.url", "http://localhost:" + etcd.getMappedPort(2379)); + return conf; + } + + @Override + public void stop() { + if (etcd != null) { + etcd.stop(); + } + } +} diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdTest.java new file mode 100644 index 0000000..b88ec67 --- /dev/null +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdTest.java @@ -0,0 +1,43 @@ +/*- + * #%L + * Quarkus-sampler + * %% + * Copyright (C) 2024 i-Cell Mobilsoft Zrt. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package hu.icellmobilsoft.quarkus.sampler.rest.test; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import jakarta.inject.Inject; + +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +@QuarkusTest +@QuarkusTestResource(value = EtcdResourceProfile.class) +class EtcdTest { + + @Inject + @ConfigProperty(name = "hello", defaultValue = "default") + String configValue; + + @Test + void test() { + Assertions.assertNotNull(configValue); + Assertions.assertEquals("world", configValue); + } +} diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/GetTestRestTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/GetTestRestTest.java index 32c7249..7231581 100644 --- a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/GetTestRestTest.java +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/GetTestRestTest.java @@ -21,6 +21,8 @@ import java.net.URL; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; import org.eclipse.microprofile.rest.client.RestClientBuilder; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -32,14 +34,13 @@ import hu.icellmobilsoft.quarkus.sampler.api.jakarta.test.ITestQuarkusSamplerServiceRest; import hu.icellmobilsoft.quarkus.sampler.dto.test.test.TestResponse; import io.quarkus.test.common.http.TestHTTPResource; -import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; /** * Quarkus test example for ITestQuarkusSamplerServiceRest interface test. */ @QuarkusTest -@DisplayName("test get test method in the service with RestAssured") +@QuarkusTestResource(value = EtcdResourceProfile.class) class GetTestRestTest { /** diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/HealthTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/MPHealthTest.java similarity index 96% rename from qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/HealthTest.java rename to qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/MPHealthTest.java index 6808923..a942807 100644 --- a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/HealthTest.java +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/MPHealthTest.java @@ -23,6 +23,8 @@ import java.net.HttpURLConnection; import java.net.URL; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; import jakarta.json.bind.Jsonb; import jakarta.json.bind.JsonbBuilder; @@ -33,12 +35,11 @@ import hu.icellmobilsoft.quarkus.sampler.rest.test.dto.HealthDto; import io.quarkus.test.common.http.TestHTTPResource; -import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; @QuarkusTest -@DisplayName("Testing mp-health") -class HealthTest { +@QuarkusTestResource(value = EtcdResourceProfile.class) +class MPHealthTest { private static final String STATUS_JSON_PATH = "status"; diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java index 2d1daf2..3395161 100644 --- a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PostTestRestTest.java @@ -21,6 +21,8 @@ import java.net.URL; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; import org.eclipse.microprofile.rest.client.RestClientBuilder; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -37,13 +39,13 @@ import hu.icellmobilsoft.quarkus.sampler.dto.test.post.SampleResponse; import hu.icellmobilsoft.quarkus.sampler.rest.test.restclient.XmlITestQuarkusSamplerServiceRest; import io.quarkus.test.common.http.TestHTTPResource; -import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; /** * Quarkus test example for ITestQuarkusSamplerServiceRest interface test. */ @QuarkusTest +@QuarkusTestResource(value = EtcdResourceProfile.class) class PostTestRestTest { /** diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PutTestRestTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PutTestRestTest.java index 4b1bb1b..0f4e13a 100644 --- a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PutTestRestTest.java +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/PutTestRestTest.java @@ -21,9 +21,10 @@ import java.net.URL; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; import org.eclipse.microprofile.rest.client.RestClientBuilder; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -38,13 +39,13 @@ import hu.icellmobilsoft.quarkus.sampler.dto.test.post.SampleResponse; import hu.icellmobilsoft.quarkus.sampler.rest.test.restclient.XmlITestQuarkusSamplerServiceRest; import io.quarkus.test.common.http.TestHTTPResource; -import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; /** * Quarkus test example for ITestQuarkusSamplerServiceRest interface test. */ @QuarkusTest +@QuarkusTestResource(value = EtcdResourceProfile.class) class PutTestRestTest { /** @@ -108,7 +109,6 @@ void putTestXml() throws BaseException { } @Test - @Disabled @DisplayName("test post method in the service with RestClient With error (dto without ContextType") void putTestWithoutContextType() { try { diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/VersionInfoTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/VersionInfoTest.java index 84286f1..2124079 100644 --- a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/VersionInfoTest.java +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/VersionInfoTest.java @@ -21,6 +21,8 @@ import java.net.URL; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; import org.eclipse.microprofile.rest.client.RestClientBuilder; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -30,7 +32,6 @@ import hu.icellmobilsoft.quarkus.sampler.api.jakarta.path.ServicePath; import hu.icellmobilsoft.quarkus.sampler.api.jakarta.system.ISystemRest; import io.quarkus.test.common.http.TestHTTPResource; -import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -38,7 +39,7 @@ * Quarkus test example for VersionInfo endpoint. */ @QuarkusTest -@DisplayName("Testing versionInfo endpoint") +@QuarkusTestResource(value = EtcdResourceProfile.class) class VersionInfoTest { /** From 662c7e6a61b7afc49742dcbbf992161d3a098bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szab=C3=B3?= Date: Mon, 12 Feb 2024 15:32:07 +0100 Subject: [PATCH 08/10] #4 - fix docker image --- .../quarkus/sampler/rest/test/EtcdResourceProfile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdResourceProfile.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdResourceProfile.java index 531d093..b1480f7 100644 --- a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdResourceProfile.java +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdResourceProfile.java @@ -31,7 +31,7 @@ public class EtcdResourceProfile implements QuarkusTestResourceLifecycleManager { - private static final String ETCD_DOCKER_IMAGE = "dockerhub-dockerio.icellmobilsoft.hu/bitnami/etcd:3"; + private static final String ETCD_DOCKER_IMAGE = "bitnami/etcd:3"; protected static GenericContainer etcd; public static Network network = Network.newNetwork(); From da49befed8fde4882316fb0001d171372b37a902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szab=C3=B3?= Date: Mon, 12 Feb 2024 16:08:48 +0100 Subject: [PATCH 09/10] #4 - fix windows build --- .github/workflows/compile_maven.yml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile_maven.yml b/.github/workflows/compile_maven.yml index dace6df..2fb17a5 100644 --- a/.github/workflows/compile_maven.yml +++ b/.github/workflows/compile_maven.yml @@ -11,10 +11,10 @@ on: - 'dependabot/**' jobs: - compile-on-os-with-jdk: + compile-on-linux-with-jdk: strategy: matrix: - os: [ 'ubuntu-latest', 'windows-latest' ] + os: [ 'ubuntu-latest'] java: [ '17', '21' ] runs-on: ${{ matrix.os }} name: Compile on ${{ matrix.os }} with JDK ${{ matrix.java }} @@ -34,3 +34,28 @@ jobs: # Maven script [ package ] - name: Build with Maven run: mvn -B package --file pom.xml + + + compile-on-windows-with-jdk: + strategy: + matrix: + os: [ 'windows-latest' ] + java: [ '17', '21' ] + runs-on: ${{ matrix.os }} + name: Compile on ${{ matrix.os }} with JDK ${{ matrix.java }} + steps: + + # https://github.com/actions/checkout + - uses: actions/checkout@v4 + + # https://github.com/actions/setup-java + - name: Set up JDK ${{ matrix.java }} + uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.java }} + distribution: 'temurin' + cache: 'maven' + + # Maven script [ package ] without Test (testcoiners is not working on windows host) + - name: Build with Maven + run: mvn -B package --file pom.xml -DskipTests=true From 84aa8dfa6c977e992ac793eac744d11ed88873f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szab=C3=B3?= Date: Mon, 12 Feb 2024 21:18:04 +0100 Subject: [PATCH 10/10] #4 - fix etcd test --- qs-services/qs-rest-service/pom.xml | 1 + .../quarkus/sampler/rest/test/EtcdTest.java | 15 +++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/qs-services/qs-rest-service/pom.xml b/qs-services/qs-rest-service/pom.xml index 0d43d73..cd959b3 100644 --- a/qs-services/qs-rest-service/pom.xml +++ b/qs-services/qs-rest-service/pom.xml @@ -14,6 +14,7 @@ --add-opens java.base/java.lang=ALL-UNNAMED + diff --git a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdTest.java b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdTest.java index b88ec67..dbac51f 100644 --- a/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdTest.java +++ b/qs-services/qs-rest-service/src/test/java/hu/icellmobilsoft/quarkus/sampler/rest/test/EtcdTest.java @@ -19,25 +19,20 @@ */ package hu.icellmobilsoft.quarkus.sampler.rest.test; -import io.quarkus.test.common.QuarkusTestResource; -import io.quarkus.test.junit.QuarkusTest; -import jakarta.inject.Inject; - -import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.config.ConfigProvider; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + @QuarkusTest @QuarkusTestResource(value = EtcdResourceProfile.class) class EtcdTest { - @Inject - @ConfigProperty(name = "hello", defaultValue = "default") - String configValue; - @Test void test() { - Assertions.assertNotNull(configValue); + String configValue = ConfigProvider.getConfig().getOptionalValue("hello", String.class).orElse("default"); Assertions.assertEquals("world", configValue); } }