Author: lindner
Date: Wed Feb 25 02:00:37 2009
New Revision: 747642
URL: http://svn.apache.org/viewvc?rev=747642&view=rev
Log:
SHINDIG-941 | Add xmlns attributes to tags per the XSD
- add xmlunit library to help ease xml testing
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanXStreamConverter.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlActivityTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlDataTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlPeopleTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamConverterTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/XSDValidator.java
incubator/shindig/trunk/java/social-api/src/test/resources/org/apache/shindig/social/opensocial/util/opensocial.xsd
incubator/shindig/trunk/pom.xml
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanXStreamConverter.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanXStreamConverter.java?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
---
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanXStreamConverter.java
(original)
+++
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanXStreamConverter.java
Wed Feb 25 02:00:37 2009
@@ -105,7 +105,7 @@
cc.mapper.setBaseObject(s); // thread safe method
String result = cc.xstream.toXML(s);
log.debug("Result is " + result);
- return "<response>" + result + "</response>";
+ return XML_DECL + "<response
xmlns=\"http://ns.opensocial.org/2008/opensocial\">" + result + "</response>";
}
} else if (obj instanceof RestfulCollection) {
XStreamConfiguration.ConverterConfig cc = converterMap
@@ -113,14 +113,14 @@
cc.mapper.setBaseObject(obj); // thread safe method
String result = cc.xstream.toXML(obj);
log.debug("Result is " + result);
- return result;
+ return XML_DECL + result;
} else if (obj instanceof DataCollection) {
XStreamConfiguration.ConverterConfig cc = converterMap
.get(XStreamConfiguration.ConverterSet.MAP);
cc.mapper.setBaseObject(obj); // thread safe method
String result = cc.xstream.toXML(obj);
log.debug("Result is " + result);
- return result;
+ return XML_DECL + result;
}
XStreamConfiguration.ConverterConfig cc = converterMap
.get(XStreamConfiguration.ConverterSet.DEFAULT);
@@ -128,7 +128,7 @@
cc.mapper.setBaseObject(obj); // thread safe method
String result = cc.xstream.toXML(obj);
log.debug("Result is " + result);
- return "<response>" + result + "</response>";
+ return XML_DECL + "<response
xmlns=\"http://ns.opensocial.org/2008/opensocial\">" + result + "</response>";
}
@SuppressWarnings("unchecked")
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java
Wed Feb 25 02:00:37 2009
@@ -129,10 +129,10 @@
atom.addPrefixedElement("itemsPerPage", "osearch:itemsPerPage");
NamespaceSet os = new NamespaceSet();
- atom.addNamespace("xmlns", OS_NS);
+ os.addNamespace("xmlns", OS_NS);
- return ImmutableMap.<String, NamespaceSet>builder().
- put("feed", atom)
+ return ImmutableMap.<String, NamespaceSet>builder()
+ .put("feed", atom)
.put("person", os)
.put("activity", os)
.put("account", os)
@@ -142,9 +142,9 @@
.put("mediaItem", os)
.put("name", os)
.put("url", os)
- .put("reponse", os)
- .put("appdata", os).
- build();
+ .put("response", os)
+ .put("appdata", os)
+ .build();
}
static {
@@ -283,7 +283,7 @@
this.injector = injector;
}
- private Multimap<String, Class<?>> getOmitMap(ConverterSet c) {
+ private static Multimap<String, Class<?>> getOmitMap(ConverterSet c) {
return Objects.firstNonNull(omitMap.get(c),
omitMap.get(ConverterSet.DEFAULT));
}
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java
Wed Feb 25 02:00:37 2009
@@ -31,12 +31,17 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import com.google.common.collect.ImmutableMap;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.easymock.EasyMock;
import org.json.JSONObject;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.custommonkey.xmlunit.NamespaceContext;
+import org.custommonkey.xmlunit.SimpleNamespaceContext;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.custommonkey.xmlunit.XpathEngine;
import javax.servlet.http.HttpServletResponse;
import javax.xml.stream.XMLInputFactory;
@@ -50,11 +55,10 @@
import java.util.Map;
public abstract class AbstractLargeRestfulTests extends EasyMockTestCase {
- protected static final String XMLSCHEMA = "
xmlns=\"http://ns.opensocial.org/2008/opensocial\" \n"
- + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
+ protected static final String XMLSCHEMA = "
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
+ " xsi:schemaLocation=\"http://ns.opensocial.org/2008/opensocial
classpath:opensocial.xsd\" ";
protected static final String XSDRESOURCE = "opensocial.xsd";
-
+ protected XpathEngine xp;
private HttpServletResponse res;
private DataServiceServlet servlet;
@@ -65,6 +69,7 @@
protected HttpServletResponse getResponse() {
return res;
}
+
protected void setResponse(HttpServletResponse res) {
this.res = res;
}
@@ -89,6 +94,9 @@
new BeanXStreamAtomConverter(new XStream081Configuration(injector)));
res = EasyMock.createMock(HttpServletResponse.class);
+ NamespaceContext ns = new SimpleNamespaceContext(ImmutableMap.of("",
"http://ns.opensocial.org/2008/opensocial"));
+ XMLUnit.setXpathNamespaceContext(ns);
+ xp = XMLUnit.newXpathEngine();
}
protected String getResponse(String path, String method, String format,
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlActivityTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlActivityTest.java?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlActivityTest.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlActivityTest.java
Wed Feb 25 02:00:37 2009
@@ -24,23 +24,16 @@
import org.junit.Test;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
+import org.custommonkey.xmlunit.XMLUnit;
-import java.io.StringReader;
import java.util.List;
import java.util.Map;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathFactory;
-
public class RestfulXmlActivityTest extends AbstractLargeRestfulTests {
- private static final String XMLSCHEMA = "
xmlns=\"http://ns.opensocial.org/2008/opensocial\" \n"
- + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
+ private static final String XMLSCHEMA = "
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
+ " xsi:schemaLocation=\"http://ns.opensocial.org/2008/opensocial
classpath:opensocial.xsd\" ";
private static final String XSDRESOURCE = "opensocial.xsd";
private Activity johnsActivity;
- private XPathFactory xpathFactory;
@Override
protected void setUp() throws Exception {
@@ -48,9 +41,6 @@
johnsActivity = new ActivityImpl("1", "john.doe");
johnsActivity.setTitle("yellow");
johnsActivity.setBody("what a color!");
-
- xpathFactory = XPathFactory.newInstance();
-
}
/**
@@ -75,12 +65,10 @@
String resp = getResponse("/activities/john.doe/@self/@app/1", "GET",
"xml", "application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- InputSource source = new InputSource(new StringReader(resp));
- XPath xp = xpathFactory.newXPath();
- NodeList result = (NodeList) xp.evaluate("/response/activity", source,
- XPathConstants.NODESET);
+
+ NodeList result = xp.getMatchingNodes("/:response/:activity",
XMLUnit.buildTestDocument(resp));
assertEquals(1, result.getLength());
Node n = result.item(0);
@@ -134,15 +122,13 @@
public void testGetActivitiesJson() throws Exception {
String resp = getResponse("/activities/john.doe/@self", "GET", "xml",
"application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- XPath xp = xpathFactory.newXPath();
- assertEquals("0", xp.evaluate("/response/startIndex", new InputSource(
- new StringReader(resp))));
- assertEquals("1", xp.evaluate("/response/totalResults", new InputSource(
- new StringReader(resp))));
- NodeList nl = (NodeList) xp.evaluate("/response/entry/activity",
- new InputSource(new StringReader(resp)), XPathConstants.NODESET);
+
+ assertEquals("0", xp.evaluate("/:response/:startIndex",
XMLUnit.buildTestDocument(resp)));
+ assertEquals("1", xp.evaluate("/:response/:totalResults",
XMLUnit.buildTestDocument(resp)));
+ NodeList nl = xp.getMatchingNodes("/:response/:entry/:activity",
XMLUnit.buildTestDocument(resp));
+
assertEquals(1, nl.getLength());
assertActivitiesEqual(johnsActivity, childNodesToMap(nl.item(0)));
@@ -196,17 +182,13 @@
String resp = getResponse("/activities/john.doe/@friends", "GET", "xml",
"application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- XPath xp = xpathFactory.newXPath();
- assertEquals("0", xp.evaluate("/response/startIndex", new InputSource(
- new StringReader(resp))));
- assertEquals("2", xp.evaluate("/response/totalResults", new InputSource(
- new StringReader(resp))));
- NodeList nl = (NodeList) xp.evaluate("/response/entry", new InputSource(
- new StringReader(resp)), XPathConstants.NODESET);
- assertEquals(2, nl.getLength());
+ assertEquals("0", xp.evaluate("/:response/:startIndex",
XMLUnit.buildTestDocument(resp)));
+ assertEquals("2", xp.evaluate("/:response/:totalResults",
XMLUnit.buildTestDocument(resp)));
+ NodeList nl = xp.getMatchingNodes("/:response/:entry",
XMLUnit.buildTestDocument(resp));
+ assertEquals(2, nl.getLength());
}
private void assertActivitiesEqual(Activity activity,
@@ -223,21 +205,18 @@
String createResponse = getResponse("/activities/john.doe/@self", "POST",
postData, "xml", "application/xml");
- XSDValidator.validate(createResponse, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(createResponse);
String resp = getResponse("/activities/john.doe/@self", "GET", "xml",
"application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- XPath xp = xpathFactory.newXPath();
- assertEquals("0", xp.evaluate("/response/startIndex", new InputSource(
- new StringReader(resp))));
- assertEquals("2", xp.evaluate("/response/totalResults", new InputSource(
- new StringReader(resp))));
- NodeList nl = (NodeList) xp.evaluate("/response/entry/activity", new
InputSource(
- new StringReader(resp)), XPathConstants.NODESET);
+ assertEquals("0", xp.evaluate("/:response/:startIndex",
XMLUnit.buildTestDocument(resp)));
+ assertEquals("2", xp.evaluate("/:response/:totalResults",
XMLUnit.buildTestDocument(resp)));
+ NodeList nl = xp.getMatchingNodes("/:response/:entry/:activity",
XMLUnit.buildTestDocument(resp));
+
assertEquals(2, nl.getLength());
Map<String, List<String>> v = childNodesToMap(nl.item(0));
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlDataTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlDataTest.java?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlDataTest.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlDataTest.java
Wed Feb 25 02:00:37 2009
@@ -18,12 +18,18 @@
package org.apache.shindig.social.dataservice.integration;
import com.google.common.collect.Maps;
+import com.google.common.collect.ImmutableMap;
import org.apache.shindig.social.opensocial.util.XSDValidator;
import org.junit.Test;
import org.w3c.dom.NodeList;
+import org.w3c.dom.Document;
import org.xml.sax.InputSource;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.custommonkey.xmlunit.NamespaceContext;
+import org.custommonkey.xmlunit.SimpleNamespaceContext;
+import org.custommonkey.xmlunit.XpathEngine;
import java.io.StringReader;
import java.util.List;
@@ -35,13 +41,9 @@
public class RestfulXmlDataTest extends AbstractLargeRestfulTests {
- private XPathFactory xpathFactory;
-
@Override
protected void setUp() throws Exception {
super.setUp();
- xpathFactory = XPathFactory.newInstance();
-
}
/**
@@ -60,16 +62,15 @@
@Test
public void testGetFriendsAppDataJson() throws Exception {
// app id is mocked out
- Map<String, String> extraParams = Maps.newHashMap();
- extraParams.put("fields", "count");
+ Map<String, String> extraParams = ImmutableMap.of("fields", "count");
String resp = getResponse("/appdata/john.doe/@friends/app", "GET",
extraParams, "xml", "application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
-
- XPath xp = xpathFactory.newXPath();
- NodeList result = (NodeList) xp.evaluate("/appdata/entry", new InputSource(
- new StringReader(resp)), XPathConstants.NODESET);
+ XSDValidator.validateOpenSocial(resp);
+
+ // /*[local-name()="TestSchema" and
namespace-uri()='http://MapTest.TestSchema']/*[local-name()="A"]
+
+ NodeList result = xp.getMatchingNodes("/:appdata/:entry",
XMLUnit.buildTestDocument(resp));
assertEquals(3, result.getLength());
Map<String, Map<String, List<String>>> v = childNodesToMapofMap(result);
@@ -78,7 +79,7 @@
assertTrue(v.containsKey("jane.doe"));
assertTrue(v.containsKey("george.doe"));
assertTrue(v.containsKey("maija.m"));
-
+
assertEquals(1, v.get("jane.doe").size());
assertEquals(1, v.get("george.doe").size());
assertEquals(0, v.get("maija.m").size());
@@ -104,11 +105,9 @@
String resp = getResponse("/appdata/john.doe/@self/app", "GET",
extraParams, "xml", "application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- XPath xp = xpathFactory.newXPath();
- NodeList result = (NodeList) xp.evaluate("/appdata/entry", new InputSource(
- new StringReader(resp)), XPathConstants.NODESET);
+ NodeList result = xp.getMatchingNodes("/:appdata/:entry",
XMLUnit.buildTestDocument(resp));
Map<String, Map<String, List<String>>> v = childNodesToMapofMap(result);
@@ -137,11 +136,9 @@
String resp = getResponse("/appdata/john.doe/@self/app", "GET",
extraParams, "xml", "application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- XPath xp = xpathFactory.newXPath();
- NodeList result = (NodeList) xp.evaluate("/appdata/entry", new InputSource(
- new StringReader(resp)), XPathConstants.NODESET);
+ NodeList result = xp.getMatchingNodes("/:appdata/:entry",
XMLUnit.buildTestDocument(resp));
Map<String, Map<String, List<String>>> v = childNodesToMapofMap(result);
@@ -170,11 +167,9 @@
String resp = getResponse("/appdata/john.doe/@self/app", "GET",
extraParams, "xml", "application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- XPath xp = xpathFactory.newXPath();
- NodeList result = (NodeList) xp.evaluate("/appdata/entry", new InputSource(
- new StringReader(resp)), XPathConstants.NODESET);
+ NodeList result = xp.getMatchingNodes("/:appdata/:entry",
XMLUnit.buildTestDocument(resp));
Map<String, Map<String, List<String>>> v = childNodesToMapofMap(result);
@@ -194,7 +189,7 @@
String resp = getResponse("/appdata/john.doe/@self/app", "DELETE",
extraParams, "xml",
"application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
assertCount("0");
@@ -203,7 +198,7 @@
getResponse("/appdata/john.doe/@self/app", "DELETE", extraParams, "xml",
"application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
assertCount(null);
}
@@ -215,11 +210,11 @@
Map<String, String> extraParams = Maps.newHashMap();
extraParams.put("fields", "count");
// should be xml ?
- String postData =
XSDValidator.XMLDEC+"<map><entry><key>count</key><value>5</value></entry></map>";
+ String postData = XSDValidator.XMLDEC +
"<map><entry><key>count</key><value>5</value></entry></map>";
String resp = getResponse("/appdata/john.doe/@self/app", "POST",
extraParams, postData,
"xml", "application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
assertCount("5");
@@ -229,12 +224,9 @@
String resp = getResponse("/appdata/john.doe/@self/app", "GET", "xml",
"application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
-
+ XSDValidator.validateOpenSocial(resp);
- XPath xp = xpathFactory.newXPath();
- NodeList result = (NodeList) xp.evaluate("/appdata/entry", new InputSource(
- new StringReader(resp)), XPathConstants.NODESET);
+ NodeList result = xp.getMatchingNodes("/:appdata/:entry",
XMLUnit.buildTestDocument(resp));
Map<String, Map<String, List<String>>> v = childNodesToMapofMap(result);
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlPeopleTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlPeopleTest.java?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlPeopleTest.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlPeopleTest.java
Wed Feb 25 02:00:37 2009
@@ -44,25 +44,19 @@
import org.junit.Test;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
+import org.custommonkey.xmlunit.XMLUnit;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathFactory;
-import java.io.StringReader;
import java.util.Date;
import java.util.List;
import java.util.Map;
public class RestfulXmlPeopleTest extends AbstractLargeRestfulTests {
private Person canonical;
- private XPathFactory xpathFactory;
@SuppressWarnings({ "boxing", "unchecked" })
@Override
protected void setUp() throws Exception {
super.setUp();
- xpathFactory = XPathFactory.newInstance();
NameImpl name = new NameImpl("Sir Shin H. Digg Social Butterfly");
name.setAdditionalName("H");
@@ -225,21 +219,19 @@
// TODO(doll): Test all of the date fields
Map<String, String> extraParams = Maps.newHashMap();
- String allFieldsParam = "";
+ StringBuilder allFieldsParam = new StringBuilder();
for (String allField : Person.Field.ALL_FIELDS) {
- allFieldsParam += allField + ',';
+ allFieldsParam.append(allField).append(',');
}
- extraParams.put("fields", allFieldsParam);
+ extraParams.put("fields", allFieldsParam.toString());
// Currently, for Shindig {pid}/@all/{uid} == {uid}/@self
String resp = getResponse("/people/canonical/@self", "GET", extraParams,
"xml", "application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- XPath xp = xpathFactory.newXPath();
- NodeList resultNodeList = (NodeList) xp.evaluate("/response/person",
- new InputSource(new StringReader(resp)), XPathConstants.NODESET);
+ NodeList resultNodeList = xp.getMatchingNodes("/:response/:person",
XMLUnit.buildTestDocument(resp));
assertEquals(1, resultNodeList.getLength());
Node personNode = resultNodeList.item(0);
@@ -446,7 +438,7 @@
private void assertStringField(Map<String, List<String>> result,
String expected, Object field) {
List<String> v = result.get(field.toString());
- String t = null;
+ String t;
if ( v == null || v.isEmpty()) {
if (expected == null ) {
return;
@@ -511,11 +503,9 @@
String resp = getResponse("/people/john.doe/@friends", "GET", extraParams,
"xml", "application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- XPath xp = xpathFactory.newXPath();
- NodeList resultNodeList = (NodeList) xp.evaluate("/response",
- new InputSource(new StringReader(resp)), XPathConstants.NODESET);
+ NodeList resultNodeList = xp.getMatchingNodes("/:response",
XMLUnit.buildTestDocument(resp));
assertEquals(1, resultNodeList.getLength());
Map<String, List<String>> result = childNodesToMap(resultNodeList.item(0));
@@ -549,11 +539,9 @@
String resp = getResponse("/people/john.doe/@friends", "GET", extraParams,
"xml", "application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- XPath xp = xpathFactory.newXPath();
- NodeList resultNodeList = (NodeList) xp.evaluate("/response",
- new InputSource(new StringReader(resp)), XPathConstants.NODESET);
+ NodeList resultNodeList = xp.getMatchingNodes("/:response",
XMLUnit.buildTestDocument(resp));
assertEquals(1, resultNodeList.getLength());
Map<String, List<String>> result = childNodesToMap(resultNodeList.item(0));
@@ -573,11 +561,9 @@
resp = getResponse("/people/john.doe/@friends", "GET", extraParams, "xml",
"application/xml");
- XSDValidator.validate(resp, XMLSCHEMA, XSDRESOURCE,false);
+ XSDValidator.validateOpenSocial(resp);
- xp = xpathFactory.newXPath();
- resultNodeList = (NodeList) xp.evaluate("/response", new InputSource(
- new StringReader(resp)), XPathConstants.NODESET);
+ resultNodeList = xp.getMatchingNodes("/:response",
XMLUnit.buildTestDocument(resp));
assertEquals(1, resultNodeList.getLength());
result = childNodesToMap(resultNodeList.item(0));
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
Wed Feb 25 02:00:37 2009
@@ -143,7 +143,7 @@
XmlUtil.parse(xml);
- String expectedXml = " <feed
xmlns=\"http://ns.opensocial.org/2008/opensocial\"
xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\" > "
+ String expectedXml = "<feed xmlns=\"http://www.w3.org/2005/Atom\"
xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\" > "
+ " <entry><id>item1</id>"
+ " <content type=\"application/xml\"
><entry><key>value</key><value>1</value></entry></content>"
+ " </entry> "
@@ -163,7 +163,7 @@
m.put("key2", "value2");
String xml = beanXmlConverter.convertToString(m);
XmlUtil.parse(xml);
- String expectedXml = "<feed
xmlns=\"http://ns.opensocial.org/2008/opensocial\" "
+ String expectedXml = "<feed xmlns=\"http://www.w3.org/2005/Atom\" "
+ " xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\">"
+ " <entry><id>key1</id><content type=\"application/xml\" >"
+ " <value>value1</value></content>"
@@ -183,7 +183,7 @@
List<String> empty = Lists.newArrayList();
String xml = beanXmlConverter.convertToString(empty);
XmlUtil.parse(xml);
- String expectedXml = "<feed
xmlns=\"http://ns.opensocial.org/2008/opensocial\" "
+ String expectedXml = "<feed xmlns=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\" >"
+ "<entry><content/></entry>"
+ "<osearch:startIndex>0</osearch:startIndex>"
@@ -199,7 +199,7 @@
emptyLists.add(emptyList);
xml = beanXmlConverter.convertToString(emptyLists);
XmlUtil.parse(xml);
- expectedXml = "<feed xmlns=\"http://ns.opensocial.org/2008/opensocial\" "
+ expectedXml = "<feed xmlns=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\" >"
+ "<entry><content><list/><list/><list/></content></entry>"
+ "<osearch:startIndex>0</osearch:startIndex>"
@@ -217,9 +217,9 @@
activities.add(activity);
String xml = beanXmlConverter.convertToString(activities);
XmlUtil.parse(xml);
- String expectedXml = "<feed
xmlns=\"http://ns.opensocial.org/2008/opensocial\" "
+ String expectedXml = "<feed xmlns=\"http://www.w3.org/2005/Atom\" "
+ "
xmlns:osearch=\"http://a9.com/-/spec/opensearch/1.1\"><entry><content>"
- + " <activity>"
+ + " <activity xmlns=\"http://ns.opensocial.org/2008/opensocial\">"
+ " <id>activityId</id>"
+ " <mediaItems>"
+ " <mimeType>image/jpg</mimeType>"
@@ -229,7 +229,7 @@
+ " <url>http://foo.com</url>"
+ " <userId>johnDoeId</userId>"
+ " </activity>"
- + " <activity>"
+ + " <activity xmlns=\"http://ns.opensocial.org/2008/opensocial\">"
+ " <id>activityId</id>"
+ " <mediaItems>"
+ " <mimeType>image/jpg</mimeType>"
@@ -239,7 +239,7 @@
+ " <url>http://foo.com</url>"
+ " <userId>johnDoeId</userId>"
+ " </activity>"
- + " <activity>"
+ + " <activity xmlns=\"http://ns.opensocial.org/2008/opensocial\">"
+ " <id>activityId</id>"
+ " <mediaItems>"
+ " <mimeType>image/jpg</mimeType>"
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamConverterTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamConverterTest.java?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamConverterTest.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamConverterTest.java
Wed Feb 25 02:00:37 2009
@@ -50,10 +50,9 @@
import java.util.Map;
public class BeanXStreamConverterTest extends TestCase {
- private static final String XMLSCHEMA = "
xmlns=\"http://ns.opensocial.org/2008/opensocial\" \n"
- + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
+ private static final String XMLSCHEMA =
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
+ " xsi:schemaLocation=\"http://ns.opensocial.org/2008/opensocial
classpath:opensocial.xsd\" ";
- private static final String XSDRESOURCE = "opensocial.xsd";
private Person johnDoe;
private Activity activity;
@@ -118,16 +117,14 @@
}
public void testPersonToXml() throws Exception {
- String xml =
XSDValidator.validate(beanXmlConverter.convertToString(johnDoe),
- XMLSCHEMA, XSDRESOURCE, true);
+ String xml =
XSDValidator.validateOpenSocial(beanXmlConverter.convertToString(johnDoe));
Element element = XmlUtil.parse(xml);
Node id = element.getElementsByTagName("id").item(0);
assertEquals(johnDoe.getId(), id.getTextContent());
}
public void testActivityToXml() throws Exception {
- String xml =
XSDValidator.validate(beanXmlConverter.convertToString(activity),
- XMLSCHEMA, XSDRESOURCE, true);
+ String xml =
XSDValidator.validateOpenSocial(beanXmlConverter.convertToString(activity));
Element element = XmlUtil.parse(xml);
Node id = element.getElementsByTagName("id").item(0);
@@ -150,7 +147,7 @@
XmlUtil.parse(xml);
- String expectedXml = "<response><map>"
+ String expectedXml = XSDValidator.XMLDEC + "<response
xmlns=\"http://ns.opensocial.org/2008/opensocial\"><map>"
+ "
<entry><key>item1</key><value><entry><key>value</key><value>1</value></entry></value></entry>
"
+ "
<entry><key>item2</key><value><entry><key>value</key><value>2</value></entry></value></entry>
"
+ "</map></response>";
@@ -164,7 +161,7 @@
m.put("key2", "value2");
String xml = beanXmlConverter.convertToString(m);
XmlUtil.parse(xml);
- String expectedXml = "<response><map>"
+ String expectedXml = XSDValidator.XMLDEC + "<response
xmlns=\"http://ns.opensocial.org/2008/opensocial\"><map>"
+ " <entry><key>key1</key><value>value1</value></entry> "
+ " <entry><key>key2</key><value>value2</value></entry> "
+ "</map></response>";
@@ -176,7 +173,7 @@
List<String> empty = Lists.newArrayList();
String xml = beanXmlConverter.convertToString(empty);
XmlUtil.parse(xml);
- String expectedXml = "<response><list/></response>";
+ String expectedXml = XSDValidator.XMLDEC + "<response
xmlns=\"http://ns.opensocial.org/2008/opensocial\"><list/></response>";
assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils
.deleteWhitespace(xml));
@@ -187,23 +184,25 @@
emptyLists.add(emptyList);
xml = beanXmlConverter.convertToString(emptyLists);
XmlUtil.parse(xml);
- expectedXml = "<response><list.container>" + " <list/>" + " <list/>"
+ expectedXml = XSDValidator.XMLDEC + "<response
xmlns=\"http://ns.opensocial.org/2008/opensocial\"><list.container>" + "
<list/>" + " <list/>"
+ " <list/>" + "</list.container></response>";
assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils
.deleteWhitespace(xml));
}
public void testElementNamesInList() throws XmlException {
+
List<Activity> activities = Lists.newArrayList();
activities.add(activity);
activities.add(activity);
activities.add(activity);
- String xml = XSDValidator.validate(beanXmlConverter
- .convertToString(activities), XMLSCHEMA, XSDRESOURCE, true);
+ String xml =
XSDValidator.validateOpenSocial(beanXmlConverter.convertToString(activities));
+
+ // This test is a bit bogus and relies on some odd voodoo in the bundled
opensocial.xsd
XmlUtil.parse(xml);
- String expectedXml = "<response>"
+ String expectedXml = "<response
xmlns=\"http://ns.opensocial.org/2008/opensocial\">"
+ "<list.container>"
- + " <activity>"
+ + " <activity xmlns=\"http://ns.opensocial.org/2008/opensocial\">"
+ " <id>activityId</id>"
+ " <mediaItems>"
+ " <mimeType>image/jpg</mimeType>"
@@ -213,7 +212,7 @@
+ " <url>http://foo.com/</url>"
+ " <userId>johnDoeId</userId>"
+ " </activity>"
- + " <activity>"
+ + " <activity xmlns=\"http://ns.opensocial.org/2008/opensocial\">"
+ " <id>activityId</id>"
+ " <mediaItems>"
+ " <mimeType>image/jpg</mimeType>"
@@ -223,7 +222,7 @@
+ " <url>http://foo.com/</url>"
+ " <userId>johnDoeId</userId>"
+ " </activity>"
- + " <activity>"
+ + " <activity xmlns=\"http://ns.opensocial.org/2008/opensocial\">"
+ " <id>activityId</id>"
+ " <mediaItems>"
+ " <mimeType>image/jpg</mimeType>"
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/XSDValidator.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/XSDValidator.java?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/XSDValidator.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/XSDValidator.java
Wed Feb 25 02:00:37 2009
@@ -121,16 +121,6 @@
return xml;
}
- if (removeContainer) {
- if (xml.startsWith("<response>")) {
- xml = xml.substring("<response>".length());
- }
- if (xml.endsWith("</response>")) {
- xml = xml.substring(0, xml.length() - "</response>".length());
- }
- }
- xml = xml.trim();
-
int start = 0;
if ( xml.startsWith("<?") ) {
start = xml.indexOf('>')+1;
@@ -156,8 +146,9 @@
*/
public static String validate(String xmlFragment, String schemaStatement,
String schemaResource, boolean removeContainer) {
+
String xml = XSDValidator.insertSchema(xmlFragment, schemaStatement,
removeContainer);
- log.debug("Valiating " + xml);
+ log.debug("Validating " + xml);
String errors = XSDValidator.validate(xml, XSDValidator.class
.getResourceAsStream(schemaResource));
if (!"".equals(errors)) {
@@ -169,4 +160,21 @@
return xml;
}
+ public static String validateOpenSocial(String xmlFragment) {
+ String XMLSCHEMA = "
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
+ + " xsi:schemaLocation=\"http://ns.opensocial.org/2008/opensocial
classpath:opensocial.xsd\" ";
+
+ String xml = XSDValidator.insertSchema(xmlFragment, XMLSCHEMA, true);
+ log.debug("Validating " + xml);
+ String errors = XSDValidator.validate(xml, XSDValidator.class
+ .getResourceAsStream("opensocial.xsd"));
+ if (!"".equals(errors)) {
+ log.error("Failed to validate " + xml);
+ }
+ if (!"".equals(errors)) {
+ throw new Error("XML document does not validate \n" + errors + '\n' +
xml);
+ }
+ return xml;
+
+ }
}
Modified:
incubator/shindig/trunk/java/social-api/src/test/resources/org/apache/shindig/social/opensocial/util/opensocial.xsd
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/resources/org/apache/shindig/social/opensocial/util/opensocial.xsd?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/resources/org/apache/shindig/social/opensocial/util/opensocial.xsd
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/resources/org/apache/shindig/social/opensocial/util/opensocial.xsd
Wed Feb 25 02:00:37 2009
@@ -12,7 +12,6 @@
<xs:element name="response" type="tns:Response" />
- <xs:element name="list.container" type="xs:anyType" />
<xs:complexType name="Response">
<xs:choice minOccurs="0" maxOccurs="unbounded" >
@@ -28,6 +27,7 @@
<xs:element minOccurs="0" maxOccurs="unbounded" name="entry"
type="tns:Entry" />
<!-- this is to allow responses to create to validate -->
<xs:element minOccurs="0" name="map" type="xs:anyType" />
+ <xs:element minOccurs="0" name="list.container" type="xs:anyType" />
</xs:choice>
</xs:complexType>
Modified: incubator/shindig/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/pom.xml?rev=747642&r1=747641&r2=747642&view=diff
==============================================================================
--- incubator/shindig/trunk/pom.xml (original)
+++ incubator/shindig/trunk/pom.xml Wed Feb 25 02:00:37 2009
@@ -1172,6 +1172,11 @@
<version>2.4</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <version>1.2</version>
+ </dependency>
</dependencies>
<dependencyManagement>