version 1.1.1.4, 1999/09/30 13:54:48 |
version 1.1.1.5, 1999/09/30 13:57:08 |
|
|
|
// JDK imports |
// JDK imports |
import java.io.*; |
import java.io.*; |
import java.net.*; |
import java.net.*; |
|
import java.text.*; |
|
|
|
// JSDK imports |
|
import javax.servlet.*; |
|
|
// JUnit imports |
// JUnit imports |
import junit.framework.*; |
import junit.framework.*; |
|
|
|
return result; |
return result; |
} |
} |
public static void main (String[] args) { |
public static void main (String[] args) { |
|
stopServletRunner(); |
new TestRunner().start(new String[] {"com.xpdeveloper.TestServlets"}); |
new TestRunner().start(new String[] {"com.xpdeveloper.TestServlets"}); |
} |
} |
protected static void startServletRunner() { |
protected static void startServletRunner() { |
|
|
|
assert("General exceptions should not occur.",false); |
assert("General exceptions should not occur.",false); |
} |
} |
} |
} |
|
/** |
|
* Exercise the PageSaver |
|
* Send a request and check the response contains the expected String. |
|
*/ |
|
public void testEditingAKnownString() |
|
{ |
|
|
|
try { |
|
String input = "My known input"; |
|
String servletName = PageSaver.class.getName(); |
|
|
|
String expectedResponse = MessageFormat.format (PageSaver.EDIT_FORMAT, new Object[]{URL_BASE+PORT_STRING+"/servlet/" + servletName,PAGE_NAME,input}); |
|
|
|
PageSaver.save(PAGE_NAME,input); |
|
|
|
String actualResponse = getServerResponse(URL_BASE+PORT_STRING+"/servlet/"+servletName + "?"+PageSaver.PAGE_EDIT_PARAM+"=" + PAGE_NAME); |
|
|
|
assert(actualResponse.equals(expectedResponse)); |
|
} |
|
catch (Exception exception) { |
|
exception.printStackTrace(); |
|
assert("General exceptions should not occur.",false); |
|
} |
|
} |
public void testLinkRendering() |
public void testLinkRendering() |
{ |
{ |
|
|
|
|
|
|
|
actualResponse = getServerResponse(URL_BASE+PORT_STRING+"/servlet/"+servletName+"?"+PageSaver.PAGE_NAME_PARAM+"=" + name2); |
actualResponse = getServerResponse(URL_BASE+PORT_STRING+"/servlet/"+servletName+"?"+PageSaver.PAGE_NAME_PARAM+"=" + name2); |
assert(actualResponse.equals(result2)); |
assert(actualResponse.equals(result2)); |
|
} |
|
catch (Exception exception) { |
|
exception.printStackTrace(); |
|
assert("General exceptions should not occur.",false); |
|
} |
|
} |
|
/** |
|
* Exercise the PageSaver |
|
* Send a request and check the response contains the expected String. |
|
*/ |
|
public void testPostingAKnownString() |
|
{ |
|
try { |
|
String input = "My known input"; |
|
|
|
String postingInput = PageSaver.PAGE_NAME_PARAM+"=" + PAGE_NAME + "&"+PageSaver.TEXT_SAVE_PARAM+"=" + input; |
|
|
|
String servletName = PageSaver.class.getName(); |
|
URL servlet = new URL(URL_BASE+PORT_STRING+"/servlet/"+servletName); |
|
HttpURLConnection connection = (HttpURLConnection) servlet.openConnection(); |
|
connection.setDoOutput(true); |
|
connection.setRequestMethod("POST"); |
|
|
|
OutputStream connectionOutputStream = connection.getOutputStream(); |
|
connectionOutputStream.write(postingInput.getBytes() ); |
|
|
|
connection.getResponseCode(); |
|
|
|
|
|
String actualPosted = PageSaver.load(PAGE_NAME); |
|
assert(actualPosted.equals(input)); |
|
|
} |
} |
catch (Exception exception) { |
catch (Exception exception) { |
exception.printStackTrace(); |
exception.printStackTrace(); |