use of ezvcard.property.Role in project ez-vcard by mangstadt.
the class VCard method addRole.
/**
* <p>
* Adds a role associated with the person.
* </p>
* <p>
* <b>Property name:</b> {@code ROLE}<br>
* <b>Supported versions:</b> {@code 2.1, 3.0, 4.0}
* </p>
* @param role the role to add (e.g. "Executive")
* @return the property object that was created
* @see <a href="http://tools.ietf.org/html/rfc6350#page-39">RFC 6350
* p.39</a>
* @see <a href="http://tools.ietf.org/html/rfc2426#page-18">RFC 2426
* p.18</a>
* @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.17</a>
*/
public Role addRole(String role) {
Role type = new Role(role);
addRole(type);
return type;
}
use of ezvcard.property.Role 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());
}
Aggregations