// Break the line at commas, return a map of the resulting strings // broken at equals sign. (<i>Ie</i>, name value pairs.) Map getRow(String line) { Map map = new HashMap(); for (Iterator iter = StringUtil.breakAt(line, ',').iterator(); iter.hasNext(); ) { String item = (String) iter.next(); List pair = StringUtil.breakAt(item, '='); map.put(pair.get(0), pair.get(1)); } return map; }
public void testFilterE() throws Exception { InputStream in; // all these should match, once filtered, the string HtmlHashEFiltered in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashE), ENC); String filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashEFiltered, filtStr); in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashF), ENC); filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashEFiltered, filtStr); in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashG), ENC); filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashEFiltered, filtStr); in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashH), ENC); filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashEFiltered, filtStr); in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashI), ENC); filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashEFiltered, filtStr); in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashJ), ENC); filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashEFiltered, filtStr); in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashK), ENC); filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashEFiltered, filtStr); in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashL), ENC); filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashEFiltered, filtStr); in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashO), ENC); filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashEFiltered, filtStr); }
public void testFilterViewedBy() throws Exception { InputStream in; String filtStr = null; in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashN), ENC); filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashNFiltered, filtStr); in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashP), ENC); filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashPFiltered, filtStr); }
public void testFilterD() throws Exception { InputStream in; in = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashD), ENC); String filtStr = StringUtil.fromInputStream(in); assertEquals(HtmlHashDFiltered, filtStr); }
public void testFilterB() throws Exception { InputStream inB; inB = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashB), ENC); String filtStrB = StringUtil.fromInputStream(inB); assertEquals(HtmlHashBFiltered, filtStrB); }
// Don't put the 2nd string through the filter - use it as a constant private void assertFilterToString(String orgString, String finalString) throws Exception { InputStream inA = fact.createFilteredInputStream( mau, new StringInputStream(orgString), Constants.DEFAULT_ENCODING); String filtered = StringUtil.fromInputStream(inA); assertEquals(filtered, finalString, filtered); }
private static void doFilterTest( ArchivalUnit au, FilterFactory fact, String nameToHash, String expectedStr) throws PluginException, IOException { InputStream actIn; actIn = fact.createFilteredInputStream( au, new StringInputStream(nameToHash), Constants.DEFAULT_ENCODING); assertEquals(expectedStr, StringUtil.fromInputStream(actIn)); }
protected void assertEqualTables(Object[][] a1, List lines) { assertEquals("numrows", a1.length, lines.size() - NUM_HEADER_LINES); for (int irow = 0; irow <= a1.length - 1; irow++) { Object expRow[] = a1[irow]; List row = StringUtil.breakAt((String) lines.get(irow + NUM_HEADER_LINES), ','); assertEquals("numcols", expRow.length, row.size()); assertEquals(("row " + irow), SetUtil.fromArray(expRow), new HashSet(row)); } }
public void testFilterA() throws Exception { InputStream inA; // viewed-by test inA = fact.createFilteredInputStream(mau, new StringInputStream(HtmlHashA), ENC); String filtStrA = StringUtil.fromInputStream(inA); assertEquals(HtmlHashAFiltered, filtStrA); }
protected void checkFilter(SimulatedArchivalUnit sau) throws Exception { log.debug("checkFilter()"); CachedUrl cu = sau.makeCachedUrl(sau.getUrlRoot() + "/001file.html"); enableFilter(sau, true); InputStream is = cu.openForHashing(); String expected = "001file.html This is file 1, depth 0, branch 0. foobar "; assertEquals(expected, StringUtil.fromInputStream(is)); is.close(); enableFilter(sau, false); cu = sau.makeCachedUrl(sau.getUrlRoot() + "/001file.html"); is = cu.openForHashing(); expected = "<HTML><HEAD><TITLE>001file.html</TITLE></HEAD><BODY>\n" + "This is file 1, depth 0, branch 0.<br><!-- comment --> " + "Citation String foobar<br><script>" + "(defun fact (n) (cond ((= n 0) 1) (t (fact (sub1 n)))))</script>\n" + "</BODY></HTML>"; assertEquals(expected, StringUtil.fromInputStream(is)); is.close(); }
public void testSimpleDatasetXML() throws Exception { log.debug3("testSimpleDatasetXML"); String file_input = StringUtil.fromInputStream(getResourceAsStream(testDatasetFile)); String xml_url = TAR_A_BASE + SUBDIR + "dataset.xml"; List<ArticleMetadata> mdList = extractFromContent(xml_url, "text/xml", file_input, nocheck_mle, null); assertEquals(6, mdList.size()); Iterator<ArticleMetadata> mdIt = mdList.iterator(); ArticleMetadata mdRecord = null; while (mdIt.hasNext()) { mdRecord = (ArticleMetadata) mdIt.next(); validateDatasetMetadataRecord(mdRecord); } }
/** * Test rewriting a link from the first argument of the window.open() call in an "onClick" * attribute on a paragraph tag. * * @throws Exception */ public void testJavaScriptFunctionOpenLinkRewriting() throws Exception { MockArchivalUnit mockAu = makeAu(); InputStream in = new ByteArrayInputStream(testOnClickLinkInput.getBytes()); ServletUtil.LinkTransform xfm = new ServletUtil.LinkTransform() { public String rewrite(String url) { return "http://www.foobar.org/ServeContent?url=" + url; } }; InputStream newIn = fact.createLinkRewriter( "text/html", mockAu, in, "UTF-8", "http://www.xyz.com/path/path1", xfm); String fout = StringUtil.fromReader(new InputStreamReader(newIn, "UTF-8")); assertEquals(testOnClickLinkOutput, fout); }
public void testFiltering() throws Exception { InputStream inA; InputStream inB; /* impactFactor test */ inA = fact.createFilteredInputStream(mau, new StringInputStream(tagsHtmlHash), ENC); assertEquals(tagsHtmlHashFiltered, StringUtil.fromInputStream(inA)); /* whiteSpace test */ inA = fact.createFilteredInputStream(mau, new StringInputStream(WhiteSpace1), ENC); inB = fact.createFilteredInputStream(mau, new StringInputStream(WhiteSpace2), ENC); assertEquals(StringUtil.fromInputStream(inA), StringUtil.fromInputStream(inB)); /* rightCol test */ inA = fact.createFilteredInputStream(mau, new StringInputStream(rightColHtml), ENC); assertEquals(rightColHtmlFiltered, StringUtil.fromInputStream(inA)); /* mathjax text */ inA = fact.createFilteredInputStream(mau, new StringInputStream(mathJaxHtml), ENC); assertEquals(mathJaxHtmlFiltered, StringUtil.fromInputStream(inA)); // header & footer test inA = fact.createFilteredInputStream(mau, new StringInputStream(hrtagsHtmlHash), ENC); assertEquals(hrtagsHtmlHashFiltered, StringUtil.fromInputStream(inA)); // metrics test inA = fact.createFilteredInputStream(mau, new StringInputStream(metricsHtml), ENC); assertEquals(metricsHtmlFiltered, StringUtil.fromInputStream(inA)); // misc test inA = fact.createFilteredInputStream(mau, new StringInputStream(miscHtml), ENC); assertEquals(miscHtmlFiltered, StringUtil.fromInputStream(inA)); }
public void testCreateSharedPLNKeyStores() throws Exception { List<String> hosts = ListUtil.list("host1", "host2.foo.bar", "host3"); List<String> hosts2 = ListUtil.list("host3", "host4"); File dir = getTempDir(); File pub = new File(dir, "pub.ks"); KeyStoreUtil.createSharedPLNKeyStores( dir, hosts, pub, "pubpass", MiscTestUtil.getSecureRandom()); assertPubKs(pub, "pubpass", hosts); for (String host : hosts) { assertPrivateKs( new File(dir, host + ".jceks"), StringUtil.fromFile(new File(dir, host + ".pass")), host); } KeyStore pubks1 = loadKeyStore("jceks", new File(dir, "pub.ks"), "pubpass"); Certificate host1cert1 = pubks1.getCertificate("host1.crt"); Certificate host3cert1 = pubks1.getCertificate("host3.crt"); String host1priv1 = StringUtil.fromFile(new File(dir, "host1.jceks")); String host3priv1 = StringUtil.fromFile(new File(dir, "host3.jceks")); // Now add host4 and generate a new key for host3 KeyStoreUtil.createSharedPLNKeyStores( dir, hosts2, pub, "pubpass", MiscTestUtil.getSecureRandom()); List<String> both = ListUtils.sum(hosts, hosts2); assertPubKs(pub, "pubpass", both); for (String host : both) { assertPrivateKs( new File(dir, host + ".jceks"), StringUtil.fromFile(new File(dir, host + ".pass")), host); } KeyStore pubks2 = loadKeyStore("jceks", new File(dir, "pub.ks"), "pubpass"); // host1 should have the same cert, host3 not Certificate host1cert2 = pubks2.getCertificate("host1.crt"); Certificate host3cert2 = pubks2.getCertificate("host3.crt"); assertEquals(host1cert1, host1cert2); assertNotEquals(host3cert1, host3cert2); // host1's private key file should be the same, host3's not String host1priv2 = StringUtil.fromFile(new File(dir, "host1.jceks")); String host3priv2 = StringUtil.fromFile(new File(dir, "host3.jceks")); assertEquals(host1priv1, host1priv2); assertNotEquals(host3priv1, host3priv2); }
// Tests that don't need a servlet environment public void testConvertDisplayString() throws Exception { // test null Object testObj = null; assertEquals("", format(testObj, ColumnDescriptor.TYPE_STRING)); // test standard numbers testObj = new Integer(123); assertEquals("123", format(testObj, ColumnDescriptor.TYPE_INT)); testObj = new Float(123321); assertEquals(testObj.toString(), format(testObj, ColumnDescriptor.TYPE_FLOAT)); // check proper 'big int' formatting testObj = new Long(12345678); assertEquals("12,345,678", format(testObj, ColumnDescriptor.TYPE_INT)); // test string testObj = "test string"; assertEquals("test string", format(testObj, ColumnDescriptor.TYPE_STRING)); // Issue 1901: verify that there is no encoding bias testObj = "<>&'\"\n"; String res = format(testObj, ColumnDescriptor.TYPE_STRING); assertEquals( "Expected \"" + StringEscapeUtils.escapeJava(testObj.toString()) + "\" but got \"" + StringEscapeUtils.escapeJava(res) + "\"; encoding bias?", "<>&'\"\n", res); // test percentage testObj = new Double(.453); assertEquals("45%", format(testObj, ColumnDescriptor.TYPE_PERCENT)); // test agreement testObj = new Double(.453); assertEquals("45.30%", format(testObj, ColumnDescriptor.TYPE_AGREEMENT)); testObj = new Double(.999999); assertEquals("99.99%", format(testObj, ColumnDescriptor.TYPE_AGREEMENT)); // test date Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DATE, 1); cal.set(Calendar.HOUR_OF_DAY, 15); cal.set(Calendar.MINUTE, 15); testObj = cal.getTime(); assertEquals( new DisplayConverter().getTableDateFormat().format(testObj), format(testObj, ColumnDescriptor.TYPE_DATE)); // test IPAddr testObj = IPAddr.getLocalHost(); assertEquals( IPAddr.getLocalHost().getHostAddress(), format(testObj, ColumnDescriptor.TYPE_IP_ADDRESS)); // test time interval long timeInt = Constants.HOUR + Constants.MINUTE; testObj = new Long(timeInt); assertEquals( StringUtil.timeIntervalToString(timeInt), format(testObj, ColumnDescriptor.TYPE_TIME_INTERVAL)); // test unknown testObj = "unknown string"; assertEquals("unknown string", format(testObj, -1)); }
// Return the serialized representation of the object String ser(LockssSerializable o) throws Exception { File tf = getTempFile("ser", ".xml"); new XStreamSerializer().serialize(tf, o); return StringUtil.fromFile(tf); }