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.ftp;
18:
19: import javax.jbi.messaging.ExchangeStatus;
20: import javax.jbi.messaging.InOnly;
21: import javax.jbi.messaging.MessageExchange;
22: import javax.jbi.messaging.NormalizedMessage;
23: import javax.xml.namespace.QName;
24:
25: import org.apache.servicemix.client.DefaultServiceMixClient;
26: import org.apache.servicemix.components.util.DefaultFileMarshaler;
27: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
28: import org.apache.servicemix.jbi.jaxp.StringSource;
29: import org.apache.servicemix.tck.Receiver;
30: import org.apache.servicemix.tck.SpringTestSupport;
31: import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
32: import org.springframework.context.support.AbstractXmlApplicationContext;
33:
34: public class PollDirectoryTest extends SpringTestSupport {
35: private static final int NUMBER = 100;
36: private static final int SIZE = 100;
37:
38: protected String directoryName = "target/pollDirectory";
39: protected String dynamicURI = "file:" + directoryName;
40:
41: public void testSendToWriterSoItCanBePolled() throws Exception {
42: // now lets make a request on this endpoint
43: DefaultServiceMixClient client = new DefaultServiceMixClient(
44: jbi);
45:
46: StringBuffer sb = new StringBuffer("<root>");
47: for (int i = 0; i < SIZE; i++) {
48: sb.append("<hello>world</hello>");
49: }
50: sb.append("</root>");
51:
52: // lets send a request to be written to a file
53: // which should then be polled
54: for (int i = 0; i < NUMBER; i++) {
55: InOnly me = client.createInOnlyExchange();
56: me.setService(new QName("urn:test", "service"));
57: NormalizedMessage message = me.getInMessage();
58: message.setProperty(
59: DefaultFileMarshaler.FILE_NAME_PROPERTY, "test" + i
60: + ".xml");
61: message.setContent(new StringSource(sb.toString()));
62: client.sendSync(me);
63: }
64:
65: Receiver receiver = (Receiver) getBean("receiver");
66: receiver.getMessageList().assertMessagesReceived(NUMBER);
67: }
68:
69: protected void assertExchangeWorked(MessageExchange me)
70: throws Exception {
71: if (me.getStatus() == ExchangeStatus.ERROR) {
72: if (me.getError() != null) {
73: throw me.getError();
74: } else {
75: fail("Received ERROR status");
76: }
77: } else if (me.getFault() != null) {
78: fail("Received fault: "
79: + new SourceTransformer().toString(me.getFault()
80: .getContent()));
81: }
82: }
83:
84: protected AbstractXmlApplicationContext createBeanFactory() {
85: return new ClassPathXmlApplicationContext("spring-polling.xml");
86: }
87:
88: }
|