Source Code Cross Referenced for XMLSchemaAssertionTest.java in  » Testing » jakarta-jmeter » org » apache » jmeter » assertions » 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 » Testing » jakarta jmeter » org.apache.jmeter.assertions 
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:         */
018:
019:        package org.apache.jmeter.assertions;
020:
021:        import java.io.BufferedInputStream;
022:        import java.io.ByteArrayOutputStream;
023:        import java.io.FileInputStream;
024:        import java.io.IOException;
025:
026:        import org.apache.jmeter.junit.JMeterTestCase;
027:        import org.apache.jmeter.samplers.SampleResult;
028:        import org.apache.jmeter.threads.JMeterContext;
029:        import org.apache.jmeter.threads.JMeterContextService;
030:        import org.apache.jmeter.threads.JMeterVariables;
031:
032:        //import org.apache.jorphan.logging.LoggingManager;
033:
034:        public class XMLSchemaAssertionTest extends JMeterTestCase {
035:
036:            private XMLSchemaAssertion assertion;
037:
038:            private SampleResult result;
039:
040:            private JMeterVariables vars;
041:
042:            private JMeterContext jmctx;
043:
044:            public XMLSchemaAssertionTest(String arg0) {
045:                super (arg0);
046:            }
047:
048:            protected void setUp() throws Exception {
049:                super .setUp();
050:                jmctx = JMeterContextService.getContext();
051:                assertion = new XMLSchemaAssertion();
052:                assertion.setThreadContext(jmctx);// This would be done by the run
053:                // command
054:                result = new SampleResult();
055:                vars = new JMeterVariables();
056:                jmctx.setVariables(vars);
057:                jmctx.setPreviousResult(result);
058:                // LoggingManager.setPriority("DEBUG","jmeter");
059:            }
060:
061:            protected void tearDown() throws Exception {
062:                super .tearDown();
063:            }
064:
065:            private ByteArrayOutputStream readBA(String name)
066:                    throws IOException {
067:                BufferedInputStream bis = new BufferedInputStream(
068:                        new FileInputStream(findTestFile(name)));
069:                ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
070:                int len = 0;
071:                byte[] data = new byte[512];
072:                while ((len = bis.read(data)) >= 0) {
073:                    baos.write(data, 0, len);
074:                }
075:                bis.close();
076:                return baos;
077:            }
078:
079:            private byte[] readFile(String name) throws IOException {
080:                return readBA(name).toByteArray();
081:            }
082:
083:            public void testAssertionOK() throws Exception {
084:                result.setResponseData(readFile("testfiles/XMLSchematest.xml"));
085:                assertion.setXsdFileName("testfiles/XMLSchema-pass.xsd");
086:                AssertionResult res = assertion.getResult(jmctx
087:                        .getPreviousResult());
088:                testLog.debug("isError() " + res.isError() + " isFailure() "
089:                        + res.isFailure());
090:                testLog.debug("failure " + res.getFailureMessage());
091:                assertFalse("Should not be an error", res.isError());
092:                assertFalse("Should not be a failure", res.isFailure());
093:            }
094:
095:            public void testAssertionFail() throws Exception {
096:                result.setResponseData(readFile("testfiles/XMLSchematest.xml"));
097:                assertion.setXsdFileName("testfiles/XMLSchema-fail.xsd");
098:                AssertionResult res = assertion.getResult(jmctx
099:                        .getPreviousResult());
100:                testLog.debug("isError() " + res.isError() + " isFailure() "
101:                        + res.isFailure());
102:                testLog.debug("failure " + res.getFailureMessage());
103:                assertTrue(res.isError());
104:                assertFalse(res.isFailure());
105:            }
106:
107:            public void testAssertionBadXSDFile() throws Exception {
108:                result.setResponseData(readFile("testfiles/XMLSchematest.xml"));
109:                assertion.setXsdFileName("xtestfiles/XMLSchema-fail.xsd");
110:                AssertionResult res = assertion.getResult(jmctx
111:                        .getPreviousResult());
112:                testLog.debug("isError() " + res.isError() + " isFailure() "
113:                        + res.isFailure());
114:                testLog.debug("failure " + res.getFailureMessage());
115:                assertTrue(res.getFailureMessage().indexOf(
116:                        "Failed to read schema document") > 0);
117:                assertTrue(res.isError());// TODO - should this be a failure?
118:                assertFalse(res.isFailure());
119:            }
120:
121:            public void testAssertionNoFile() throws Exception {
122:                result.setResponseData(readFile("testfiles/XMLSchematest.xml"));
123:                assertion.setXsdFileName("");
124:                AssertionResult res = assertion.getResult(jmctx
125:                        .getPreviousResult());
126:                testLog.debug("isError() " + res.isError() + " isFailure() "
127:                        + res.isFailure());
128:                testLog.debug("failure " + res.getFailureMessage());
129:                assertEquals(XMLSchemaAssertion.FILE_NAME_IS_REQUIRED, res
130:                        .getFailureMessage());
131:                assertFalse(res.isError());
132:                assertTrue(res.isFailure());
133:            }
134:
135:            public void testAssertionNoResult() throws Exception {
136:                // result.setResponseData - not set
137:                assertion.setXsdFileName("testfiles/XMLSchema-fail.xsd");
138:                AssertionResult res = assertion.getResult(jmctx
139:                        .getPreviousResult());
140:                testLog.debug("isError() " + res.isError() + " isFailure() "
141:                        + res.isFailure());
142:                testLog.debug("failure " + res.getFailureMessage());
143:                assertEquals(AssertionResult.RESPONSE_WAS_NULL, res
144:                        .getFailureMessage());
145:                assertFalse(res.isError());
146:                assertTrue(res.isFailure());
147:            }
148:
149:            public void testAssertionEmptyResult() throws Exception {
150:                result.setResponseData("".getBytes());
151:                assertion.setXsdFileName("testfiles/XMLSchema-fail.xsd");
152:                AssertionResult res = assertion.getResult(jmctx
153:                        .getPreviousResult());
154:                testLog.debug("isError() " + res.isError() + " isFailure() "
155:                        + res.isFailure());
156:                testLog.debug("failure " + res.getFailureMessage());
157:                assertEquals(AssertionResult.RESPONSE_WAS_NULL, res
158:                        .getFailureMessage());
159:                assertFalse(res.isError());
160:                assertTrue(res.isFailure());
161:            }
162:
163:            public void testAssertionBlankResult() throws Exception {
164:                result.setResponseData(" ".getBytes());
165:                assertion.setXsdFileName("testfiles/XMLSchema-fail.xsd");
166:                AssertionResult res = assertion.getResult(jmctx
167:                        .getPreviousResult());
168:                testLog.debug("isError() " + res.isError() + " isFailure() "
169:                        + res.isFailure());
170:                testLog.debug("failure " + res.getFailureMessage());
171:                assertTrue(res.getFailureMessage().indexOf(
172:                        "Premature end of file") > 0);
173:                assertTrue(res.isError());
174:                assertFalse(res.isFailure());
175:            }
176:
177:            public void testXMLTrailingcontent() throws Exception {
178:                ByteArrayOutputStream baos = readBA("testfiles/XMLSchematest.xml");
179:                baos.write("extra".getBytes());
180:                result.setResponseData(baos.toByteArray());
181:                assertion.setXsdFileName("testfiles/XMLSchema-pass.xsd");
182:                AssertionResult res = assertion.getResult(jmctx
183:                        .getPreviousResult());
184:                testLog.debug("isError() " + res.isError() + " isFailure() "
185:                        + res.isFailure());
186:                testLog.debug("failure " + res.getFailureMessage());
187:                assertTrue(res.getFailureMessage().indexOf(
188:                        "Content is not allowed in trailing section") > 0);
189:                assertTrue(res.isError());
190:                assertFalse(res.isFailure());
191:            }
192:
193:            public void testXMLTrailingwhitespace() throws Exception {
194:                ByteArrayOutputStream baos = readBA("testfiles/XMLSchematest.xml");
195:                baos.write(" \t\n".getBytes());
196:                result.setResponseData(baos.toByteArray());
197:                assertion.setXsdFileName("testfiles/XMLSchema-pass.xsd");
198:                AssertionResult res = assertion.getResult(jmctx
199:                        .getPreviousResult());
200:                testLog.debug("xisError() " + res.isError() + " isFailure() "
201:                        + res.isFailure());
202:                testLog.debug("failure " + res.getFailureMessage());
203:                assertFalse(res.isError());
204:                assertFalse(res.isFailure());
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.