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