use of ezvcard.property.asserter.VCardAsserter in project ez-vcard by mangstadt.
the class XCardReaderTest method cannotParseException.
@Test
public void cannotParseException() throws Exception {
// @formatter:off
String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<group name=\"grp\">" + "<cannotparse><text>value1</text></cannotparse>" + "</group>" + "<cannotparse><text>value2</text></cannotparse>" + "<x-foo><text>value</text></x-foo>" + "</vcard>" + "</vcards>";
XCardReader reader = new XCardReader(xml);
reader.registerScribe(new CannotParseScribe());
VCardAsserter asserter = new VCardAsserter(reader);
asserter.next(V4_0);
asserter.rawProperty("x-foo").dataType(VCardDataType.TEXT).value("value").noMore();
asserter.xml().group("grp").value("<cannotparse xmlns=\"" + V4_0.getXmlNamespace() + "\"><text>value1</text></cannotparse>").next().value("<cannotparse xmlns=\"" + V4_0.getXmlNamespace() + "\"><text>value2</text></cannotparse>").noMore();
asserter.warnings(25, 25);
asserter.done();
// @formatter:on
}
use of ezvcard.property.asserter.VCardAsserter in project ez-vcard by mangstadt.
the class SampleVCardsTest method gmailVCard.
@Test
public void gmailVCard() throws Throwable {
VCardAsserter asserter = read("John_Doe_GMAIL.vcf");
asserter.next(V3_0);
// @formatter:off
asserter.simpleProperty(FormattedName.class).value("Mr. John Richter, James Doe Sr.").noMore();
asserter.structuredName().family("Doe").given("John").additional("Richter, James").prefixes("Mr.").suffixes("Sr.").noMore();
asserter.email().types(EmailType.INTERNET, EmailType.HOME).value("john.doe@ibm.com").noMore();
asserter.telephone().types(TelephoneType.CELL).text("905-555-1234").next().types(TelephoneType.HOME).text("905-666-1234").noMore();
asserter.address().extendedAddress("Crescent moon drive" + NEWLINE + "555-asd" + NEWLINE + "Nice Area, Albaney, New York 12345" + NEWLINE + "United States of America").types(AddressType.HOME).noMore();
asserter.listProperty(Organization.class).values("IBM").noMore();
asserter.simpleProperty(Title.class).value("Money Counter").noMore();
asserter.dateProperty(Birthday.class).date("1980-03-22").noMore();
asserter.simpleProperty(Url.class).value("http://www.ibm.com").param("TYPE", "WORK").noMore();
asserter.simpleProperty(Note.class).value("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + NEWLINE + "Favotire Color: Blue").noMore();
asserter.rawProperty("X-PHONETIC-FIRST-NAME").value("Jon").noMore();
asserter.rawProperty("X-PHONETIC-LAST-NAME").value("Dow").noMore();
asserter.rawProperty("X-ABDATE").group("item1").value("1975-03-01").noMore();
asserter.rawProperty("X-ABLABEL").group("item1").value("_$!<Anniversary>!$_").next().group("item2").value("_$!<Spouse>!$_").noMore();
asserter.rawProperty("X-ABRELATEDNAMES").group("item2").value("Jenny").noMore();
VCard vcard = asserter.getVCard();
asserter.validate().prop(vcard.getEmails().get(0), // "TYPE=WORK" not valid in vCard 3.0
9).run();
// @formatter:on
asserter.done();
}
use of ezvcard.property.asserter.VCardAsserter in project ez-vcard by mangstadt.
the class SampleVCardsTest method thunderbird.
@Test
public void thunderbird() throws Throwable {
VCardAsserter asserter = read("thunderbird-MoreFunctionsForAddressBook-extension.vcf");
asserter.next(V3_0);
// @formatter:off
asserter.structuredName().param("CHARSET", "UTF-8").family("Doe").given("John").noMore();
asserter.simpleProperty(FormattedName.class).param("CHARSET", "UTF-8").value("John Doe").noMore();
asserter.listProperty(Organization.class).param("CHARSET", "UTF-8").values("TheOrganization", "TheDepartment").noMore();
asserter.listProperty(Nickname.class).param("CHARSET", "UTF-8").values("Johnny").noMore();
asserter.address().param("CHARSET", "UTF-8").extendedAddress("222 Broadway").streetAddress("Suite 100").locality("New York").region("NY").postalCode("98765").country("USA").types(AddressType.WORK, AddressType.POSTAL).next().param("CHARSET", "UTF-8").extendedAddress("123 Main St").streetAddress("Apt 10").locality("Austin").region("TX").postalCode("12345").country("USA").types(AddressType.HOME, AddressType.POSTAL).noMore();
asserter.telephone().types(TelephoneType.WORK, TelephoneType.VOICE).text("555-555-1111").next().types(TelephoneType.HOME, TelephoneType.VOICE).text("555-555-2222").next().types(TelephoneType.CELL, TelephoneType.VOICE).text("555-555-5555").next().types(TelephoneType.FAX).text("555-555-3333").next().types(TelephoneType.PAGER).text("555-555-4444").noMore();
asserter.email().types(EmailType.PREF, EmailType.INTERNET).value("doe.john@hotmail.com").next().types(EmailType.INTERNET).value("additional-email@company.com").next().types(EmailType.INTERNET).value("additional-email1@company.com").next().types(EmailType.INTERNET).value("additional-email2@company.com").next().types(EmailType.INTERNET).value("additional-email3@company.com").noMore();
asserter.simpleProperty(Url.class).value("http://www.private-webpage.com").param("TYPE", "HOME").next().value("http://www.work-webpage.com").param("TYPE", "WORK").noMore();
asserter.simpleProperty(Title.class).param("CHARSET", "UTF-8").value("TheTitle").noMore();
asserter.listProperty(Categories.class).param("CHARSET", "UTF-8").values(// commas are incorrectly escaped, so there is only 1 item
"category1, category2, category3").noMore();
asserter.dateProperty(Birthday.class).date("1970-09-21").noMore();
asserter.simpleProperty(Note.class).param("CHARSET", "UTF-8").value("This is the notes field." + NEWLINE + "Second Line" + NEWLINE + NEWLINE + "Fourth Line" + NEWLINE + "You can put anything in the \"note\" field; even curse words.").noMore();
asserter.binaryProperty(Photo.class).param("ENCODING", "b").param("TYPE", "JPEG").contentType(ImageType.JPEG).dataLength(8940).noMore();
asserter.rawProperty("X-SPOUSE").value("TheSpouse").noMore();
asserter.rawProperty("X-ANNIVERSARY").value("1990-04-30").noMore();
VCard vcard = asserter.getVCard();
asserter.validate().prop(vcard.getStructuredName(), // CHARSET not supported in 3.0
6).prop(vcard.getFormattedName(), // CHARSET not supported in 3.0
6).prop(vcard.getOrganization(), // CHARSET not supported in 3.0
6).prop(vcard.getNickname(), // CHARSET not supported in 3.0
6).prop(vcard.getAddresses().get(0), // CHARSET not supported in 3.0
6).prop(vcard.getAddresses().get(1), // CHARSET not supported in 3.0
6).prop(vcard.getTitles().get(0), // CHARSET not supported in 3.0
6).prop(vcard.getCategories(), // CHARSET not supported in 3.0
6).prop(vcard.getNotes().get(0), // CHARSET not supported in 3.0
6).run();
// @formatter:on
asserter.done();
}
use of ezvcard.property.asserter.VCardAsserter in project ez-vcard by mangstadt.
the class SampleVCardsTest method gmailSingle2.
/**
* File generated on 5/7/2016.
*/
@Test
public void gmailSingle2() throws Throwable {
VCardAsserter asserter = read("gmail-single2.vcf");
asserter.next(V3_0);
// @formatter:off
asserter.simpleProperty(FormattedName.class).value("VCard Test").noMore();
asserter.structuredName().family("Test").given("VCard").noMore();
asserter.listProperty(Nickname.class).values("TheNickname").noMore();
asserter.email().types(EmailType.INTERNET).value("email@example.com").next().types(EmailType.INTERNET, EmailType.HOME).value("homeemail@example.com").next().types(EmailType.INTERNET, EmailType.WORK).value("workemail@example.com").next().types(EmailType.INTERNET).value("otheremail@example.com").next().types(EmailType.INTERNET).group("item1").value("customcategory@example.com").noMore();
asserter.telephone().text("5555551111").next().types(TelephoneType.HOME).text("5555551112").next().types(TelephoneType.WORK).text("5555551113").next().text("5555551114").next().types(TelephoneType.CELL).text("5555551115").next().types(TelephoneType.get("MAIN")).text("5555551116").next().types(TelephoneType.HOME, TelephoneType.FAX).text("5555551117").next().types(TelephoneType.WORK, TelephoneType.FAX).text("5555551118").next().group("item2").text("5555551119").next().types(TelephoneType.PAGER).text("5555551120").next().group("item3").text("5555551121").noMore();
asserter.address().streetAddress("111 Main St").locality("NY").region("New York").postalCode("10011").next().types(AddressType.HOME).streetAddress("112 Main St").locality("NY").region("New York").postalCode("10011").next().types(AddressType.WORK).streetAddress("113 Main St").locality("NY").region("New York").postalCode("10011").next().streetAddress("114 Main St").locality("NY").region("New York").postalCode("10011").next().group("item4").streetAddress("115 Main St").locality("NY").region("New York").postalCode("10011").noMore();
asserter.listProperty(Organization.class).values("TheCompany").noMore();
asserter.simpleProperty(Title.class).value("TheJobTitle").noMore();
asserter.dateProperty(Birthday.class).date("1912-06-23").noMore();
asserter.simpleProperty(Url.class).value("http://www.example1.com").next().group("item5").value("http://www.example2.com").next().group("item6").value("http://www.example3.com").next().group("item7").value("http://www.example4.com").next().param("TYPE", "WORK").value("http://www.example5.com").next().group("item8").value("http://www.example6.com").noMore();
asserter.simpleProperty(Note.class).value("note line 1" + NEWLINE + "note line 2" + NEWLINE + "CustomField: field value").noMore();
asserter.rawProperty("X-PHONETIC-FIRST-NAME").value("ThePhoneticFirstName").noMore();
asserter.rawProperty("X-PHONETIC-LAST-NAME").value("ThePhoneticLastName").noMore();
asserter.rawProperty("X-ABLabel").group("item1").value("CustomEmailCategory").next().group("item2").value("GRAND_CENTRAL").next().group("item3").value("CustomePhoneCategory").next().group("item4").value("CustomAddressCategory").next().group("item5").value("PROFILE").next().group("item6").value("BLOG").next().group("item7").value("_$!<HomePage>!$_").next().group("item8").value("CustomWebsiteCategory").next().group("item9").value("_$!<Anniversary>!$_").next().group("item10").value("CustomDateCategory").next().group("item11").value("_$!<Spouse>!$_").next().group("item12").value("_$!<Child>!$_").next().group("item13").value("_$!<Mother>!$_").next().group("item14").value("_$!<Father>!$_").next().group("item15").value("_$!<Parent>!$_").next().group("item16").value("_$!<Brother>!$_").next().group("item17").value("_$!<Sister>!$_").next().group("item18").value("_$!<Friend>!$_").next().group("item19").value("RELATIVE").next().group("item20").value("_$!<Manager>!$_").next().group("item21").value("_$!<Assistant>!$_").next().group("item22").value("REFERRED_BY").next().group("item23").value("_$!<Partner>!$_").next().group("item24").value("DOMESTIC_PARTNER").next().group("item25").value("CustomRelationCategory").noMore();
asserter.rawProperty("X-GTALK").value("IM2").noMore();
asserter.rawProperty("X-AIM").value("IM3").noMore();
asserter.rawProperty("X-YAHOO").value("IM4").noMore();
asserter.rawProperty("X-SKYPE").value("IM5").noMore();
asserter.rawProperty("X-QQ").value("IM6").noMore();
asserter.rawProperty("X-MSN").value("IM7").noMore();
asserter.rawProperty("X-ICQ").value("IM8").noMore();
asserter.rawProperty("X-JABBER").value("IM9").noMore();
asserter.rawProperty("X-ABDATE").group("item9").value("1930-03-20").next().value("1776-07-04").next().group("item10").value("2000-09-12").noMore();
asserter.rawProperty("X-ABRELATEDNAMES").value("Name1").next().group("item11").value("Name2").next().group("item12").value("Name3").next().group("item13").value("Name4").next().group("item14").value("Name5").next().group("item15").value("Name6").next().group("item16").value("Name7").next().group("item17").value("Name8").next().group("item18").value("Name9").next().group("item19").value("Name10").next().group("item20").value("Name11").next().group("item21").value("Name12").next().group("item22").value("Name13").next().group("item23").value("Name14").next().group("item24").value("Name15").next().group("item25").value("Name16").noMore();
VCard vcard = asserter.getVCard();
asserter.validate().prop(vcard.getEmails().get(1), // "TYPE=HOME" not valid in vCard 3.0
9).prop(vcard.getEmails().get(2), // "TYPE=WORK" not valid in vCard 3.0
9).run();
// @formatter:on
asserter.done();
}
use of ezvcard.property.asserter.VCardAsserter in project ez-vcard by mangstadt.
the class SampleVCardsTest method iPhoneVCard.
@Test
public void iPhoneVCard() throws Throwable {
VCardAsserter asserter = read("John_Doe_IPHONE.vcf");
asserter.next(V3_0);
// @formatter:off
asserter.simpleProperty(ProductId.class).value("-//Apple Inc.//iOS 5.0.1//EN").noMore();
asserter.structuredName().family("Doe").given("John").additional("Richter", "James").prefixes("Mr.").suffixes("Sr.").noMore();
asserter.simpleProperty(FormattedName.class).value("Mr. John Richter James Doe Sr.").noMore();
asserter.listProperty(Nickname.class).values("Johny").noMore();
asserter.listProperty(Organization.class).values("IBM", "Accounting").noMore();
asserter.simpleProperty(Title.class).value("Money Counter").noMore();
asserter.email().group("item1").types(EmailType.INTERNET, EmailType.PREF).value("john.doe@ibm.com").noMore();
asserter.telephone().types(TelephoneType.CELL, TelephoneType.VOICE, TelephoneType.PREF).text("905-555-1234").next().types(TelephoneType.HOME, TelephoneType.VOICE).text("905-666-1234").next().types(TelephoneType.WORK, TelephoneType.VOICE).text("905-777-1234").next().types(TelephoneType.HOME, TelephoneType.FAX).text("905-888-1234").next().types(TelephoneType.WORK, TelephoneType.FAX).text("905-999-1234").next().types(TelephoneType.PAGER).text("905-111-1234").next().group("item2").text("905-222-1234").noMore();
asserter.address().group("item3").streetAddress("Silicon Alley 5", "").locality("New York").region("New York").postalCode("12345").country("United States of America").types(AddressType.HOME, AddressType.PREF).next().group("item4").streetAddress("Street4" + NEWLINE + "Building 6" + NEWLINE + "Floor 8").locality("New York").postalCode("12345").country("USA").types(AddressType.WORK).noMore();
asserter.simpleProperty(Url.class).group("item5").value("http://www.ibm.com").param("TYPE", "pref").noMore();
asserter.dateProperty(Birthday.class).date("2012-06-06").noMore();
asserter.binaryProperty(Photo.class).param("ENCODING", "b").param("TYPE", "JPEG").contentType(ImageType.JPEG).dataLength(32531).noMore();
asserter.rawProperty("X-ABLABEL").group("item2").value("_$!<AssistantPhone>!$_").next().group("item5").value("_$!<HomePage>!$_").noMore();
asserter.rawProperty("X-ABADR").group("item3").value("Silicon Alley").next().group("item4").value("Street 4, Building 6,\\n Floor 8\\nNew York\\nUSA").noMore();
// @formatter:on
asserter.validate().run();
asserter.done();
}
Aggregations