You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2021/02/19 12:38:53 UTC

[camel-kafka-connector] branch camel-master updated: Abstracted the CXF service client setup from the CXF test code

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

orpiske pushed a commit to branch camel-master
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector.git


The following commit(s) were added to refs/heads/camel-master by this push:
     new 65415a9  Abstracted the CXF service client setup from the CXF test code
65415a9 is described below

commit 65415a953d99a89b2477b58a4af2ca6378cc1cb6
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Fri Feb 19 12:07:54 2021 +0100

    Abstracted the CXF service client setup from the CXF test code
---
 .../kafkaconnector/cxf/client/CXFServiceUtil.java  | 48 ++++++++++++++++++++++
 .../cxf/source/CamelSourceCXFITCase.java           | 18 +-------
 2 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/tests/itests-cxf/src/test/java/org/apache/camel/kafkaconnector/cxf/client/CXFServiceUtil.java b/tests/itests-cxf/src/test/java/org/apache/camel/kafkaconnector/cxf/client/CXFServiceUtil.java
new file mode 100644
index 0000000..67a060c
--- /dev/null
+++ b/tests/itests-cxf/src/test/java/org/apache/camel/kafkaconnector/cxf/client/CXFServiceUtil.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.kafkaconnector.cxf.client;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.ext.logging.LoggingInInterceptor;
+import org.apache.cxf.ext.logging.LoggingOutInterceptor;
+import org.apache.cxf.frontend.ClientFactoryBean;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+
+public final class CXFServiceUtil {
+
+    private CXFServiceUtil() {
+
+    }
+
+    public static <T> T getService(String address, Class<T> clazz) {
+        ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
+        ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
+
+        clientBean.setAddress(address);
+        clientBean.setServiceClass(clazz);
+
+        Bus bus = BusFactory.newInstance().createBus();
+        clientBean.setBus(bus);
+
+        bus.getInInterceptors().add(new LoggingInInterceptor());
+        bus.getOutInterceptors().add(new LoggingOutInterceptor());
+
+        return (T) proxyFactory.create();
+    }
+}
diff --git a/tests/itests-cxf/src/test/java/org/apache/camel/kafkaconnector/cxf/source/CamelSourceCXFITCase.java b/tests/itests-cxf/src/test/java/org/apache/camel/kafkaconnector/cxf/source/CamelSourceCXFITCase.java
index 719501c..9a75ea4 100644
--- a/tests/itests-cxf/src/test/java/org/apache/camel/kafkaconnector/cxf/source/CamelSourceCXFITCase.java
+++ b/tests/itests-cxf/src/test/java/org/apache/camel/kafkaconnector/cxf/source/CamelSourceCXFITCase.java
@@ -24,12 +24,7 @@ import org.apache.camel.kafkaconnector.common.ConnectorPropertyFactory;
 import org.apache.camel.kafkaconnector.common.clients.kafka.KafkaClient;
 import org.apache.camel.kafkaconnector.common.utils.NetworkUtils;
 import org.apache.camel.kafkaconnector.common.utils.TestUtils;
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.ext.logging.LoggingInInterceptor;
-import org.apache.cxf.ext.logging.LoggingOutInterceptor;
-import org.apache.cxf.frontend.ClientFactoryBean;
-import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.camel.kafkaconnector.cxf.client.CXFServiceUtil;
 import org.apache.kafka.clients.consumer.ConsumerRecord;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -66,7 +61,6 @@ public class CamelSourceCXFITCase extends AbstractKafkaTest {
     @BeforeEach
     public void setUp() {
         received = 0;
-
     }
 
     private <T> boolean checkRecord(ConsumerRecord<String, T> record) {
@@ -88,15 +82,7 @@ public class CamelSourceCXFITCase extends AbstractKafkaTest {
 
         // ensure cxf source connector is up
         Thread.sleep(5000);
-        ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
-        ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
-        clientBean.setAddress(SIMPLE_ENDPOINT_ADDRESS);
-        clientBean.setServiceClass(HelloService.class);
-        Bus bus = BusFactory.newInstance().createBus();
-        clientBean.setBus(bus);
-        bus.getInInterceptors().add(new LoggingInInterceptor());
-        bus.getOutInterceptors().add(new LoggingOutInterceptor());
-        HelloService client = (HelloService) proxyFactory.create();
+        HelloService client = CXFServiceUtil.getService(SIMPLE_ENDPOINT_ADDRESS, HelloService.class);
         try {
             String result = client.echo(TEST_MESSAGE);
             assertEquals(result, TEST_MESSAGE);