KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > wsif > WsifTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 JavaDoc;
22
23 import org.apache.servicemix.tck.TestSupport;
24 import org.springframework.context.support.AbstractXmlApplicationContext;
25 import org.w3c.dom.Node JavaDoc;
26 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
27
28 /**
29  * @version $Revision: 426415 $
30  */

31 public class WsifTest extends TestSupport {
32     QName JavaDoc serviceName = new QName JavaDoc("http://servicemix.org/cheese/", "checkAvailability");
33
34     public static final int MESSAGES = 2;
35     
36     public void testUsingXMLMessaging() throws Exception JavaDoc {
37         for (int i = 0; i < MESSAGES; i++) {
38             String JavaDoc file = "request.xml";
39     
40             Object JavaDoc answer = requestServiceWithFileRequest(serviceName, file);
41             assertTrue("Shoud return a DOM Node: " + answer, answer instanceof Node JavaDoc);
42             Node JavaDoc node = (Node JavaDoc) answer;
43             System.out.println(transformer.toString(node));
44     
45             String JavaDoc 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 JavaDoc {
54         for (int i = 0; i < MESSAGES; i++) {
55             // START SNIPPET: wsif
56
InOut exchange = client.createInOutExchange();
57     
58             exchange.getInMessage().setProperty("zipCode", "10505");
59             client.sendSync(exchange);
60     
61             NormalizedMessage out = exchange.getOutMessage();
62             String JavaDoc result = (String JavaDoc) out.getProperty("result");
63     
64             System.out.println("Found value: " + result);
65             // END SNIPPET: wsif
66

67             assertEquals("should have no fault", null, exchange.getFault());
68             Exception JavaDoc 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 JavaDoc {
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 JavaDoc 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 JavaDoc result = (String JavaDoc) 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