You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/01/02 17:00:01 UTC
svn commit: r1226449 [3/5] - in /camel/trunk: ./ apache-camel/
apache-camel/src/main/descriptors/ components/ components/camel-mina2/
components/camel-mina2/src/ components/camel-mina2/src/main/
components/camel-mina2/src/main/java/ components/camel-mi...
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2FiltersTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2FiltersTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2FiltersTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2FiltersTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,115 @@
+/**
+ * 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.mina2;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.Context;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.jndi.JndiContext;
+import org.apache.mina.core.filterchain.IoFilter;
+import org.apache.mina.core.filterchain.IoFilterAdapter;
+import org.apache.mina.core.session.IoSession;
+import org.junit.Test;
+
+/**
+ * For unit testing the <tt>filters</tt> option.
+ */
+public class Mina2FiltersTest extends BaseMina2Test {
+
+ @Test
+ public void testFilterListRef() throws Exception {
+ testFilter("mina2:tcp://localhost:{{port}}?textline=true&minaLogger=true&sync=false&filters=#myFilters");
+ }
+
+ @Test
+ public void testFilterElementRef() throws Exception {
+ testFilter("mina2:tcp://localhost:{{port}}?textline=true&minaLogger=true&sync=false&filters=#myFilter");
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ TestFilter.called = 0;
+ super.tearDown();
+ }
+
+ private void testFilter(final String uri) throws Exception {
+ context.addRoutes(new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from(uri).to("mock:result");
+ }
+ });
+
+ MockEndpoint mock = this.getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+
+ Endpoint endpoint = context.getEndpoint(uri);
+ Exchange exchange = endpoint.createExchange();
+ Producer producer = endpoint.createProducer();
+ producer.start();
+
+ // set input and execute it
+ exchange.getIn().setBody("Hello World");
+ producer.process(exchange);
+
+ Field field = producer.getClass().getDeclaredField("session");
+ field.setAccessible(true);
+ IoSession session = (IoSession) field.get(producer);
+ assertTrue("There should be a test filter", session.getFilterChain().contains(TestFilter.class.getCanonicalName()));
+
+ assertEquals("The filter should have been called twice (producer and consumer)", 2, TestFilter.called);
+
+ assertMockEndpointsSatisfied();
+
+ producer.stop();
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ JndiContext answer = new JndiContext();
+ IoFilter myFilter = new TestFilter();
+ List<IoFilter> myFilters = new ArrayList<IoFilter>();
+ myFilters.add(myFilter);
+
+ answer.bind("myFilters", myFilters);
+ answer.bind("myFilter", myFilter);
+ return answer;
+ }
+
+ public static final class TestFilter extends IoFilterAdapter {
+
+ public static volatile int called;
+
+ @Override
+ public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception {
+ incCalled();
+ nextFilter.sessionCreated(session);
+ }
+
+ public static synchronized void incCalled() {
+ called++;
+ }
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2FiltersTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2FiltersTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOnlyRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOnlyRouteTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOnlyRouteTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOnlyRouteTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,57 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * Unit test to verify that MINA can be used with an InOnly MEP but still use sync to send and receive data
+ * from a remote server.
+ */
+public class Mina2InOnlyRouteTest extends BaseMina2Test {
+
+ @Test
+ public void testInOnlyUsingMina() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Bye Chad");
+ mock.setResultWaitTime(5000);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from("mina2:tcp://localhost:{{port}}?sync=true").process(new Processor() {
+
+ public void process(Exchange exchange) throws Exception {
+ String body = exchange.getIn().getBody(String.class);
+ exchange.getOut().setBody("Bye " + body);
+ }
+ });
+
+ from("timer://start?period=10000&delay=2000").setBody(constant("Chad")).to("mina2:tcp://localhost:{{port}}?sync=true&lazySessionCreation=true").to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOnlyRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOnlyRouteTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutCloseSessionWhenCompleteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutCloseSessionWhenCompleteTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutCloseSessionWhenCompleteTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutCloseSessionWhenCompleteTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,51 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * Unit test for close session when complete test.
+ */
+public class Mina2InOutCloseSessionWhenCompleteTest extends BaseMina2Test {
+
+ @Test
+ public void testCloseSessionWhenComplete() throws Exception {
+ Object out = template.requestBody("mina2:tcp://localhost:{{port}}?sync=true&textline=true", "Chad");
+ assertEquals("Bye Chad", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from("mina2:tcp://localhost:{{port}}?sync=true&textline=true").process(new Processor() {
+
+ public void process(Exchange exchange) throws Exception {
+ String body = exchange.getIn().getBody(String.class);
+ exchange.getOut().setBody("Bye " + body);
+ exchange.getOut().setHeader(Mina2Constants.MINA_CLOSE_SESSION_WHEN_COMPLETE, true);
+ }
+ });
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutCloseSessionWhenCompleteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutCloseSessionWhenCompleteTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,62 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * Unit test to verify that MINA can be used with an InOut MEP but still use sync to send and receive data
+ * from a remote server.
+ */
+public class Mina2InOutRouteTest extends BaseMina2Test {
+
+ @Test
+ public void testInOutUsingMina() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Bye Chad");
+ // we should preserve headers
+ mock.expectedHeaderReceived("city", "Woodbine");
+ mock.setResultWaitTime(5000);
+
+ Object out = template.requestBodyAndHeader("direct:in", "Chad", "city", "Woodbine");
+
+ assertMockEndpointsSatisfied();
+ assertEquals("Bye Chad", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from("mina2:tcp://localhost:{{port}}?sync=true").process(new Processor() {
+
+ public void process(Exchange exchange) throws Exception {
+ String body = exchange.getIn().getBody(String.class);
+ exchange.getOut().setBody("Bye " + body);
+ }
+ });
+
+ from("direct:in").to("mina2:tcp://localhost:{{port}}?sync=true&lazySessionCreation=true").to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTextLineDelimiterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTextLineDelimiterTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTextLineDelimiterTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTextLineDelimiterTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,59 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * Unit test to verify that MINA can be used with an InOut MEP but still use sync to send and receive data
+ * from a remote server and using MAC textline delimiter.
+ */
+public class Mina2InOutRouteTextLineDelimiterTest extends BaseMina2Test {
+
+ @Test
+ public void testInOutUsingMina() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Bye Chad");
+ // we should preserve headers
+ mock.setResultWaitTime(5000);
+
+ Object out = template.requestBody("mina2:tcp://localhost:{{port}}?sync=true&textline=true&textlineDelimiter=MAC", "Chad");
+
+ assertMockEndpointsSatisfied();
+ assertEquals("Bye Chad", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from("mina2:tcp://localhost:{{port}}?sync=true&textline=true&textlineDelimiter=MAC").process(new Processor() {
+
+ public void process(Exchange exchange) throws Exception {
+ String body = exchange.getIn().getBody(String.class);
+ exchange.getOut().setBody("Bye " + body);
+ }
+ }).to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTextLineDelimiterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutRouteTextLineDelimiterTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutWithForcedNoResponseTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutWithForcedNoResponseTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutWithForcedNoResponseTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutWithForcedNoResponseTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,73 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.ExchangeTimedOutException;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * Unit test with InOut however we want sometimes to not send a response.
+ */
+public class Mina2InOutWithForcedNoResponseTest extends BaseMina2Test {
+
+ int port1;
+ int port2;
+
+ @Test
+ public void testResponse() throws Exception {
+ Object out = template.requestBody("mina2:tcp://localhost:" + port1 + "?sync=true", "Woodbine");
+ assertEquals("Hello Chad", out);
+ }
+
+ @Test
+ public void testNoResponseDisconnectOnNoReplyFalse() throws Exception {
+ try {
+ template.requestBody("mina2:tcp://localhost:" + port2 + "?sync=true&timeout=100", "London");
+ Thread.sleep(1000);
+ fail("Should throw an exception");
+ } catch (RuntimeCamelException e) {
+ assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ public void configure() throws Exception {
+ port1 = getPort();
+ port2 = getNextPort();
+
+ from("mina2:tcp://localhost:" + port1 + "?sync=true")
+ .choice()
+ .when(body().isEqualTo("Woodbine"))
+ .transform(constant("Hello Chad"))
+ .otherwise()
+ .transform(constant(null));
+
+ from("mina2:tcp://localhost:" + port2 + "?sync=true&disconnectOnNoReply=false&noReplyLogLevel=OFF").
+ choice()
+ .when(body().isEqualTo("Woodbine"))
+ .transform(constant("Hello Chad")).
+ otherwise()
+ .transform(constant(null));
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutWithForcedNoResponseTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2InOutWithForcedNoResponseTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2LoggerOptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2LoggerOptionTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2LoggerOptionTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2LoggerOptionTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,127 @@
+/**
+ * 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.mina2;
+
+import java.lang.reflect.Field;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.mina.core.session.IoSession;
+import org.junit.Test;
+
+/**
+ * For unit testing the <tt>logger</tt> option.
+ */
+public class Mina2LoggerOptionTest extends BaseMina2Test {
+
+ @Test
+ public void testLoggerOptionTrue() throws Exception {
+ final String uri = "mina2:tcp://localhost:{{port}}?textline=true&minaLogger=true&sync=false";
+ context.addRoutes(new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from(uri).to("mock:result");
+ }
+ });
+
+ MockEndpoint mock = this.getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+
+ Endpoint endpoint = context.getEndpoint(uri);
+ Exchange exchange = endpoint.createExchange();
+ Producer producer = endpoint.createProducer();
+ producer.start();
+
+ // set input and execute it
+ exchange.getIn().setBody("Hello World");
+ producer.process(exchange);
+
+ Field field = producer.getClass().getDeclaredField("session");
+ field.setAccessible(true);
+ IoSession session = (IoSession) field.get(producer);
+ assertTrue("There should be a logger filter", session.getFilterChain().contains("logger"));
+
+ assertMockEndpointsSatisfied();
+ producer.stop();
+ }
+
+ @Test
+ public void testLoggerOptionFalse() throws Exception {
+ final String uri = "mina2:tcp://localhost:{{port}}?textline=true&minaLogger=false&sync=false";
+ context.addRoutes(new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from(uri).to("mock:result");
+ }
+ });
+
+ MockEndpoint mock = this.getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+
+ Endpoint endpoint = context.getEndpoint(uri);
+ Exchange exchange = endpoint.createExchange();
+ Producer producer = endpoint.createProducer();
+ producer.start();
+
+ // set input and execute it
+ exchange.getIn().setBody("Hello World");
+ producer.process(exchange);
+
+ Field field = producer.getClass().getDeclaredField("session");
+ field.setAccessible(true);
+ IoSession session = (IoSession) field.get(producer);
+ assertFalse("There should NOT be a logger filter", session.getFilterChain().contains("logger"));
+
+ assertMockEndpointsSatisfied();
+
+ producer.stop();
+ }
+
+ @Test
+ public void testNoLoggerOption() throws Exception {
+ final String uri = "mina2:tcp://localhost:{{port}}?textline=true&sync=false";
+ context.addRoutes(new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from(uri).to("mock:result");
+ }
+ });
+
+ MockEndpoint mock = this.getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+
+ Endpoint endpoint = context.getEndpoint(uri);
+ Exchange exchange = endpoint.createExchange();
+ Producer producer = endpoint.createProducer();
+ producer.start();
+
+ // set input and execute it
+ exchange.getIn().setBody("Hello World");
+ producer.process(exchange);
+
+ Field field = producer.getClass().getDeclaredField("session");
+ field.setAccessible(true);
+ IoSession session = (IoSession) field.get(producer);
+ assertFalse("There should NOT default be a logger filter", session.getFilterChain().contains("logger"));
+
+ assertMockEndpointsSatisfied();
+ producer.stop();
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2LoggerOptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2LoggerOptionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2MaxLineLengthTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2MaxLineLengthTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2MaxLineLengthTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2MaxLineLengthTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,69 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2MaxLineLengthTest extends BaseMina2Test {
+
+ @Test
+ public void testSendToServer() {
+ String request = "";
+ for (int c = 0; c < 4000; c++) {
+ request += "A";
+ }
+
+ // START SNIPPET: e3
+ String out = (String) template.requestBody("mina2:tcp://localhost:{{port}}?sync=true&textline=true&encoderMaxLineLength=5000&decoderMaxLineLength=5000", request);
+ assertEquals(request, out);
+ // END SNIPPET: e3
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ // START SNIPPET: e1
+ // lets setup a server on port {{port}}
+ // we set the sync option so we will send a reply
+ // and we let the request-reply be processed in the MyServerProcessor
+ from("mina2:tcp://localhost:{{port}}?sync=true&textline=true&encoderMaxLineLength=5000&decoderMaxLineLength=5000").process(new MyServerProcessor());
+ // END SNIPPET: e1
+ }
+ };
+ }
+
+ // START SNIPPET: e2
+ private static class MyServerProcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+ // get the input from the IN body
+ String request = exchange.getIn().getBody(String.class);
+ // echo back the response on the OUT body
+ exchange.getOut().setBody(request);
+ }
+ }
+ // END SNIPPET: e2
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2MaxLineLengthTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2MaxLineLengthTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoDefaultCodecTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoDefaultCodecTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoDefaultCodecTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoDefaultCodecTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,55 @@
+/**
+ * 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.mina2;
+
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.mina.core.filterchain.IoFilterChain.Entry;
+import org.junit.Test;
+
+/**
+ * For unit testing the <tt>noDefaultCodec</tt> option.
+ */
+public class Mina2NoDefaultCodecTest extends BaseMina2Test {
+
+ int port1;
+ int port2;
+
+ @Test
+ public void testFilter() throws Exception {
+ port1 = getPort();
+ port2 = getNextPort();
+
+ final String uri1 = "mina2:tcp://localhost:" + port1 + "?allowDefaultCodec=false";
+ final String uri2 = "mina2:tcp://localhost:" + port2;
+
+ context.addRoutes(new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from(uri1).to("mock:result");
+ from(uri2).to("mock:result");
+ }
+ });
+
+ Mina2Producer producer1 = (Mina2Producer) context.getEndpoint(uri1).createProducer();
+ Mina2Producer producer2 = (Mina2Producer) context.getEndpoint(uri2).createProducer();
+ List<Entry> filters1 = producer1.getFilterChain().getAll();
+ List<Entry> filters2 = producer2.getFilterChain().getAll();
+ assertTrue(filters1.size() < filters2.size());
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoDefaultCodecTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoDefaultCodecTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoResponseFromServerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoResponseFromServerTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoResponseFromServerTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoResponseFromServerTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,107 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.junit.Test;
+
+/**
+ * Unit test to test what happens if remote server closes session but doesn't reply
+ */
+public class Mina2NoResponseFromServerTest extends BaseMina2Test {
+
+ @Test
+ public void testNoResponse() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(0);
+
+ try {
+ template.requestBody("mina2:tcp://localhost:{{port}}?sync=true&codec=#myCodec", "Hello World");
+ fail("Should throw a CamelExchangeException");
+ } catch (RuntimeCamelException e) {
+ assertIsInstanceOf(CamelExchangeException.class, e.getCause());
+ assertTrue(e.getCause().getMessage().startsWith("The OUT message was not received within"));
+ }
+
+ mock.assertIsSatisfied();
+ }
+
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("myCodec", new MyCodec());
+ return jndi;
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from("mina2:tcp://localhost:{{port}}?sync=true&codec=#myCodec").transform(constant("Bye World")).to("mock:result");
+ }
+ };
+ }
+
+ private static class MyCodec implements ProtocolCodecFactory {
+
+ public ProtocolEncoder getEncoder(IoSession session) throws Exception {
+ return new ProtocolEncoder() {
+
+ public void encode(IoSession ioSession, Object message, ProtocolEncoderOutput out)
+ throws Exception {
+ // close session instead of returning a reply
+ ioSession.close(true);
+ }
+
+ public void dispose(IoSession ioSession) throws Exception {
+ // do nothing
+ }
+ };
+
+ }
+
+ public ProtocolDecoder getDecoder(IoSession session) throws Exception {
+ return new ProtocolDecoder() {
+
+ public void decode(IoSession ioSession, IoBuffer in,
+ ProtocolDecoderOutput out) throws Exception {
+ // close session instead of returning a reply
+ ioSession.close(true);
+ }
+
+ public void finishDecode(IoSession ioSession, ProtocolDecoderOutput protocolDecoderOutput)
+ throws Exception {
+ // do nothing
+ }
+
+ public void dispose(IoSession ioSession) throws Exception {
+ // do nothing
+ }
+ };
+ }
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoResponseFromServerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2NoResponseFromServerTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerAnotherConcurrentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerAnotherConcurrentTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerAnotherConcurrentTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerAnotherConcurrentTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,95 @@
+/**
+ * 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.mina2;
+
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2ProducerAnotherConcurrentTest extends BaseMina2Test {
+
+ @Test
+ public void testSimple() throws Exception {
+ String out = template.requestBody("direct:start", "A", String.class);
+ assertEquals("Bye A", out);
+ }
+
+ @Test
+ public void testNoConcurrentProducers() throws Exception {
+ doSendMessages(1, 1);
+ }
+
+ @Test
+ public void testConcurrentProducers() throws Exception {
+ doSendMessages(200, 5);
+ }
+
+ private void doSendMessages(int files, int poolSize) throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(files);
+
+ ExecutorService executor = Executors.newFixedThreadPool(poolSize);
+ Map<Integer, Future<Object>> responses = new ConcurrentHashMap<Integer, Future<Object>>();
+ for (int i = 0; i < files; i++) {
+ final int index = i;
+ Future<Object> out = executor.submit(new Callable<Object>() {
+
+ public Object call() throws Exception {
+ return template.requestBody("direct:start", index, String.class);
+ }
+ });
+ responses.put(index, out);
+ }
+
+ assertMockEndpointsSatisfied();
+ assertEquals(files, responses.size());
+
+ for (int i = 0; i < files; i++) {
+ Object out = responses.get(i).get();
+ assertEquals("Bye " + i, out);
+ }
+ executor.shutdownNow();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from("direct:start").to("mina2:tcp://localhost:{{port}}?sync=true");
+
+ from("mina2:tcp://localhost:{{port}}?sync=true").process(new Processor() {
+
+ public void process(Exchange exchange) throws Exception {
+ String body = exchange.getIn().getBody(String.class);
+ exchange.getOut().setBody("Bye " + body);
+ }
+ }).to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerAnotherConcurrentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerAnotherConcurrentTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerConcurrentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerConcurrentTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerConcurrentTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerConcurrentTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,93 @@
+/**
+ * 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.mina2;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2ProducerConcurrentTest extends BaseMina2Test {
+
+ @Test
+ public void testNoConcurrentProducers() throws Exception {
+ doSendMessages(1, 1);
+ }
+
+ @Test
+ public void testConcurrentProducers() throws Exception {
+ doSendMessages(10, 5);
+ }
+
+ private void doSendMessages(int files, int poolSize) throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(files);
+
+ ExecutorService executor = Executors.newFixedThreadPool(poolSize);
+ Map<Integer, Future<Object>> responses = new ConcurrentHashMap<Integer, Future<Object>>();
+ for (int i = 0; i < files; i++) {
+ final int index = i;
+ Future<Object> out = executor.submit(new Callable<Object>() {
+
+ public Object call() throws Exception {
+ return template.requestBody("mina2:tcp://localhost:{{port}}?sync=true", index, String.class);
+ }
+ });
+ responses.put(index, out);
+ }
+
+ assertMockEndpointsSatisfied();
+ assertEquals(files, responses.size());
+
+ // get all responses
+ Set<Object> unique = new HashSet<Object>();
+ for (Future<Object> future : responses.values()) {
+ unique.add(future.get());
+ }
+
+ // should be 10 unique responses
+ assertEquals("Should be " + files + " unique responses", files, unique.size());
+ executor.shutdownNow();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from("mina2:tcp://localhost:{{port}}?sync=true").process(new Processor() {
+
+ public void process(Exchange exchange) throws Exception {
+ String body = exchange.getIn().getBody(String.class);
+ exchange.getOut().setBody("Bye " + body);
+ }
+ }).to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerConcurrentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerConcurrentTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownMockTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownMockTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownMockTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownMockTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,86 @@
+/**
+ * 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.mina2;
+
+
+import java.lang.reflect.Field;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.mina.transport.socket.SocketConnector;
+import org.junit.Test;
+
+import static org.easymock.classextension.EasyMock.createMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+
+/**
+ * Unit testing for using a MinaProducer that it can shutdown properly (CAMEL-395)
+ */
+public class Mina2ProducerShutdownMockTest extends BaseMina2Test {
+
+ @Test
+ public void testProducerShutdownTestingWithMock() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+
+ // create our mock and record expected behavior = that worker timeout should be set to 0
+ SocketConnector mockConnector = createMock(SocketConnector.class);
+ mockConnector.dispose(true);
+ replay(mockConnector);
+
+ // normal camel code to get a producer
+ Endpoint endpoint = context.getEndpoint(
+ "mina2:tcp://localhost:{{port}}?textline=true&sync=false");
+ Exchange exchange = endpoint.createExchange();
+ Producer producer = endpoint.createProducer();
+ producer.start();
+
+ // set input and execute it
+ exchange.getIn().setBody("Hello World");
+ producer.process(exchange);
+
+ // insert our mock instead of real MINA IoConnector
+ Field field = producer.getClass().getDeclaredField("connector");
+ field.setAccessible(true);
+ field.set(producer, mockConnector);
+
+ //
+ // Everything is asynchronous.
+ // We need to wait a second to make sure we get the message.
+ //
+ Thread.sleep(1000);
+ // stop using our mock
+ producer.stop();
+
+ verify(mockConnector);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:tcp://localhost:{{port}}?textline=true&sync=false").to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownMockTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownMockTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,90 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.Ignore;
+
+/**
+ * Unit testing for using a MinaProducer that it can shutdown properly (CAMEL-395)
+ * <p>
+ * Run this test from maven: mvn exec:java and see the output if there is a error.
+ */
+@Ignore
+public class Mina2ProducerShutdownTest {
+
+ private static final String URI = "mina2:tcp://localhost:6321?textline=true&sync=false";
+ private long start;
+ private CamelContext context;
+
+ public static void main(String[] args) throws Exception {
+ Mina2ProducerShutdownTest me = new Mina2ProducerShutdownTest();
+ me.testProducer();
+ }
+
+ public void testProducer() throws Exception {
+ // use shutdown hook to verify that we have stopped within 5 seconds
+ Thread hook = new AssertShutdownHook();
+ Runtime.getRuntime().addShutdownHook(hook);
+
+ start = System.currentTimeMillis();
+
+ context = new DefaultCamelContext();
+ context.addRoutes(createRouteBuilder());
+ context.start();
+
+ sendMessage();
+
+ context.stop();
+ }
+
+ private class AssertShutdownHook extends Thread {
+
+ public void run() {
+ long diff = System.currentTimeMillis() - start;
+ if (diff > 5000) {
+ System.err.println("ERROR: MinaProducer should be able to shutdown within 5000 millis: time=" + diff);
+ }
+ }
+ }
+
+ private void sendMessage() throws Exception {
+ Endpoint endpoint = context.getEndpoint(URI);
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setBody("Hello World");
+
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+ }
+
+ private RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from(URI).to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ProducerShutdownTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverseProtocolHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverseProtocolHandler.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverseProtocolHandler.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverseProtocolHandler.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,46 @@
+/**
+ * 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.mina2;
+
+import org.apache.mina.core.service.IoHandler;
+import org.apache.mina.core.service.IoHandlerAdapter;
+import org.apache.mina.core.session.IoSession;
+
+/**
+ * {@link IoHandler} implementation of reverser server protocol.
+ *
+ */
+public class Mina2ReverseProtocolHandler extends IoHandlerAdapter {
+
+ public void exceptionCaught(IoSession session, Throwable cause) {
+ cause.printStackTrace();
+ // Close connection when unexpected exception is caught.
+ session.close(true);
+ }
+
+ public void messageReceived(IoSession session, Object message) {
+ // Reverse reveiced string
+ String str = message.toString();
+ StringBuilder buf = new StringBuilder(str.length());
+ for (int i = str.length() - 1; i >= 0; i--) {
+ buf.append(str.charAt(i));
+ }
+
+ // and write it back.
+ session.write(buf.toString());
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverseProtocolHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverseProtocolHandler.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverserServer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverserServer.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverserServer.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverserServer.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,60 @@
+/**
+ * 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.mina2;
+
+import java.net.InetSocketAddress;
+import java.nio.charset.Charset;
+
+import org.apache.mina.core.service.IoAcceptor;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
+import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
+
+/**
+ * (<b>Entry point</b>) Reverser server which reverses all text lines from
+ * clients.
+ */
+public class Mina2ReverserServer {
+
+ protected int port = 6321;
+ private IoAcceptor acceptor;
+
+ public Mina2ReverserServer(int port) {
+ this.port = port;
+ }
+
+ public void start() throws Exception {
+ acceptor = new NioSocketAcceptor();
+
+ // Prepare the configuration
+ ((NioSocketAcceptor) acceptor).setReuseAddress(true);
+ Charset charset = Charset.forName("UTF-8");
+ acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));
+ acceptor.setHandler(new Mina2ReverseProtocolHandler());
+
+ // Bind
+ acceptor.bind(new InetSocketAddress(port));
+ }
+
+ public void stop() throws Exception {
+ acceptor.unbind();
+ }
+
+ public int getPort() {
+ return port;
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverserServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2ReverserServer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SendToProcessorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SendToProcessorTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SendToProcessorTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SendToProcessorTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,65 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.FailedToCreateProducerException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class Mina2SendToProcessorTest extends BaseMina2Test {
+
+ @Test
+ public void testConnectionOnStartupTest() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("mina2:tcp://localhost:{{port}}?sync=false&lazySessionCreation=false");
+ }
+ });
+
+ try {
+ context.start();
+ fail("Should have thrown an exception");
+ } catch (FailedToCreateProducerException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testConnectionOnSendMessage() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("mina2:tcp://localhost:{{port}}?sync=false");
+ }
+ });
+
+ try {
+ context.start();
+ } catch (Exception e) {
+ fail("Should not have thrown an exception");
+ }
+
+ }
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SendToProcessorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SendToProcessorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,43 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Unit test spring based mina endpoint configuration.
+ */
+public class Mina2SpringMinaEndpointTest extends CamelSpringTestSupport {
+
+ @Test
+ public void testMinaSpringEndpoint() throws Exception {
+ MockEndpoint result = getMockEndpoint("mock:result");
+ result.expectedMessageCount(1);
+
+ template.sendBody("myMinaEndpoint", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/mina2/SpringMinaEndpointTest-context.xml");
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointUDPTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointUDPTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointUDPTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointUDPTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,43 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Unit test spring based mina endpoint configuration.
+ */
+public class Mina2SpringMinaEndpointUDPTest extends CamelSpringTestSupport {
+
+ @Test
+ public void testMinaSpringEndpoint() throws Exception {
+ MockEndpoint result = getMockEndpoint("mock:result");
+ result.expectedMessageCount(1);
+
+ template.sendBody("myMinaEndpoint", "Hello World\n");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/mina2/SpringMinaEndpointUDPTest-context.xml");
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointUDPTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMinaEndpointUDPTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMultipleUDPTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMultipleUDPTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMultipleUDPTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMultipleUDPTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,53 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ *
+ * @author chad.beaulac
+ */
+public class Mina2SpringMultipleUDPTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext(
+ "org/apache/camel/component/mina2/SpringMultipleUDPTest-context.xml");
+ }
+
+ @Test
+ public void testMinaSpringProtobufEndpoint() throws Exception {
+ MockEndpoint result = getMockEndpoint("mock:result");
+ result.expectedMessageCount(7);
+
+ int fooValue = 15;
+
+ for (int i = 0; i < 7; i++) {
+ template.requestBody("myMinaEndpoint", "Hello World" + i + "\n");
+ }
+
+ // Sleep for awhile to let the messages go through.
+ Thread.sleep(3000);
+
+ assertMockEndpointsSatisfied();
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMultipleUDPTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2SpringMultipleUDPTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpLineDelimiterUsingPlainSocketTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpLineDelimiterUsingPlainSocketTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpLineDelimiterUsingPlainSocketTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpLineDelimiterUsingPlainSocketTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,149 @@
+/**
+ * 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.mina2;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * To test camel-mina component using a TCP client that communicates using TCP socket communication.
+ *
+ * @version
+ */
+public class Mina2TcpLineDelimiterUsingPlainSocketTest extends BaseMina2Test {
+
+ @Test
+ public void testSendAndReceiveOnce() throws Exception {
+ String response = sendAndReceive("World");
+
+ assertNotNull("Nothing received from Mina", response);
+ assertEquals("Hello World", response);
+ }
+
+ @Test
+ public void testSendAndReceiveTwice() throws Exception {
+ String london = sendAndReceive("London");
+ String paris = sendAndReceive("Paris");
+
+ assertNotNull("Nothing received from Mina", london);
+ assertNotNull("Nothing received from Mina", paris);
+ assertEquals("Hello London", london);
+ assertEquals("Hello Paris", paris);
+ }
+
+ @Test
+ public void testReceiveNoResponseSinceOutBodyIsNull() throws Exception {
+ String out = sendAndReceive("force-null-out-body");
+ assertNull("no data should be recieved", out);
+ }
+
+ @Test
+ public void testReceiveNoResponseSinceOutBodyIsNullTwice() throws Exception {
+ String out = sendAndReceive("force-null-out-body");
+ assertNull("no data should be recieved", out);
+
+ out = sendAndReceive("force-null-out-body");
+ assertNull("no data should be recieved", out);
+ }
+
+ @Test
+ public void testExchangeFailedOutShouldBeNull() throws Exception {
+ String out = sendAndReceive("force-exception");
+ assertTrue("out should not be the same as in when the exchange has failed", !"force-exception".equals(out));
+ assertEquals("should get the exception here", out, "java.lang.IllegalArgumentException: Forced exception");
+ }
+
+ private String sendAndReceive(String input) throws IOException {
+ byte buf[] = new byte[128];
+
+ Socket soc = new Socket();
+ soc.connect(new InetSocketAddress("localhost", getPort()));
+
+ // Send message using plain Socket to test if this works
+ OutputStream os = null;
+ InputStream is = null;
+ try {
+ os = soc.getOutputStream();
+ // must append MAC newline at the end to flag end of textline to Camel-Mina
+ os.write((input + "\r").getBytes());
+
+ is = soc.getInputStream();
+ int len = is.read(buf);
+ if (len == -1) {
+ // no data received
+ return null;
+ }
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ if (os != null) {
+ os.close();
+ }
+ soc.close();
+ }
+
+ // convert the buffer to chars
+ StringBuilder sb = new StringBuilder();
+ for (byte b : buf) {
+ char ch = (char) b;
+ if (ch == '\r' || ch == 0) {
+ // use MAC delimiter denotes end of text (added in the end in the processor below)
+ break;
+ } else {
+ sb.append(ch);
+ }
+ }
+
+ return sb.toString();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ // use no delay for fast unit testing
+ errorHandler(defaultErrorHandler().maximumRedeliveries(2));
+
+ from("mina2:tcp://localhost:{{port}}?textline=true&minaLogger=true&textlineDelimiter=MAC&sync=true").process(new Processor() {
+
+ public void process(Exchange e) {
+ String in = e.getIn().getBody(String.class);
+ if ("force-null-out-body".equals(in)) {
+ // forcing a null out body
+ e.getOut().setBody(null);
+ } else if ("force-exception".equals(in)) {
+ // clear out before throwing exception
+ e.getOut().setBody(null);
+ throw new IllegalArgumentException("Forced exception");
+ } else {
+ e.getOut().setBody("Hello " + in);
+ }
+ }
+ });
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpLineDelimiterUsingPlainSocketTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpLineDelimiterUsingPlainSocketTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,47 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2TcpTest extends BaseMina2Test {
+
+ @Test
+ public void testMinaRoute() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ Object body = "Hello there!";
+ endpoint.expectedBodiesReceived(body);
+
+ template.sendBodyAndHeader("mina2:tcp://localhost:{{port}}?sync=false&minaLogger=true", body, "cheese", 123);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:tcp://localhost:{{port}}?sync=false&minaLogger=true").to("log:before?showAll=true").to("mock:result").to("log:after?showAll=true");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineDelimiterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineDelimiterTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineDelimiterTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineDelimiterTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,47 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2TcpTextlineDelimiterTest extends BaseMina2Test {
+
+ @Test
+ public void testMinaRoute() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ Object body = "Hello there!";
+ endpoint.expectedBodiesReceived(body);
+
+ template.sendBodyAndHeader("mina2:tcp://localhost:{{port}}?sync=false&textline=true&textlineDelimiter=UNIX", body, "cheese", 123);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:tcp://localhost:{{port}}?sync=false&textline=true&textlineDelimiter=UNIX").to("log:before?showAll=true").to("mock:result").to("log:after?showAll=true");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineDelimiterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineDelimiterTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date