Source Code Cross Referenced for TestFileProvider.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: TestFileProvider.java 2277 2006-10-21 11:53:50Z 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:
032:        import javax.jbi.messaging.ExchangeStatus;
033:        import javax.jbi.messaging.InOnly;
034:        import javax.xml.namespace.QName;
035:        import javax.xml.transform.stream.StreamSource;
036:
037:        import junit.framework.TestCase;
038:
039:        import org.apache.servicemix.client.DefaultServiceMixClient;
040:        import org.apache.servicemix.components.file.FilePoller;
041:        import org.apache.servicemix.jbi.container.ActivationSpec;
042:        import org.apache.servicemix.jbi.container.JBIContainer;
043:        import org.apache.servicemix.tck.Receiver;
044:        import org.apache.servicemix.tck.ReceiverComponent;
045:
046:        import com.bostechcorp.cbesb.common.util.FileUtil;
047:        import com.bostechcorp.cbesb.runtime.file.FileOperator;
048:
049:        /**
050:         * @author j.zhang
051:         * @version 1.0.0
052:         */
053:        public class TestFileProvider extends TestCase {
054:
055:            protected JBIContainer container;
056:
057:            private static final String CONFIG = "target/test-data/config";
058:            private static final String IN = "target/test-data/in";
059:            private static final String OUT = "target/test-data/out";
060:            private static final String RESULT = "target/test-data/result";
061:
062:            protected void setUp() throws Exception {
063:                container = new JBIContainer();
064:                container.setUseMBeanServer(false);
065:                container.setCreateMBeanServer(false);
066:                container.setEmbedded(true);
067:                container.setCreateJmxConnector(false);
068:                container.init();
069:                deleteFile();
070:            }
071:
072:            protected void tearDown() throws Exception {
073:                if (container != null) {
074:                    container.shutDown();
075:                }
076:            }
077:
078:            /*
079:             * The component flow for this testing are as follow:
080:             * 
081:             * SMClient creates -> InOnly -> route FileComponent's Provider side -> Write into the
082:             * outbox directory -> picked up by FilePoller -> route to ReceiverComponent
083:             * 
084:             */
085:
086:            protected long testInOnly(String msg, boolean streaming)
087:                    throws Exception {
088:                // HTTP Component
089:                FileComponent component = new FileComponent();
090:                // ((FileLifeCycle)
091:                // component.getLifeCycle()).getConfiguration().setStreamingEnabled(streaming);
092:                container.activateComponent(component, "FileProviderTest");
093:
094:                // Add a receiver component
095:                Receiver receiver = new ReceiverComponent();
096:                ActivationSpec asReceiver = new ActivationSpec("receiver",
097:                        receiver);
098:                asReceiver.setService(new QName(
099:                        "http://file.bostechcorp.com/Test", "FileInterface"));
100:                container.activateComponent(asReceiver);
101:
102:                // Add the FilePoller
103:                FilePoller connector = new FilePoller();
104:                connector.setFile(new File("target/test-data/out/outbox"));
105:                ActivationSpec asConnector = new ActivationSpec("connector",
106:                        connector);
107:                asConnector.setDestinationService(new QName(
108:                        "http://file.bostechcorp.com/Test", "FileInterface"));
109:                container.activateComponent(asConnector);
110:
111:                // Start container
112:                container.start();
113:
114:                // Deploy SU
115:                URL url = getClass().getClassLoader().getResource(
116:                        "provider/file.wsdl");
117:                File path = new File(new URI(url.toString()));
118:                path = path.getParentFile();
119:                component.getServiceUnitManager().deploy("provider",
120:                        path.getAbsolutePath());
121:                component.getServiceUnitManager().start("provider");
122:
123:                // Call it
124:                DefaultServiceMixClient client = new DefaultServiceMixClient(
125:                        container);
126:                InOnly in = client.createInOnlyExchange();
127:                in.setInterfaceName(new QName(
128:                        "http://file.bostechcorp.com/Test", "FileInterface"));
129:                in.getInMessage().setContent(
130:                        new StreamSource(new ByteArrayInputStream(msg
131:                                .getBytes())));
132:
133:                long t0 = System.currentTimeMillis();
134:                client.sendSync(in);
135:                long t1 = System.currentTimeMillis();
136:                assertTrue(in.getStatus() == ExchangeStatus.DONE);
137:
138:                // let us give FilePoller some time to pick up files
139:                try {
140:                    Thread.sleep(10 * 1000);
141:                } catch (InterruptedException e) {
142:                    e.printStackTrace();
143:                }
144:
145:                // Check we received the message
146:                // receiver.getMessageList().assertMessagesReceived(1);
147:                File f = new File("message0");
148:                if (!f.exists())
149:                    fail("Failed to create result file");
150:                String result = FileUtil.readStringFromFile("message0");
151:                String expected = result = FileUtil
152:                        .readStringFromFile("target/classes/message0");
153:                assertTrue(result.equals(expected));
154:                f.delete();
155:                // return t1 - t0;
156:
157:                component.getServiceUnitManager().stop("provider");
158:                component.getServiceUnitManager().shutDown("provider");
159:                component.getServiceUnitManager().undeploy("provider",
160:                        path.getAbsolutePath());
161:
162:                return t1 - t0;
163:            }
164:
165:            public void testInOnly() throws Exception {
166:                testInOnly(
167:                        "<DataEnvelope><XMLRecord><hello>world</hello></XMLRecord></DataEnvelope>",
168:                        false);
169:            }
170:
171:            /**
172:             * Clean output folder. Delete all of the test files and folders.
173:             */
174:            private void deleteFile() {
175:                File[] config = FileOperator.scanDir(CONFIG);
176:                File[] in = FileOperator.scanDir(IN);
177:                File[] out = FileOperator.scanDir(OUT);
178:                File[] result = FileOperator.scanDir(RESULT);
179:                for (int i = 0; i < config.length; i++) {
180:                    if (!(config[i].delete())) {
181:                        File[] configs = FileOperator.scanDir(config[i]
182:                                .getPath());
183:                        for (int j = 0; j < configs.length; j++) {
184:                            configs[j].delete();
185:                        }
186:                        config[i].delete();
187:                    }
188:                }
189:                for (int i = 0; i < in.length; i++) {
190:                    if (!(in[i].delete())) {
191:                        File[] ins = FileOperator.scanDir(in[i].getPath());
192:                        for (int j = 0; j < ins.length; j++) {
193:                            ins[j].delete();
194:                        }
195:                        in[i].delete();
196:                    }
197:                }
198:                for (int i = 0; i < out.length; i++) {
199:                    if (!(out[i].delete())) {
200:                        File[] outs = FileOperator.scanDir(out[i].getPath());
201:                        for (int j = 0; j < outs.length; j++) {
202:                            outs[j].delete();
203:                        }
204:                        out[i].delete();
205:                    }
206:                }
207:                for (int i = 0; i < result.length; i++) {
208:                    if (!(result[i].delete())) {
209:                        File[] results = FileOperator.scanDir(result[i]
210:                                .getPath());
211:                        for (int j = 0; j < results.length; j++) {
212:                            results[j].delete();
213:                        }
214:                        result[i].delete();
215:                    }
216:                }
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.