Add intial tests for XML parsing
This commit is contained in:
parent
b5355b3c12
commit
e38dcdf7a7
@ -0,0 +1,15 @@
|
||||
package com.google.refine.tests.expr.functions.xml;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.expr.functions.xml.InnerXml;
|
||||
import com.google.refine.tests.util.TestUtils;
|
||||
|
||||
public class InnerXmlTests {
|
||||
@Test
|
||||
public void serializeInnerXml() {
|
||||
String json = "{\"description\":\"The innerXml/innerHtml of an XML/HTML element\",\"params\":\"Element e\",\"returns\":\"String innerXml/innerHtml\"}";
|
||||
TestUtils.isSerializedTo(new InnerXml(), json);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.google.refine.tests.expr.functions.html;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.expr.functions.html.OwnText;
|
||||
import com.google.refine.tests.util.TestUtils;
|
||||
|
||||
public class OwnTextTests {
|
||||
@Test
|
||||
public void serializeOwnText() {
|
||||
String json = "{\"description\":\"Gets the text owned by this XML/HTML element only; does not get the combined text of all children.\",\"params\":\"Element e\",\"returns\":\"String ownText\"}";
|
||||
TestUtils.isSerializedTo(new OwnText(), json);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
package com.google.refine.tests.expr.functions.xml;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
||||
import com.google.refine.expr.EvalError;
|
||||
import com.google.refine.expr.functions.xml.ParseXml;
|
||||
import com.google.refine.grel.ControlFunctionRegistry;
|
||||
import com.google.refine.grel.Function;
|
||||
import com.google.refine.tests.RefineTest;
|
||||
import com.google.refine.tests.util.TestUtils;
|
||||
|
||||
|
||||
public class ParseXmlTests extends RefineTest {
|
||||
|
||||
static Properties bindings;
|
||||
static String x = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<root xmlns:foaf=\"http://xmlns.com/foaf/0.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" +
|
||||
" <foaf:Person>\n" +
|
||||
" <foaf:name>John Doe</foaf:name>\n" +
|
||||
" <head>head1</head>\n" +
|
||||
" <head>head2</head>\n" +
|
||||
" <BODY>body1</BODY>\n" +
|
||||
" <foaf:homepage rdf:resource=\"http://www.example.com\"/>\n" +
|
||||
" </foaf:Person>\n" +
|
||||
" <foaf:Person>\n" +
|
||||
" <foaf:name>Héloïse Dupont</foaf:name>\n" +
|
||||
" <head>head3</head>\n" +
|
||||
" <BODY>body2</BODY>\n" +
|
||||
" <foaf:title/>\n" +
|
||||
" </foaf:Person>\n" +
|
||||
"</root>";
|
||||
|
||||
@Override
|
||||
@BeforeTest
|
||||
public void init() {
|
||||
logger = LoggerFactory.getLogger(this.getClass());
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void SetUp() {
|
||||
bindings = new Properties();
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
public void TearDown() {
|
||||
bindings = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a control function by name and invoke it with a variable number of args
|
||||
*/
|
||||
private static Object invoke(String name,Object... args) {
|
||||
// registry uses static initializer, so no need to set it up
|
||||
Function function = ControlFunctionRegistry.getFunction(name);
|
||||
if (function == null) {
|
||||
throw new IllegalArgumentException("Unknown function "+name);
|
||||
}
|
||||
if (args == null) {
|
||||
return function.call(bindings,new Object[0]);
|
||||
} else {
|
||||
return function.call(bindings,args);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeParseXml() {
|
||||
String json = "{\"description\":\"Parses a string as XML\",\"params\":\"string s\",\"returns\":\"XML object\"}";
|
||||
TestUtils.isSerializedTo(new ParseXml(), json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseXml() {
|
||||
Assert.assertTrue(invoke("parseXml") instanceof EvalError);
|
||||
Assert.assertTrue(invoke("parseXml","x") instanceof org.jsoup.nodes.Document);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.google.refine.tests.expr.functions.xml;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.expr.functions.xml.SelectXml;
|
||||
import com.google.refine.tests.util.TestUtils;
|
||||
|
||||
public class SelectXmlTests {
|
||||
@Test
|
||||
public void serializeSelectXml() {
|
||||
String json = "{\"description\":\"Selects an element from an XML or HTML element using selector syntax.\",\"params\":\"Element e, String s\",\"returns\":\"XML/HTML Elements\"}";
|
||||
TestUtils.isSerializedTo(new SelectXml(), json);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.google.refine.tests.expr.functions.xml;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.expr.functions.xml.XmlAttr;
|
||||
import com.google.refine.tests.util.TestUtils;
|
||||
|
||||
public class xmlAttrTests {
|
||||
@Test
|
||||
public void serializeXmlAttr() {
|
||||
String json = "{\"description\":\"Selects a value from an attribute on an xml or html Element.\",\"params\":\"Element e, String s\",\"returns\":\"String attribute Value\"}";
|
||||
TestUtils.isSerializedTo(new XmlAttr(), json);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.google.refine.tests.expr.functions.xml;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.expr.functions.xml.XmlText;
|
||||
import com.google.refine.tests.util.TestUtils;
|
||||
|
||||
public class xmlTextTests {
|
||||
@Test
|
||||
public void serializeXmlText() {
|
||||
String json = "{\"description\":\"Selects the text from within an element (including all child elements)\",\"params\":\"Element e\",\"returns\":\"String text\"}";
|
||||
TestUtils.isSerializedTo(new XmlText(), json);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user