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 javax.jbi.messaging.ExchangeStatus;
20: import javax.jbi.messaging.InOnly;
21: import javax.jbi.messaging.MessageExchange;
22: import javax.jbi.servicedesc.ServiceEndpoint;
23:
24: import org.apache.servicemix.client.DefaultServiceMixClient;
25: import org.apache.servicemix.client.ServiceMixClient;
26: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
27: import org.apache.servicemix.jbi.jaxp.StringSource;
28: import org.apache.servicemix.jbi.util.FileUtil;
29: import org.apache.servicemix.tck.SpringTestSupport;
30: import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
31: import org.springframework.context.support.AbstractXmlApplicationContext;
32:
33: public class DynamicEndpointTest extends SpringTestSupport {
34: protected String dynamicURI = "truezip://target/dynamicEndpoint.zip?truezip.tempFilePrefix=dynamicEp-";
35:
36: protected void setUp() throws Exception {
37: super .setUp();
38: FileUtil.deleteFile(new java.io.File(
39: "target/dynamicEndpoint.zip"));
40: }
41:
42: public void testSendingToDynamicEndpoint() throws Exception {
43: ServiceMixClient client = new DefaultServiceMixClient(jbi);
44:
45: ServiceEndpoint se = client
46: .resolveEndpointReference(dynamicURI);
47: assertNotNull("We should find a service endpoint!", se);
48:
49: InOnly exchange = client.createInOnlyExchange();
50: exchange.setEndpoint(se);
51: exchange.getInMessage().setContent(
52: new StringSource("<hello>world</hello>"));
53: client.sendSync(exchange);
54:
55: assertExchangeWorked(exchange);
56: }
57:
58: protected void assertExchangeWorked(MessageExchange me)
59: throws Exception {
60: if (me.getStatus() == ExchangeStatus.ERROR) {
61: if (me.getError() != null) {
62: throw me.getError();
63: } else {
64: fail("Received ERROR status");
65: }
66: } else if (me.getFault() != null) {
67: fail("Received fault: "
68: + new SourceTransformer().toString(me.getFault()
69: .getContent()));
70: }
71: }
72:
73: protected AbstractXmlApplicationContext createBeanFactory() {
74: return new ClassPathXmlApplicationContext(
75: "spring-no-endpoints.xml");
76: }
77:
78: }
|