Search in sources :

Example 66 with VCard

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

Example 67 with VCard

use of ezvcard.VCard 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));
}
Also used : XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 68 with VCard

use of ezvcard.VCard 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);
}
Also used : Note(ezvcard.property.Note) XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) Photo(ezvcard.property.Photo) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 69 with VCard

use of ezvcard.VCard 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);
}
Also used : Xml(ezvcard.property.Xml) XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 70 with VCard

use of ezvcard.VCard 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);
}
Also used : XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) Document(org.w3c.dom.Document) 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