Permalink
Browse files

housekeeping

  • Loading branch information...
1 parent f4363fd commit 82f4738d145649b8e9169af1b99364d32d2f1ba2 unclebob committed Jan 3, 2010
@@ -4,6 +4,6 @@ PropertiesToXmlUpdate=applied
FilesAttributeUpdate=applied
SymLinkPropertyFormatUpdate=applied
VirtualWikiDeprecationUpdate=applied
-Version=v20100101
-WhereUsedAttributeUpdate=applied
+Version=v20100103
RecentChangesAttributeUpdate=applied
+WhereUsedAttributeUpdate=applied
@@ -209,7 +209,7 @@ private void initializeTest() {
}
private void checkForAndReportVersionMismatch() {
- double expectedVersionNumber = SlimClient.EXPECTED_SLIM_VERSION;
+ double expectedVersionNumber = SlimClient.MINIMUM_REQUIRED_SLIM_VERSION;
double serverVersionNumber = slimClient.getServerVersion();
if (!slimClient.versionsMatch())
exceptions.addException("Slim Protocol Version Error",
@@ -7,6 +7,7 @@
import fitnesse.http.SimpleResponse;
import fitnesse.responders.run.TestSummary;
import fitnesse.responders.run.TestSystemListener;
+import fitnesse.slim.SlimClient;
import fitnesse.slimTables.HtmlTableScanner;
import fitnesse.slimTables.Table;
import fitnesse.slimTables.TableScanner;
@@ -414,6 +415,13 @@ public void versionMismatchIsNotReported() throws Exception {
getResultsForPageContents("");
assertTestResultsDoNotContain("Slim Protocol Version Error");
}
+
+ @Test
+ public void versionMismatchIsReported() throws Exception {
+ SlimClient.MINIMUM_REQUIRED_SLIM_VERSION = 1000.0; // I doubt will ever get here.
+ getResultsForPageContents("");
+ assertTestResultsContain("Slim Protocol Version Error");
+ }
@Test
public void checkTestClassPrecededByDefine() throws Exception {
@@ -2,6 +2,9 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.slim;
+import util.ListUtility;
+import util.StreamReader;
+
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
@@ -10,11 +13,8 @@
import java.util.List;
import java.util.Map;
-import util.ListUtility;
-import util.StreamReader;
-
public class SlimClient {
- public static final double EXPECTED_SLIM_VERSION = 0.1;
+ public static double MINIMUM_REQUIRED_SLIM_VERSION = 0.1;
private Socket client;
private StreamReader reader;
private BufferedWriter writer;
@@ -64,9 +64,9 @@ public boolean isConnected() {
}
public boolean versionsMatch() {
- return slimServerVersion == EXPECTED_SLIM_VERSION;
+ return slimServerVersion >= MINIMUM_REQUIRED_SLIM_VERSION;
}
-
+
public Map<String, Object> invokeAndGetResponse(List<Object> statements) throws Exception {
String instructions = ListSerializer.serialize(statements);
writeString(instructions);
@@ -2,15 +2,15 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.slim;
+import fitnesse.socketservice.SocketServer;
+import util.StreamReader;
+
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.List;
-import util.StreamReader;
-import fitnesse.socketservice.SocketServer;
-
public class SlimServer implements SocketServer {
private StreamReader reader;
private BufferedWriter writer;
@@ -59,7 +59,7 @@ private void initialize(Socket s) throws Exception {
executor = slimFactory.getListExecutor(verbose);
reader = new StreamReader(s.getInputStream());
writer = new BufferedWriter(new OutputStreamWriter(s.getOutputStream(), "UTF-8"));
- writer.write(String.format("Slim -- %s\n", SlimVersion.VERSION));
+ writer.write(String.format("Slim -- V%s\n", SlimVersion.VERSION));
writer.flush();
}
@@ -2,16 +2,23 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.slim;
-public class SlimServiceTest extends SlimServiceTestBase{
+import org.junit.After;
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+import static util.ListUtility.list;
- protected String getImport() {
- return "fitnesse.slim.test";
- }
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class SlimServiceTest {
+ protected List<Object> statements;
+ protected SlimClient slimClient;
protected void startSlimService() throws Exception {
SlimService.main(new String[]{"8099"});
}
-
protected String expectedExceptionMessage() {
return "java.lang.Exception: This is my exception";
@@ -20,5 +27,159 @@ protected String expectedExceptionMessage() {
protected String expectedStopTestExceptionMessage() {
return "ABORT_SLIM_TEST:fitnesse.slim.test.TestSlim$StopTestException: This is a stop test exception";
}
+
+ @Before
+ public void setUp() throws Exception {
+ createSlimService();
+ slimClient = new SlimClient("localhost", 8099);
+ statements = new ArrayList<Object>();
+ slimClient.connect();
+ }
+
+ protected void createSlimService() throws Exception {
+ while (!tryCreateSlimService())
+ Thread.sleep(10);
+ }
+
+ private boolean tryCreateSlimService() throws Exception {
+ try {
+ startSlimService();
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ @After
+ public void after() throws Exception {
+ teardown();
+ }
+
+ protected void teardown() throws Exception {
+ slimClient.sendBye();
+ slimClient.close();
+ }
+
+ @Test
+ public void emptySession() throws Exception {
+ assertTrue("Connected", slimClient.isConnected());
+ }
+
+ @Test
+ public void versionNumberShouldBeDetected() throws Exception {
+ double slimVersion = Double.parseDouble(SlimVersion.VERSION);
+ assertEquals(slimVersion, slimClient.getServerVersion(), .0001);
+ }
+
+ @Test
+ public void callOneMethod() throws Exception {
+ addImportAndMake();
+ addEchoInt("id", "1");
+ Map<String, Object> result = slimClient.invokeAndGetResponse(statements);
+ assertEquals("1", result.get("id"));
+ }
+
+ private void addEchoInt(String id, String number) {
+ statements.add(list(id, "call", "testSlim", "echoInt", number));
+ }
+
+ private void addImportAndMake() {
+ statements.add(list("i1", "import", "fitnesse.slim.test"));
+ statements.add(list("m1", "make", "testSlim", "TestSlim"));
+ }
+
+ @Test
+ public void makeManyCallsInOrderToTestLongSequencesOfInstructions() throws Exception {
+ addImportAndMake();
+ for (int i = 0; i < 1000; i++)
+ addEchoInt(String.format("id_%d", i), Integer.toString(i));
+ Map<String, Object> result = slimClient.invokeAndGetResponse(statements);
+ for (int i = 0; i < 1000; i++)
+ assertEquals(i, Integer.parseInt((String) result.get(String.format("id_%d", i))));
+ }
+
+ @Test
+ public void callWithLineBreakInStringArgument() throws Exception {
+ addImportAndMake();
+ statements.add(list("id", "call", "testSlim", "echoString", "hello\nworld\n"));
+ Map<String, Object> result = slimClient.invokeAndGetResponse(statements);
+ assertEquals("hello\nworld\n", result.get("id"));
+ }
+
+ @Test
+ public void callWithMultiByteChar() throws Exception {
+ addImportAndMake();
+ statements.add(list("id", "call", "testSlim", "echoString", "K\u00f6ln"));
+ Map<String, Object> result = slimClient.invokeAndGetResponse(statements);
+ assertEquals("K\u00f6ln", result.get("id"));
+ }
+
+ @Test
+ public void makeManyIndividualCalls() throws Exception {
+ addImportAndMake();
+ slimClient.invokeAndGetResponse(statements);
+ for (int i = 0; i < 100; i++) {
+ statements.clear();
+ addEchoInt("id", "42");
+ Map<String, Object> result = slimClient.invokeAndGetResponse(statements);
+ assertEquals(1, result.size());
+ assertEquals("42", result.get("id"));
+ }
+ }
+
+ @Test
+ public void callFunctionThatDoesntExist() throws Exception {
+ addImportAndMake();
+ statements.add(list("id", "call", "testSlim", "noSuchFunction"));
+ Map<String, Object> results = slimClient.invokeAndGetResponse(statements);
+ assertContainsException("message:<<NO_METHOD_IN_CLASS", "id", results);
+ }
+
+ private void assertContainsException(String message, String id, Map<String, Object> results) {
+ String result = (String) results.get(id);
+ assertTrue(result, result.indexOf(SlimServer.EXCEPTION_TAG) != -1 && result.indexOf(message) != -1);
+ }
+
+ @Test
+ public void makeClassThatDoesntExist() throws Exception {
+ statements.add(list("m1", "make", "me", "NoSuchClass"));
+ Map<String, Object> results = slimClient.invokeAndGetResponse(statements);
+ assertContainsException("message:<<COULD_NOT_INVOKE_CONSTRUCTOR", "m1", results);
+ }
+
+ @Test
+ public void useInstanceThatDoesntExist() throws Exception {
+ addImportAndMake();
+ statements.add(list("id", "call", "noInstance", "f"));
+ Map<String, Object> results = slimClient.invokeAndGetResponse(statements);
+ assertContainsException("message:<<NO_INSTANCE", "id", results);
+ }
+
+ @Test
+ public void verboseArgument() throws Exception {
+ String args[] = {"-v", "99"};
+ assertTrue(SlimService.parseCommandLine(args));
+ assertTrue(SlimService.verbose);
+ }
+
+ @Test
+ public void notStopTestExceptionThrown() throws Exception {
+ addImportAndMake();
+ statements.add(list("id", "call", "testSlim", "throwNormal"));
+ statements.add(list("id2", "call", "testSlim", "throwNormal"));
+ Map<String, Object> results = slimClient.invokeAndGetResponse(statements);
+ assertContainsException("__EXCEPTION__:" + expectedExceptionMessage(), "id", results);
+ assertContainsException("__EXCEPTION__:" + expectedExceptionMessage(), "id2", results);
+ }
+
+ @Test
+ public void stopTestExceptionThrown() throws Exception {
+ addImportAndMake();
+ statements.add(list("id", "call", "testSlim", "throwStopping"));
+ statements.add(list("id2", "call", "testSlim", "throwNormal"));
+ Map<String, Object> results = slimClient.invokeAndGetResponse(statements);
+ assertContainsException("__EXCEPTION__:" + expectedStopTestExceptionMessage(), "id", results);
+ assertNull(results.get("id2"));
+ }
}
Oops, something went wrong.

0 comments on commit 82f4738

Please sign in to comment.