Source Code Cross Referenced for XSLTMediatorTest.java in  » ESB » synapse » org » apache » synapse » mediators » transform » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » synapse » org.apache.synapse.mediators.transform 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one
003:         *  or more contributor license agreements.  See the NOTICE file
004:         *  distributed with this work for additional information
005:         *  regarding copyright ownership.  The ASF licenses this file
006:         *  to you under the Apache License, Version 2.0 (the
007:         *  "License"); you may not use this file except in compliance
008:         *  with the License.  You may obtain a copy of the License at
009:         *
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         *  Unless required by applicable law or agreed to in writing,
013:         *  software distributed under the License is distributed on an
014:         *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         *  KIND, either express or implied.  See the License for the
016:         *  specific language governing permissions and limitations
017:         *  under the License.
018:         */
019:
020:        package org.apache.synapse.mediators.transform;
021:
022:        import junit.framework.TestCase;
023:        import org.apache.axiom.om.OMContainer;
024:        import org.apache.axiom.om.OMElement;
025:        import org.apache.synapse.MessageContext;
026:        import org.apache.synapse.config.Entry;
027:        import org.apache.synapse.mediators.MediatorProperty;
028:        import org.apache.synapse.mediators.TestUtils;
029:        import org.apache.synapse.util.xpath.SynapseXPath;
030:
031:        import java.net.URL;
032:        import java.util.ArrayList;
033:        import java.util.HashMap;
034:        import java.util.List;
035:        import java.util.Map;
036:
037:        public class XSLTMediatorTest extends TestCase {
038:
039:            private static final String SOURCE = "<m0:CheckPriceRequest xmlns:m0=\"http://services.samples/xsd\">\n"
040:                    + "<m0:Code>String</m0:Code>\n" + "</m0:CheckPriceRequest>";
041:
042:            private static final String ENCLOSING_SOURCE = "<m:someOtherElement xmlns:m=\"http://someother\">"
043:                    + "<m0:CheckPriceRequest xmlns:m0=\"http://services.samples/xsd\">\n"
044:                    + "<m0:Code>String</m0:Code>\n"
045:                    + "</m0:CheckPriceRequest>"
046:                    + "</m:someOtherElement>";
047:
048:            XSLTMediator transformMediator = null;
049:
050:            public void testTransformXSLTCustomSource() throws Exception {
051:
052:                // create a new switch mediator
053:                transformMediator = new XSLTMediator();
054:
055:                // set xpath condition to select source
056:                SynapseXPath xpath = new SynapseXPath("//m0:CheckPriceRequest");
057:                xpath.addNamespace("m0", "http://services.samples/xsd");
058:                transformMediator.setSource(xpath);
059:
060:                // set XSLT transformation URL
061:                transformMediator.setXsltKey("xslt-key");
062:                List list = new ArrayList();
063:                MediatorProperty mp = new MediatorProperty();
064:                mp.setName("parama1");
065:                mp.setValue("value1");
066:                list.add(mp);
067:                transformMediator.addAllProperties(list);
068:                Map props = new HashMap();
069:                Entry prop = new Entry();
070:                prop.setType(Entry.URL_SRC);
071:                prop
072:                        .setSrc(new URL(
073:                                "file:./../../repository/conf/sample/resources/transform/transform_unittest.xslt"));
074:                props.put("xslt-key", prop);
075:
076:                // invoke transformation, with static enveope
077:                MessageContext synCtx = TestUtils
078:                        .getTestContextForXSLTMediator(SOURCE, props);
079:                transformMediator.mediate(synCtx);
080:
081:                // validate result
082:                OMContainer body = synCtx.getEnvelope().getBody();
083:                if (body.getFirstOMChild().getNextOMSibling() instanceof  OMElement) {
084:
085:                    OMElement getQuoteElem = (OMElement) body.getFirstOMChild()
086:                            .getNextOMSibling();
087:                    assertTrue("GetQuote".equals(getQuoteElem.getLocalName()));
088:                    assertTrue("http://www.webserviceX.NET/"
089:                            .equals(getQuoteElem.getNamespace()
090:                                    .getNamespaceURI()));
091:
092:                    OMElement symbolElem = getQuoteElem.getFirstElement();
093:                    assertTrue("symbol".equals(symbolElem.getLocalName()));
094:                    assertTrue("http://www.webserviceX.NET/".equals(symbolElem
095:                            .getNamespace().getNamespaceURI()));
096:
097:                    assertTrue("String".equals(symbolElem.getText()));
098:                } else {
099:                    fail("Unexpected element found in SOAP body");
100:                }
101:            }
102:
103:            /**
104:             * If a source element for transformation is not found, default to soap body
105:             * @throws Exception
106:             */
107:            public void testTransformXSLTDefaultSource() throws Exception {
108:
109:                // create a new switch mediator
110:                transformMediator = new XSLTMediator();
111:
112:                // set XSLT transformation URL
113:                transformMediator.setXsltKey("xslt-key");
114:
115:                Map props = new HashMap();
116:                Entry prop = new Entry();
117:                prop.setType(Entry.URL_SRC);
118:                prop
119:                        .setSrc(new URL(
120:                                "file:./../../repository/conf/sample/resources/transform/transform_unittest.xslt"));
121:                props.put("xslt-key", prop);
122:
123:                // invoke transformation, with static enveope
124:                MessageContext synCtx = TestUtils
125:                        .getTestContextForXSLTMediator(SOURCE, props);
126:                transformMediator.mediate(synCtx);
127:
128:                // validate result
129:                OMContainer body = synCtx.getEnvelope().getBody();
130:                if (body.getFirstOMChild().getNextOMSibling() instanceof  OMElement) {
131:
132:                    OMElement getQuoteElem = (OMElement) body.getFirstOMChild()
133:                            .getNextOMSibling();
134:                    assertTrue("GetQuote".equals(getQuoteElem.getLocalName()));
135:                    assertTrue("http://www.webserviceX.NET/"
136:                            .equals(getQuoteElem.getNamespace()
137:                                    .getNamespaceURI()));
138:
139:                    OMElement symbolElem = getQuoteElem.getFirstElement();
140:                    assertTrue("symbol".equals(symbolElem.getLocalName()));
141:                    assertTrue("http://www.webserviceX.NET/".equals(symbolElem
142:                            .getNamespace().getNamespaceURI()));
143:
144:                    assertTrue("String".equals(symbolElem.getText()));
145:                } else {
146:                    fail("Unexpected element found in SOAP body");
147:                }
148:            }
149:
150:            public void testTransformXSLTLargeMessagesCSV() throws Exception {
151:
152:                // create a new switch mediator
153:                transformMediator = new XSLTMediator();
154:                // set XSLT transformation URL
155:                transformMediator.setXsltKey("xslt-key");
156:
157:                for (int i = 0; i < 2; i++) {
158:                    Map props = new HashMap();
159:                    Entry prop = new Entry();
160:                    prop.setType(Entry.URL_SRC);
161:                    prop
162:                            .setSrc(new URL(
163:                                    "file:./../../repository/conf/sample/resources/transform/transform_load.xml"));
164:                    props.put("xslt-key", prop);
165:
166:                    // invoke transformation, with static enveope
167:                    MessageContext synCtx = TestUtils
168:                            .getTestContextForXSLTMediatorUsingFile(
169:                                    "./../../repository/conf/sample/resources/transform/message.xml",
170:                                    props);
171:                    //MessageContext synCtx = TestUtils.getTestContextForXSLTMediator(SOURCE, props);
172:                    transformMediator.mediate(synCtx);
173:                    //            synCtx.getEnvelope().serializeAndConsume(new FileOutputStream("/tmp/out.xml"));
174:                    //            System.gc();
175:                    //            System.out.println("done : " + i + " :: " + Runtime.getRuntime().freeMemory());
176:                }
177:            }
178:
179:            public void testTransformXSLTLargeMessagesXML() throws Exception {
180:
181:                // create a new switch mediator
182:                transformMediator = new XSLTMediator();
183:                // set XSLT transformation URL
184:                transformMediator.setXsltKey("xslt-key");
185:
186:                for (int i = 0; i < 2; i++) {
187:                    Map props = new HashMap();
188:                    Entry prop = new Entry();
189:                    prop.setType(Entry.URL_SRC);
190:                    prop
191:                            .setSrc(new URL(
192:                                    "file:./../../repository/conf/sample/resources/transform/transform_load_3.xml"));
193:                    props.put("xslt-key", prop);
194:
195:                    // invoke transformation, with static enveope
196:                    MessageContext synCtx = TestUtils
197:                            .getTestContextForXSLTMediatorUsingFile(
198:                                    "./../../repository/conf/sample/resources/transform/message.xml",
199:                                    props);
200:                    //MessageContext synCtx = TestUtils.getTestContextForXSLTMediator(SOURCE, props);
201:                    transformMediator.mediate(synCtx);
202:                    //            System.gc();
203:                    //            System.out.println("done : " + i + " :: " + Runtime.getRuntime().freeMemory());
204:                }
205:            }
206:
207:            public void testSynapse242() throws Exception {
208:
209:                // create a new switch mediator
210:                transformMediator = new XSLTMediator();
211:                // set XSLT transformation URL
212:                transformMediator.setXsltKey("xslt-key");
213:
214:                Map props = new HashMap();
215:                Entry prop = new Entry();
216:                prop.setType(Entry.URL_SRC);
217:                prop
218:                        .setSrc(new URL(
219:                                "file:./../../repository/conf/sample/resources/transform/transform_load_2.xml"));
220:                props.put("xslt-key", prop);
221:
222:                // invoke transformation, with static enveope
223:                MessageContext synCtx = TestUtils
224:                        .getTestContextForXSLTMediatorUsingFile(
225:                                "./../../repository/conf/sample/resources/transform/med_message.xml",
226:                                props);
227:                transformMediator.mediate(synCtx);
228:
229:                // validate result
230:                OMContainer body = synCtx.getEnvelope().getBody();
231:                assertTrue(body.getFirstOMChild().getNextOMSibling() instanceof  OMElement);
232:                assertTrue(((OMElement) body.getFirstOMChild()
233:                        .getNextOMSibling()).getText().length() > 0);
234:            }
235:
236:            public void testTransformXSLTSmallMessages() throws Exception {
237:
238:                // create a new switch mediator
239:                transformMediator = new XSLTMediator();
240:                // set XSLT transformation URL
241:                transformMediator.setXsltKey("xslt-key");
242:
243:                for (int i = 0; i < 5; i++) {
244:                    Map props = new HashMap();
245:                    Entry prop = new Entry();
246:                    prop.setType(Entry.URL_SRC);
247:                    prop
248:                            .setSrc(new URL(
249:                                    "file:./../../repository/conf/sample/resources/transform/transform_load_2.xml"));
250:                    props.put("xslt-key", prop);
251:
252:                    // invoke transformation, with static enveope
253:                    MessageContext synCtx = TestUtils
254:                            .getTestContextForXSLTMediatorUsingFile(
255:                                    "./../../repository/conf/sample/resources/transform/small_message.xml",
256:                                    props);
257:                    //MessageContext synCtx = TestUtils.getTestContextForXSLTMediator(SOURCE, props);
258:                    transformMediator.mediate(synCtx);
259:                    //System.out.println("done : " + i + " :: " + Runtime.getRuntime().freeMemory());
260:                }
261:            }
262:
263:            public void testTransformXSLTCustomSourceNonMainElement()
264:                    throws Exception {
265:
266:                // create a new switch mediator
267:                transformMediator = new XSLTMediator();
268:
269:                // set xpath condition to select source
270:                SynapseXPath xpath = new SynapseXPath("//m0:CheckPriceRequest");
271:                xpath.addNamespace("m0", "http://services.samples/xsd");
272:                transformMediator.setSource(xpath);
273:
274:                // set XSLT transformation URL
275:                transformMediator.setXsltKey("xslt-key");
276:
277:                Map props = new HashMap();
278:                Entry prop = new Entry();
279:                prop.setType(Entry.URL_SRC);
280:                prop
281:                        .setSrc(new URL(
282:                                "file:./../../repository/conf/sample/resources/transform/transform_unittest.xslt"));
283:                props.put("xslt-key", prop);
284:
285:                // invoke transformation, with static enveope
286:                MessageContext synCtx = TestUtils
287:                        .getTestContextForXSLTMediator(ENCLOSING_SOURCE, props);
288:                transformMediator.mediate(synCtx);
289:
290:                // validate result
291:                OMContainer body = synCtx.getEnvelope().getBody();
292:                if (body.getFirstOMChild().getNextOMSibling() instanceof  OMElement) {
293:
294:                    OMElement someOtherElem = (OMElement) body
295:                            .getFirstOMChild().getNextOMSibling();
296:                    assertTrue("someOtherElement".equals(someOtherElem
297:                            .getLocalName()));
298:                    assertTrue("http://someother".equals(someOtherElem
299:                            .getNamespace().getNamespaceURI()));
300:
301:                    OMElement getQuoteElem = (OMElement) someOtherElem
302:                            .getFirstOMChild();
303:                    assertTrue("GetQuote".equals(getQuoteElem.getLocalName()));
304:                    assertTrue("http://www.webserviceX.NET/"
305:                            .equals(getQuoteElem.getNamespace()
306:                                    .getNamespaceURI()));
307:
308:                    OMElement symbolElem = getQuoteElem.getFirstElement();
309:                    assertTrue("symbol".equals(symbolElem.getLocalName()));
310:                    assertTrue("http://www.webserviceX.NET/".equals(symbolElem
311:                            .getNamespace().getNamespaceURI()));
312:
313:                    assertTrue("String".equals(symbolElem.getText()));
314:                } else {
315:                    fail("Unexpected element found in SOAP body");
316:                }
317:            }
318:
319:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.