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);
}
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);
}
}
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);
}
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\".*?\\?>.*"));
}
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");
}
Aggregations