Author: ffang
Date: Mon Jun 1 10:07:52 2009
New Revision: 780605
URL: http://svn.apache.org/viewvc?rev=780605&view=rev
Log:
[SMX4-290]Improve test coverage :: SMX4 :: cxf-transport-nmr
Modified:
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/pom.xml
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/AbstractJBITest.java
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
Modified: servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/pom.xml?rev=780605&r1=780604&r2=780605&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/pom.xml (original)
+++ servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/pom.xml Mon Jun 1
10:07:52 2009
@@ -173,6 +173,21 @@
</execution>
</executions>
</plugin>
+ <!-- exclude generated class from Cobertura reports -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <configuration>
+ <instrumentation>
+ <excludes>
+
<exclude>org/apache/servicemix/cxf/transport/nmr/ObjectFactory.class</exclude>
+
<exclude>org/apache/servicemix/cxf/transport/nmr/package-info.class</exclude>
+
<exclude>org/apache/servicemix/cxf/transport/nmr/AddressType.class</exclude>
+ </excludes>
+ </instrumentation>
+ </configuration>
+ </plugin>
+
</plugins>
</build>
Modified:
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java?rev=780605&r1=780604&r2=780605&view=diff
==============================================================================
---
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
(original)
+++
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
Mon Jun 1 10:07:52 2009
@@ -85,8 +85,7 @@
* @return the inbuilt backchannel
*/
protected Conduit getInbuiltBackChannel(Message inMessage) {
- return new
BackChannelConduit(EndpointReferenceUtils.getAnonymousEndpointReference(),
- inMessage);
+ return null;
}
public void shutdown() {
@@ -120,43 +119,5 @@
throw new ServiceMixException(ex);
}
}
-
-
- protected class BackChannelConduit extends AbstractConduit {
-
- protected Message inMessage;
- protected NMRDestination nmrDestination;
-
- BackChannelConduit(EndpointReferenceType ref, Message message) {
- super(ref);
- inMessage = message;
- }
-
- /**
- * Register a message observer for incoming messages.
- *
- * @param observer the observer to notify on receipt of incoming
- */
- public void setMessageObserver(MessageObserver observer) {
- // shouldn't be called for a back channel conduit
- }
-
- /**
- * Send an outbound message, assumed to contain all the name-value
- * mappings of the corresponding input message (if any).
- *
- * @param message the message to be sent.
- */
- public void prepare(Message message) throws IOException {
- // setup the message to be send back
- Channel dc = channel;
- message.put(Exchange.class, inMessage.get(Exchange.class));
- message.setContent(OutputStream.class, new
NMRDestinationOutputStream(inMessage, dc));
- }
-
- protected Logger getLogger() {
- return LOG;
- }
- }
-
+
}
Modified:
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/AbstractJBITest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/AbstractJBITest.java?rev=780605&r1=780604&r2=780605&view=diff
==============================================================================
---
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/AbstractJBITest.java
(original)
+++
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/AbstractJBITest.java
Mon Jun 1 10:07:52 2009
@@ -49,11 +49,16 @@
protected Message inMessage;
protected IMocksControl control;
protected NMR nmr;
+ protected NMRTransportFactory nmrTransportFactory;
+
@Before
public void setUp() {
BusFactory bf = BusFactory.newInstance();
bus = bf.createBus();
BusFactory.setDefaultBus(bus);
+ nmrTransportFactory = new NMRTransportFactory();
+ nmrTransportFactory.setBus(bus);
+ nmrTransportFactory.registerWithBindingManager();
control = EasyMock.createNiceControl();
}
@@ -66,14 +71,16 @@
}
- protected NMRConduit setupJBIConduit(boolean send, boolean decoupled) {
+ protected NMRConduit setupJBIConduit(boolean send, boolean decoupled)
throws IOException {
if (decoupled) {
// setup the reference type
} else {
target = control.createMock(EndpointReferenceType.class);
}
nmr = control.createMock(NMR.class);
- NMRConduit jbiConduit = new NMRConduit(bus, target, nmr);
+ nmrTransportFactory.setNmr(nmr);
+ //NMRConduit jbiConduit = new NMRConduit(bus, target, nmr);
+ NMRConduit jbiConduit = (NMRConduit)
nmrTransportFactory.getConduit(null, target);
if (send) {
// setMessageObserver
@@ -99,7 +106,7 @@
try {
conduit.prepare(message);
} catch (IOException ex) {
- assertFalse("JMSConduit can't perpare to send out message", false);
+ assertFalse("NMRConduit can't perpare to send out message", false);
ex.printStackTrace();
}
OutputStream os = message.getContent(OutputStream.class);
Modified:
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java?rev=780605&r1=780604&r2=780605&view=diff
==============================================================================
---
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
(original)
+++
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
Mon Jun 1 10:07:52 2009
@@ -19,13 +19,24 @@
package org.apache.servicemix.cxf.transport.nmr;
+import java.io.ByteArrayInputStream;
import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.InterfaceInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.transport.MessageObserver;
import org.apache.servicemix.nmr.api.Channel;
+import org.apache.servicemix.nmr.api.EndpointRegistry;
import org.easymock.EasyMock;
@@ -75,4 +86,52 @@
//Verify send method was called.
EasyMock.verify(channel);
}
+
+
+ @Test
+ public void testNMRDestination() throws Exception {
+ EndpointInfo ei = new EndpointInfo();
+ ei.setAddress("nmr://dumy");
+ ei.setName(new QName("http://test", "endpoint"));
+ ServiceInfo si = new ServiceInfo();
+ si.setName(new QName("http://test", "service"));
+ InterfaceInfo interInfo = new InterfaceInfo(si, new
QName("http://test", "interface"));
+ si.setInterface(interInfo);
+ ei.setService(si);
+ org.apache.servicemix.nmr.api.NMR nmr =
control.createMock(org.apache.servicemix.nmr.api.NMR.class);
+ nmrTransportFactory.setNmr(nmr);
+ NMRDestination destination = (NMRDestination)
nmrTransportFactory.getDestination(ei);
+ assertNotNull(destination);
+ String destName = ei.getService().getName().toString()
+ + ei.getInterface().getName().toString();
+ try {
+ nmrTransportFactory.putDestination(destName, destination);
+ fail();
+ } catch (Exception e) {
+ //should catch exception here since try put duplicated destination
+ }
+ assertEquals(destination,
nmrTransportFactory.getDestination(destName));
+ nmrTransportFactory.removeDestination(destName);
+ nmrTransportFactory.putDestination(destName, destination);
+
+ org.apache.servicemix.nmr.api.Exchange xchg =
control.createMock(org.apache.servicemix.nmr.api.Exchange.class);
+ org.apache.servicemix.nmr.api.Message inMsg =
control.createMock(org.apache.servicemix.nmr.api.Message.class);
+ EasyMock.expect(xchg.getIn()).andReturn(inMsg);
+
+ Source source = new StreamSource(new ByteArrayInputStream(
+ "<message>TestHelloWorld</message>".getBytes()));
+ EasyMock.expect(inMsg.getBody(Source.class)).andReturn(source);
+ EndpointRegistry endpoints =
control.createMock(EndpointRegistry.class);
+ EasyMock.expect(nmr.getEndpointRegistry()).andReturn(endpoints);
+
EasyMock.expect(nmrTransportFactory.getNmr().getEndpointRegistry()).andReturn(endpoints);
+ control.replay();
+ observer = new MessageObserver() {
+ public void onMessage(Message m) {
+ inMessage = m;
+ }
+ };
+ destination.setMessageObserver(observer);
+ destination.process(xchg);
+ assertNotNull(inMessage);
+ }
}