01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.truezip;
18:
19: import java.io.File;
20:
21: import javax.jbi.messaging.ExchangeStatus;
22: import javax.jbi.messaging.InOnly;
23: import javax.jbi.messaging.MessageExchange;
24: import javax.jbi.messaging.NormalizedMessage;
25: import javax.xml.namespace.QName;
26:
27: import org.apache.servicemix.client.DefaultServiceMixClient;
28: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
29: import org.apache.servicemix.jbi.jaxp.StringSource;
30: import org.apache.servicemix.jbi.util.FileUtil;
31: import org.apache.servicemix.tck.SpringTestSupport;
32: import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
33: import org.springframework.context.support.AbstractXmlApplicationContext;
34:
35: public class SpringComponentTest extends SpringTestSupport {
36:
37: protected void setUp() throws Exception {
38: FileUtil.deleteFile(new File("target/componentOutput.zip"));
39: super .setUp();
40: }
41:
42: public void testSendingToStaticEndpoint() throws Exception {
43: DefaultServiceMixClient client = new DefaultServiceMixClient(
44: jbi);
45: InOnly me = client.createInOnlyExchange();
46: me.setService(new QName("urn:test", "service"));
47: NormalizedMessage message = me.getInMessage();
48:
49: message.setProperty("name", "cheese");
50: message.setContent(new StringSource("<hello>world</hello>"));
51:
52: client.sendSync(me);
53: assertExchangeWorked(me);
54: }
55:
56: protected void assertExchangeWorked(MessageExchange me)
57: throws Exception {
58: if (me.getStatus() == ExchangeStatus.ERROR) {
59: if (me.getError() != null) {
60: throw me.getError();
61: } else {
62: fail("Received ERROR status");
63: }
64: } else if (me.getFault() != null) {
65: fail("Received fault: "
66: + new SourceTransformer().toString(me.getFault()
67: .getContent()));
68: }
69: }
70:
71: protected AbstractXmlApplicationContext createBeanFactory() {
72: return new ClassPathXmlApplicationContext("spring.xml");
73: }
74:
75: }
|