UtilTest.java revision 1145
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/**
* Test of the methods in <code>org.opensolaris.opengrok.web.Util</code>.
*/
public class UtilTest {
private static Locale savedLocale;
public static void setUpClass() {
// Some of the methods have different results in different locales.
// Set locale to en_US for these tests.
}
public static void tearDownClass() {
savedLocale = null;
}
@Test
public void htmlize() {
String[][] input_output = {
{"This is a test", "This is a test" },
{"Newline\nshould become <br/>",
"Newline<br/>should become <br/>" },
{"Open & Grok", "Open & Grok" },
{"&<>", "&amp;&lt;&gt;" },
};
// 1 arg
// 2 args
}
}
@Test
public void breadcrumbPath() {
// Are these two correct? Why don't we create links?
assertEquals("<a href=\"/root/xx\">xx</a>",
assertEquals("<a href=\"/r/a\">a</a>/<a href=\"/r/a/b\">b</a>",
assertEquals("<a href=\"/r/a\">a</a>/<a href=\"/r/a/b\">b</a>/",
assertEquals("<a href=\"/r/java\">java</a>." +
assertEquals("<a href=\"/root/xx&project=y\">xx</a>",
assertEquals("<a href=\"/root/xx&project=y\">xx</a>",
assertEquals("<a href=\"/r/\">..</a>/" +
"<a href=\"/r/a\">a</a>/" +
"<a href=\"/r/a/b\">b</a>/" +
"<a href=\"/r/a\">..</a>/" +
"<a href=\"/r/a/c\">c</a>/" +
"/" +
"<a href=\"/r/a/c/d\">d</a>",
}
@Test
public void redableSize() {
assertEquals("<b>8,796,093,022,208M</b>",
}
@Test
public void readableLine() throws Exception {
assertEquals("\n<a class=\"l\" name=\"42\" href=\"#42\"> 42 </a>",
assertEquals("\n<a class=\"hl\" name=\"110\" href=\"#110\"> 110 </a>",
}
@Test
public void uid() {
assertEquals("\u0000etc\u0000passwd\u0000date",
}
@Test
public void uid2url() {
}
@Test
public void URIEncode() {
}
@Test
public void URIEncodePath() {
assertEquals("/a//x/yz/%23%23/%20/%20%3F",
}
@Test
public void formQuoteEscape() {
}
@Test
public void diffline() {
String[] strings=Util.diffline("\"(ses_id, mer_id, pass_id, \" + refCol +\" , mer_ref, amnt, cur, ps_id, ret_url, d_req_time, d_req_mil, h_resp_time, h_resp_mil) \"","\"(ses_id, mer_id, pass_id, \" + refCol +\" , mer_ref, amnt, cur, ps_id, ret_url, exp_url, d_req_time, d_req_mil, h_resp_time, h_resp_mil) \"");
assertEquals(strings[0],"\"(ses_id, mer_id, pass_id, \" + refCol +\" , mer_ref, amnt, cur, ps_id, ret_url, d_req_time, d_req_mil, h_resp_time, h_resp_mil) \"");
assertEquals(strings[1],"\"(ses_id, mer_id, pass_id, \" + refCol +\" , mer_ref, amnt, cur, ps_id, ret_url, <span class=\"a\">exp_url, </span>d_req_time, d_req_mil, h_resp_time, h_resp_mil) \"");
strings=Util.diffline("\"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\", values);","\"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\", values);");
assertEquals(strings[1],"\"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?<span class=\"a\">, ?</span>)\", values);");
strings=Util.diffline("* An error occured or there is non-numeric stuff at the end","* An error occurred or there is non-numeric stuff at the end");
assertEquals(strings[1],"* An error occur<span class=\"a\">r</span>ed or there is non-numeric stuff at the end");
}
@Test
public void dumpConfiguration() throws Exception {
// Verify that we got a table.
// Verify that the output is well-formed.
}
@Test
public void jsStringLiteral() {
assertEquals("\"abc\\n\\r\\\"\\\\\"",
}
}