Source Code Cross Referenced for TestSupport.java in  » ESB » servicemix » org » apache » servicemix » tck » 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 » servicemix » org.apache.servicemix.tck 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.servicemix.tck;
018:
019:        import java.io.IOException;
020:        import java.util.Date;
021:
022:        import javax.jbi.messaging.Fault;
023:        import javax.jbi.messaging.InOnly;
024:        import javax.jbi.messaging.NormalizedMessage;
025:        import javax.xml.namespace.QName;
026:        import javax.xml.parsers.ParserConfigurationException;
027:        import javax.xml.transform.Source;
028:        import javax.xml.transform.TransformerException;
029:
030:        import org.w3c.dom.Node;
031:
032:        import org.xml.sax.SAXException;
033:
034:        import org.apache.servicemix.client.ServiceMixClient;
035:        import org.apache.servicemix.jbi.container.SpringJBIContainer;
036:        import org.apache.servicemix.jbi.jaxp.StringSource;
037:        import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
038:
039:        /**
040:         * @version $Revision: 564607 $
041:         */
042:        public abstract class TestSupport extends SpringTestSupport {
043:            protected ServiceMixClient client;
044:
045:            protected Receiver receiver;
046:
047:            protected void setUp() throws Exception {
048:                super .setUp();
049:                client = (ServiceMixClient) getBean("client");
050:                SpringJBIContainer jbi = (SpringJBIContainer) getBean("jbi");
051:                receiver = (Receiver) jbi.getBean("receiver");
052:            }
053:
054:            /**
055:             * Sends messages to the given service and asserts that the receiver gets
056:             * them all
057:             * 
058:             * @param service
059:             * @throws javax.jbi.messaging.MessagingException
060:             */
061:            protected void assertSendAndReceiveMessages(QName service)
062:                    throws Exception {
063:                sendMessages(service, messageCount);
064:                assertMessagesReceived(messageCount);
065:            }
066:
067:            protected void sendMessages(QName service, int messageCount)
068:                    throws Exception {
069:                sendMessages(service, messageCount, true, null);
070:            }
071:
072:            protected void sendMessages(QName service, int messageCount,
073:                    String message) throws Exception {
074:                sendMessages(service, messageCount, true, message);
075:            }
076:
077:            /**
078:             * Sends the given number of messages to the given service
079:             * 
080:             * @param service
081:             * @throws javax.jbi.messaging.MessagingException
082:             */
083:            protected void sendMessages(QName service, int messageCount,
084:                    boolean sync, String msg) throws Exception {
085:                for (int i = 1; i <= messageCount; i++) {
086:                    InOnly exchange = client.createInOnlyExchange();
087:
088:                    NormalizedMessage message = exchange.getInMessage();
089:                    message.setProperty("name", "James");
090:                    message.setProperty("id", new Integer(i));
091:                    message.setProperty("idText", "" + i);
092:                    if (msg != null && msg.length() > 0) {
093:                        message.setContent(new StringSource(msg));
094:                    } else {
095:                        message.setContent(new StringSource(
096:                                createMessageXmlText(i)));
097:                    }
098:
099:                    exchange.setService(service);
100:                    if (sync) {
101:                        client.sendSync(exchange);
102:                    } else {
103:                        client.send(exchange);
104:                    }
105:
106:                    // lets assert that we have no failure
107:                    Exception error = exchange.getError();
108:                    if (error != null) {
109:                        throw error;
110:                    }
111:
112:                    Fault fault = exchange.getFault();
113:                    assertEquals("Should have no fault!", null, fault);
114:                }
115:            }
116:
117:            protected String createMessageXmlText(int index) {
118:                return "<sample id='" + index + "' sent='" + new Date()
119:                        + "'>hello world!</sample>";
120:            }
121:
122:            protected void assertMessagesReceived() throws Exception {
123:                assertMessagesReceived(messageCount);
124:            }
125:
126:            protected void assertMessagesReceived(int messageCount)
127:                    throws Exception {
128:                assertNotNull("receiver not found in JBI container", receiver);
129:
130:                MessageList messageList = receiver.getMessageList();
131:                assertMessagesReceived(messageList, messageCount);
132:            }
133:
134:            protected MessageList assertMessagesReceived(String receiverName,
135:                    int messageCount) throws Exception {
136:                Receiver rcv = (Receiver) getBean(receiverName);
137:                assertNotNull("receiver: " + receiverName
138:                        + " not found in JBI container", rcv);
139:
140:                MessageList messageList = rcv.getMessageList();
141:                assertMessagesReceived(messageList, messageCount);
142:                return messageList;
143:            }
144:
145:            /**
146:             * Performs a request using the given file from the classpath as the request
147:             * body and return the answer
148:             * 
149:             * @param serviceName
150:             * @param fileOnClassPath
151:             * @return
152:             * @throws JBIException
153:             */
154:            protected Object requestServiceWithFileRequest(QName serviceName,
155:                    String fileOnClassPath) throws Exception {
156:                Source content = getSourceFromClassPath(fileOnClassPath);
157:                ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(
158:                        serviceName);
159:                Object answer = client.request(resolver, null, null, content);
160:                if (answer instanceof  Source) {
161:                    answer = transformer.toDOMNode((Source) answer);
162:                }
163:                return answer;
164:            }
165:
166:            /**
167:             * Performs a request using the given file from the classpath as the request
168:             * body and return the answer
169:             * 
170:             * @param serviceName
171:             * @param fileOnClassPath
172:             * @return
173:             * @throws JBIException
174:             */
175:            protected void sendServiceWithFileRequest(QName serviceName,
176:                    String fileOnClassPath) throws Exception {
177:                Source content = getSourceFromClassPath(fileOnClassPath);
178:                ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(
179:                        serviceName);
180:                client.send(resolver, null, null, content);
181:            }
182:
183:            protected void assertMessageHeader(MessageList messageList,
184:                    int index, String propertyName, Object expectedValue) {
185:                NormalizedMessage message = (NormalizedMessage) messageList
186:                        .getMessages().get(index);
187:                assertNotNull("Message: " + index + " is null!", message);
188:
189:                Object value = message.getProperty(propertyName);
190:                assertEquals("property: " + propertyName, expectedValue, value);
191:            }
192:
193:            protected void assertMessageBody(MessageList messageList,
194:                    int index, String expectedXml) throws TransformerException {
195:                NormalizedMessage message = (NormalizedMessage) messageList
196:                        .getMessages().get(index);
197:                assertNotNull("Message: " + index + " is null!", message);
198:
199:                Source content = message.getContent();
200:                assertNotNull("Message content: " + index + " is null!",
201:                        content);
202:                String value = transformer.toString(content);
203:
204:                assertEquals("message XML for: " + index, expectedXml, value);
205:            }
206:
207:            protected void assertMessageXPath(MessageList messageList,
208:                    int index, String xpath, String expectedValue)
209:                    throws TransformerException, ParserConfigurationException,
210:                    IOException, SAXException {
211:                NormalizedMessage message = (NormalizedMessage) messageList
212:                        .getMessages().get(index);
213:                assertNotNull("Message: " + index + " is null!", message);
214:
215:                Source content = message.getContent();
216:                assertNotNull("Message content: " + index + " is null!",
217:                        content);
218:                Node node = transformer.toDOMNode(content);
219:
220:                String value = textValueOfXPath(node, xpath);
221:                String xmlText = transformer.toString(node);
222:
223:                if (log.isTraceEnabled()) {
224:                    log
225:                            .trace("Message: " + index + " received XML: "
226:                                    + xmlText);
227:                }
228:
229:                assertEquals("message XML: " + index + " for xpath: " + xpath
230:                        + " body was: " + xmlText, expectedValue, value);
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.