use of ezvcard.property.Url 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());
}
use of ezvcard.property.Url in project ez-vcard by mangstadt.
the class XCardReaderTest method read_rfc6351_example.
@Test
public void read_rfc6351_example() throws Throwable {
VCardAsserter asserter = read("rfc6351-example.xml");
asserter.next(V4_0);
// @formatter:off
asserter.simpleProperty(FormattedName.class).value("Simon Perreault").noMore();
asserter.structuredName().family("Perreault").given("Simon").suffixes("ing. jr", "M.Sc.").noMore();
asserter.dateProperty(Birthday.class).partialDate(PartialDate.builder().month(2).date(3).build()).noMore();
asserter.dateProperty(Anniversary.class).partialDate(PartialDate.builder().year(2009).month(8).date(8).hour(14).minute(30).offset(new UtcOffset(false, -5, 0)).build()).noMore();
asserter.property(Gender.class).expected(Gender.male()).noMore();
asserter.simpleProperty(Language.class).value("fr").param("PREF", "1").next().value("en").param("PREF", "2").noMore();
asserter.listProperty(Organization.class).values("Viagenie").param("TYPE", "work").noMore();
asserter.address().streetAddress("2875 boul. Laurier, suite D2-630").locality("Quebec").region("QC").postalCode("G1V 2M2").country("Canada").label("Simon Perreault\n2875 boul. Laurier, suite D2-630\nQuebec, QC, Canada\nG1V 2M2").types(AddressType.WORK).noMore();
asserter.telephone().uri(new TelUri.Builder("+1-418-656-9254").extension("102").build()).types(TelephoneType.WORK, TelephoneType.VOICE).next().uri(new TelUri.Builder("+1-418-262-6501").build()).types(TelephoneType.WORK, TelephoneType.TEXT, TelephoneType.VOICE, TelephoneType.CELL, TelephoneType.VIDEO).noMore();
asserter.email().value("simon.perreault@viagenie.ca").types(EmailType.WORK).noMore();
asserter.geo().latitude(46.766336).longitude(-71.28955).param("TYPE", "work").noMore();
asserter.binaryProperty(Key.class).url("http://www.viagenie.ca/simon.perreault/simon.asc").param("TYPE", "work").noMore();
asserter.timezone().text("America/Montreal").noMore();
asserter.simpleProperty(Url.class).value("http://nomis80.org").param("TYPE", "home").noMore();
// @formatter:on
asserter.validate().run();
asserter.done();
}
use of ezvcard.property.Url in project ez-vcard by mangstadt.
the class VCard method addUrl.
/**
* <p>
* Adds a URL. URLs can point to websites such as a personal homepage or
* business website.
* </p>
* <p>
* <b>Property name:</b> {@code URL}<br>
* <b>Supported versions:</b> {@code 2.1, 3.0, 4.0}
* </p>
* @param url the URL to add (e.g. "http://example.com")
* @return the property object that was created
* @see <a href="http://tools.ietf.org/html/rfc6350#page-47">RFC 6350
* p.47</a>
* @see <a href="http://tools.ietf.org/html/rfc2426#page-25">RFC 2426
* p.25</a>
* @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.21</a>
*/
public Url addUrl(String url) {
Url type = new Url(url);
addUrl(type);
return type;
}
Aggregations