use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.
the class XCardDocumentTest method add_basicType.
@Test
public void add_basicType() throws Throwable {
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
XCardDocument xcard = new XCardDocument();
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.write(vcard);
Document actual = xcard.getDocument();
// @formatter:off
String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "</vcard>" + "</vcards>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
assertXMLEqual(expected, actual);
}
use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.
the class XCardDocumentTest method write_prettyPrint.
@Test
public void write_prettyPrint() throws Throwable {
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
XCardDocument xcard = new XCardDocument();
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.write(vcard);
String actual = xcard.write(2);
// @formatter:off
String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + NEWLINE + " <vcard>" + NEWLINE + " <fn>" + NEWLINE + " <text>John Doe</text>" + NEWLINE + " </fn>" + NEWLINE + " </vcard>" + NEWLINE + "</vcards>";
// @formatter:on
// use "String.contains()" to ignore the XML declaration at the top
assertTrue("Expected:" + NEWLINE + expected + NEWLINE + NEWLINE + "Actual:" + NEWLINE + actual, actual.contains(expected));
}
use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.
the class XCardDocumentTest method add_group.
@Test
public void add_group() throws Throwable {
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
Note note = vcard.addNote("This is a\nnote.");
note.setGroup("group1");
note.setLanguage("en");
Photo photo = new Photo("http://example.com/image.jpg", ImageType.JPEG);
photo.setGroup("group1");
vcard.addPhoto(photo);
note = vcard.addNote("Bonjour.");
note.setGroup("group2");
XCardDocument xcard = new XCardDocument();
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.write(vcard);
Document actual = xcard.getDocument();
// @formatter:off
String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "<group name=\"group1\">" + "<photo>" + "<parameters>" + "<mediatype><text>image/jpeg</text></mediatype>" + "</parameters>" + "<uri>http://example.com/image.jpg</uri>" + "</photo>" + "<note>" + "<parameters>" + "<language><language-tag>en</language-tag></language>" + "</parameters>" + "<text>This is a\nnote.</text>" + "</note>" + "</group>" + "<group name=\"group2\">" + "<note><text>Bonjour.</text></note>" + "</group>" + "</vcard>" + "</vcards>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
assertXMLEqual(expected, actual);
}
use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.
the class XCardDocumentTest method add_xml_property_with_null_value.
@Test
public void add_xml_property_with_null_value() throws Throwable {
VCard vcard = new VCard();
Xml xmlProperty = new Xml((Document) null);
vcard.addXml(xmlProperty);
XCardDocument xcard = new XCardDocument();
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.write(vcard);
Document actual = xcard.getDocument();
// @formatter:off
String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard />" + "</vcards>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
assertXMLEqual(expected, actual);
}
use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.
the class XCardDocumentTest method add_existing_vcards_element.
@Test
public void add_existing_vcards_element() throws Throwable {
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
XCardDocument xcard = new XCardDocument("<root><vcards xmlns=\"" + V4_0.getXmlNamespace() + "\"><a /></vcards></root>");
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.write(vcard);
Document actual = xcard.getDocument();
// @formatter:off
String xml = "<root>" + "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<a />" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "</vcard>" + "</vcards>" + "</root>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
assertXMLEqual(expected, actual);
}
Aggregations