KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > net > FTPTest


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.net;
18
19 import org.apache.servicemix.jbi.jaxp.StringSource;
20 import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
21 import org.apache.servicemix.tck.TestSupport;
22 import org.springframework.context.support.AbstractXmlApplicationContext;
23 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
24
25 import javax.jbi.messaging.InOnly;
26 import javax.jbi.messaging.NormalizedMessage;
27 import javax.xml.namespace.QName JavaDoc;
28
29 /**
30  * Warning: this test case requires an FTP server running on localhost with user / password
31  * of [servicemix/rocks].
32  * <p/>
33  * For details of how to set this up on OS X see
34  * <a HREF="http://www.ldml.com/services/support/macosx/ftpUserCreate.html">this tutorial</a>
35  *
36  * @version $Revision: 426415 $
37  */

38 public class FTPTest extends TestSupport {
39
40     public void testSendUsingMessageContentAndUniquelyGeneratedName() throws Exception JavaDoc {
41
42         // START SNIPPET: content
43
InOnly exchange = client.createInOnlyExchange();
44         NormalizedMessage message = exchange.getInMessage();
45
46         message.setContent(new StringSource("<hello>world!</hello>"));
47
48         client.sendSync(exchange);
49         // END SNIPPET: content
50
}
51
52     public void testSendUsingMessageProperties() throws Exception JavaDoc {
53
54         // START SNIPPET: properties
55
InOnly exchange = client.createInOnlyExchange();
56         NormalizedMessage message = exchange.getInMessage();
57
58         message.setProperty("org.apache.servicemix.file.name", "cheese.txt");
59         message.setProperty("org.apache.servicemix.file.content", "Hello World!");
60
61         client.sendSync(exchange);
62         // END SNIPPET: properties
63
}
64
65     public void testSendUsingMessageContentAndExpressionName() throws Exception JavaDoc {
66
67         QName JavaDoc service = new QName JavaDoc("http://servicemix.org/cheese/", "ftpSenderWithExpression");
68         ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(service);
69
70         InOnly exchange = client.createInOnlyExchange(resolver);
71         NormalizedMessage message = exchange.getInMessage();
72
73         message.setContent(new StringSource("<order id='abc123'><customer>Duff Beer</customer><value>599.99</value></order>"));
74
75         client.sendSync(exchange);
76     }
77
78     protected AbstractXmlApplicationContext createBeanFactory() {
79         return new ClassPathXmlApplicationContext("org/apache/servicemix/components/net/ftp.xml");
80     }
81 }
82
Popular Tags