1 17 package org.apache.servicemix.eip; 18 19 import javax.jbi.messaging.ExchangeStatus; 20 import javax.jbi.messaging.InOnly; 21 import javax.jbi.messaging.InOptionalOut; 22 import javax.jbi.messaging.InOut; 23 import javax.jbi.messaging.RobustInOnly; 24 import javax.xml.namespace.QName ; 25 26 import org.apache.servicemix.eip.patterns.StaticRoutingSlip; 27 import org.apache.servicemix.eip.support.ExchangeTarget; 28 29 30 public class StaticRoutingSlipTest extends AbstractEIPTest { 31 32 protected StaticRoutingSlip routingSlip; 33 34 protected void setUp() throws Exception { 35 super.setUp(); 36 37 routingSlip = new StaticRoutingSlip(); 38 routingSlip.setTargets( 39 new ExchangeTarget[] { 40 createServiceExchangeTarget(new QName ("target1")), 41 createServiceExchangeTarget(new QName ("target2")), 42 createServiceExchangeTarget(new QName ("target3")) 43 }); 44 configurePattern(routingSlip); 45 activateComponent(routingSlip, "routingSlip"); 46 } 47 48 public void testInOnly() throws Exception { 49 InOnly me = client.createInOnlyExchange(); 50 me.setService(new QName ("routingSlip")); 51 me.getInMessage().setContent(createSource("<hello/>")); 52 client.sendSync(me); 53 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 54 assertNotNull(me.getError()); 55 assertEquals("Use an InOut MEP", me.getError().getMessage()); 56 } 57 58 public void testRobustInOnly() throws Exception { 59 RobustInOnly me = client.createRobustInOnlyExchange(); 60 me.setService(new QName ("routingSlip")); 61 me.getInMessage().setContent(createSource("<hello/>")); 62 client.sendSync(me); 63 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 64 assertNotNull(me.getError()); 65 assertEquals("Use an InOut MEP", me.getError().getMessage()); 66 } 67 68 public void testInOptionalOut() throws Exception { 69 InOptionalOut me = client.createInOptionalOutExchange(); 70 me.setService(new QName ("routingSlip")); 71 me.getInMessage().setContent(createSource("<hello/>")); 72 client.sendSync(me); 73 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 74 assertNotNull(me.getError()); 75 assertEquals("Use an InOut MEP", me.getError().getMessage()); 76 } 77 78 public void testDone() throws Exception { 79 activateComponent(new ReturnOutComponent(), "target1"); 80 activateComponent(new ReturnOutComponent(), "target2"); 81 activateComponent(new ReturnOutComponent(), "target3"); 82 83 InOut me = client.createInOutExchange(); 84 me.setService(new QName ("routingSlip")); 85 me.getInMessage().setContent(createSource("<hello/>")); 86 client.sendSync(me); 87 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 88 assertNotNull(me.getOutMessage()); 89 client.done(me); 90 91 listener.assertExchangeCompleted(); 92 } 93 94 public void testFaultOnFirst() throws Exception { 95 activateComponent(new ReturnFaultComponent(), "target1"); 96 activateComponent(new ReturnOutComponent(), "target2"); 97 activateComponent(new ReturnOutComponent(), "target3"); 98 99 InOut me = client.createInOutExchange(); 100 me.setService(new QName ("routingSlip")); 101 me.getInMessage().setContent(createSource("<hello/>")); 102 client.sendSync(me); 103 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 104 assertNotNull(me.getFault()); 105 client.done(me); 106 107 listener.assertExchangeCompleted(); 108 } 109 110 public void testErrorOnFirst() throws Exception { 111 activateComponent(new ReturnErrorComponent(), "target1"); 112 activateComponent(new ReturnOutComponent(), "target2"); 113 activateComponent(new ReturnOutComponent(), "target3"); 114 115 InOut me = client.createInOutExchange(); 116 me.setService(new QName ("routingSlip")); 117 me.getInMessage().setContent(createSource("<hello/>")); 118 client.sendSync(me); 119 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 120 121 listener.assertExchangeCompleted(); 122 } 123 124 public void testFaultOnSecond() throws Exception { 125 activateComponent(new ReturnOutComponent(), "target1"); 126 activateComponent(new ReturnFaultComponent(), "target2"); 127 activateComponent(new ReturnOutComponent(), "target3"); 128 129 InOut me = client.createInOutExchange(); 130 me.setService(new QName ("routingSlip")); 131 me.getInMessage().setContent(createSource("<hello/>")); 132 client.sendSync(me); 133 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 134 assertNotNull(me.getFault()); 135 client.done(me); 136 137 listener.assertExchangeCompleted(); 138 } 139 140 public void testErrorOnSecond() throws Exception { 141 activateComponent(new ReturnOutComponent(), "target1"); 142 activateComponent(new ReturnErrorComponent(), "target2"); 143 activateComponent(new ReturnOutComponent(), "target3"); 144 145 InOut me = client.createInOutExchange(); 146 me.setService(new QName ("routingSlip")); 147 me.getInMessage().setContent(createSource("<hello/>")); 148 client.sendSync(me); 149 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 150 151 listener.assertExchangeCompleted(); 152 } 153 154 public void testFaultOnThird() throws Exception { 155 activateComponent(new ReturnOutComponent(), "target1"); 156 activateComponent(new ReturnOutComponent(), "target2"); 157 activateComponent(new ReturnFaultComponent(), "target3"); 158 159 InOut me = client.createInOutExchange(); 160 me.setService(new QName ("routingSlip")); 161 me.getInMessage().setContent(createSource("<hello/>")); 162 client.sendSync(me); 163 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 164 assertNotNull(me.getFault()); 165 client.done(me); 166 167 listener.assertExchangeCompleted(); 168 } 169 170 public void testErrorOnThird() throws Exception { 171 activateComponent(new ReturnOutComponent(), "target1"); 172 activateComponent(new ReturnOutComponent(), "target2"); 173 activateComponent(new ReturnErrorComponent(), "target3"); 174 175 InOut me = client.createInOutExchange(); 176 me.setService(new QName ("routingSlip")); 177 me.getInMessage().setContent(createSource("<hello/>")); 178 client.sendSync(me); 179 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 180 181 listener.assertExchangeCompleted(); 182 } 183 184 185 } 186 | Popular Tags |