Search in sources :

Example 61 with VCard

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

the class VCardWriterTest method setVersionStrict_nested.

@Test
public void setVersionStrict_nested() throws Throwable {
    VCard vcard = new VCard();
    VCard agentVCard = new VCard();
    // only supported by 4.0
    agentVCard.setGender(Gender.male());
    Agent agent = new Agent(agentVCard);
    vcard.setAgent(agent);
    StringWriter sw = new StringWriter();
    VCardWriter vcw = new VCardWriter(sw, VCardVersion.V2_1);
    vcw.setAddProdId(false);
    vcw.setVersionStrict(false);
    vcw.write(vcard);
    String actual = sw.toString();
    // @formatter:off
    String expected = "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "AGENT:\r\n" + "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "GENDER:M\r\n" + "END:VCARD\r\n" + "END:VCARD\r\n";
    // @formatter:on
    assertEquals(actual, expected);
}
Also used : Agent(ezvcard.property.Agent) StringWriter(java.io.StringWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 62 with VCard

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

the class VCardWriterTest method setIncludeTrailingSemicolons.

@Test
public void setIncludeTrailingSemicolons() throws Throwable {
    VCard vcard = new VCard();
    StructuredName n = new StructuredName();
    n.setFamily("Family");
    vcard.setStructuredName(n);
    {
        StringWriter sw = new StringWriter();
        VCardWriter writer = new VCardWriter(sw, VCardVersion.V2_1);
        writer.setAddProdId(false);
        writer.write(vcard);
        writer.setIncludeTrailingSemicolons(true);
        writer.write(vcard);
        writer.setIncludeTrailingSemicolons(false);
        writer.write(vcard);
        String actual = sw.toString();
        // @formatter:off
        String expected = "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "N:Family\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "N:Family;;;;\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "N:Family\r\n" + "END:VCARD\r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
    {
        StringWriter sw = new StringWriter();
        VCardWriter writer = new VCardWriter(sw, VCardVersion.V3_0);
        writer.setAddProdId(false);
        writer.write(vcard);
        writer.setIncludeTrailingSemicolons(true);
        writer.write(vcard);
        writer.setIncludeTrailingSemicolons(false);
        writer.write(vcard);
        String actual = sw.toString();
        // @formatter:off
        String expected = "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "N:Family\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "N:Family;;;;\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "N:Family\r\n" + "END:VCARD\r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
    {
        StringWriter sw = new StringWriter();
        VCardWriter writer = new VCardWriter(sw, VCardVersion.V4_0);
        writer.setAddProdId(false);
        writer.write(vcard);
        writer.setIncludeTrailingSemicolons(true);
        writer.write(vcard);
        writer.setIncludeTrailingSemicolons(false);
        writer.write(vcard);
        String actual = sw.toString();
        // @formatter:off
        String expected = "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "N:Family;;;;\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "N:Family;;;;\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "N:Family\r\n" + "END:VCARD\r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
}
Also used : StringWriter(java.io.StringWriter) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Test(org.junit.Test)

Example 63 with VCard

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

the class VCardWriterTest method skipMeException.

@Test
public void skipMeException() throws Throwable {
    VCard vcard = new VCard();
    vcard.addProperty(new SkipMeProperty());
    vcard.addExtendedProperty("X-FOO", "value");
    StringWriter sw = new StringWriter();
    VCardWriter vcw = new VCardWriter(sw, VCardVersion.V3_0);
    vcw.setAddProdId(false);
    vcw.registerScribe(new SkipMeScribe());
    vcw.write(vcard);
    String actual = sw.toString();
    // @formatter:off
    String expected = "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "X-FOO:value\r\n" + "END:VCARD\r\n";
    // @formatter:on
    assertEquals(actual, expected);
}
Also used : StringWriter(java.io.StringWriter) SkipMeScribe(ezvcard.io.scribe.SkipMeScribe) SkipMeProperty(ezvcard.property.SkipMeProperty) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 64 with VCard

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

the class XCardDocumentTest method write_xmlVerison_invalid.

@Test
public void write_xmlVerison_invalid() throws Throwable {
    VCard vcard = new VCard();
    XCardDocument xcard = new XCardDocument();
    xcard.addVCard(vcard);
    String xml = xcard.write(null, "10.17");
    assertTrue(xml.matches("(?i)<\\?xml.*?version=\"1.0\".*?\\?>.*"));
}
Also used : VCard(ezvcard.VCard) Test(org.junit.Test)

Example 65 with VCard

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

the class XCardDocumentTest method write_rfc6351_example.

@Test
public void write_rfc6351_example() throws Throwable {
    VCard vcard = new VCard();
    vcard.setFormattedName("Simon Perreault");
    StructuredName n = new StructuredName();
    n.setFamily("Perreault");
    n.setGiven("Simon");
    n.getSuffixes().add("ing. jr");
    n.getSuffixes().add("M.Sc.");
    vcard.setStructuredName(n);
    Birthday bday = new Birthday(PartialDate.builder().month(2).date(3).build());
    vcard.setBirthday(bday);
    Anniversary anniversary = new Anniversary(PartialDate.builder().year(2009).month(8).date(8).hour(14).minute(30).offset(new UtcOffset(false, -5, 0)).build());
    vcard.setAnniversary(anniversary);
    vcard.setGender(Gender.male());
    vcard.addLanguage("fr").setPref(1);
    vcard.addLanguage("en").setPref(2);
    vcard.setOrganization("Viagenie").setType("work");
    Address adr = new Address();
    adr.setStreetAddress("2875 boul. Laurier, suite D2-630");
    adr.setLocality("Quebec");
    adr.setRegion("QC");
    adr.setPostalCode("G1V 2M2");
    adr.setCountry("Canada");
    adr.getTypes().add(AddressType.WORK);
    adr.setLabel("Simon Perreault\n2875 boul. Laurier, suite D2-630\nQuebec, QC, Canada\nG1V 2M2");
    vcard.addAddress(adr);
    TelUri telUri = new TelUri.Builder("+1-418-656-9254").extension("102").build();
    Telephone tel = new Telephone(telUri);
    tel.getTypes().add(TelephoneType.WORK);
    tel.getTypes().add(TelephoneType.VOICE);
    vcard.addTelephoneNumber(tel);
    tel = new Telephone(new TelUri.Builder("+1-418-262-6501").build());
    tel.getTypes().add(TelephoneType.WORK);
    tel.getTypes().add(TelephoneType.TEXT);
    tel.getTypes().add(TelephoneType.VOICE);
    tel.getTypes().add(TelephoneType.CELL);
    tel.getTypes().add(TelephoneType.VIDEO);
    vcard.addTelephoneNumber(tel);
    vcard.addEmail("simon.perreault@viagenie.ca", EmailType.WORK);
    Geo geo = new Geo(46.766336, -71.28955);
    geo.setType("work");
    vcard.setGeo(geo);
    Key key = new Key("http://www.viagenie.ca/simon.perreault/simon.asc", null);
    key.setType("work");
    vcard.addKey(key);
    vcard.setTimezone(new Timezone("America/Montreal"));
    vcard.addUrl("http://nomis80.org").setType("home");
    assertValidate(vcard).versions(V4_0).run();
    assertExample(vcard, "rfc6351-example.xml");
}
Also used : Timezone(ezvcard.property.Timezone) Address(ezvcard.property.Address) Telephone(ezvcard.property.Telephone) Anniversary(ezvcard.property.Anniversary) TelUri(ezvcard.util.TelUri) Birthday(ezvcard.property.Birthday) Geo(ezvcard.property.Geo) UtcOffset(ezvcard.util.UtcOffset) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Key(ezvcard.property.Key) 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