Author: vmassol
Date: 2007-10-01 11:10:55 +0200 (Mon, 01 Oct 2007)
New Revision: 5192
Modified:
xwiki-products/xwiki-enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/XhtmlValidityTest.java
Log:
XE-130: Fix Velocity warnings
* Make the build fail when there are velocity warnings or errors.
Patch submitted by Marius Florea
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-09-30 23:44:56 UTC (rev 5191)
+++
xwiki-products/xwiki-enterprise/trunk/distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/XhtmlValidityTest.java
2007-10-01 09:10:55 UTC (rev 5192)
@@ -19,10 +19,12 @@
*/
package com.xpn.xwiki.it.xmlrpc;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
+import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
@@ -138,6 +140,15 @@
// 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);
@@ -159,9 +170,36 @@
}
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)
+ {
+ return output.indexOf("ERROR") >= 0 || output.indexOf("ERR") >= 0;
+ }
+
+ private static boolean hasWarnings(String output)
+ {
+ return output.indexOf("WARNING") >= 0 || output.indexOf("WARN") >= 0;
+ }
+
private static List readXarContents(String fileName) throws Exception
{
FileInputStream fileIS = new FileInputStream(fileName);
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications