1 17 package org.apache.servicemix.components.validation; 18 19 import javax.jbi.messaging.Fault; 20 import javax.jbi.messaging.InOut; 21 import javax.jbi.messaging.NormalizedMessage; 22 23 import org.apache.servicemix.client.ServiceMixClient; 24 import org.apache.servicemix.jbi.container.SpringJBIContainer; 25 import org.apache.servicemix.tck.Receiver; 26 import org.apache.servicemix.tck.SpringTestSupport; 27 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; 28 import org.springframework.context.support.AbstractXmlApplicationContext; 29 30 33 public class ValidationTest extends SpringTestSupport { 34 protected ServiceMixClient client; 35 protected Receiver receiver; 36 37 protected void setUp() throws Exception { 38 super.setUp(); 39 SpringJBIContainer jbi = (SpringJBIContainer) getBean("jbi"); 40 receiver = (Receiver) jbi.getBean("receiver"); 41 } 42 43 public void testValidMessage() throws Exception { 44 client = (ServiceMixClient) getBean("defaultErrorHandlerClient"); 45 46 InOut exchange = client.createInOutExchange(); 47 exchange.getInMessage().setContent(getSourceFromClassPath("requestValid.xml")); 48 client.sendSync(exchange); 49 50 NormalizedMessage out = exchange.getOutMessage(); 51 Fault fault = exchange.getFault(); 52 Exception error = exchange.getError(); 53 54 assertEquals("error", null, error); 55 assertEquals("fault", null, fault); 56 57 assertNotNull("Should have an out message", out); 58 } 59 60 public void testInvalidMessage() throws Exception { 61 client = (ServiceMixClient) getBean("defaultErrorHandlerClient"); 62 63 InOut exchange = client.createInOutExchange(); 64 exchange.getInMessage().setContent(getSourceFromClassPath("requestInvalid.xml")); 65 client.sendSync(exchange); 66 67 NormalizedMessage out = exchange.getOutMessage(); 68 Fault fault = exchange.getFault(); 69 Exception error = exchange.getError(); 70 71 assertEquals("out", null, out); 72 assertNotNull("Should have a fault", fault); 73 74 System.out.println("error is: " + error); 75 76 System.out.println("Fault is..."); 77 System.out.println(transformer.toString(fault.getContent())); 78 79 } 82 83 public void testInvalidMessageWithMessageAwareErrorHandler() throws Exception { 84 client = (ServiceMixClient) getBean("messageAwareErrorHandlerClient"); 85 86 InOut exchange = client.createInOutExchange(); 87 exchange.getInMessage().setContent(getSourceFromClassPath("requestInvalid.xml")); 88 client.sendSync(exchange); 89 90 NormalizedMessage out = exchange.getOutMessage(); 91 Fault fault = exchange.getFault(); 92 Exception error = exchange.getError(); 93 94 assertEquals("out", null, out); 95 assertNotNull("Should have a fault", fault); 96 97 System.out.println("error is: " + error); 98 99 System.out.println("Fault is..."); 100 System.out.println(transformer.toString(fault.getContent())); 101 102 } 105 106 protected AbstractXmlApplicationContext createBeanFactory() { 107 return new ClassPathXmlApplicationContext("org/apache/servicemix/components/validation/example.xml"); 108 } 109 } 110 | Popular Tags |