Author: gertv
Date: Fri May 22 08:48:50 2009
New Revision: 777433
URL: http://svn.apache.org/viewvc?rev=777433&view=rev
Log:
SMXCOMP-532: Improve test coverage for servicemix-camel
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java
(with props)
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java
(with props)
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java
(with props)
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java
(with props)
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java
(with props)
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java?rev=777433&view=auto
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java
(added)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java
Fri May 22 08:48:50 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.servicemix.camel;
+
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.tck.mock.MockMessageExchange;
+
+/**
+ * Test cases for {...@link CamelConsumerEndpoint}
+ */
+public class CamelConsumerEndpointTest extends JbiTestSupport {
+
+ public void testInvalidMessageExchangeDoesNotThrowException() throws
Exception {
+ String endpointName =
+
jbiContainer.getRegistry().getExternalEndpointsForService(CamelConsumerEndpoint.SERVICE_NAME)[0].getEndpointName();
+ CamelConsumerEndpoint endpoint =
+ (CamelConsumerEndpoint)
component.getRegistry().getEndpoint(CamelConsumerEndpoint.SERVICE_NAME + ":" +
endpointName);
+
+ try {
+ // now, let's shamelessly process a completely fake
MessageExchange...
+ endpoint.process(new MockMessageExchange() {
+ @Override
+ public String getExchangeId() {
+ return "a-fake-exchange-id";
+ }
+ });
+ } catch (Exception e) {
+ // ... and still expect the endpoint to behave properly
+ fail("Should not throw " + e);
+ }
+ }
+
+ @Override
+ protected void appendJbiActivationSpecs(List<ActivationSpec>
activationSpecList) {
+ // no additional JBI activation specs required
+ }
+
+ @Override
+ protected void configureContainer(JBIContainer container) throws Exception
{
+ super.configureContainer(container);
+ }
+
+ @Override
+ protected RouteBuilder createRoutes() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:a").to("jbi:endpoint:urn:test:service:endpoint");
+ from("jbi:endpoint:urn:test:service:endpoint").to("log:info");
+ }
+ };
+ }
+}
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java?rev=777433&view=auto
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java
(added)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java
Fri May 22 08:48:50 2009
@@ -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.servicemix.camel;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for {...@link JbiComponent}
+ */
+public class JbiComponentTest extends TestCase {
+
+ private static final String IN_OUT = "http://www.w3.org/ns/wsdl/in-out";
+
+ public void testGetUriWithMep() throws Exception {
+ JbiComponent component = createJbiComponent();
+ JbiEndpoint endpoint = (JbiEndpoint)
component.createEndpoint("jbi:endpoint:urn:test:service?mep=in-out");
+ assertEquals(IN_OUT, endpoint.getMep());
+ }
+
+ public void testNullWhenNoJbiUri() throws Exception {
+
assertNull(createJbiComponent().createEndpoint("somethingelse:service:urn:test"));
+ }
+
+ public void testExceptionWhenIllegalUri() {
+ // expecting an exception when uri doesn't have name, endpoint or
service after the jbi:
+
assertIllegalArgumentExceptionOnInvalidUri("jbi:illegal:urn:test:service");
+ // expecting an exception when using the wrong separators
+
assertIllegalArgumentExceptionOnInvalidUri("jbi:endpoint:urn:test/service");
+ }
+
+ private void assertIllegalArgumentExceptionOnInvalidUri(String uri) {
+ JbiComponent component = createJbiComponent();
+ JbiEndpoint endpoint = (JbiEndpoint) component.createEndpoint(uri);
+ try {
+ component.createJbiEndpointFromCamel(endpoint);
+ fail("Should have thrown an IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // ok, at least we got the exception we expected
+ }
+ }
+
+ private JbiComponent createJbiComponent() {
+ return new JbiComponent(new CamelJbiComponent());
+ }
+}
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java?rev=777433&view=auto
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java
(added)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java
Fri May 22 08:48:50 2009
@@ -0,0 +1,111 @@
+/*
+ * 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.servicemix.camel;
+
+import java.util.List;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOptionalOut;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+
+/**
+ * Tests on handling JBI InOnly exchanges by Camel
+ */
+public class JbiInOptionalOutCamelTest extends JbiTestSupport {
+
+ public void testInOptionalOutFromCamelEndpoint() throws Exception {
+ MockEndpoint inonly = getMockEndpoint("mock:in-optional-out");
+ inonly.expectedMessageCount(1);
+
+ client.sendBody("direct:in-optional-out", new
StringSource("<request>Does this MEP confuse you?</request>"));
+
+ inonly.assertIsSatisfied();
+ }
+
+ public void testInOptionalOutFromJbiWithDone() throws Exception {
+ MockEndpoint inonly = getMockEndpoint("mock:in-optional-out");
+ inonly.expectedMessageCount(1);
+
+ InOptionalOut exchange =
getServicemixClient().createInOptionalOutExchange();
+ exchange.setService(new QName("urn:test", "in-optional-out"));
+ exchange.getInMessage().setContent(new StringSource("<request>Does
this MEP confuse you?</request>"));
+ getServicemixClient().sendSync(exchange);
+ assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+ inonly.assertIsSatisfied();
+
+ // let's send the done and wait for a moment until it's handled
+ getServicemixClient().done(exchange);
+ Thread.sleep(500);
+ }
+
+ public void testInOptionalOutFromJbiWithFault() throws Exception {
+ MockEndpoint inonly = getMockEndpoint("mock:in-optional-out");
+ inonly.expectedMessageCount(1);
+
+ InOptionalOut exchange =
getServicemixClient().createInOptionalOutExchange();
+ exchange.setService(new QName("urn:test", "in-optional-out"));
+ exchange.getInMessage().setContent(new StringSource("<request>Does
this MEP confuse you?</request>"));
+ getServicemixClient().sendSync(exchange);
+ assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+ inonly.assertIsSatisfied();
+
+ // let's send back a fault to the Camel provider endpoint
+ exchange.setFault(exchange.createFault());
+ exchange.getFault().setContent(new StringSource("<response>Oh no,
things are going astray!</response>"));
+ getServicemixClient().sendSync(exchange);
+ assertEquals(ExchangeStatus.DONE, exchange.getStatus());
+ }
+
+ public void testInOptionalOutFromJbiWithError() throws Exception {
+ MockEndpoint inonly = getMockEndpoint("mock:in-optional-out");
+ inonly.expectedMessageCount(1);
+
+ InOptionalOut exchange =
getServicemixClient().createInOptionalOutExchange();
+ exchange.setService(new QName("urn:test", "in-optional-out"));
+ exchange.getInMessage().setContent(new StringSource("<request>Does
this MEP confuse you?</request>"));
+ getServicemixClient().sendSync(exchange);
+ assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+ inonly.assertIsSatisfied();
+
+ // let's back an error to the Camel provider endpoint and wait for a
moment until it's handled
+ exchange.setError(new JbiException("Oh no, things are going astray!"));
+ getServicemixClient().send(exchange);
+ Thread.sleep(500);
+ }
+
+
+ @Override
+ protected void appendJbiActivationSpecs(List<ActivationSpec>
activationSpecList) {
+ // no additional activation specs required
+ }
+
+ @Override
+ protected RouteBuilder createRoutes() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from("direct:in-optional-out").to("jbi:service:urn:test:in-optional-out?mep=in-optional-out");
+
from("jbi:service:urn:test:in-optional-out").to("mock:in-optional-out");
+ }
+ };
+ }
+}
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java?rev=777433&view=auto
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java
(added)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java
Fri May 22 08:48:50 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.servicemix.camel;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.jbi.messaging.NormalizedMessage;
+
+import junit.framework.TestCase;
+
+import org.apache.camel.Message;
+import org.apache.servicemix.tck.mock.MockNormalizedMessage;
+
+/**
+ * Test cases for {...@link JbiMessage}
+ */
+public class JbiMessageTest extends TestCase {
+
+ private static final String ATTACHMENT_ID = "attachment.png";
+ private static final String ANOTHER_ATTACHMENT_ID =
"another_attachment.png";
+ private static final DataHandler ATTACHMENT = new DataHandler(new
FileDataSource("attachment.png"));
+ private static final DataHandler ANOTHER_ATTACHMENT = new DataHandler(new
FileDataSource("attachment.png"));
+
+ public void testAttachmentsWithNormalizedMessage() throws Exception {
+ NormalizedMessage jbiMessage = new MockNormalizedMessage();
+ jbiMessage.addAttachment(ATTACHMENT_ID, ATTACHMENT);
+
+ // make sure the Camel Message also has the attachment
+ JbiMessage camelMessage = new JbiMessage(jbiMessage);
+ assertSame(ATTACHMENT, camelMessage.getAttachment(ATTACHMENT_ID));
+
+ // and ensure that attachments are propagated back to the underlying
NormalizedMessage
+ camelMessage.addAttachment(ANOTHER_ATTACHMENT_ID, ANOTHER_ATTACHMENT);
+ assertSame(ANOTHER_ATTACHMENT,
jbiMessage.getAttachment(ANOTHER_ATTACHMENT_ID));
+
+ // and they should also be on the Camel Message itself
+ camelMessage.setNormalizedMessage(null);
+ assertSame(ANOTHER_ATTACHMENT,
camelMessage.getAttachment(ANOTHER_ATTACHMENT_ID));
+ }
+
+ public void testCopyMessage() throws Exception {
+ JbiMessage message = new JbiMessage();
+ Message copy = message.copy();
+ assertTrue(copy instanceof JbiMessage);
+ }
+
+}
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java?rev=777433&view=auto
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java
(added)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java
Fri May 22 08:48:50 2009
@@ -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.servicemix.camel;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+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.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+
+/**
+ * Tests on handling JBI InOnly exchanges by Camel
+ */
+public class JbiOperationCamelTest extends JbiTestSupport {
+
+ private static final String OPERATION = "doit";
+
+ public void testInOnlySetOperationOnCamelEndpoint() throws Exception {
+ MockEndpoint inonly = getMockEndpoint("mock:in-only");
+ inonly.expectedMessageCount(1);
+
+ // either set the operation on the Camel JBI Endpoint
+ client.sendBody("direct:in-only", new StringSource("<request>How about
adding an operation?</request>"));
+
+ inonly.assertIsSatisfied();
+ Exchange exchange = inonly.getExchanges().get(0);
+ assertEquals(OPERATION, exchange.getProperty("jbi.operation"));
+ }
+
+ public void testInOnlySetOperationOnCamelExchange() throws Exception {
+ MockEndpoint inonly = getMockEndpoint("mock:in-only");
+ inonly.expectedMessageCount(1);
+
+ // this time, we set the target operation on the Camel Exchange
+ client.send("direct:in-only-noop", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.setProperty("jbi.operation", OPERATION);
+ exchange.getIn().setBody(new StringSource("<request>Sending
you the operation, could you please perform it?</request>"));
+ }
+ });
+
+ inonly.assertIsSatisfied();
+ Exchange exchange = inonly.getExchanges().get(0);
+ assertEquals(OPERATION, exchange.getProperty("jbi.operation"));
+ }
+
+ @Override
+ protected void appendJbiActivationSpecs(List<ActivationSpec>
activationSpecList) {
+ // no additional activation specs required
+ }
+
+ @Override
+ protected RouteBuilder createRoutes() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from("direct:in-only").to("jbi:service:urn:test:in-only?operation=" +
OPERATION);
+
from("direct:in-only-noop").to("log:info").to("jbi:service:urn:test:in-only");
+
+ from("jbi:service:urn:test:in-only").process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ JbiExchange jbi = (JbiExchange) exchange;
+ assertEquals(new QName(OPERATION),
jbi.getMessageExchange().getOperation());
+ }
+ }).to("mock:in-only");
+ }
+ };
+ }
+}
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java
------------------------------------------------------------------------------
svn:eol-style = native