1 17 package org.apache.servicemix.components.wsif; 18 19 import javax.jbi.messaging.InOut; 20 import javax.jbi.messaging.NormalizedMessage; 21 import javax.xml.namespace.QName ; 22 23 import org.apache.servicemix.tck.TestSupport; 24 import org.springframework.context.support.AbstractXmlApplicationContext; 25 import org.w3c.dom.Node ; 26 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; 27 28 31 public class WsifTest extends TestSupport { 32 QName serviceName = new QName ("http://servicemix.org/cheese/", "checkAvailability"); 33 34 public static final int MESSAGES = 2; 35 36 public void testUsingXMLMessaging() throws Exception { 37 for (int i = 0; i < MESSAGES; i++) { 38 String file = "request.xml"; 39 40 Object answer = requestServiceWithFileRequest(serviceName, file); 41 assertTrue("Shoud return a DOM Node: " + answer, answer instanceof Node ); 42 Node node = (Node ) answer; 43 System.out.println(transformer.toString(node)); 44 45 String text = textValueOfXPath(node, "/*/*[local-name()='part']").trim(); 46 47 System.out.println("Found value: " + text); 48 49 assertTrue("price text should not be empty", text.length() > 0); 50 } 51 } 52 53 public void testUsingWSIFStyleJBI() throws Exception { 54 for (int i = 0; i < MESSAGES; i++) { 55 InOut exchange = client.createInOutExchange(); 57 58 exchange.getInMessage().setProperty("zipCode", "10505"); 59 client.sendSync(exchange); 60 61 NormalizedMessage out = exchange.getOutMessage(); 62 String result = (String ) out.getProperty("result"); 63 64 System.out.println("Found value: " + result); 65 67 assertEquals("should have no fault", null, exchange.getFault()); 68 Exception error = exchange.getError(); 69 if (error != null) { 70 throw error; 71 } 72 assertEquals("should have no error", null, error); 73 assertNotNull("must have an output message!", out); 74 75 assertTrue("price text should not be empty", result.length() > 0); 76 } 77 } 78 79 public void testUsingWSIFStyleJBIWithEarlyErrorHandling() throws Exception { 80 for (int i = 0; i < MESSAGES; i++) { 81 InOut exchange = client.createInOutExchange(); 82 83 exchange.getInMessage().setProperty("zipCode", "10505"); 84 client.sendSync(exchange); 85 86 Exception error = exchange.getError(); 87 if (error != null) { 88 throw error; 89 } 90 91 assertEquals("should have no fault", null, exchange.getFault()); 92 assertEquals("should have no error", null, error); 93 94 NormalizedMessage out = exchange.getOutMessage(); 95 assertNotNull("must have an output message!", out); 96 97 String result = (String ) out.getProperty("result"); 98 99 System.out.println("Found value: " + result); 100 101 assertTrue("price text should not be empty", result.length() > 0); 102 } 103 } 104 105 protected AbstractXmlApplicationContext createBeanFactory() { 106 return new ClassPathXmlApplicationContext("org/apache/servicemix/components/wsif/example.xml"); 107 } 108 } 109 | Popular Tags |