[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-commons-dev
Subject: cvs commit: jakarta-commons/latka/src/test/org/apache/commons/latka/junit TestAll.java TestJUnitEven
From: morgand () apache ! org
Date: 2001-10-17 15:35:59
[Download RAW message or body]
morgand 01/10/17 08:35:59
Added: latka/src/java/org/apache/commons/latka/junit
JUnitEventReporter.java JUnitTestAdapter.java
latka/src/test/org/apache/commons/latka/junit TestAll.java
TestJUnitEventReporter.java
TestJUnitTestAdapter.java
Log:
adding junit integration
Revision Changes Path
1.1 \
jakarta-commons/latka/src/java/org/apache/commons/latka/junit/JUnitEventReporter.java \
Index: JUnitEventReporter.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.commons.latka.junit;
import org.apache.commons.latka.AbstractReporter;
import org.apache.commons.latka.ValidationException;
import org.apache.commons.latka.event.RequestErrorEvent;
import org.apache.commons.latka.event.RequestEvent;
import org.apache.commons.latka.event.RequestFailedEvent;
import org.apache.commons.latka.event.SuiteEvent;
import org.apache.log4j.Category;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
/**
* @author Chuck Burdick
* @version $Id: JUnitEventReporter.java,v 1.1 2001/10/17 15:35:58 morgand Exp $
*/
public class JUnitEventReporter extends AbstractReporter {
private static final Category _log = \
Category.getInstance(JUnitEventReporter.class);
private TestResult _testResult = null;
protected JUnitEventReporter(TestResult result) {
_testResult = result;
}
private class EventTestAdapter implements Test {
private AssertionFailedError _failed = null;
private Throwable _error = null;
public EventTestAdapter() { }
public EventTestAdapter(AssertionFailedError t) { _failed = t; }
public EventTestAdapter(Throwable t) { _error = t; }
public int countTestCases() { return 1; }
public void run(TestResult result) {
result.startTest(this);
if (_error != null) {
result.addError(this, _error);
} else if (_failed != null) {
result.addFailure(this, _failed);
}
result.endTest(this);
}
}
/** Methods to extend LatkaEventInfo **/
public void requestError(RequestEvent event) {
_log.debug("Received latka RequestErrorEvent");
super.requestError(event);
Throwable error = ((RequestErrorEvent)event).getError();
Test test = new EventTestAdapter(error);
test.run(_testResult);
}
public void requestFailed(RequestEvent event) {
_log.debug("Received latka RequestFailedEvent");
super.requestFailed(event);
RequestFailedEvent fe = (RequestFailedEvent)event;
ValidationException ve = (ValidationException)fe.getValidationException();
AssertionFailedError failure = new AssertionFailedError(ve.getReason());
Test test = new EventTestAdapter(failure);
test.run(_testResult);
}
public void requestSkipped(RequestEvent event) {
_log.debug("Received latka RequestSkippedEvent");
super.requestSkipped(event);
AssertionFailedError failure = new AssertionFailedError(
"Skipped due to earlier error");
Test test = new EventTestAdapter(failure);
test.run(_testResult);
}
public void requestSucceeded(RequestEvent event) {
_log.debug("Received latka RequestSucceededEvent");
super.requestSucceeded(event);
Test test = new EventTestAdapter();
test.run(_testResult);
}
public void suiteCompleted(SuiteEvent event) {
}
}
1.1 \
jakarta-commons/latka/src/java/org/apache/commons/latka/junit/JUnitTestAdapter.java
Index: JUnitTestAdapter.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.commons.latka.junit;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.latka.Latka;
import org.apache.commons.latka.LatkaException;
import org.apache.commons.latka.Suite;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Category;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import junit.framework.Test;
import junit.framework.TestResult;
/**
* @author Chuck Burdick
* @version $Id: JUnitTestAdapter.java,v 1.1 2001/10/17 15:35:58 morgand Exp $
*/
public class JUnitTestAdapter implements Test {
private static final int ERROR = 0;
private static final int FAILED = 1;
private static final int SKIPPED = 2;
private static final int SUCCEEDED = 3;
private static final Category _log = \
Category.getInstance(JUnitTestAdapter.class);
private Suite _latkaSuite = null;
private TestResult _testResult = null;
private int _testCount = 0;
protected JUnitTestAdapter(Suite suite, int testCount) {
_latkaSuite = suite;
_testCount = testCount;
}
public static Test createTestFromResource(String resourceName) {
Test result = null;
ClassLoader loader = JUnitTestAdapter.class.getClassLoader();
URL resource = loader.getResource(resourceName);
if (resource != null) {
result = createTestFromURL(resource);
}
return result;
}
public static Test createTestFromURL(String url) {
Test result = null;
try {
result = createTestFromURL(new URL(url));
} catch (MalformedURLException e) {
_log.error("Unable to create URL " + url, e);
}
return result;
}
public static Test createTestFromURL(URL url) {
Test result = null;
try {
InputSource source = new InputSource(url.toString());
Suite suite = new Suite(url);
result = new JUnitTestAdapter(suite, parse(source));
} catch (Throwable t) {
_log.error("Unable to obtain xml from URL " + url.toString(), t);
}
return result;
}
protected static int parse(InputSource xml)
throws IOException, SAXException,
FactoryConfigurationError, ParserConfigurationException {
int result = 0;
XMLReader reader = null;
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
SAXParser parser = factory.newSAXParser();
reader = parser.getXMLReader();
TestCounter handler = new TestCounter();
reader.setContentHandler(handler);
reader.parse(xml);
result = handler.getCount();
return result;
}
private static class TestCounter extends DefaultHandler {
private int _count = 0;
public TestCounter() { _count = 0; }
public void startElement(
String uri, String localName, String qName, Attributes atts) {
if (qName.equals("request")) { _count++; }
}
public int getCount() { return _count; }
}
/** Methods to implement Test **/
public int countTestCases() {
return _testCount;
}
public void run(TestResult r) {
BasicConfigurator.configure();
_log.debug("Attempting to perform latka tests");
Latka latka = new Latka();
try {
// latka.runTests(_latkaSuite, new JUnitEventReporter(r));
latka.runTests(_latkaSuite, new org.apache.commons.latka.XMLReporter());
} catch (LatkaException e) {
_log.error("Unable to execute latka tests", e);
}
}
public static void main(String[] args) {
Test test = JUnitTestAdapter.createTestFromResource("TestCommonsWebsite.xml");
test.run(new TestResult());
}
}
1.1 \
jakarta-commons/latka/src/test/org/apache/commons/latka/junit/TestAll.java
Index: TestAll.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.commons.latka.junit;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.log4j.BasicConfigurator;
/**
* @author Chuck Burdick
* @version $Id: TestAll.java,v 1.1 2001/10/17 15:35:58 morgand Exp $
*/
public class TestAll extends TestCase {
public TestAll(String testName) {
super(testName);
}
public static Test suite() {
// BasicConfigurator.configure();
TestSuite suite = new TestSuite();
suite.addTest(TestJUnitEventReporter.suite());
suite.addTest(TestJUnitTestAdapter.suite());
String resource = "TestCommonsWebsite.xml";
suite.addTest(JUnitTestAdapter.createTestFromResource(resource));
return suite;
}
public static void main(String args[]) {
String[] testCaseName = { TestAll.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
}
1.1 \
jakarta-commons/latka/src/test/org/apache/commons/latka/junit/TestJUnitEventReporter.java
Index: TestJUnitEventReporter.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.commons.latka.junit;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.latka.ValidationException;
import org.apache.commons.latka.event.RequestErrorEvent;
import org.apache.commons.latka.event.RequestEvent;
import org.apache.commons.latka.event.RequestFailedEvent;
import org.apache.commons.latka.event.RequestSkippedEvent;
import org.apache.commons.latka.event.RequestSucceededEvent;
import org.apache.commons.latka.http.Request;
import org.apache.commons.latka.http.Response;
import org.apache.commons.latka.http.SessionImpl;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import junit.framework.TestSuite;
/**
* @author Chuck Burdick
* @version $Id: TestJUnitEventReporter.java,v 1.1 2001/10/17 15:35:58 morgand Exp \
$
*/
public class TestJUnitEventReporter extends TestCase {
private JUnitEventReporter _reporter = null;
private TestResult _result = null;
private Request _request = null;
public TestJUnitEventReporter(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestJUnitEventReporter.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestJUnitEventReporter.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
public void setUp() throws MalformedURLException {
_result = new TestResult();
_reporter = new JUnitEventReporter(_result);
URL url = new URL("http://www.example.com/");
SessionImpl session = new SessionImpl();
_request = session.createRequest(url, Request.HTTP_METHOD_GET);
}
public void testSuccess() {
RequestEvent e = new RequestSucceededEvent(_request, null);
_reporter.requestSucceeded(e);
assertEquals("Should have run 1 test", 1, _result.runCount());
assertEquals("Should have 0 errors", 0, _result.errorCount());
assertEquals("Should have 0 failures", 0, _result.failureCount());
assertTrue("Should represent a successful run", _result.wasSuccessful());
}
public void testError() {
RequestEvent e = new RequestErrorEvent(
_request, null, new Exception("test exception"));
_reporter.requestError(e);
assertEquals("Should have run 1 test", 1, _result.runCount());
assertEquals("Should have 1 error", 1, _result.errorCount());
assertEquals("Should have 0 failures", 0, _result.failureCount());
assertTrue("Should not represent a successful run",
!_result.wasSuccessful());
}
public void testFailed() {
RequestEvent e = new RequestFailedEvent(
_request, null, new ValidationException());
_reporter.requestFailed(e);
assertEquals("Should have run 1 test", 1, _result.runCount());
assertEquals("Should have 0 errors", 0, _result.errorCount());
assertEquals("Should have 1 failure", 1, _result.failureCount());
assertTrue("Should not represent a successful run",
!_result.wasSuccessful());
}
public void testSkipped() {
RequestEvent e = new RequestSkippedEvent(_request, null);
_reporter.requestSkipped(e);
assertEquals("Should have run 1 test", 1, _result.runCount());
assertEquals("Should have 0 errors", 0, _result.errorCount());
assertEquals("Should have 1 failure", 1, _result.failureCount());
assertTrue("Should not represent a successful run",
!_result.wasSuccessful());
}
}
1.1 \
jakarta-commons/latka/src/test/org/apache/commons/latka/junit/TestJUnitTestAdapter.java
Index: TestJUnitTestAdapter.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.commons.latka.junit;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.latka.Latka;
import org.apache.commons.latka.Suite;
import org.xml.sax.InputSource;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import junit.framework.TestSuite;
/**
* @author Chuck Burdick
* @version $Id: TestJUnitTestAdapter.java,v 1.1 2001/10/17 15:35:58 morgand Exp $
*/
public class TestJUnitTestAdapter extends TestCase {
private String _resourceName = "TestCommonsWebsite.xml";
private JUnitTestAdapter _adapter = null;
private Suite _suite = null;
public TestJUnitTestAdapter(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestJUnitTestAdapter.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestJUnitTestAdapter.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
public void setUp() throws MalformedURLException {
_suite = new Suite(new InputStreamReader(
getClass().getClassLoader().getResourceAsStream(_resourceName)));
_adapter = new JUnitTestAdapter(_suite, 9);
}
public void testParser() throws Throwable {
assertEquals(
"Should parse the xml and count the request objects", 9,
_adapter.parse(
new InputSource(
getClass().getClassLoader().getResource(
_resourceName).toString())));
}
public void testCount() {
assertEquals("Should get 1 TestCase for each request",
9, _adapter.countTestCases());
}
public void testCreateNullAdapterFromResource() {
Test myTest = JUnitTestAdapter.createTestFromResource("bogus");
assertNull("Should get null object back", myTest);
}
public void testCreateAdapterFromResource() {
Test myTest = JUnitTestAdapter.createTestFromResource(_resourceName);
assertNotNull("Should get object back", myTest);
assertEquals("Should get 1 TestCase for each request",
9, myTest.countTestCases());
}
public void testCreateNullAdapterFromURL() {
String url = "http://www.example.com/";
Test myTest = JUnitTestAdapter.createTestFromURL(url);
assertNull("Should get null object back", myTest);
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic