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.Pipeline; 27 import org.apache.servicemix.tck.ReceiverComponent; 28 29 public class PipelineTest extends AbstractEIPTest { 30 31 protected Pipeline pipeline; 32 33 protected void setUp() throws Exception { 34 super.setUp(); 35 36 pipeline = new Pipeline(); 37 pipeline.setTransformer(createServiceExchangeTarget(new QName ("transformer"))); 38 pipeline.setTarget(createServiceExchangeTarget(new QName ("target"))); 39 configurePattern(pipeline); 40 activateComponent(pipeline, "pipeline"); 41 } 42 43 public void testInOut() throws Exception { 44 InOut me = client.createInOutExchange(); 45 me.setService(new QName ("pipeline")); 46 me.getInMessage().setContent(createSource("<hello/>")); 47 client.sendSync(me); 48 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 49 } 50 51 public void testInOptionalOut() throws Exception { 52 InOptionalOut me = client.createInOptionalOutExchange(); 53 me.setService(new QName ("pipeline")); 54 me.getInMessage().setContent(createSource("<hello/>")); 55 client.sendSync(me); 56 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 57 } 58 59 public void testInOnly() throws Exception { 60 activateComponent(new ReturnOutComponent(), "transformer"); 61 ReceiverComponent target = activateReceiver("target"); 62 63 InOnly me = client.createInOnlyExchange(); 64 me.setService(new QName ("pipeline")); 65 me.getInMessage().setContent(createSource("<hello/>")); 66 client.sendSync(me); 67 assertEquals(ExchangeStatus.DONE, me.getStatus()); 68 69 target.getMessageList().assertMessagesReceived(1); 70 71 listener.assertExchangeCompleted(); 72 } 73 74 public void testInOnlyWithTransformerFault() throws Exception { 75 activateComponent(new ReturnFaultComponent(), "transformer"); 76 ReceiverComponent target = activateReceiver("target"); 77 78 InOnly me = client.createInOnlyExchange(); 79 me.setService(new QName ("pipeline")); 80 me.getInMessage().setContent(createSource("<hello/>")); 81 client.sendSync(me); 82 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 83 84 target.getMessageList().assertMessagesReceived(0); 85 86 listener.assertExchangeCompleted(); 87 } 88 89 public void testInOnlyWithTransformerError() throws Exception { 90 activateComponent(new ReturnErrorComponent(), "transformer"); 91 ReceiverComponent target = activateReceiver("target"); 92 93 InOnly me = client.createInOnlyExchange(); 94 me.setService(new QName ("pipeline")); 95 me.getInMessage().setContent(createSource("<hello/>")); 96 client.sendSync(me); 97 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 98 99 target.getMessageList().assertMessagesReceived(0); 100 101 listener.assertExchangeCompleted(); 102 } 103 104 public void testInOnlyWithTargetError() throws Exception { 105 activateComponent(new ReturnOutComponent(), "transformer"); 106 activateComponent(new ReturnErrorComponent(), "target"); 107 108 InOnly me = client.createInOnlyExchange(); 109 me.setService(new QName ("pipeline")); 110 me.getInMessage().setContent(createSource("<hello/>")); 111 client.sendSync(me); 112 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 113 114 listener.assertExchangeCompleted(); 115 } 116 117 public void testRobustInOnly() throws Exception { 118 activateComponent(new ReturnOutComponent(), "transformer"); 119 ReceiverComponent target = activateReceiver("target"); 120 121 RobustInOnly me = client.createRobustInOnlyExchange(); 122 me.setService(new QName ("pipeline")); 123 me.getInMessage().setContent(createSource("<hello/>")); 124 client.sendSync(me); 125 assertEquals(ExchangeStatus.DONE, me.getStatus()); 126 127 target.getMessageList().assertMessagesReceived(1); 128 129 listener.assertExchangeCompleted(); 130 } 131 132 public void testRobustInOnlyWithTransformerFault() throws Exception { 133 activateComponent(new ReturnFaultComponent(), "transformer"); 134 ReceiverComponent target = activateReceiver("target"); 135 136 RobustInOnly me = client.createRobustInOnlyExchange(); 137 me.setService(new QName ("pipeline")); 138 me.getInMessage().setContent(createSource("<hello/>")); 139 client.sendSync(me); 140 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 141 assertNotNull(me.getFault()); 142 client.done(me); 143 144 target.getMessageList().assertMessagesReceived(0); 145 146 listener.assertExchangeCompleted(); 147 } 148 149 public void testRobustInOnlyWithTransformerFaultAndError() throws Exception { 150 activateComponent(new ReturnFaultComponent(), "transformer"); 151 ReceiverComponent target = activateReceiver("target"); 152 153 RobustInOnly me = client.createRobustInOnlyExchange(); 154 me.setService(new QName ("pipeline")); 155 me.getInMessage().setContent(createSource("<hello/>")); 156 client.sendSync(me); 157 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 158 assertNotNull(me.getFault()); 159 client.fail(me, new Exception ("I do not like faults")); 160 161 target.getMessageList().assertMessagesReceived(0); 162 163 listener.assertExchangeCompleted(); 164 } 165 166 public void testRobustInOnlyWithTransformerError() throws Exception { 167 activateComponent(new ReturnErrorComponent(), "transformer"); 168 ReceiverComponent target = activateReceiver("target"); 169 170 RobustInOnly me = client.createRobustInOnlyExchange(); 171 me.setService(new QName ("pipeline")); 172 me.getInMessage().setContent(createSource("<hello/>")); 173 client.sendSync(me); 174 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 175 176 target.getMessageList().assertMessagesReceived(0); 177 178 listener.assertExchangeCompleted(); 179 } 180 181 public void testRobustInOnlyWithTargetFault() throws Exception { 182 activateComponent(new ReturnOutComponent(), "transformer"); 183 activateComponent(new ReturnFaultComponent(), "target"); 184 185 RobustInOnly me = client.createRobustInOnlyExchange(); 186 me.setService(new QName ("pipeline")); 187 me.getInMessage().setContent(createSource("<hello/>")); 188 client.sendSync(me); 189 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 190 assertNotNull(me.getFault()); 191 client.done(me); 192 193 listener.assertExchangeCompleted(); 194 } 195 196 public void testRobustInOnlyWithTargetFaultAndError() throws Exception { 197 activateComponent(new ReturnOutComponent(), "transformer"); 198 activateComponent(new ReturnFaultComponent(), "target"); 199 200 RobustInOnly me = client.createRobustInOnlyExchange(); 201 me.setService(new QName ("pipeline")); 202 me.getInMessage().setContent(createSource("<hello/>")); 203 client.sendSync(me); 204 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 205 assertNotNull(me.getFault()); 206 client.fail(me, new Exception ("I do not like faults")); 207 208 listener.assertExchangeCompleted(); 209 } 210 211 public void testRobustInOnlyWithTargetError() throws Exception { 212 activateComponent(new ReturnOutComponent(), "transformer"); 213 activateComponent(new ReturnErrorComponent(), "target"); 214 215 RobustInOnly me = client.createRobustInOnlyExchange(); 216 me.setService(new QName ("pipeline")); 217 me.getInMessage().setContent(createSource("<hello/>")); 218 client.sendSync(me); 219 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 220 221 listener.assertExchangeCompleted(); 222 } 223 224 } 225 | Popular Tags |