use of ezvcard.VCard in project ez-vcard by mangstadt.
the class XCardWriterTest method write_existing_vcards_element.
@Test
public void write_existing_vcards_element() throws Exception {
Document document = XmlUtils.toDocument("<root><a><vcards xmlns=\"" + V4_0.getXmlNamespace() + "\" /></a><b /></root>");
Node element = document.getFirstChild().getFirstChild().getFirstChild();
XCardWriter writer = new XCardWriter(element);
writer.setAddProdId(false);
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
writer.write(vcard);
writer.close();
// @formatter:off
String xml = "<root>" + "<a>" + "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "</vcard>" + "</vcards>" + "</a>" + "<b />" + "</root>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
assertXMLEqual(expected, document);
}
use of ezvcard.VCard in project ez-vcard by mangstadt.
the class XCardWriterTest method write_existing_dom_document.
@Test
public void write_existing_dom_document() throws Exception {
Document document = XmlUtils.toDocument("<root><a /><b /></root>");
XCardWriter writer = new XCardWriter(document);
writer.setAddProdId(false);
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
writer.write(vcard);
writer.close();
// @formatter:off
String xml = "<root>" + "<a />" + "<b />" + "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "</vcard>" + "</vcards>" + "</root>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
assertXMLEqual(expected, document);
}
use of ezvcard.VCard in project ez-vcard by mangstadt.
the class XCardWriterTest method skipMeException.
@Test
public void skipMeException() throws Exception {
writer.registerScribe(new SkipMeScribe());
VCard vcard = new VCard();
vcard.addProperty(new SkipMeProperty());
vcard.addExtendedProperty("x-foo", "value");
writer.write(vcard);
writer.close();
// @formatter:off
String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<x-foo><unknown>value</unknown></x-foo>" + "</vcard>" + "</vcards>";
// @formatter:on
assertOutput(expected);
}
use of ezvcard.VCard in project ez-vcard by mangstadt.
the class XCardWriterTest method write_utf8.
@Test
public void write_utf8() throws Exception {
File file = tempFolder.newFile();
XCardWriter writer = new XCardWriter(file);
writer.setAddProdId(false);
VCard vcard = new VCard();
vcard.addNote("\u019dote");
writer.write(vcard);
writer.close();
String xml = new Gobble(file).asString("UTF-8");
assertTrue(xml.matches("(?i)<\\?xml.*?encoding=\"utf-8\".*?\\?>.*"));
assertTrue(xml.matches(".*?<note><text>\u019dote</text></note>.*"));
}
use of ezvcard.VCard in project ez-vcard by mangstadt.
the class AgentTest method set_value.
@Test
public void set_value() {
VCard vcard = new VCard();
Agent agent = new Agent();
agent.setUrl("one");
assertEquals("one", agent.getUrl());
assertNull(agent.getVCard());
agent.setVCard(vcard);
assertNull(agent.getUrl());
assertEquals(vcard, agent.getVCard());
agent.setUrl("one");
assertEquals("one", agent.getUrl());
assertNull(agent.getVCard());
}
Aggregations