KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > util > CopyTransformerTest


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.util;
18
19 import java.io.Reader JavaDoc;
20 import java.io.StringReader JavaDoc;
21
22 import javax.jbi.messaging.NormalizedMessage;
23 import javax.xml.transform.Source JavaDoc;
24 import javax.xml.transform.sax.SAXSource JavaDoc;
25 import javax.xml.transform.stream.StreamSource JavaDoc;
26
27 import junit.framework.TestCase;
28
29 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
30 import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
31 import org.xml.sax.InputSource JavaDoc;
32
33 public class CopyTransformerTest extends TestCase {
34
35     private CopyTransformer transformer = CopyTransformer.getInstance();
36     
37     public void testWithSAXSource() throws Exception JavaDoc {
38         Reader JavaDoc r = new StringReader JavaDoc("<hello>world</hello>");
39         Source JavaDoc src = new SAXSource JavaDoc(new InputSource JavaDoc(r));
40         NormalizedMessage msg = copyMessage(src);
41         r.close();
42         new SourceTransformer().contentToString(msg);
43     }
44     
45     public void testWithStreamSource() throws Exception JavaDoc {
46         Reader JavaDoc r = new StringReader JavaDoc("<hello>world</hello>");
47         Source JavaDoc src = new StreamSource JavaDoc(r);
48         NormalizedMessage msg = copyMessage(src);
49         r.close();
50         new SourceTransformer().contentToString(msg);
51     }
52     
53     protected NormalizedMessage copyMessage(Source JavaDoc src) throws Exception JavaDoc {
54         NormalizedMessage from = new NormalizedMessageImpl();
55         NormalizedMessage to = new NormalizedMessageImpl();
56         from.setContent(src);
57         transformer.transform(null, from, to);
58         return to;
59     }
60     
61 }
62
Popular Tags