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 2024/01/15 10:40:38 UTC

(camel) branch main updated: CAMEL-20113: camel/tests consolidating (#12778)

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

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 7ef14b53a5b CAMEL-20113: camel/tests consolidating (#12778)
7ef14b53a5b is described below

commit 7ef14b53a5b59ccbb558017d4c07dd194c6f076a
Author: Ivan Kulaga <ku...@gmail.com>
AuthorDate: Mon Jan 15 16:40:31 2024 +0600

    CAMEL-20113: camel/tests consolidating (#12778)
    
    apache.camel.itest.jms
    -JMSTransactionIsTransactedRedeliveredTest - almost the same case is tested in org.apache.camel.component.jms.tx.JMSTransactionIsTransactedRedeliveredTest, so this test is deleted.
    org.apache.camel.itest.nettyhttp
    -NettyHttpClientChunkedResponseTest - created similar test in netty-http component, with chunked response but without jetty. Original test was deleted.
---
 .../http/NettyHttpClientChunkedResponseTest.java   |  50 +++++++++
 .../JMSTransactionIsTransactedRedeliveredTest.java | 119 ---------------------
 .../NettyHttpClientChunkedResponseTest.java        |  69 ------------
 .../JMSTransactionIsTransactedRedeliveredTest.xml  |  80 --------------
 4 files changed, 50 insertions(+), 268 deletions(-)

diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpClientChunkedResponseTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpClientChunkedResponseTest.java
new file mode 100644
index 00000000000..d5d3fa8e266
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpClientChunkedResponseTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.component.netty.http;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class NettyHttpClientChunkedResponseTest extends BaseNettyTest {
+
+    @Test
+    public void testNettyHttpClientChunkedResponse() throws Exception {
+        getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
+
+        String out = template.requestBody("netty-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+        assertEquals("Bye World", out);
+
+        MockEndpoint.assertIsSatisfied(context);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("netty-http:http://0.0.0.0:{{port}}/foo")
+                        .to("mock:input")
+                        .setHeader("Transfer-Encoding", constant("chunked"))
+                        .transform().simple("Bye World");
+            }
+        };
+    }
+
+}
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JMSTransactionIsTransactedRedeliveredTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JMSTransactionIsTransactedRedeliveredTest.java
deleted file mode 100644
index 7efd7f563e3..00000000000
--- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JMSTransactionIsTransactedRedeliveredTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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.itest.jms;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.AdviceWith;
-import org.apache.camel.builder.AdviceWithRouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.itest.utils.extensions.JmsServiceExtension;
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-/**
- * Test that exchange.isExternalRedelivered() is kept around even when Message implementation changes from JmsMessage to
- * DefaultMessage, when routing from JMS over Jetty.
- */
-public class JMSTransactionIsTransactedRedeliveredTest extends CamelSpringTestSupport {
-    @RegisterExtension
-    public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension();
-
-    private static int port = AvailablePortFinder.getNextAvailable();
-    static {
-        //set them as system properties so Spring can use the property placeholder
-        //things to set them into the URL's in the spring contexts
-        System.setProperty("Jetty.port", Integer.toString(port));
-    }
-
-    @Override
-    protected ClassPathXmlApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext(
-                "/org/apache/camel/itest/jms/JMSTransactionIsTransactedRedeliveredTest.xml");
-    }
-
-    @Override
-    public boolean isUseAdviceWith() {
-        return true;
-    }
-
-    @Test
-    void testTransactionSuccess() throws Exception {
-        AdviceWith.adviceWith(context.getRouteDefinitions().get(0), context, new AdviceWithRouteBuilder() {
-            @Override
-            public void configure() {
-                onException(AssertionError.class).to("log:error", "mock:error");
-            }
-        });
-        context.start();
-
-        // there should be no assertion errors
-        MockEndpoint error = getMockEndpoint("mock:error");
-        error.expectedMessageCount(0);
-
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        mock.expectedBodiesReceived("Bye World");
-        // success at 3rd attempt
-        mock.message(0).header("count").isEqualTo(3);
-
-        MockEndpoint jetty = getMockEndpoint("mock:jetty");
-        jetty.expectedMessageCount(1);
-
-        template.sendBody("jms:queue:okay", "Hello World");
-
-        mock.assertIsSatisfied();
-        jetty.assertIsSatisfied();
-        error.assertIsSatisfied();
-    }
-
-    public static class MyBeforeProcessor implements Processor {
-        private int count;
-
-        @Override
-        public void process(Exchange exchange) {
-            ++count;
-
-            // the first is not redelivered
-            if (count == 1) {
-                assertFalse(exchange.isExternalRedelivered(), "Should not be external redelivered");
-            } else {
-                assertTrue(exchange.isExternalRedelivered(), "Should be external redelivered");
-            }
-
-            if (count < 3) {
-                throw new IllegalArgumentException("Forced exception");
-            }
-            exchange.getIn().setHeader("count", count);
-        }
-    }
-
-    public static class MyAfterProcessor implements Processor {
-        @Override
-        public void process(Exchange exchange) {
-            // origin message should be a external redelivered
-            assertTrue(exchange.isExternalRedelivered(), "Should be external redelivered");
-        }
-    }
-
-}
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/nettyhttp/NettyHttpClientChunkedResponseTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/nettyhttp/NettyHttpClientChunkedResponseTest.java
deleted file mode 100644
index b8130759733..00000000000
--- a/tests/camel-itest/src/test/java/org/apache/camel/itest/nettyhttp/NettyHttpClientChunkedResponseTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.itest.nettyhttp;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.junit5.CamelTestSupport;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-public class NettyHttpClientChunkedResponseTest extends CamelTestSupport {
-
-    private int port1;
-    private int port2;
-
-    @Test
-    void testNettyHttpRouteClientChunked() {
-        invokeService(port2, false);
-    }
-
-    private void invokeService(int port, boolean checkChunkedHeader) {
-        Exchange out = template.request("netty-http:http://localhost:" + port + "/test",
-                exchange -> exchange.getIn().setBody("Camel in chunks."));
-
-        assertNotNull(out);
-        assertEquals("Bye Camel in chunks.", out.getMessage().getBody(String.class));
-        if (checkChunkedHeader) {
-            assertEquals("chunked", out.getMessage().getHeader("Transfer-Encoding"));
-        }
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() {
-        return new RouteBuilder() {
-            @Override
-            public void configure() {
-                port1 = AvailablePortFinder.getNextAvailable();
-                port2 = AvailablePortFinder.getNextAvailable();
-
-                // use jetty as server as it supports sending response as chunked encoding
-                from("jetty:http://localhost:" + port1 + "/test")
-                        .setHeader("Transfer-Encoding", constant("chunked"))
-                        .transform().simple("Bye ${body}");
-
-                // set up a netty http proxy
-                from("netty-http:http://localhost:" + port2 + "/test")
-                        .to("netty-http:http://localhost:" + port1 + "/test?bridgeEndpoint=true&throwExceptionOnFailure=false");
-
-            }
-        };
-    }
-}
diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JMSTransactionIsTransactedRedeliveredTest.xml b/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JMSTransactionIsTransactedRedeliveredTest.xml
deleted file mode 100644
index 0776a850094..00000000000
--- a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JMSTransactionIsTransactedRedeliveredTest.xml
+++ /dev/null
@@ -1,80 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
-    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.
-
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
-
-  <bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent"/>
-
-  <bean id="poolConnectionFactory" class="org.messaginghub.pooled.jms.JmsPoolConnectionFactory" init-method="start" destroy-method="stop">
-    <property name="maxConnections" value="8"/>
-    <property name="connectionFactory" ref="jmsConnectionFactory"/>
-  </bean>
-
-  <bean id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory">
-    <property name="brokerURL" value="vm://itest-jms?broker.persistent=false&amp;create=false"/>
-  </bean>
-
-  <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
-    <property name="connectionFactory" ref="poolConnectionFactory"/>
-  </bean>
-
-  <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
-    <property name="connectionFactory" ref="poolConnectionFactory"/>
-    <property name="transacted" value="true"/>
-    <property name="transactionManager" ref="jmsTransactionManager"/>
-    <!-- we do not want any exceptions to be logged -->
-    <property name="errorHandlerLoggingLevel" value="OFF"/>
-    <property name="errorHandlerLogStackTrace" value="false"/>
-  </bean>
-
-  <camelContext xmlns="http://camel.apache.org/schema/spring">
-
-    <!-- we do not want any exceptions to be logged, neither that a rollback occurred -->
-    <errorHandler id="txEH" type="TransactionErrorHandler" rollbackLoggingLevel="OFF">
-      <redeliveryPolicy logStackTrace="false" logExhausted="false"/>
-    </errorHandler>
-
-    <route errorHandlerRef="txEH">
-      <from uri="jms:queue:okay"/>
-      <transacted/>
-      <to uri="mock:before"/>
-      <process ref="myBeforeProcessor"/>
-      <to uri="http://localhost:{{Jetty.port}}/test"/>
-      <process ref="myAfterProcessor"/>
-      <to uri="mock:result"/>
-    </route>
-
-    <route>
-      <from uri="jetty:http://localhost:{{Jetty.port}}/test"/>
-      <transform>
-        <constant>Bye World</constant>
-      </transform>
-      <to uri="mock:jetty"/>
-    </route>
-
-  </camelContext>
-
-  <bean id="myBeforeProcessor" class="org.apache.camel.itest.jms.JMSTransactionIsTransactedRedeliveredTest.MyBeforeProcessor"/>
-  <bean id="myAfterProcessor" class="org.apache.camel.itest.jms.JMSTransactionIsTransactedRedeliveredTest.MyAfterProcessor"/>
-
-</beans>