use of com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider in project ph-commons by phax.
the class XMLMapHandlerTest method testReadBuildInfo.
@Test
public void testReadBuildInfo() {
final ICommonsMap<String, String> aMap = new CommonsHashMap<>();
final IReadableResource aRes = new ClassPathResource("xml/buildinfo.xml");
assertTrue(XMLMapHandler.readMap(aRes, aMap).isSuccess());
assertNull(XMLMapHandler.readMap(new ClassPathResource("test1.txt")));
assertTrue(aMap.containsKey("buildinfo.version"));
assertEquals("1", aMap.get("buildinfo.version"));
assertTrue(XMLMapHandler.readMap(aRes).containsKey("buildinfo.version"));
assertEquals("1", XMLMapHandler.readMap(aRes).get("buildinfo.version"));
assertTrue(XMLMapHandler.writeMap(aMap, new ByteArrayOutputStreamProvider()).isSuccess());
assertTrue(XMLMapHandler.writeMap(aMap, new NonBlockingByteArrayOutputStream()).isSuccess());
}
use of com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider in project ph-commons by phax.
the class XMLListHandlerTest method testRead.
@Test
public void testRead() {
ICommonsList<String> aList = new CommonsArrayList<>();
final IReadableResource aRes = new ClassPathResource("xml/list.xml");
XMLListHandler.readList(aRes, aList);
assertEquals(3, aList.size());
assertTrue(aList.contains("item1"));
assertNotNull(XMLListHandler.readList(aRes));
assertNull(XMLListHandler.readList(new ClassPathResource("test1.txt")));
assertEquals(3, XMLListHandler.readList(aRes).size());
assertTrue(XMLListHandler.readList(aRes).contains("item1"));
assertTrue(XMLListHandler.writeList(aList, new NonBlockingByteArrayOutputStream()).isSuccess());
final String sXML = "<root><item/><item value='a' /><item value='a' /></root>";
aList = XMLListHandler.readList(new StringInputStreamProvider(sXML, StandardCharsets.ISO_8859_1));
assertNotNull(aList);
assertEquals(2, aList.size());
assertEquals("a", aList.get(0));
assertEquals("a", aList.get(1));
final ICommonsSet<String> aSet = new CommonsHashSet<>();
XMLListHandler.readList(new StringInputStreamProvider(sXML, StandardCharsets.ISO_8859_1), aSet);
assertEquals(1, aSet.size());
assertTrue(aSet.contains("a"));
assertTrue(XMLListHandler.writeList(aList, new NonBlockingByteArrayOutputStream()).isSuccess());
assertTrue(XMLListHandler.writeList(aList, new ByteArrayOutputStreamProvider()).isSuccess());
}
use of com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider in project ph-commons by phax.
the class XMLMapHandlerTest method testWriteInvalid.
@Test
public void testWriteInvalid() {
final ICommonsMap<String, String> aMap = new CommonsHashMap<>();
try {
XMLMapHandler.writeMap(aMap, (IHasOutputStream) null);
fail();
} catch (final NullPointerException ex) {
}
try {
XMLMapHandler.writeMap(null, new ByteArrayOutputStreamProvider());
fail();
} catch (final NullPointerException ex) {
}
try {
XMLMapHandler.writeMap(aMap, (OutputStream) null);
fail();
} catch (final NullPointerException ex) {
}
try {
XMLMapHandler.writeMap(null, new NonBlockingByteArrayOutputStream());
fail();
} catch (final NullPointerException ex) {
}
}
use of com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider in project ph-commons by phax.
the class XMLEmitterTest method testMisc.
@Test
public void testMisc() {
assertEquals("<!DOCTYPE qname PUBLIC \"pubid\" \"sysid\">", XMLEmitter.getDocTypeHTMLRepresentation(EXMLSerializeVersion.XML_10, EXMLIncorrectCharacterHandling.DEFAULT, new MicroDocumentType("qname", "pubid", "sysid")));
assertEquals("<!DOCTYPE qname PUBLIC \"pubid\" \"sysid\">", XMLEmitter.getDocTypeHTMLRepresentation(EXMLSerializeVersion.XML_11, EXMLIncorrectCharacterHandling.DEFAULT, new MicroDocumentType("qname", "pubid", "sysid")));
CommonsTestHelper.testToStringImplementation(new XMLEmitter(new ByteArrayOutputStreamProvider().getWriter(StandardCharsets.ISO_8859_1, EAppend.DEFAULT), XMLWriterSettings.DEFAULT_XML_SETTINGS));
}
Aggregations