Author: RaffaelloPelagalli
Date: 2007-10-02 16:25:19 +0200 (Tue, 02 Oct 2007)
New Revision: 5206
Modified:
xwiki-products/xwiki-enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/XhtmlValidityTest.java
Log:
There was a bug in the previous patch that I applied. Indeed if a test raised
an exception then
the default stdout/stderr console output was suppressed.
Also, it's a better practice to do this sort of things in setUp()/tearDown().
NOTE: The previous commit seem not to have worked for some reason on the new
repository. Now
doing it again using svn command line client.
Modified:
xwiki-products/xwiki-enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/XhtmlValidityTest.java
===================================================================
---
xwiki-products/xwiki-enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/XhtmlValidityTest.java
2007-10-02 14:18:00 UTC (rev 5205)
+++
xwiki-products/xwiki-enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/XhtmlValidityTest.java
2007-10-02 14:25:19 UTC (rev 5206)
@@ -80,6 +80,28 @@
private int errors = 0;
+ /**
+ * We save the stdout stream since we replace it with our own in order to
verify that XWiki
+ * doesn't generated any error while validating documents and we fail the
build if it does.
+ */
+ private PrintStream stdout;
+
+ /**
+ * The new stdout stream we're using to replace the default console output.
+ */
+ private ByteArrayOutputStream out;
+
+ /**
+ * We save the stderr stream since we replace it with our own in order to
verify that XWiki
+ * doesn't generated any error while validating documents and we fail the
build if it does.
+ */
+ private PrintStream stderr;
+
+ /**
+ * The new stderr stream we're using to replace the default console output.
+ */
+ private ByteArrayOutputStream err;
+
public XhtmlValidityTest(String fullPageName)
{
super("testValidityOfDocument");
@@ -126,10 +148,39 @@
rpc = new Confluence("http://127.0.0.1:8080/xwiki/xmlrpc");
rpc.login("Admin", "admin");
+
+ // TODO Until we find a way to incrementally display the result of
tests this stays
+ System.out.println(getName());
+
+ // We redirect the stdout and the stderr in order to detect
(server-side) error/warning
+ // messages like the ones generated by the velocity parser
+ this.stdout = System.out;
+ this.out = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(this.out));
+ this.stderr = System.err;
+ this.err = new ByteArrayOutputStream();
+ System.setErr(new PrintStream(this.err));
}
protected void tearDown() throws Exception
{
+ // Restore original stdout and stderr streams.
+ String output = this.out.toString();
+ String errput = this.err.toString();
+
+ System.setOut(this.stdout);
+ System.out.print(output);
+ System.setErr(this.stderr);
+ System.err.print(errput);
+
+ // Detect server-side error/warning messages from the stdout
+ assertFalse(hasErrors(output));
+ assertFalse(hasWarnings(output));
+
+ // Detect server-side error/warning messages from the stderr
+ assertFalse(hasErrors(errput));
+ assertFalse(hasWarnings(errput));
+
rpc.logout();
super.tearDown();
@@ -137,18 +188,6 @@
public void testValidityOfDocument() throws Exception
{
- // TODO Until we find a way to incrementally display the result of
tests this stays
- System.out.println(getName());
-
- // We redirect the stdout and the stderr in order to detect
(server-side) error/warning
- // messages like the ones generated by the velocity parser
- PrintStream stdout = System.out;
- ByteArrayOutputStream newOut = new ByteArrayOutputStream();
- System.setOut(new PrintStream(newOut));
- PrintStream stderr = System.err;
- ByteArrayOutputStream newErr = new ByteArrayOutputStream();
- System.setErr(new PrintStream(newErr));
-
Page page = rpc.getPage(fullPageName);
String renderedContent = rpc.renderContent(page);
assertNotNull(renderedContent);
@@ -171,31 +210,15 @@
errors += assertCssValid(page.getUrl());
}
- // Restore original stdout and stderr streams.
- System.setOut(stdout);
- String output = newOut.toString();
- System.out.print(output);
- System.setErr(stderr);
- String errput = newErr.toString();
- System.err.print(errput);
-
assertTrue(errors == 0);
-
- // Detect server-side error/warning messages from the stdout
- assertFalse(hasErrors(output));
- assertFalse(hasWarnings(output));
-
- // Detect server-side error/warning messages from the stderr
- assertFalse(hasErrors(errput));
- assertFalse(hasWarnings(errput));
}
- private static boolean hasErrors(String output)
+ private boolean hasErrors(String output)
{
return output.indexOf("ERROR") >= 0 || output.indexOf("ERR") >= 0;
}
- private static boolean hasWarnings(String output)
+ private boolean hasWarnings(String output)
{
return output.indexOf("WARNING") >= 0 || output.indexOf("WARN") >= 0;
}
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications