Search in sources :

Example 81 with VCard

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);
}
Also used : Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 82 with VCard

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);
}
Also used : Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 83 with VCard

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);
}
Also used : SkipMeScribe(ezvcard.io.scribe.SkipMeScribe) SkipMeProperty(ezvcard.property.SkipMeProperty) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 84 with VCard

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>.*"));
}
Also used : Gobble(ezvcard.util.Gobble) File(java.io.File) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 85 with VCard

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());
}
Also used : VCard(ezvcard.VCard) Test(org.junit.Test)

Aggregations

VCard (ezvcard.VCard)191 Test (org.junit.Test)134 StringWriter (java.io.StringWriter)29 StructuredName (ezvcard.property.StructuredName)23 Person (com.google.api.services.people.v1.model.Person)22 Telephone (ezvcard.property.Telephone)21 Photo (ezvcard.property.Photo)17 Email (ezvcard.property.Email)16 List (java.util.List)16 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)15 Document (org.w3c.dom.Document)15 VCardVersion (ezvcard.VCardVersion)14 XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)14 Address (ezvcard.property.Address)14 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)13 Collectors (java.util.stream.Collectors)12 Name (com.google.api.services.people.v1.model.Name)11 File (java.io.File)11 Truth.assertThat (com.google.common.truth.Truth.assertThat)10 Pair (com.google.gdata.util.common.base.Pair)10