Search in sources :

Example 76 with VCardAsserter

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

the class JCardReaderTest method no_version.

@Test
public void no_version() throws Exception {
    // @formatter:off
    VCardAsserter asserter = readJson("[\"vcard\"," + "[" + "[\"fn\", {}, \"text\", \"John Doe\"]" + "]" + "]");
    // default to 4.0
    asserter.next(V4_0);
    asserter.simpleProperty(FormattedName.class).value("John Doe").noMore();
    asserter.warnings(29);
    asserter.done();
// @formatter:on
}
Also used : VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 77 with VCardAsserter

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

the class JCardReaderTest method cannotParseException.

@Test
public void cannotParseException() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"version\", {}, \"text\", \"4.0\"]," + "[\"cannotparse\", {}, \"text\", \"value\"]," + "[\"x-foo\", {}, \"text\", \"value\"]" + "]" + "]";
    JCardReader reader = new JCardReader(json);
    reader.registerScribe(new CannotParseScribe());
    VCardAsserter asserter = new VCardAsserter(reader);
    asserter.next(V4_0);
    asserter.rawProperty("x-foo").dataType(VCardDataType.TEXT).value("value").noMore();
    asserter.rawProperty("cannotparse").dataType(VCardDataType.TEXT).value("value").noMore();
    asserter.warnings(25);
    asserter.done();
// @formatter:on
}
Also used : CannotParseScribe(ezvcard.io.scribe.CannotParseScribe) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 78 with VCardAsserter

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

the class XCardReaderTest method skipMeException.

@Test
public void skipMeException() throws Exception {
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<skipme><text>value</text></skipme>" + "<x-foo><text>value</text></x-foo>" + "</vcard>" + "</vcards>";
    XCardReader reader = new XCardReader(xml);
    reader.registerScribe(new SkipMeScribe());
    VCardAsserter asserter = new VCardAsserter(reader);
    asserter.next(V4_0);
    asserter.rawProperty("x-foo").dataType(VCardDataType.TEXT).value("value").noMore();
    asserter.warnings(22);
    asserter.done();
// @formatter:on
}
Also used : SkipMeScribe(ezvcard.io.scribe.SkipMeScribe) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 79 with VCardAsserter

use of ezvcard.property.asserter.VCardAsserter 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();
}
Also used : UtcOffset(ezvcard.util.UtcOffset) Organization(ezvcard.property.Organization) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Key(ezvcard.property.Key) Url(ezvcard.property.Url) Test(org.junit.Test)

Example 80 with VCardAsserter

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

the class XCardReaderTest method read_multiple_vcards_elements.

@Test
public void read_multiple_vcards_elements() throws Exception {
    // @formatter:off
    VCardAsserter asserter = readXml("<root>" + "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>Dr. Gregory House M.D.</text></fn>" + "</vcard>" + "</vcards>" + "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>Dr. Lisa Cuddy M.D.</text></fn>" + "</vcard>" + "</vcards>" + "</root>");
    asserter.next(V4_0);
    asserter.simpleProperty(FormattedName.class).value("Dr. Gregory House M.D.").noMore();
    asserter.next(V4_0);
    asserter.simpleProperty(FormattedName.class).value("Dr. Lisa Cuddy M.D.").noMore();
    asserter.done();
// @formatter:on
}
Also used : VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Aggregations

VCardAsserter (ezvcard.property.asserter.VCardAsserter)86 Test (org.junit.Test)84 Url (ezvcard.property.Url)12 VCard (ezvcard.VCard)10 VCardVersion (ezvcard.VCardVersion)10 FreeBusyUrl (ezvcard.property.FreeBusyUrl)9 Note (ezvcard.property.Note)7 Organization (ezvcard.property.Organization)7 Photo (ezvcard.property.Photo)7 FormattedName (ezvcard.property.FormattedName)6 Key (ezvcard.property.Key)6 UtcOffset (ezvcard.util.UtcOffset)5 CannotParseScribe (ezvcard.io.scribe.CannotParseScribe)4 SkipMeScribe (ezvcard.io.scribe.SkipMeScribe)4 TelUri (ezvcard.util.TelUri)4 Label (ezvcard.property.Label)3 StreamReader (ezvcard.io.StreamReader)2 Categories (ezvcard.property.Categories)2 Utf8Writer (ezvcard.util.Utf8Writer)2 File (java.io.File)2