public void append(Appendable buf, Object pojo) throws IOException { buf.append(convertToString(pojo)); } }
public void append(Appendable buf, Object pojo) throws IOException { buf.append(convertToString(pojo)); } }
public void append(Appendable buf, Object pojo) throws IOException { buf.append(convertToString(pojo)); } }
public void append(Appendable buf, Object pojo) throws IOException { buf.append(convertToString(pojo)); } }
public void append(Appendable buf, Object pojo) throws IOException { buf.append(convertToString(pojo)); } }
@Test public void testToXmlOnSimpleClass() throws Exception { // since this doent implement the model, it wont get mapped correctly, hence // we cant validate SimplePerson cassie = new SimplePerson("5", "robot"); String xml = beanXmlConverter.convertToString(cassie); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); Node name = element.getElementsByTagName("name").item(0); assertEquals("5", id.getTextContent()); assertEquals("robot", name.getTextContent()); }
@Test public void testToXmlOnSimpleClass() throws Exception { // since this doent implement the model, it wont get mapped correctly, hence // we cant validate SimplePerson cassie = new SimplePerson("5", "robot"); String xml = beanXmlConverter.convertToString(cassie); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); Node name = element.getElementsByTagName("name").item(0); assertEquals("5", id.getTextContent()); assertEquals("robot", name.getTextContent()); }
@Test public void testToXmlOnSimpleClass() throws Exception { // since this doent implement the model, it wont get mapped correctly, hence // we cant validate SimplePerson cassie = new SimplePerson("5", "robot"); String xml = beanXmlConverter.convertToString(cassie); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); Node name = element.getElementsByTagName("name").item(0); assertEquals("5", id.getTextContent()); assertEquals("robot", name.getTextContent()); }
@Test public void testMapsToXml() throws Exception { // This is the structure our app data currently takes Map<String, Map<String, String>> map = Maps.newTreeMap(); Map<String, String> item1Map = Maps.newHashMap(); item1Map.put("value", "1"); map.put("item1", item1Map); Map<String, String> item2Map = Maps.newHashMap(); item2Map.put("value", "2"); map.put("item2", item2Map); String xml = beanXmlConverter.convertToString(map); XmlUtil.parse(xml); 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>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils .deleteWhitespace(xml)); }
@Test public void testPersonToXml() throws Exception { String xml = XSDValidator.validateOpenSocial(beanXmlConverter.convertToString(johnDoe)); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); assertEquals(johnDoe.getId(), id.getTextContent()); }
@Test public void testActivityToXml() throws Exception { String xml = XSDValidator.validateOpenSocial(beanXmlConverter.convertToString(activity)); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); assertEquals(activity.getId(), id.getTextContent()); }
@Test public void testPersonToXml() throws Exception { String xml = XSDValidator.validateOpenSocial(beanXmlConverter.convertToString(johnDoe)); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); assertEquals(johnDoe.getId(), id.getTextContent()); }
@Test public void testMapsToXml() throws Exception { // This is the structure our app data currently takes Map<String, Map<String, String>> map = Maps.newTreeMap(); Map<String, String> item1Map = Maps.newHashMap(); item1Map.put("value", "1"); map.put("item1", item1Map); Map<String, String> item2Map = Maps.newHashMap(); item2Map.put("value", "2"); map.put("item2", item2Map); String xml = beanXmlConverter.convertToString(map); XmlUtil.parse(xml); 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>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils .deleteWhitespace(xml)); }
@Test public void testPersonToXml() throws Exception { String xml = XSDValidator.validateOpenSocial(beanXmlConverter.convertToString(johnDoe)); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); assertEquals(johnDoe.getId(), id.getTextContent()); }
@Test public void testActivityToXml() throws Exception { String xml = XSDValidator.validateOpenSocial(beanXmlConverter.convertToString(activity)); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); assertEquals(activity.getId(), id.getTextContent()); }
@Test public void testActivityToXml() throws Exception { String xml = XSDValidator.validateOpenSocial(beanXmlConverter.convertToString(activity)); Element element = XmlUtil.parse(xml); Node id = element.getElementsByTagName("id").item(0); assertEquals(activity.getId(), id.getTextContent()); }
@Test public void testMapToXml() throws XmlException { Map<String, String> m = Maps.newLinkedHashMap(); m.put("key1", "value1"); m.put("key2", "value2"); String xml = beanXmlConverter.convertToString(m); XmlUtil.parse(xml); 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>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils .deleteWhitespace(xml)); }
@Test public void testMapToXml() throws XmlException { Map<String, String> m = Maps.newLinkedHashMap(); m.put("key1", "value1"); m.put("key2", "value2"); String xml = beanXmlConverter.convertToString(m); XmlUtil.parse(xml); 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>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils .deleteWhitespace(xml)); }
@Test public void testMapToXml() throws XmlException { Map<String, String> m = Maps.newLinkedHashMap(); m.put("key1", "value1"); m.put("key2", "value2"); String xml = beanXmlConverter.convertToString(m); XmlUtil.parse(xml); 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>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils .deleteWhitespace(xml)); }
@Test public void testEmptyList() throws XmlException { List<String> empty = Lists.newArrayList(); String xml = beanXmlConverter.convertToString(empty); XmlUtil.parse(xml); String expectedXml = XSDValidator.XMLDEC + "<response xmlns=\"http://ns.opensocial.org/2008/opensocial\"><list/></response>"; assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils .deleteWhitespace(xml)); List<List<String>> emptyLists = Lists.newArrayList(); List<String> emptyList = Lists.newArrayList(); emptyLists.add(emptyList); emptyLists.add(emptyList); emptyLists.add(emptyList); xml = beanXmlConverter.convertToString(emptyLists); XmlUtil.parse(xml); 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)); }