KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > validation > ValidationTest


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.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 /**
31  * @version $Revision: 430194 $
32  */

33 public class ValidationTest extends SpringTestSupport {
34     protected ServiceMixClient client;
35     protected Receiver receiver;
36
37     protected void setUp() throws Exception JavaDoc {
38         super.setUp();
39         SpringJBIContainer jbi = (SpringJBIContainer) getBean("jbi");
40         receiver = (Receiver) jbi.getBean("receiver");
41     }
42
43     public void testValidMessage() throws Exception JavaDoc {
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 JavaDoc 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 JavaDoc {
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 JavaDoc 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         // TODO?
80
//assertEquals("error", null, error);
81
}
82
83     public void testInvalidMessageWithMessageAwareErrorHandler() throws Exception JavaDoc {
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 JavaDoc 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         // TODO?
103
//assertEquals("error", null, error);
104
}
105
106     protected AbstractXmlApplicationContext createBeanFactory() {
107         return new ClassPathXmlApplicationContext("org/apache/servicemix/components/validation/example.xml");
108     }
109 }
110
Popular Tags