1 16 17 package org.apache.commons.latka.junit; 18 19 import java.net.MalformedURLException ; 20 import java.net.URL ; 21 22 import junit.framework.Test; 23 import junit.framework.TestCase; 24 import junit.framework.TestResult; 25 import junit.framework.TestSuite; 26 27 import org.apache.commons.latka.ValidationException; 28 import org.apache.commons.latka.event.RequestErrorEvent; 29 import org.apache.commons.latka.event.RequestEvent; 30 import org.apache.commons.latka.event.RequestFailedEvent; 31 import org.apache.commons.latka.event.RequestSkippedEvent; 32 import org.apache.commons.latka.event.RequestSucceededEvent; 33 import org.apache.commons.latka.http.Request; 34 import org.apache.commons.latka.http.SessionImpl; 35 36 40 public class TestJUnitEventReporter extends TestCase { 41 private JUnitEventReporter _reporter = null; 42 private TestResult _result = null; 43 private Request _request = null; 44 45 public TestJUnitEventReporter(String testName) { 46 super(testName); 47 } 48 49 public static Test suite() { 50 return new TestSuite(TestJUnitEventReporter.class); 51 } 52 53 public static void main(String args[]) { 54 String [] testCaseName = { TestJUnitEventReporter.class.getName() }; 55 junit.textui.TestRunner.main(testCaseName); 56 } 57 58 public void setUp() throws MalformedURLException { 59 _result = new TestResult(); 60 _reporter = new JUnitEventReporter(_result); 61 62 URL url = new URL ("http://www.example.com/"); 63 SessionImpl session = new SessionImpl(); 64 _request = session.createRequest(url, Request.HTTP_METHOD_GET, "1.1"); 65 } 66 67 public void testSuccess() { 68 RequestEvent e = new RequestSucceededEvent(_request, null); 69 _reporter.requestSucceeded(e); 70 assertEquals("Should have run 1 test", 1, _result.runCount()); 71 assertEquals("Should have 0 errors", 0, _result.errorCount()); 72 assertEquals("Should have 0 failures", 0, _result.failureCount()); 73 assertTrue("Should represent a successful run", _result.wasSuccessful()); 74 } 75 76 public void testError() { 77 RequestEvent e = new RequestErrorEvent( 78 _request, null, new Exception ("test exception")); 79 _reporter.requestError(e); 80 assertEquals("Should have run 1 test", 1, _result.runCount()); 81 assertEquals("Should have 1 error", 1, _result.errorCount()); 82 assertEquals("Should have 0 failures", 0, _result.failureCount()); 83 assertTrue("Should not represent a successful run", 84 !_result.wasSuccessful()); 85 } 86 87 88 public void testFailed() { 89 RequestEvent e = new RequestFailedEvent( 90 _request, null, new ValidationException()); 91 _reporter.requestFailed(e); 92 assertEquals("Should have run 1 test", 1, _result.runCount()); 93 assertEquals("Should have 0 errors", 0, _result.errorCount()); 94 assertEquals("Should have 1 failure", 1, _result.failureCount()); 95 assertTrue("Should not represent a successful run", 96 !_result.wasSuccessful()); 97 } 98 99 public void testSkipped() { 100 RequestEvent e = new RequestSkippedEvent(_request, null); 101 _reporter.requestSkipped(e); 102 assertEquals("Should have run 1 test", 1, _result.runCount()); 103 assertEquals("Should have 0 errors", 0, _result.errorCount()); 104 assertEquals("Should have 1 failure", 1, _result.failureCount()); 105 assertTrue("Should not represent a successful run", 106 !_result.wasSuccessful()); 107 } 108 } 109 | Popular Tags |