diff --git a/lib/simple-core-2.5.3.jar b/lib/simple-core-2.5.3.jar new file mode 100644 index 0000000..1680939 --- /dev/null +++ b/lib/simple-core-2.5.3.jar Binary files differ diff --git a/src/main/uk/org/floop/collabunit/CollabRunner.java b/src/main/uk/org/floop/collabunit/CollabRunner.java index 43deff7..0f44542 100644 --- a/src/main/uk/org/floop/collabunit/CollabRunner.java +++ b/src/main/uk/org/floop/collabunit/CollabRunner.java @@ -6,9 +6,18 @@ */ package uk.org.floop.collabunit; +import java.io.IOException; +import java.net.ServerSocket; + import junit.framework.Test; import junit.framework.TestResult; import junit.runner.BaseTestRunner; +import simple.http.ProtocolHandler; +import simple.http.connect.Connection; +import simple.http.connect.ConnectionFactory; +import simple.http.load.LoaderEngine; +import simple.http.load.LoadingException; +import simple.http.serve.HandlerFactory; /** * @author alex @@ -18,6 +27,9 @@ */ public class CollabRunner extends BaseTestRunner { +/* + */ + private TestResult results; /* (non-Javadoc) @@ -39,7 +51,19 @@ /** * */ - public CollabRunner() { + public CollabRunner(String path, int port) { + try { + LoaderEngine engine = new LoaderEngine(); + engine.load("results", "uk.org.floop.collabunit.TestResultsService"); + engine.link(path, "results"); + ProtocolHandler handler = HandlerFactory.getInstance(engine); + Connection connection = ConnectionFactory.getConnection(handler); + connection.connect(new ServerSocket(port)); + } catch (IOException e) { + e.printStackTrace(); + } catch (LoadingException e) { + e.printStackTrace(); + } results = new TestResult(); results.addListener(this); } @@ -66,6 +90,7 @@ public boolean runTest(Test test) { test.run(results); + TestResultsService.setResults(results); return results.wasSuccessful(); } } diff --git a/src/main/uk/org/floop/collabunit/TestResultsService.java b/src/main/uk/org/floop/collabunit/TestResultsService.java new file mode 100644 index 0000000..a596879 --- /dev/null +++ b/src/main/uk/org/floop/collabunit/TestResultsService.java @@ -0,0 +1,68 @@ +/* + * Created on Nov 3, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package uk.org.floop.collabunit; + +import java.io.PrintStream; +import java.util.Enumeration; + +import junit.framework.TestCase; +import junit.framework.TestFailure; +import junit.framework.TestResult; +import simple.http.Request; +import simple.http.Response; +import simple.http.load.BasicService; +import simple.http.serve.Context; + +/** + * @author alex + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class TestResultsService extends BasicService { + + static private TestResult results; + + static public void setResults(TestResult results) { + TestResultsService.results = results; + } + + public TestResultsService(Context context) { + super(context); + } + + + /* (non-Javadoc) + * @see simple.http.serve.BasicResource#process(simple.http.Request, simple.http.Response) + */ + protected void process(Request request, Response response) throws Exception { + request.set("Content-Type", "application/rdf+xml"); + PrintStream out = response.getPrintStream(); + out.println(""); + if (results != null) { + for (Enumeration i = results.errors(); i.hasMoreElements();) { + TestFailure failure = (TestFailure)i.nextElement(); + if (failure.failedTest() instanceof TestCase) { + out.println(" "); + out.println(" " + failure.exceptionMessage() + ""); + out.println(" "); + } + } + for (Enumeration j = results.failures(); j.hasMoreElements();) { + TestFailure failure = (TestFailure)j.nextElement(); + if (failure.failedTest() instanceof TestCase) { + out.println(" "); + out.println(" " + failure.exceptionMessage() + ""); + out.println(" "); + } + } + } + out.println(""); + out.close(); + } + +} diff --git a/src/tests/uk/org/floop/collabunit/CollabRunnerTest.java b/src/tests/uk/org/floop/collabunit/CollabRunnerTest.java index 068717b..51a29df 100644 --- a/src/tests/uk/org/floop/collabunit/CollabRunnerTest.java +++ b/src/tests/uk/org/floop/collabunit/CollabRunnerTest.java @@ -18,7 +18,7 @@ public class CollabRunnerTest extends TestCase { public void testCollabRunner() { - CollabRunner runner = new CollabRunner(); + CollabRunner runner = new CollabRunner("/results.rdf", 8080); Test test = runner.getTest("uk.org.floop.collabunit.DummyTest"); assertNotNull("Test shouldn't be null.", test); assertTrue("Failed to run test which should always pass.", diff --git a/src/tests/uk/org/floop/collabunit/DummyTest.java b/src/tests/uk/org/floop/collabunit/DummyTest.java index 0fe6605..91f1075 100644 --- a/src/tests/uk/org/floop/collabunit/DummyTest.java +++ b/src/tests/uk/org/floop/collabunit/DummyTest.java @@ -17,6 +17,10 @@ public class DummyTest extends TestCase { public void testAlwaysPass() { - assertTrue(true); + assertTrue("This is supposed to pass", true); + } + + public void testAlwaysFail() { + assertTrue("This is supposed to fail.", false); } }