Search in sources :

Example 31 with VCardAsserter

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

the class VCardReaderTest method read_multiple.

@Test
public void read_multiple() throws Exception {
    // @formatter:off
    VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "FN:John Doe\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "FN:Jane Doe\r\n" + "END:VCARD\r\n");
    asserter.next(V2_1);
    asserter.simpleProperty(FormattedName.class).value("John Doe").noMore();
    asserter.next(V3_0);
    asserter.simpleProperty(FormattedName.class).value("Jane Doe").noMore();
    asserter.done();
// @formatter:on
}
Also used : VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 32 with VCardAsserter

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

the class VCardReaderTest method label_properties.

/**
 * LABEL properties should be assigned to an ADR and stored in the
 * "Address.getLabel()" field. LABELs that could not be assigned to an ADR
 * should go in "VCard.getOrphanedLabels()".
 */
@Test
public void label_properties() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + version.getVersion() + "\r\n" + "ADR;TYPE=home;TYPE=parcel:;;123 Main St.;Austin;TX;91827;USA\r\n" + "LABEL;TYPE=parcel;TYPE=home:123 Main St.\\nAustin\\, TX 91827\\nUSA\r\n" + "ADR;TYPE=work:;;200 Broadway;New York;NY;12345;USA\r\n" + "LABEL;TYPE=parcel:200 Broadway\\nNew York\\, NY 12345\\nUSA\r\n" + "END:VCARD\r\n");
        asserter.next(version);
        asserter.address().streetAddress("123 Main St.").locality("Austin").region("TX").postalCode("91827").country("USA").label("123 Main St." + NEWLINE + "Austin, TX 91827" + NEWLINE + "USA").types(AddressType.HOME, AddressType.PARCEL).next().streetAddress("200 Broadway").locality("New York").region("NY").postalCode("12345").country("USA").types(AddressType.WORK).noMore();
        asserter.simpleProperty(Label.class).value("200 Broadway" + NEWLINE + "New York, NY 12345" + NEWLINE + "USA").param("TYPE", "parcel").noMore();
        asserter.done();
    // @formatter:on
    }
}
Also used : Label(ezvcard.property.Label) VCardVersion(ezvcard.VCardVersion) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 33 with VCardAsserter

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

the class VCardReaderTest method nameless_parameters.

/**
 * All nameless parameters should be assigned a name.
 */
@Test
public void nameless_parameters() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "PROP;TEXT;QUOTED-PRINTABLE;HOME;FOO:\r\n" + "END:VCARD\r\n");
        asserter.next(version);
        asserter.rawProperty("PROP").param("ENCODING", "QUOTED-PRINTABLE").param("TYPE", "HOME", "FOO").dataType(VCardDataType.TEXT).value("").noMore();
        asserter.done();
    // @formatter:on
    }
}
Also used : VCardVersion(ezvcard.VCardVersion) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 34 with VCardAsserter

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

the class VCardReaderTest method skipMeException.

@Test
public void skipMeException() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "SKIPME:value\r\n" + "X-FOO:value\r\n" + "END:VCARD\r\n";
        VCardReader reader = new VCardReader(str);
        reader.registerScribe(new SkipMeScribe());
        VCardAsserter asserter = new VCardAsserter(reader);
        asserter.next(version);
        asserter.rawProperty("X-FOO").value("value").noMore();
        asserter.warnings(22);
        asserter.done();
    // @formatter:on
    }
}
Also used : SkipMeScribe(ezvcard.io.scribe.SkipMeScribe) VCardVersion(ezvcard.VCardVersion) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 35 with VCardAsserter

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

the class XCardDocumentTest method readXml.

private static VCardAsserter readXml(String xml) throws SAXException {
    XCardDocument xcard = new XCardDocument(xml);
    StreamReader reader = xcard.reader();
    return new VCardAsserter(reader);
}
Also used : StreamReader(ezvcard.io.StreamReader) InputStreamReader(java.io.InputStreamReader) VCardAsserter(ezvcard.property.asserter.VCardAsserter)

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