Update tests for XML and HTML functions

This commit is contained in:
Owen Stephens 2018-11-21 15:59:15 +00:00
parent d144a5dccf
commit 58352e4e56
3 changed files with 15 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package com.google.refine.tests.expr.functions.html;
import org.jsoup.Jsoup;
import org.testng.annotations.Test;
import java.util.Properties;
@ -26,7 +27,7 @@ public class ParseHtmlTests extends RefineTest {
" <body>\n" +
" <h1>head1</h1>\n" +
" <div class=\"class1\">\n" +
" <p>para1</p>\n" +
" <p>para1 <strong>strong text</strong></p>\n" +
" <p>para2</p>\n" +
" </div>\n" +
" </body>\n" +
@ -74,6 +75,11 @@ public class ParseHtmlTests extends RefineTest {
public void testParseHtml() {
Assert.assertTrue(invoke("parseHtml") instanceof EvalError);
Assert.assertTrue(invoke("parseHtml","h") instanceof org.jsoup.nodes.Document);
Assert.assertTrue(invoke("select",Jsoup.parse(h),"p") instanceof org.jsoup.select.Elements);
Assert.assertTrue(invoke("innerHtml",Jsoup.parse(h).select("p").first()) instanceof String);
Assert.assertEquals(invoke("innerHtml",Jsoup.parse(h).select("p").first()),"para1 <strong>strong text</strong>");
Assert.assertEquals(invoke("htmlAttr",Jsoup.parse(h).select("div").first(),"class"),"class1");
Assert.assertEquals(invoke("ownText",Jsoup.parse(h).select("p").first()),"para1");
}
}

View File

@ -1,8 +1,8 @@
package com.google.refine.tests.expr.functions.html;
package com.google.refine.tests.expr.functions.xml;
import org.testng.annotations.Test;
import com.google.refine.expr.functions.html.OwnText;
import com.google.refine.expr.functions.xml.OwnText;
import com.google.refine.tests.util.TestUtils;
public class OwnTextTests {

View File

@ -1,5 +1,7 @@
package com.google.refine.tests.expr.functions.xml;
import org.jsoup.parser.Parser;
import org.jsoup.Jsoup;
import org.testng.annotations.Test;
import java.util.Properties;
@ -80,6 +82,10 @@ public class ParseXmlTests extends RefineTest {
public void testParseXml() {
Assert.assertTrue(invoke("parseXml") instanceof EvalError);
Assert.assertTrue(invoke("parseXml","x") instanceof org.jsoup.nodes.Document);
Assert.assertTrue(invoke("select",Jsoup.parse(x,"",Parser.xmlParser()),"foaf|Person") instanceof org.jsoup.select.Elements);
Assert.assertEquals(invoke("innerXml",Jsoup.parse(x,"",Parser.xmlParser()).select("foaf|Person").first()),"<foaf:name>\n John Doe\n</foaf:name>\n<head>\n head1\n</head>\n<head>\n head2\n</head>\n<BODY>\n body1\n</BODY>\n<foaf:homepage rdf:resource=\"http://www.example.com\" />");
Assert.assertEquals(invoke("xmlAttr",Jsoup.parse(x,"",Parser.xmlParser()).select("foaf|homepage").first(),"rdf:resource"),"http://www.example.com");
Assert.assertEquals(invoke("ownText",Jsoup.parse(x,"",Parser.xmlParser()).select("BODY").first()),"body1");
}
}