1 20 package org.apache.cactus.internal.client; 21 22 import junit.framework.TestCase; 23 24 import org.apache.cactus.internal.WebTestResult; 25 26 31 public class TestWebTestResultParser extends TestCase 32 { 33 38 public void testParseNoException() throws ParsingException 39 { 40 WebTestResult initialResult = new WebTestResult(); 41 WebTestResultParser parser = new WebTestResultParser(); 42 WebTestResult result = parser.parse(initialResult.toXml()); 43 44 assertNotNull(result); 45 assertTrue(!result.hasException()); 46 assertNull(result.getExceptionClassName()); 47 assertNull(result.getExceptionMessage()); 48 assertNull(result.getExceptionStackTrace()); 49 } 50 51 56 public void testParseWithException() throws ParsingException 57 { 58 Exception e = new Exception ("test exception"); 59 WebTestResult initialResult = new WebTestResult(e); 60 WebTestResultParser parser = new WebTestResultParser(); 61 WebTestResult result = parser.parse(initialResult.toXml()); 62 63 assertNotNull(result); 64 assertTrue("There is no exception in the test result !", 65 result.hasException()); 66 assertEquals("java.lang.Exception", result.getExceptionClassName()); 67 assertEquals("test exception", result.getExceptionMessage()); 68 assertTrue("Should not be empty", 69 result.getExceptionStackTrace().length() > 0); 70 } 71 72 78 public void testReadRootElementEmpty() throws ParsingException 79 { 80 WebTestResult initialResult = new WebTestResult(); 81 WebTestResultParser parser = new WebTestResultParser(); 82 83 String buffer = parser.readRootElement(initialResult.toXml()); 84 85 assertEquals("", buffer); 86 } 87 88 94 public void testReadRootElementFull() throws ParsingException 95 { 96 String expectedStart = "<exception classname=\"" 97 + "java.lang.Exception\"><message><![CDATA[test exception]]>" 98 + "</message><stacktrace><![CDATA["; 99 String expectedEnd = "]]></stacktrace></exception>"; 100 101 Exception e = new Exception ("test exception"); 102 WebTestResult initialResult = new WebTestResult(e); 103 WebTestResultParser parser = new WebTestResultParser(); 104 105 String buffer = parser.readRootElement(initialResult.toXml()); 106 107 assertTrue("Should have started with [" + expectedStart + "]", 108 buffer.startsWith(expectedStart)); 109 assertTrue("Should have ended with [" + expectedEnd + "]", 110 buffer.endsWith(expectedEnd)); 111 } 112 113 118 public void testReadExceptionClassName() throws ParsingException 119 { 120 String expectedStart = "<message><![CDATA[test exception]]>" 121 + "</message><stacktrace><![CDATA["; 122 String expectedEnd = "]]></stacktrace>"; 123 124 Exception e = new Exception ("test exception"); 125 WebTestResult initialResult = new WebTestResult(e); 126 WebTestResultParser parser = new WebTestResultParser(); 127 String buffer = parser.readRootElement(initialResult.toXml()); 128 129 buffer = parser.readExceptionClassname(buffer); 130 assertEquals("java.lang.Exception", parser.exceptionClassname); 131 assertTrue("Should have started with [" + expectedStart + "]", 132 buffer.startsWith(expectedStart)); 133 assertTrue("Should have ended with [" + expectedEnd + "]", 134 buffer.endsWith(expectedEnd)); 135 } 136 137 142 public void testReadExceptionMessage() throws ParsingException 143 { 144 String expectedStart = "<stacktrace><![CDATA["; 145 String expectedEnd = "]]></stacktrace>"; 146 147 Exception e = new Exception ("test exception"); 148 WebTestResult initialResult = new WebTestResult(e); 149 WebTestResultParser parser = new WebTestResultParser(); 150 String buffer = parser.readRootElement(initialResult.toXml()); 151 152 buffer = parser.readExceptionClassname(buffer); 153 154 buffer = parser.readExceptionMessage(buffer); 155 assertEquals("test exception", parser.exceptionMessage); 156 assertTrue("Should have started with [" + expectedStart + "]", 157 buffer.startsWith(expectedStart)); 158 assertTrue("Should have ended with [" + expectedEnd + "]", 159 buffer.endsWith(expectedEnd)); 160 } 161 } 162 | Popular Tags |