diff options
| author | reger <reger18@arcor.de> | 2014-02-27 22:48:17 +0100 |
|---|---|---|
| committer | reger <reger18@arcor.de> | 2014-02-27 22:48:17 +0100 |
| commit | c8d437b69a3f4fb64988462dd5ddcb950b7562f4 (patch) | |
| tree | fb65c3f012e2c2d8853592c828bbad2ee067ce37 /test/net | |
| parent | d346520ed620d95a7c00c8c8b88be764b7b0990c (diff) | |
clean up test sources
rename to current package names and move to default location
Diffstat (limited to 'test/net')
7 files changed, 267 insertions, 13 deletions
diff --git a/test/net/yacy/cora/document/id/DigestURLTest.java b/test/net/yacy/cora/document/id/DigestURLTest.java index a5dc2dc94..059650bac 100644 --- a/test/net/yacy/cora/document/id/DigestURLTest.java +++ b/test/net/yacy/cora/document/id/DigestURLTest.java @@ -1,12 +1,12 @@ package net.yacy.cora.document.id; import java.net.MalformedURLException; - import junit.framework.TestCase; +import org.junit.Test; public class DigestURLTest extends TestCase { - + @Test public void testIdentPort() throws MalformedURLException { String[][] testStrings = new String[][]{ new String[]{"http://www.yacy.net:", "http://www.yacy.net/"}, diff --git a/test/net/yacy/cora/document/id/MultiProtocolURLTest.java b/test/net/yacy/cora/document/id/MultiProtocolURLTest.java index 09b50c4ac..af6f932fc 100644 --- a/test/net/yacy/cora/document/id/MultiProtocolURLTest.java +++ b/test/net/yacy/cora/document/id/MultiProtocolURLTest.java @@ -79,13 +79,16 @@ public class MultiProtocolURLTest { // valid IPv6 local loopback addresses testurls.put("http://[0:0:0:0:0:0:0:1]/index.html", Boolean.TRUE); testurls.put("http://[::1]/index.html", Boolean.TRUE); + testurls.put("http://[::1]:8090/index.html", Boolean.TRUE); + testurls.put("http://[0::1]/index.html", Boolean.TRUE); - // test urls for issue with IPv6 misinterpretation + // test urls for possible issue with IPv6 misinterpretation testurls.put("http://fcedit.com", Boolean.FALSE); testurls.put("http://fdedit.com", Boolean.FALSE); + testurls.put("http://fe8edit.com", Boolean.FALSE); // valid IPv6 examples taken from http://www.ietf.org/rfc/rfc2732.txt cap 2. - testurls.put("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html", Boolean.FALSE); + testurls.put("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html", Boolean.TRUE); // ip is link-local (fe80/10) testurls.put("http://[1080:0:0:0:8:800:200C:417A]/index.html", Boolean.FALSE); testurls.put("http://[3ffe:2a00:100:7031::1]", Boolean.FALSE); testurls.put("http://[1080::8:800:200C:417A]/foo", Boolean.FALSE); @@ -98,8 +101,8 @@ public class MultiProtocolURLTest { MultiProtocolURL uri = new MultiProtocolURL(u); boolean result = uri.isLocal(); - assertEquals(u, testurls.get(u), result); System.out.println ("testIsLocal: " + u + " -> " + result); + assertEquals(u, testurls.get(u), result); } } diff --git a/test/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnectorTest.java b/test/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnectorTest.java index 61bbec506..5f6c0b66f 100644 --- a/test/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnectorTest.java +++ b/test/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnectorTest.java @@ -44,20 +44,15 @@ public class EmbeddedSolrConnectorTest { * Test of query solr via jetty */ @Test - public void testQuery() { + public void testQuery() throws IOException { System.out.println("adding test document to solr"); SolrInputDocument doc = new SolrInputDocument(); doc.addField(CollectionSchema.id.name(), "ABCD0000abcd"); doc.addField(CollectionSchema.title.name(), "Lorem ipsum"); doc.addField(CollectionSchema.host_s.name(), "yacy.net"); doc.addField(CollectionSchema.text_t.name(), "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); - try { - solr.add(doc); - } catch (final IOException ex) { - fail("IOException adding test document to Solr"); - } catch (final SolrException ex) { - fail("SolrExceptin adding test document to Solr"); - } + + solr.add(doc); solr.commit(true); System.out.println("query solr"); diff --git a/test/net/yacy/cora/protocol/HeaderFrameworkTest.java b/test/net/yacy/cora/protocol/HeaderFrameworkTest.java new file mode 100644 index 000000000..792e67be8 --- /dev/null +++ b/test/net/yacy/cora/protocol/HeaderFrameworkTest.java @@ -0,0 +1,22 @@ +package net.yacy.cora.protocol; + +import java.util.Date; +import junit.framework.TestCase; +import org.junit.Test; + +public class HeaderFrameworkTest extends TestCase { + + /** + * Test of httpHeader date parsing routine + */ + @Test + public void testParseHTTPDate() { + Date parsedDate = HeaderFramework.parseHTTPDate("Tue, 08 Jul 2003 21:22:46 GMT"); + + // returned date must not be null + assertNotNull(parsedDate); + + // Print Result + System.out.println("testParseHTTPDate: " + parsedDate.toString()); + } +} diff --git a/test/net/yacy/document/ParserTest.java b/test/net/yacy/document/ParserTest.java new file mode 100644 index 000000000..6582edbfb --- /dev/null +++ b/test/net/yacy/document/ParserTest.java @@ -0,0 +1,155 @@ +package net.yacy.document; + +import static org.junit.Assert.assertThat; +import static org.junit.matchers.JUnitMatchers.containsString; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import net.yacy.cora.document.id.AnchorURL; +import net.yacy.document.parser.docParser; +import net.yacy.document.parser.odtParser; +import net.yacy.document.parser.ooxmlParser; +import net.yacy.document.parser.pdfParser; + +import org.junit.Test; + + +public class ParserTest { + + @Test public void testooxmlParsers() throws FileNotFoundException, Parser.Failure, MalformedURLException, UnsupportedEncodingException, IOException { + final String[][] testFiles = new String[][] { + // meaning: filename in test/parsertest, mimetype, title, creator, description, + new String[]{"umlaute_windows.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "In München steht ein Hofbräuhaus, dort gibt es Bier in Maßkrügen", "", ""}, + new String[]{"umlaute_windows.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "Folie 1", "", ""}, + }; + + for (final String[] testFile : testFiles) { + try { + final String filename = "test/parsertest/" + testFile[0]; + final File file = new File(filename); + final String mimetype = testFile[1]; + final AnchorURL url = new AnchorURL("http://localhost/"+filename); + + AbstractParser p = new ooxmlParser(); + final Document[] docs = p.parse(url, mimetype, null, new FileInputStream(file)); + for (final Document doc: docs) { + final Reader content = new InputStreamReader(doc.getTextStream(), doc.getCharset()); + final StringBuilder str = new StringBuilder(); + int c; + while( (c = content.read()) != -1 ) + str.append((char)c); + + System.out.println("Parsed " + filename + ": " + str); + assertThat(str.toString(), containsString("In München steht ein Hofbräuhaus, dort gibt es Bier in Maßkrügen")); + assertThat(doc.dc_title(), containsString(testFile[2])); + assertThat(doc.dc_creator(), containsString(testFile[3])); + assertThat(doc.dc_description()[0], containsString(testFile[4])); + } + } catch (final InterruptedException ex) {} + } + } + + @Test public void testodtParsers() throws FileNotFoundException, Parser.Failure, MalformedURLException, UnsupportedEncodingException, IOException { + final String[][] testFiles = new String[][] { + // meaning: filename in test/parsertest, mimetype, title, creator, description, + new String[]{"umlaute_linux.odt", "application/vnd.oasis.opendocument.text", "Münchner Hofbräuhaus", "", "Kommentar zum Hofbräuhaus"}, + new String[]{"umlaute_linux.ods", "application/vnd.oasis.opendocument.spreadsheat", "", "", ""}, + new String[]{"umlaute_linux.odp", "application/vnd.oasis.opendocument.presentation", "", "", ""}, + }; + + for (final String[] testFile : testFiles) { + try { + final String filename = "test/parsertest/" + testFile[0]; + final File file = new File(filename); + final String mimetype = testFile[1]; + final AnchorURL url = new AnchorURL("http://localhost/"+filename); + + AbstractParser p = new odtParser(); + final Document[] docs = p.parse(url, mimetype, null, new FileInputStream(file)); + for (final Document doc: docs) { + final Reader content = new InputStreamReader(doc.getTextStream(), doc.getCharset()); + final StringBuilder str = new StringBuilder(); + int c; + while( (c = content.read()) != -1 ) + str.append((char)c); + + System.out.println("Parsed " + filename + ": " + str); + assertThat(str.toString(), containsString("In München steht ein Hofbräuhaus, dort gibt es Bier in Maßkrügen")); + // assertThat(doc.dc_title(), containsString(testFile[2])); + assertThat(doc.dc_creator(), containsString(testFile[3])); + assertThat(doc.dc_description()[0], containsString(testFile[4])); + } + } catch (final InterruptedException ex) {} + } + } + + @Test public void testpdfParsers() throws FileNotFoundException, Parser.Failure, MalformedURLException, UnsupportedEncodingException, IOException { + final String[][] testFiles = new String[][] { + // meaning: filename in test/parsertest, mimetype, title, creator, description, + new String[]{"umlaute_linux.pdf", "application/pdf", "", "", ""}, + }; + + for (final String[] testFile : testFiles) { + try { + final String filename = "test/parsertest/" + testFile[0]; + final File file = new File(filename); + final String mimetype = testFile[1]; + final AnchorURL url = new AnchorURL("http://localhost/"+filename); + + AbstractParser p = new pdfParser(); + final Document[] docs = p.parse(url, mimetype, null, new FileInputStream(file)); + for (final Document doc: docs) { + final Reader content = new InputStreamReader(doc.getTextStream(), doc.getCharset()); + final StringBuilder str = new StringBuilder(); + int c; + while( (c = content.read()) != -1 ) + str.append((char)c); + + System.out.println("Parsed " + filename + ": " + str); + assertThat(str.toString(), containsString("In München steht ein Hofbräuhaus, dort gibt es Bier in Maßkrügen")); + assertThat(doc.dc_title(), containsString(testFile[2])); + assertThat(doc.dc_creator(), containsString(testFile[3])); + assertThat(doc.dc_description()[0], containsString(testFile[4])); + } + } catch (final InterruptedException ex) {} + } + } + + @Test public void testdocParsers() throws FileNotFoundException, Parser.Failure, MalformedURLException, UnsupportedEncodingException, IOException { + final String[][] testFiles = new String[][] { + // meaning: filename in test/parsertest, mimetype, title, creator, description, + new String[]{"umlaute_windows.doc", "application/msword", "", "", ""}, + }; + + for (final String[] testFile : testFiles) { + try { + final String filename = "test/parsertest/" + testFile[0]; + final File file = new File(filename); + final String mimetype = testFile[1]; + final AnchorURL url = new AnchorURL("http://localhost/"+filename); + + AbstractParser p = new docParser(); + final Document[] docs = p.parse(url, mimetype, null, new FileInputStream(file)); + for (final Document doc: docs) { + final Reader content = new InputStreamReader(doc.getTextStream(), doc.getCharset()); + final StringBuilder str = new StringBuilder(); + int c; + while( (c = content.read()) != -1 ) + str.append((char)c); + + System.out.println("Parsed " + filename + ": " + str); + assertThat(str.toString(), containsString("In München steht ein Hofbräuhaus, dort gibt es Bier in Maßkrügen")); + assertThat(doc.dc_title(), containsString(testFile[2])); + assertThat(doc.dc_creator(), containsString(testFile[3])); + assertThat(doc.dc_description()[0], containsString(testFile[4])); + } + } catch (final InterruptedException ex) {} + } + } + } diff --git a/test/net/yacy/document/parser/htmlParserTest.java b/test/net/yacy/document/parser/htmlParserTest.java new file mode 100644 index 000000000..f4f18ddaf --- /dev/null +++ b/test/net/yacy/document/parser/htmlParserTest.java @@ -0,0 +1,42 @@ +package net.yacy.document.parser; + +import java.nio.charset.Charset; +import junit.framework.TestCase; +import org.junit.Test; + +public class htmlParserTest extends TestCase { + + @Test + public void testGetRealCharsetEncoding() { + String[][] testStrings = new String[][] { + new String[]{null,null}, + new String[]{"windows1250","windows-1250"}, + new String[]{"windows_1250","windows-1250"}, + new String[]{"ISO-8859-1","ISO-8859-1"}, + new String[]{"ISO8859-1","ISO-8859-1"}, + new String[]{"ISO-88591","ISO-8859-1"}, + new String[]{"ISO88591","ISO-8859-1"}, + new String[]{"iso_8859_1","ISO-8859-1"}, + new String[]{"cp-1252","windows-1252"}, + new String[]{"gb_2312","gb2312"}, // was: x-EUC-CN + new String[]{"gb_2312-80","gb2312"}, // was: x-EUC-CN + new String[]{"UTF-8;","UTF-8"} + }; + + for (int i=0; i < testStrings.length; i++) { + // desired conversion result + String shouldBe = testStrings[i][1]; + shouldBe = shouldBe!=null ? shouldBe.toLowerCase() : null; + + // conversion result + String charset = htmlParser.patchCharsetEncoding(testStrings[i][0]); + + // test if equal + assertEquals(shouldBe, charset!=null ? charset.toLowerCase() : null); + System.out.println("testGetRealCharsetEncoding: " + (testStrings[i][0]!=null?testStrings[i][0]:"null") + " -> " + (charset!=null?charset:"null") + " | Supported: " + (charset!=null?Charset.isSupported(charset):false)); + + } + + } + +} diff --git a/test/net/yacy/peers/operation/yacyVersionTest.java b/test/net/yacy/peers/operation/yacyVersionTest.java new file mode 100644 index 000000000..8de1dfe11 --- /dev/null +++ b/test/net/yacy/peers/operation/yacyVersionTest.java @@ -0,0 +1,37 @@ +package net.yacy.peers.operation; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; + +public class yacyVersionTest extends TestCase { + + /** + * Test method for 'yacy.combinedVersionString2PrettyString(String)' + * @author Bost + */ + @Test + public void testCombinedVersionString2PrettyString() { + Assert.assertArrayEquals(new String[]{"dev","0000"}, yacyVersion.combined2prettyVersion("")); // not a number + Assert.assertArrayEquals(new String[]{"dev","0000"}, yacyVersion.combined2prettyVersion(" ")); // not a number + Assert.assertArrayEquals(new String[]{"dev","02417"}, yacyVersion.combined2prettyVersion("0.10002417")); + Assert.assertArrayEquals(new String[]{"dev","0244"}, yacyVersion.combined2prettyVersion("0.1000244")); + Assert.assertArrayEquals(new String[]{"dev","02417"}, yacyVersion.combined2prettyVersion("0.10002417")); + Assert.assertArrayEquals(new String[]{"dev","0000"}, yacyVersion.combined2prettyVersion("0.100024400")); // input is too long + Assert.assertArrayEquals(new String[]{"dev","0244"}, yacyVersion.combined2prettyVersion("0.1090244")); + Assert.assertArrayEquals(new String[]{"0.110","0244"}, yacyVersion.combined2prettyVersion("0.1100244")); + Assert.assertArrayEquals(new String[]{"0.111","0244"}, yacyVersion.combined2prettyVersion("0.1110244")); + Assert.assertArrayEquals(new String[]{"dev","0000"}, yacyVersion.combined2prettyVersion("0.0")); // input is valid - no warning generated + Assert.assertArrayEquals(new String[]{"dev","0000"}, yacyVersion.combined2prettyVersion(" 0.11102440")); // spaces are not allowed + Assert.assertArrayEquals(new String[]{"0.111","0000"}, yacyVersion.combined2prettyVersion("0.111")); // was (input is too short) + Assert.assertArrayEquals(new String[]{"dev","0000"}, yacyVersion.combined2prettyVersion("0.1112440\t\n")); // \t and \n are not allowed + Assert.assertArrayEquals(new String[]{"dev","0000"}, yacyVersion.combined2prettyVersion("124353432xxxx4546399999")); // not a number + too long + Assert.assertArrayEquals(new String[]{"dev","0000"}, yacyVersion.combined2prettyVersion("123456789x")); // not a number + Assert.assertArrayEquals(new String[]{"dev","0000"}, yacyVersion.combined2prettyVersion("9999999999")); // missing decimal point + Assert.assertArrayEquals(new String[]{"999.999","9990"}, yacyVersion.combined2prettyVersion("999.999999")); // was (floating point part must have 3 and SVN-Version 4 digits) + Assert.assertArrayEquals(new String[]{"0.999","99999"}, yacyVersion.combined2prettyVersion("0.99999999")); + Assert.assertArrayEquals(new String[]{"99999.004","56789"}, yacyVersion.combined2prettyVersion("99999.00456789")); + Assert.assertArrayEquals(new String[]{"dev","0000"}, yacyVersion.combined2prettyVersion("99999.003456789")); // input is too long + } + +} |
