KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > mps > MPSSettingTest


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.mps;
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.jbi.jaxp.StringSource;
24 import org.apache.servicemix.tck.TestSupport;
25 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
26 import org.springframework.context.support.AbstractXmlApplicationContext;
27
28 /**
29  * @author Rmaon Buckland
30  * @version $Revision: $
31  */

32 public class MPSSettingTest extends TestSupport {
33
34     
35     /**
36      * load the property set from the spring injects string (fixed set)
37      * @throws Exception
38      */

39     public void testStaticStringPropertySet() throws Exception JavaDoc {
40         QName JavaDoc service = new QName JavaDoc("http://servicemix.org/cheese/", "mpsFixed");
41
42         InOut exchange = client.createInOutExchange();
43         exchange.setService(service);
44
45         NormalizedMessage message = exchange.getInMessage();
46         message.setContent(new StringSource(createMessageXmlText(777888)));
47         message.setProperty("prop.xpath.or.keep.existing","someValue");
48         message.setProperty("other.set.property","thatOtherValue");
49         client.sendSync(exchange);
50
51         NormalizedMessage outMessage = exchange.getOutMessage();
52
53         assertTrue(outMessage.getProperty("property.1").equals("foobarAndCheese"));
54         assertTrue(outMessage.getProperty("property.2").equals("777888"));
55         assertTrue(outMessage.getProperty("prop.xpath.or.keep.existing").equals("someValue"));
56         // this property is configured, but there is no "value to resolve it to"
57
assertTrue(outMessage.getProperty("new.prop.name") == null);
58         assertTrue(outMessage.getProperty("property.3").equals("thatOtherValue"));
59         
60     }
61     
62     
63     /**
64      * Load the property set using an xpath applied to the in message
65      * @throws Exception
66      */

67     public void testtestXpathLoadingPropertySet() throws Exception JavaDoc {
68         QName JavaDoc service = new QName JavaDoc("http://servicemix.org/cheese/", "mpsXpath");
69
70         InOut exchange = client.createInOutExchange();
71         exchange.setService(service);
72
73         NormalizedMessage message = exchange.getInMessage();
74         message.setContent(new StringSource(createMessageXmlText(400)));
75         client.sendSync(exchange);
76
77         NormalizedMessage outMessage = exchange.getOutMessage();
78
79         assertTrue(outMessage.getProperty("my-superdooper.property").equals("wishAusMadeItTotheFinals"));
80         
81     }
82     
83     /**
84      * load the property set from a JBI property value
85      * @throws Exception
86      */

87     public void testJBIPropertyLoadingPropertySet() throws Exception JavaDoc {
88         QName JavaDoc service = new QName JavaDoc("http://servicemix.org/cheese/", "mpsJBIPropsPS");
89
90         InOut exchange = client.createInOutExchange();
91         exchange.setService(service);
92
93         NormalizedMessage message = exchange.getInMessage();
94         message.setProperty(MessagePropertySetterXML.MPS_PROP_NAME_PROPERTYSET,"hello");
95         message.setContent(new StringSource(createMessageXmlText(54)));
96         client.sendSync(exchange);
97
98         NormalizedMessage outMessage = exchange.getOutMessage();
99
100         assertTrue(outMessage.getProperty("my-superdooper.property").equals("wishAusMadeItTotheFinals"));
101         
102     }
103     
104     
105     protected AbstractXmlApplicationContext createBeanFactory() {
106         return new ClassPathXmlApplicationContext("org/apache/servicemix/components/mps/servicemix-mps-test.xml");
107     }
108 }
109
110
111
Popular Tags