Source Code Cross Referenced for TestFileConsumer.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » component » file » 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.file 
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:         * $Id: TestFileConsumer.java 2626 2006-10-27 02:14:20Z jzhang $
024:         */
025:        package com.bostechcorp.cbesb.runtime.component.file;
026:
027:        import java.io.ByteArrayInputStream;
028:        import java.io.File;
029:        import java.net.URI;
030:        import java.net.URL;
031:        import javax.jbi.messaging.ExchangeStatus;
032:        import javax.jbi.messaging.RobustInOnly;
033:        import javax.xml.namespace.QName;
034:        import javax.xml.transform.stream.StreamSource;
035:
036:        import junit.framework.TestCase;
037:
038:        import org.apache.servicemix.client.DefaultServiceMixClient;
039:        import org.apache.servicemix.components.file.FileWriter;
040:        import org.apache.servicemix.jbi.container.ActivationSpec;
041:        import org.apache.servicemix.jbi.container.JBIContainer;
042:
043:        import com.bostechcorp.cbesb.common.util.FileUtil;
044:        import com.bostechcorp.cbesb.runtime.file.FileOperator;
045:
046:        public class TestFileConsumer extends TestCase {
047:
048:            protected JBIContainer container = new JBIContainer();
049:
050:            private static final String CONFIG = "target/test-data/config";
051:            private static final String IN = "target/test-data/in";
052:            private static final String OUT = "target/test-data/out";
053:            private static final String RESULT = "target/test-data/result";
054:
055:            protected void setUp() throws Exception {
056:                container.setUseMBeanServer(false);
057:                container.setCreateMBeanServer(false);
058:                container.setEmbedded(true);
059:                container.setCreateJmxConnector(false);
060:                container.init();
061:                deleteFile();
062:            }
063:
064:            protected void tearDown() throws Exception {
065:                if (container != null) {
066:                    container.shutDown();
067:                }
068:            }
069:
070:            /**
071:             * The component flow for this test case  is listed as follow:
072:             * 
073:             * SMClient creates -> RobustInOnly  -> route FileWriter component -> Write it into the inbox directory 
074:             * -> picked up by FileComponent's consumer side -> Create a InOnly message -> route to ReceiverComponent 
075:             * 
076:             */
077:            public void testInOnlyCase1() throws Exception {
078:                runTestCase("consumer/file.wsdl", "provider/file.wsdl",
079:                        "<hello>world</hello>", false);
080:            }
081:
082:            public void testInOnlyCase2() throws Exception {
083:                runTestCase("consumer2/file.wsdl", "provider2/file.wsdl",
084:                        "<hello>world</hello>", false);
085:            }
086:
087:            protected long runTestCase(String consumer, String provider,
088:                    String msg, boolean streaming) throws Exception {
089:                // File Component
090:                FileComponent component = new FileComponent();
091:                container.activateComponent(component, "FileComponent");
092:
093:                // Add the FileWriter
094:                FileWriter invoker = new FileWriter();
095:                invoker.setDirectory(new File("target/test-data/in/inbox"));
096:
097:                ActivationSpec asInvoker = new ActivationSpec("invoker",
098:                        invoker);
099:                asInvoker.setService(new QName("urn:test", "invoker"));
100:                container.activateComponent(asInvoker);
101:
102:                // Start container
103:                container.start();
104:
105:                // Deploy SU
106:                URL url = getClass().getClassLoader().getResource(consumer);
107:                File path = new File(new URI(url.toString()));
108:                path = path.getParentFile();
109:                component.getServiceUnitManager().deploy("consumer",
110:                        path.getAbsolutePath());
111:                component.getServiceUnitManager().start("consumer");
112:
113:                // File provider
114:                URL urlProvider = getClass().getClassLoader().getResource(
115:                        provider);
116:                File wsdlPath = new File(new URI(urlProvider.toString()));
117:                wsdlPath = wsdlPath.getParentFile();
118:                component.getServiceUnitManager().deploy("provider",
119:                        wsdlPath.getAbsolutePath());
120:                component.getServiceUnitManager().start("provider");
121:
122:                // Call it
123:                DefaultServiceMixClient client = new DefaultServiceMixClient(
124:                        container);
125:                RobustInOnly in = client.createRobustInOnlyExchange();
126:                in.setService(new QName("urn:test", "invoker"));
127:                in.getInMessage().setContent(
128:                        new StreamSource(new ByteArrayInputStream(msg
129:                                .getBytes())));
130:
131:                long t0 = System.currentTimeMillis();
132:                client.sendSync(in);
133:                long t1 = System.currentTimeMillis();
134:                assertTrue(in.getStatus() == ExchangeStatus.DONE);
135:
136:                try {
137:                    Thread.sleep(10 * 1000);
138:                    System.err.println("Sleep 10 s!");
139:                } catch (Exception e) {
140:                    e.printStackTrace();
141:                }
142:
143:                File f = new File("message0");
144:                if (!f.exists())
145:                    fail("Failed to create result file");
146:                String result = FileUtil.readStringFromFile("message0");
147:                String expected = result = FileUtil
148:                        .readStringFromFile("target/classes/message0");
149:                assertTrue(result.equals(expected));
150:                f.delete();
151:                return t1 - t0;
152:            }
153:
154:            /**
155:             * Clean output folder. Delete all of the test files and folders.
156:             */
157:            private void deleteFile() {
158:                File[] config = FileOperator.scanDir(CONFIG);
159:                File[] in = FileOperator.scanDir(IN);
160:                File[] out = FileOperator.scanDir(OUT);
161:                File[] result = FileOperator.scanDir(RESULT);
162:                for (int i = 0; i < config.length; i++) {
163:                    if (!(config[i].delete())) {
164:                        File[] configs = FileOperator.scanDir(config[i]
165:                                .getPath());
166:                        for (int j = 0; j < configs.length; j++) {
167:                            configs[j].delete();
168:                        }
169:                        config[i].delete();
170:                    }
171:                }
172:                for (int i = 0; i < in.length; i++) {
173:                    if (!(in[i].delete())) {
174:                        File[] ins = FileOperator.scanDir(in[i].getPath());
175:                        for (int j = 0; j < ins.length; j++) {
176:                            ins[j].delete();
177:                        }
178:                        in[i].delete();
179:                    }
180:                }
181:                for (int i = 0; i < out.length; i++) {
182:                    if (!(out[i].delete())) {
183:                        File[] outs = FileOperator.scanDir(out[i].getPath());
184:                        for (int j = 0; j < outs.length; j++) {
185:                            outs[j].delete();
186:                        }
187:                        out[i].delete();
188:                    }
189:                }
190:                for (int i = 0; i < result.length; i++) {
191:                    if (!(result[i].delete())) {
192:                        File[] results = FileOperator.scanDir(result[i]
193:                                .getPath());
194:                        for (int j = 0; j < results.length; j++) {
195:                            results[j].delete();
196:                        }
197:                        result[i].delete();
198:                    }
199:                }
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.