Search in sources :

Example 71 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class XCardDocumentTest method write_prettyPrint_invalid_value.

@Test
public void write_prettyPrint_invalid_value() 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();
    String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\"><vcard><fn><text>John Doe</text></fn></vcard></vcards>";
    // 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 72 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class XCardDocumentTest method add_embedded_vcards_not_supported.

@Test
public void add_embedded_vcards_not_supported() throws Throwable {
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    vcard.addProperty(new EmbeddedProperty());
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.registerScribe(new EmbeddedScribe());
    writer.write(vcard);
    VCard parsedVCard = Ezvcard.parseXml(xcard.write()).first();
    assertTrue(parsedVCard.getExtendedProperties().isEmpty());
}
Also used : XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 73 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class XCardDocumentTest method add_extendedTypes.

@Test
public void add_extendedTypes() throws Throwable {
    VCard vcard = new VCard();
    // contains marshal methods and QName
    LuckyNumProperty num = new LuckyNumProperty(24);
    vcard.addProperty(num);
    // contains marshal methods, but does not have a QName
    SalaryProperty salary = new SalaryProperty(1000000);
    vcard.addProperty(salary);
    // does not contain marshal methods nor QName
    AgeProperty age = new AgeProperty(22);
    vcard.addProperty(age);
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.registerScribe(new LuckyNumScribe());
    writer.registerScribe(new SalaryScribe());
    writer.registerScribe(new AgeScribe());
    writer.write(vcard);
    Document actual = xcard.getDocument();
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<a:lucky-num xmlns:a=\"http://luckynum.com\">24</a:lucky-num>" + "<x-salary>1000000</x-salary>" + "<x-age><unknown>22</unknown></x-age>" + "</vcard>" + "</vcards>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(XmlUtils.toString(actual), expected, actual);
}
Also used : AgeScribe(ezvcard.io.AgeProperty.AgeScribe) AgeProperty(ezvcard.io.AgeProperty) SalaryProperty(ezvcard.io.SalaryProperty) XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) LuckyNumScribe(ezvcard.io.LuckyNumProperty.LuckyNumScribe) SalaryScribe(ezvcard.io.SalaryProperty.SalaryScribe) LuckyNumProperty(ezvcard.io.LuckyNumProperty) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 74 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class XCardDocumentTest method add_skipMeException.

@Test
public void add_skipMeException() throws Throwable {
    VCard vcard = new VCard();
    vcard.addProperty(new SkipMeProperty());
    vcard.addExtendedProperty("x-foo", "value");
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.registerScribe(new SkipMeScribe());
    writer.write(vcard);
    Document actual = xcard.getDocument();
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<x-foo><unknown>value</unknown></x-foo>" + "</vcard>" + "</vcards>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(expected, actual);
}
Also used : XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) SkipMeScribe(ezvcard.io.scribe.SkipMeScribe) SkipMeProperty(ezvcard.property.SkipMeProperty) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 75 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class XCardReaderTest method close_before_stream_ends.

@Test
public void close_before_stream_ends() throws Exception {
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>Dr. Gregory House M.D.</text></fn>" + "</vcard>" + "<vcard>" + "<fn><text>Dr. Lisa Cuddy M.D.</text></fn>" + "</vcard>" + "</vcards>";
    // @formatter:on
    XCardReader reader = new XCardReader(xml);
    VCard vcard = reader.readNext();
    assertVersion(V4_0, vcard);
    assertPropertyCount(1, vcard);
    assertEquals("Dr. Gregory House M.D.", vcard.getFormattedName().getValue());
    assertParseWarnings(reader);
    reader.close();
    assertNoMoreVCards(reader);
}
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