From 6fcf219cab73b83e0179a8f6f8233f7ca11aaf92 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Mon, 15 Aug 2022 11:54:34 +0200 Subject: [PATCH] Move code-first ClientGreetingClientTest to the client test module --- .../it/cxf/GreetingClientWebService.java | 17 ---- .../it/cxf/ClientGreetingClientTest.java | 95 ------------------- .../cxf/client/it/CodeFirstClient.java | 34 +++++++ .../cxf/client/it/CxfClientResource.java | 11 +++ .../src/main/resources/application.properties | 6 ++ .../cxf/client/it/CxfClientTest.java | 15 +++ 6 files changed, 66 insertions(+), 112 deletions(-) delete mode 100644 integration-tests/basic/src/main/java/io/quarkiverse/it/cxf/GreetingClientWebService.java delete mode 100644 integration-tests/basic/src/test/java/io/quarkiverse/it/cxf/ClientGreetingClientTest.java create mode 100644 integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CodeFirstClient.java diff --git a/integration-tests/basic/src/main/java/io/quarkiverse/it/cxf/GreetingClientWebService.java b/integration-tests/basic/src/main/java/io/quarkiverse/it/cxf/GreetingClientWebService.java deleted file mode 100644 index 126dc65ec..000000000 --- a/integration-tests/basic/src/main/java/io/quarkiverse/it/cxf/GreetingClientWebService.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.quarkiverse.it.cxf; - -import javax.jws.WebMethod; -import javax.jws.WebParam; -import javax.jws.WebService; -import javax.xml.ws.RequestWrapper; - -@WebService -public interface GreetingClientWebService { - - @WebMethod - String reply(@WebParam(name = "text") String text); - - @WebMethod - @RequestWrapper(localName = "Ping", targetNamespace = "http://cxf.it.quarkiverse.io/", className = "io.quarkiverse.it.cxf.Ping") - String ping(@WebParam(name = "text") String text); -} \ No newline at end of file diff --git a/integration-tests/basic/src/test/java/io/quarkiverse/it/cxf/ClientGreetingClientTest.java b/integration-tests/basic/src/test/java/io/quarkiverse/it/cxf/ClientGreetingClientTest.java deleted file mode 100644 index 500cb2a49..000000000 --- a/integration-tests/basic/src/test/java/io/quarkiverse/it/cxf/ClientGreetingClientTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package io.quarkiverse.it.cxf; - -import static io.restassured.RestAssured.given; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.lang.reflect.Proxy; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.xml.ws.WebServiceException; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import io.quarkiverse.cxf.CXFClientInfo; -import io.quarkiverse.cxf.annotation.CXFClient; -import io.quarkus.test.junit.QuarkusTest; - -/** - * {@link GreetingClientWebService} is SEI-identical with {@link GreetingWebService}. This test is - * about whether we can access {@code GreetingWebService}'s EP via {@code GreetingClientWebService}. - */ -@QuarkusTest -class ClientGreetingClientTest { - - @Inject - @CXFClient - GreetingClientWebService defaultClient; - - @Inject - @CXFClient("greetingclient") - GreetingClientWebService greetingClient; - - @Inject - @CXFClient("greetingclient-fault") - GreetingClientWebService faultyClient; - - @Inject - @Named("io.quarkiverse.it.cxf.GreetingClientWebService") - CXFClientInfo greetingInfo; - - @Test - public void testClientProxyInjected() { - Assertions.assertNotNull(defaultClient); - Assertions.assertNotNull(greetingClient); - Assertions.assertNotNull(faultyClient); - } - - @Test - public void testClientProxyIsproxy() { - assertTrue(Proxy.isProxyClass(defaultClient.getClass())); - assertTrue(Proxy.isProxyClass(greetingClient.getClass())); - assertTrue(Proxy.isProxyClass(faultyClient.getClass())); - } - - @Test - public void testClientInfoInjected() { - Assertions.assertNotNull(greetingInfo); - } - - @Test - public void testDefaultEpAddress() { - Assertions.assertEquals( - "http://localhost:8080/io.quarkiverse.it.cxf.greetingclientwebservice", - this.greetingInfo.getEndpointAddress()); - } - - @Test - public void testActiveEpAddress() { - /* Too bad - there is no way of retrieving this information */ - assertTrue(true); - } - - @Test - public void testWsdlAvailable() { - // http://localhost:8081/soap/greeting - // TODO: get dynamically quarkus' test port. - given().port(8081) - .when().get("/soap/greeting?wsdl") - .then().statusCode(200); - } - - @Test - public void testPing() { - Assertions.assertEquals("Hello hello", greetingClient.ping("hello")); - Assertions.assertEquals("Hello hello", defaultClient.ping("hello")); - } - - @Test - public void testOutInterceptorPresent() { - Assertions.assertThrows(WebServiceException.class, () -> { - faultyClient.ping("hello"); - }); - } -} diff --git a/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CodeFirstClient.java b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CodeFirstClient.java new file mode 100644 index 000000000..72227e552 --- /dev/null +++ b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CodeFirstClient.java @@ -0,0 +1,34 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual + * contributors by the @authors tag. See the copyright.txt in the + * distribution for a full listing of individual contributors. + * + * 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. + */ +package io.quarkiverse.cxf.client.it; + +import javax.jws.WebMethod; +import javax.jws.WebService; + +/** + * An incomplete copy of + * https://github.com/l2x6/calculator-ws/blob/1.0/src/main/java/org/jboss/as/quickstarts/wscalculator/CalculatorService.java + * CXF should be able to use this to produce a partial client communicating with a compatible service endpoint. + */ +@WebService(targetNamespace = CodeFirstClient.TARGET_NS, name = "CalculatorService") +public interface CodeFirstClient { + + public static final String TARGET_NS = "http://www.jboss.org/eap/quickstarts/wscalculator/Calculator"; + + @WebMethod + public int multiply(int intA, int intB); +} diff --git a/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CxfClientResource.java b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CxfClientResource.java index c82815da2..eae3e6f5c 100644 --- a/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CxfClientResource.java +++ b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CxfClientResource.java @@ -31,6 +31,10 @@ public class CxfClientResource { @CXFClient("mySkewedCalculator") // name used in application.properties CalculatorService mySkewedCalculator; + @Inject + @CXFClient("codeFirstClient") // name used in application.properties + CodeFirstClient codeFirstClient; + @Inject @CXFClient("myFaultyCalculator") // name used in application.properties CalculatorService myFaultyCalculator; @@ -50,6 +54,13 @@ public Response multiplyDefault(@PathParam("client") String client, @QueryParam( } } + @GET + @Path("/codeFirstClient/multiply") + @Produces(MediaType.TEXT_PLAIN) + public int codeFirstClient(@PathParam("client") String client, @QueryParam("a") int a, @QueryParam("b") int b) { + return codeFirstClient.multiply(a, b); + } + @GET @Path("/calculator/{client}/addOperands") @Produces(MediaType.TEXT_PLAIN) diff --git a/integration-tests/client/src/main/resources/application.properties b/integration-tests/client/src/main/resources/application.properties index 1568e2921..2ad3662e7 100644 --- a/integration-tests/client/src/main/resources/application.properties +++ b/integration-tests/client/src/main/resources/application.properties @@ -15,3 +15,9 @@ quarkus.cxf.client.mySkewedCalculator.wsdl=${cxf.it.skewed-calculator.baseUri}/c quarkus.cxf.client.mySkewedCalculator.client-endpoint-url=${cxf.it.skewed-calculator.baseUri}/calculator-ws/CalculatorService quarkus.cxf.client.mySkewedCalculator.endpoint-namespace=http://www.jboss.org/eap/quickstarts/wscalculator/Calculator quarkus.cxf.client.mySkewedCalculator.endpoint-name=Calculator + +#quarkus.cxf.client.codeFirstClient.wsdl=${cxf.it.calculator.baseUri}/calculator-ws/CalculatorService?wsdl +quarkus.cxf.client.codeFirstClient.client-endpoint-url=${cxf.it.calculator.baseUri}/calculator-ws/CalculatorService +quarkus.cxf.client.codeFirstClient.service-interface=io.quarkiverse.cxf.client.it.CodeFirstClient +quarkus.cxf.client.codeFirstClient.endpoint-namespace=http://www.jboss.org/eap/quickstarts/wscalculator/Calculatorrr +quarkus.cxf.client.codeFirstClient.endpoint-name=CalculatorService diff --git a/integration-tests/client/src/test/java/io/quarkiverse/cxf/client/it/CxfClientTest.java b/integration-tests/client/src/test/java/io/quarkiverse/cxf/client/it/CxfClientTest.java index 73d6bac1a..4ba2406cf 100644 --- a/integration-tests/client/src/test/java/io/quarkiverse/cxf/client/it/CxfClientTest.java +++ b/integration-tests/client/src/test/java/io/quarkiverse/cxf/client/it/CxfClientTest.java @@ -73,6 +73,20 @@ void outInterceptor() { .body(is("No luck at this time, Luke!")); } + /** + * Test whether a code-first client (without WSDL) works properly. + */ + @Test + void codeFirstClient() { + RestAssured.given() + .queryParam("a", 3) + .queryParam("b", 4) + .get("/cxf/client/codeFirstClient/multiply") + .then() + .statusCode(200) + .body(is("12")); + } + /** * Check whether we can get the WSDL URL configured in application.properties from the application code via * {@link CXFClientInfo}. @@ -123,6 +137,7 @@ void wsdlUpToDate() throws IOException { .getValue("quarkus.cxf.client.myCalculator.wsdl", String.class); final String staticCopyPath = "src/main/cxf-codegen-resources/wsdl/CalculatorService.wsdl"; + /* The changing Docker IP address in the WSDL should not matter */ final String sanitizerRegex = ""; final String staticCopyContent = Files .readString(Paths.get(staticCopyPath), StandardCharsets.UTF_8)