1 16 17 package org.apache.commons.latka.junit; 18 19 import java.io.File ; 20 import java.net.SocketException ; 21 22 import junit.framework.Test; 23 import junit.framework.TestCase; 24 import junit.framework.TestSuite; 25 26 import org.apache.commons.latka.Suite; 27 import org.xml.sax.InputSource ; 28 29 33 public class TestJUnitTestAdapter extends TestCase { 34 private String _xmlFileName = "src/distribution/tests/samples/TestCommonsWebsite.xml"; 35 private File _xmlFile = null; 36 private JUnitTestAdapter _adapter = null; 37 private Suite _suite = null; 38 39 public TestJUnitTestAdapter(String testName) { 40 super(testName); 41 } 42 43 public static Test suite() { 44 return new TestSuite(TestJUnitTestAdapter.class); 45 } 46 47 public static void main(String args[]) { 48 String [] testCaseName = { TestJUnitTestAdapter.class.getName() }; 49 junit.textui.TestRunner.main(testCaseName); 50 } 51 52 public void setUp() throws Exception { 53 super.setUp(); 54 String baseDir = System.getProperty("basedir"); 55 assertNotNull("The system property basedir was not defined.", baseDir); 56 String fs = System.getProperty("file.separator"); 57 assertNotNull("The system property file.separator was not defined.", fs); 58 _xmlFileName = baseDir + fs + _xmlFileName; 59 _xmlFile = new File (_xmlFileName); 60 _suite = new Suite(_xmlFile.toURL()); 61 _adapter = new JUnitTestAdapter(_suite, 9); 62 } 63 64 public void testParser() throws Throwable { 65 try { 66 assertEquals("Should parse the xml and count the request objects", 67 9, 68 JUnitTestAdapter.parse(new InputSource (_xmlFile.toURL().toString()))); 69 } catch (SocketException se) { 70 if (se.getMessage().indexOf("unreachable") == -1) { 72 fail("SocketException: " + se.toString()); 73 } 74 } 75 } 76 77 public void testCount() { 78 assertEquals("Should get 1 TestCase for each request", 79 9, _adapter.countTestCases()); 80 } 81 82 public void testCreateNullAdapterFromResource() { 83 Test myTest = JUnitTestAdapter.createTestFromResource("bogus"); 84 assertNull("Should get null object back", myTest); 85 } 86 87 public void testCreateAdapterFromFile() { 88 Test myTest = JUnitTestAdapter.createTestFromFile(_xmlFile); 89 assertNotNull("Should get object back from file", myTest); 90 assertEquals("Should get 1 TestCase for each request", 91 9, myTest.countTestCases()); 92 } 93 94 public void testCreateAdapterFromFileName() { 95 Test myTest = JUnitTestAdapter.createTestFromFile(_xmlFileName); 96 assertNotNull("Should get object back from file name", myTest); 97 assertEquals("Should get 1 TestCase for each request", 98 9, myTest.countTestCases()); 99 } 100 101 public void testCreateNullAdapterFromURL() { 102 String url = "http://www.latka-example-dummy-url.com/"; 103 Test myTest = JUnitTestAdapter.createTestFromURL(url); 104 assertNull("Should get null object back from bad url", myTest); 105 } 106 } 107
| Popular Tags
|