Source Code Cross Referenced for TransformerProviderTest.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » component » transformer » 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 » cbesb 1.2 » com.bostechcorp.cbesb.runtime.component.transformer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ChainBuilder ESB
003:         *          Visual Enterprise Integration
004:         * 
005:         * Copyright (C) 2006 Bostech Corporation
006:         * 
007:         * This program is free software; you can redistribute it and/or modify 
008:         * it under the terms of the GNU General Public License as published by 
009:         * the Free Software Foundation; either version 2 of the License, or 
010:         * (at your option) any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful, 
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of 
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
015:         * General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License 
018:         * along with this program; if not, write to the Free Software 
019:         * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307 
020:         * USA
021:         *
022:         *
023:         *
024:         */
025:        /*
026:         * Copyright 2005-2006 The Apache Software Foundation.
027:         *
028:         * Licensed under the Apache License, Version 2.0 (the "License");
029:         * you may not use this file except in compliance with the License.
030:         * You may obtain a copy of the License at
031:         *
032:         *      http://www.apache.org/licenses/LICENSE-2.0
033:         *
034:         * Unless required by applicable law or agreed to in writing, software
035:         * distributed under the License is distributed on an "AS IS" BASIS,
036:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
037:         * See the License for the specific language governing permissions and
038:         * limitations under the License.
039:         */
040:        package com.bostechcorp.cbesb.runtime.component.transformer;
041:
042:        import java.io.File;
043:        import java.io.FileInputStream;
044:        import java.net.URI;
045:        import java.net.URL;
046:
047:        import javax.jbi.messaging.ExchangeStatus;
048:        import javax.jbi.messaging.InOut;
049:        import javax.jbi.messaging.NormalizedMessage;
050:        import javax.xml.namespace.QName;
051:        import javax.xml.transform.Source;
052:        import javax.xml.transform.dom.DOMSource;
053:
054:        import junit.framework.TestCase;
055:
056:        import org.apache.servicemix.client.DefaultServiceMixClient;
057:        import org.apache.servicemix.jbi.container.JBIContainer;
058:        import org.apache.servicemix.jbi.jaxp.SourceTransformer;
059:        import org.apache.servicemix.jbi.messaging.InOutImpl;
060:        import org.w3c.dom.Document;
061:
062:        import com.bostechcorp.cbesb.common.util.Dom;
063:        import com.bostechcorp.cbesb.common.util.FileUtil;
064:        import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.NormalizedMessageHandler;
065:        import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.StringSource;
066:
067:        public class TransformerProviderTest extends TestCase {
068:
069:            protected JBIContainer container;
070:
071:            protected void setUp() throws Exception {
072:                container = new JBIContainer();
073:                container.setUseMBeanServer(false);
074:                container.setCreateMBeanServer(false);
075:                container.setEmbedded(true);
076:                container.setCreateJmxConnector(false);
077:                container.init();
078:            }
079:
080:            protected void tearDown() throws Exception {
081:                if (container != null) {
082:                    container.shutDown();
083:                }
084:            }
085:
086:            /*
087:             * The component flow for this testing are as follow:
088:             * 
089:             * SMClient creates -> InOnly  -> route FileComponent's Provider side -> Write into the outbox directory 
090:             * -> picked up by FilePoller -> route to ReceiverComponent 
091:             * 
092:             */
093:
094:            protected long testInOut(File inputFile, boolean streaming,
095:                    boolean isXml) throws Exception {
096:
097:                // ParserConfig Component    	
098:                TransformerComponent component = new TransformerComponent();
099:                container.activateComponent(component,
100:                        "TransformerProviderTest");
101:
102:                // Start container
103:                container.start();
104:
105:                // Deploy SU
106:                URL url = getClass().getClassLoader().getResource(
107:                        "provider/transformer.wsdl");
108:                File path = new File(new URI(url.toString()));
109:                path = path.getParentFile();
110:                component.getServiceUnitManager().deploy("provider",
111:                        path.getAbsolutePath());
112:                component.getServiceUnitManager().start("provider");
113:
114:                // Call it
115:                DefaultServiceMixClient client = new DefaultServiceMixClient(
116:                        container);
117:                InOut inout = new InOutImpl("exchangeId");
118:
119:                inout
120:                        .setInterfaceName(new QName(
121:                                "http://parser.bostechcorp.com/Test",
122:                                "XformInterface"));
123:                NormalizedMessage nmsg = inout.createMessage();
124:
125:                //Create an instance of DataMessageUtil to wrap the NormalizedMessage
126:                NormalizedMessageHandler dataMessage1 = new NormalizedMessageHandler(
127:                        nmsg);
128:                //Add the Source as a record        
129:                if (isXml) {
130:                    Document input = Dom.getDomTree(inputFile, null);
131:                    input.normalizeDocument();
132:                    dataMessage1.addRecord(new DOMSource(input));
133:                } else {
134:                    dataMessage1.addRecord(new StringSource(FileUtil
135:                            .readString(new FileInputStream(inputFile))));
136:                }
137:
138:                dataMessage1.debugContents();
139:
140:                nmsg = dataMessage1.generateMessageContent();
141:                inout.setMessage(nmsg, "In");
142:
143:                long t0 = System.currentTimeMillis();
144:
145:                boolean result = client.sendSync(inout);
146:                assertTrue(result);
147:                assertTrue(inout.getStatus() == ExchangeStatus.ACTIVE);
148:                NormalizedMessage out = inout.getOutMessage();
149:                assertNotNull(out);
150:                Source src = out.getContent();
151:                assertNotNull(src);
152:
153:                String resultXML = "";
154:                System.err.println(resultXML = new SourceTransformer()
155:                        .toString(src));
156:                assertTrue(
157:                        "ParserConfig result fails to match: ",
158:                        resultXML
159:                                .equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><DataEnvelope><XMLRecord><Message xmlns=\"http://www.bostechcorp.com/variable\"><ID>Record 1</ID><Data>This is the data for record 1</Data></Message></XMLRecord><XMLRecord><Message xmlns=\"http://www.bostechcorp.com/variable\"><ID>Record 2</ID><Data>This is the data for record 2</Data></Message></XMLRecord><XMLRecord><Message xmlns=\"http://www.bostechcorp.com/variable\"><ID>Record 3</ID><Data>This is the data for record 3</Data></Message></XMLRecord><XMLRecord><Message xmlns=\"http://www.bostechcorp.com/variable\"><ID>Record 4</ID><Data>This is the data for record 4</Data></Message></XMLRecord><XMLRecord><Message xmlns=\"http://www.bostechcorp.com/variable\"><ID>Record 5</ID><Data>This is the data for record 5</Data></Message></XMLRecord></DataEnvelope>"));
160:
161:                inout.setStatus(ExchangeStatus.DONE);
162:                client.send(inout);
163:                long t1 = System.currentTimeMillis();
164:
165:                //     Let us sleep for a while and give other side a chance to receive exchange
166:                try {
167:                    Thread.sleep(5 * 1000);
168:                } catch (InterruptedException e) {
169:                    // TODO Auto-generated catch block
170:                    e.printStackTrace();
171:                }
172:
173:                component.getServiceUnitManager().stop("provider");
174:                component.getServiceUnitManager().shutDown("provider");
175:                component.getServiceUnitManager().undeploy("provider",
176:                        path.getAbsolutePath());
177:
178:                return t1 - t0;
179:            }
180:
181:            public void testInOut() {
182:                try {
183:                    //			testInOut(new File("target/test-data/in/sendsuppressIn.xml"), false, true);
184:                    //			testInOut(new File("target/test-data/in/contacts.txt"), false, false);
185:                    testInOut(new File("target/test-data/in/variabletag.txt"),
186:                            false, false);
187:                } catch (Exception e) {
188:                    // TODO Auto-generated catch block
189:                    e.printStackTrace();
190:                    fail();
191:                }
192:            }
193:
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.