Search in sources :

Example 16 with Email

use of ezvcard.property.Email in project ez-vcard by mangstadt.

the class HCardPageTest method create_then_parse.

@Test
public void create_then_parse() throws Exception {
    // create template
    VCard expected = createFullVCard();
    HCardPage template = new HCardPage();
    template.add(expected);
    String html = template.write();
    // write to file for manual inspection
    FileWriter writer = new FileWriter(new File("target", "vcard.html"));
    writer.write(html);
    writer.close();
    // parse template
    HCardParser reader = new HCardParser(html);
    VCard actual = reader.readNext();
    reader.close();
    assertEquals("Claus", actual.getSortString().getValue());
    assertEquals(expected.getClassification().getValue(), actual.getClassification().getValue());
    assertEquals(expected.getMailer().getValue(), actual.getMailer().getValue());
    assertEquals(expected.getFormattedName().getValue(), actual.getFormattedName().getValue());
    assertEquals(expected.getUid().getValue(), actual.getUid().getValue());
    assertEquals(expected.getNickname().getValues(), actual.getNickname().getValues());
    assertEquals(expected.getOrganization().getValues(), actual.getOrganization().getValues());
    assertEquals(expected.getCategories().getValues(), actual.getCategories().getValues());
    assertEquals(expected.getBirthday().getDate(), actual.getBirthday().getDate());
    assertEquals(expected.getRevision().getValue(), actual.getRevision().getValue());
    assertEquals(expected.getGeo().getLatitude(), actual.getGeo().getLatitude());
    assertEquals(expected.getGeo().getLongitude(), actual.getGeo().getLongitude());
    assertEquals(expected.getTimezone().getOffset(), actual.getTimezone().getOffset());
    // text value is not written
    assertNull(actual.getTimezone().getText());
    {
        StructuredName e = expected.getStructuredName();
        StructuredName a = actual.getStructuredName();
        assertEquals(e.getFamily(), a.getFamily());
        assertEquals(e.getGiven(), a.getGiven());
        assertEquals(e.getAdditionalNames(), a.getAdditionalNames());
        assertEquals(e.getPrefixes(), a.getPrefixes());
        assertEquals(e.getSuffixes(), a.getSuffixes());
        assertTrue(a.getSortAs().isEmpty());
    }
    assertEquals(expected.getTitles().size(), actual.getTitles().size());
    for (int i = 0; i < expected.getTitles().size(); i++) {
        Title e = expected.getTitles().get(i);
        Title a = actual.getTitles().get(i);
        assertEquals(e.getValue(), a.getValue());
    }
    assertEquals(expected.getRoles().size(), actual.getRoles().size());
    for (int i = 0; i < expected.getRoles().size(); i++) {
        Role e = expected.getRoles().get(i);
        Role a = actual.getRoles().get(i);
        assertEquals(e.getValue(), a.getValue());
    }
    assertEquals(expected.getNotes().size(), actual.getNotes().size());
    for (int i = 0; i < expected.getNotes().size(); i++) {
        Note e = expected.getNotes().get(i);
        Note a = actual.getNotes().get(i);
        assertEquals(e.getValue(), a.getValue());
    }
    assertEquals(expected.getUrls().size(), actual.getUrls().size());
    for (int i = 0; i < expected.getUrls().size(); i++) {
        Url e = expected.getUrls().get(i);
        Url a = actual.getUrls().get(i);
        assertEquals(e.getValue(), a.getValue());
    }
    assertEquals(expected.getImpps().size(), actual.getImpps().size());
    for (int i = 0; i < expected.getImpps().size(); i++) {
        Impp e = expected.getImpps().get(i);
        Impp a = actual.getImpps().get(i);
        assertEquals(e.getUri(), a.getUri());
    }
    assertEquals(expected.getEmails().size(), actual.getEmails().size());
    for (int i = 0; i < expected.getEmails().size(); i++) {
        Email e = expected.getEmails().get(i);
        Email a = actual.getEmails().get(i);
        assertEquals(e.getValue(), a.getValue());
        assertEquals(e.getTypes(), a.getTypes());
    }
    assertEquals(expected.getTelephoneNumbers().size(), actual.getTelephoneNumbers().size());
    for (int i = 0; i < expected.getTelephoneNumbers().size(); i++) {
        Telephone e = expected.getTelephoneNumbers().get(i);
        Telephone a = actual.getTelephoneNumbers().get(i);
        if (e.getText() != null) {
            assertEquals(e.getText(), a.getText());
        } else {
            TelUri uri = e.getUri();
            if (uri.getExtension() == null) {
                assertEquals(e.getUri().getNumber(), a.getText());
            } else {
                assertEquals(e.getUri().getNumber() + " x" + uri.getExtension(), a.getText());
            }
        }
        assertEquals(e.getTypes(), a.getTypes());
    }
    assertEquals(expected.getAddresses().size(), actual.getAddresses().size());
    for (int i = 0; i < expected.getAddresses().size(); i++) {
        Address e = expected.getAddresses().get(i);
        Address a = actual.getAddresses().get(i);
        assertEquals(e.getPoBox(), a.getPoBox());
        assertEquals(e.getExtendedAddress(), a.getExtendedAddress());
        assertEquals(e.getStreetAddress(), a.getStreetAddress());
        assertEquals(e.getLocality(), a.getLocality());
        assertEquals(e.getRegion(), a.getRegion());
        assertEquals(e.getPostalCode(), a.getPostalCode());
        assertEquals(e.getCountry(), a.getCountry());
        assertEquals(e.getLabel(), a.getLabel());
        assertEquals(e.getTypes(), a.getTypes());
    }
    assertEquals(expected.getPhotos().size(), actual.getPhotos().size());
    for (int i = 0; i < expected.getPhotos().size(); i++) {
        Photo e = expected.getPhotos().get(i);
        Photo a = actual.getPhotos().get(i);
        assertEquals(e.getContentType(), a.getContentType());
        assertArrayEquals(e.getData(), a.getData());
    }
    assertEquals(expected.getSounds().size(), actual.getSounds().size());
    for (int i = 0; i < expected.getSounds().size(); i++) {
        Sound e = expected.getSounds().get(i);
        Sound a = actual.getSounds().get(i);
        assertEquals(e.getContentType(), a.getContentType());
        assertArrayEquals(e.getData(), a.getData());
    }
    assertEquals("ez-vcard " + Ezvcard.VERSION, actual.getProductId().getValue());
}
Also used : Email(ezvcard.property.Email) Telephone(ezvcard.property.Telephone) Address(ezvcard.property.Address) Impp(ezvcard.property.Impp) FileWriter(java.io.FileWriter) Title(ezvcard.property.Title) TelUri(ezvcard.util.TelUri) Photo(ezvcard.property.Photo) Sound(ezvcard.property.Sound) SortString(ezvcard.property.SortString) Url(ezvcard.property.Url) Role(ezvcard.property.Role) Note(ezvcard.property.Note) VCard(ezvcard.VCard) File(java.io.File) StructuredName(ezvcard.property.StructuredName) Test(org.junit.Test)

Example 17 with Email

use of ezvcard.property.Email in project ez-vcard by mangstadt.

the class EmailScribeTest method parseHtml_types.

@Test
public void parseHtml_types() {
    Email expected = new Email("johndoe@example.com");
    expected.getTypes().add(EmailType.HOME);
    // @formatter:off
    sensei.assertParseHtml("<a href=\"mailto:johndoe@example.com\">" + "<span class=\"type\">Home</span> Email" + "</a>").run(expected);
// @formatter:on
}
Also used : Email(ezvcard.property.Email) Test(org.junit.Test)

Example 18 with Email

use of ezvcard.property.Email in project ez-vcard by mangstadt.

the class VCard method addEmail.

/**
 * <p>
 * Adds an email address.
 * </p>
 * <p>
 * <b>Property name:</b> {@code EMAIL}<br>
 * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0}
 * </p>
 * @param email the email address to add (e.g. "johndoe@aol.com")
 * @param types the type(s) to assign to the email
 * @return the property object that was created
 * @see <a href="http://tools.ietf.org/html/rfc6350#page-36">RFC 6350
 * p.36</a>
 * @see <a href="http://tools.ietf.org/html/rfc2426#page-15">RFC 2426
 * p.15</a>
 * @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.15</a>
 */
public Email addEmail(String email, EmailType... types) {
    Email property = new Email(email);
    property.getTypes().addAll(Arrays.asList(types));
    addEmail(property);
    return property;
}
Also used : Email(ezvcard.property.Email)

Aggregations

Email (ezvcard.property.Email)18 Test (org.junit.Test)10 VCard (ezvcard.VCard)6 StructuredName (ezvcard.property.StructuredName)5 Telephone (ezvcard.property.Telephone)5 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)4 Person (com.google.api.services.people.v1.model.Person)4 Address (ezvcard.property.Address)3 Address (com.google.api.services.people.v1.model.Address)2 Name (com.google.api.services.people.v1.model.Name)2 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Nullable (com.google.gdata.util.common.base.Nullable)2 Pair (com.google.gdata.util.common.base.Pair)2 File (java.io.File)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 List (java.util.List)2 Locale (java.util.Locale)2 Function (java.util.function.Function)2