You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2022/12/01 07:06:41 UTC

[camel-quarkus] 08/08: Test Java first CXF server endpoint with multiple SEI methods #4306

This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch 2.13.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 1db470c2a8581189e883382e2ee9d77bc2318b52
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Wed Nov 30 14:11:57 2022 +0100

    Test Java first CXF server endpoint with multiple SEI methods #4306
---
 .../cxf/soap/server/it}/CodeFirstService.java      | 15 ++++++--
 .../cxf/soap/server/it/CxfSoapRoutes.java          | 13 ++++++-
 .../cxf/soap/server/it/CxfSoapServiceTest.java     | 43 ++++++++++++++--------
 3 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/integration-test-groups/cxf-soap/cxf-soap-server/src/main/java/com/helloworld/service/CodeFirstService.java b/integration-test-groups/cxf-soap/cxf-soap-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CodeFirstService.java
similarity index 62%
rename from integration-test-groups/cxf-soap/cxf-soap-server/src/main/java/com/helloworld/service/CodeFirstService.java
rename to integration-test-groups/cxf-soap/cxf-soap-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CodeFirstService.java
index c3fc931c12..245e0e210b 100644
--- a/integration-test-groups/cxf-soap/cxf-soap-server/src/main/java/com/helloworld/service/CodeFirstService.java
+++ b/integration-test-groups/cxf-soap/cxf-soap-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CodeFirstService.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.helloworld.service;
+package org.apache.camel.quarkus.component.cxf.soap.server.it;
 
 import javax.jws.WebMethod;
 import javax.jws.WebParam;
@@ -23,11 +23,18 @@ import javax.jws.WebService;
 import javax.jws.soap.SOAPBinding;
 import javax.jws.soap.SOAPBinding.ParameterStyle;
 
-@WebService(targetNamespace = "http://www.helloworld.com/CodeFirstService/", name = "CodeFirstService")
+@WebService(targetNamespace = CodeFirstService.TARGET_NS, name = "CodeFirstService", serviceName = "CodeFirstService")
 @SOAPBinding(parameterStyle = ParameterStyle.BARE)
 public interface CodeFirstService {
+    public static final String TARGET_NS = "http://www.helloworld.com/CodeFirstService/";
+
     @WebMethod(operationName = "Hello", action = "https://www.helloworld.com/CodeFirstService/Hello")
-    @WebResult(name = "HelloResponse", targetNamespace = "http://www.helloworld.com/CodeFirstService/")
+    @WebResult(name = "HelloResponse", targetNamespace = TARGET_NS)
     String hello(
-            @WebParam(name = "HelloRequest", targetNamespace = "http://www.helloworld.com/CodeFirstService/") String var1);
+            @WebParam(name = "HelloRequest", targetNamespace = TARGET_NS) String var1);
+
+    @WebMethod(operationName = "GoodBye", action = "https://www.helloworld.com/CodeFirstService/GoodBye")
+    @WebResult(name = "GoodByeResponse", targetNamespace = TARGET_NS)
+    String goodBye(
+            @WebParam(name = "GoodByeRequest", targetNamespace = TARGET_NS) String var1);
 }
diff --git a/integration-test-groups/cxf-soap/cxf-soap-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CxfSoapRoutes.java b/integration-test-groups/cxf-soap/cxf-soap-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CxfSoapRoutes.java
index 46fa8ad7a0..45e09365a7 100644
--- a/integration-test-groups/cxf-soap/cxf-soap-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CxfSoapRoutes.java
+++ b/integration-test-groups/cxf-soap/cxf-soap-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CxfSoapRoutes.java
@@ -30,7 +30,6 @@ import javax.xml.xpath.XPathConstants;
 
 import org.w3c.dom.Element;
 
-import com.helloworld.service.CodeFirstService;
 import com.helloworld.service.HelloPortType;
 import com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl;
 import org.apache.camel.builder.RouteBuilder;
@@ -67,7 +66,17 @@ public class CxfSoapRoutes extends RouteBuilder {
                         .setBody().simple("Hello ${body} from CXF service");
 
         from("cxf:bean:codeFirstServiceEndpoint")
-                .setBody().constant("Hello CamelQuarkusCXF");
+                .choice()
+                .when(simple("${header.operationName} == 'Hello'"))
+                .setBody().simple("Hello ${body} code first")
+                .endChoice()
+                .when(simple("${header.operationName} == 'GoodBye'"))
+                .setBody().simple("Good bye ${body} code first")
+                .endChoice()
+                .otherwise()
+                .process(e -> {
+                    throw new IllegalStateException("Unexpected operation " + e.getMessage().getHeader("operationName"));
+                });
 
         from("cxf:bean:echoServiceResponseFromRouteCxfMessageDataFormat")
                 .process(exchange -> {
diff --git a/integration-test-groups/cxf-soap/cxf-soap-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CxfSoapServiceTest.java b/integration-test-groups/cxf-soap/cxf-soap-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CxfSoapServiceTest.java
index 60dec478d7..79106560aa 100644
--- a/integration-test-groups/cxf-soap/cxf-soap-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CxfSoapServiceTest.java
+++ b/integration-test-groups/cxf-soap/cxf-soap-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/server/it/CxfSoapServiceTest.java
@@ -24,14 +24,18 @@ import io.quarkiverse.cxf.test.QuarkusCxfClientTestUtil;
 import io.quarkus.runtime.LaunchMode;
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
-import io.restassured.http.ContentType;
+import io.restassured.config.RestAssuredConfig;
 import org.eclipse.microprofile.config.Config;
 import org.eclipse.microprofile.config.ConfigProvider;
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.Matchers;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
 
+import static io.quarkiverse.cxf.test.QuarkusCxfClientTestUtil.anyNs;
+
 @QuarkusTest
 class CxfSoapServiceTest {
 
@@ -53,24 +57,33 @@ class CxfSoapServiceTest {
     }
 
     @Test
-    public void testCodeFirstSoapService() {
+    public void codeFirstWsdl() {
 
-        final String response = RestAssured.given()
-                .contentType(ContentType.XML)
-                .body("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://www.helloworld.com/CodeFirstService/\">\n"
-                        +
-                        "   <soapenv:Header/>\n" +
-                        "   <soapenv:Body>\n" +
-                        "      <ser:HelloRequest>HelloWorld</ser:HelloRequest>\n" +
-                        "   </soapenv:Body>\n" +
-                        "</soapenv:Envelope>")
-                .post("/soapservice/codefirst")
+        RestAssuredConfig config = RestAssured.config();
+        config.getXmlConfig().namespaceAware(false);
+        RestAssured.given()
+                .config(config)
+                .when().get("/soapservice/codefirst?wsdl")
                 .then()
                 .statusCode(200)
-                .assertThat()
-                .extract().asString();
+                .body(
+                        /* Make sure that the two operations are available in the generated WSDL */
+                        Matchers.hasXPath(
+                                anyNs("definitions", "binding", "operation")
+                                        + "[1]/@*[local-name() = 'name']",
+                                CoreMatchers.is("GoodBye")),
+                        Matchers.hasXPath(
+                                anyNs("definitions", "binding", "operation")
+                                        + "[2]/@*[local-name() = 'name']",
+                                CoreMatchers.is("Hello")));
+    }
 
-        org.junit.jupiter.api.Assertions.assertTrue(response.contains("Hello CamelQuarkusCXF"));
+    @Test
+    public void codeFirstSoapService() {
+        final CodeFirstService client = QuarkusCxfClientTestUtil.getClient(CodeFirstService.TARGET_NS, CodeFirstService.class,
+                "/soapservice/codefirst");
+        Assertions.assertEquals("Hello Joe code first", client.hello("Joe"));
+        Assertions.assertEquals("Good bye Laszlo code first", client.goodBye("Laszlo"));
     }
 
     @ParameterizedTest