Search in sources :

Example 56 with VCardAsserter

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

the class VCardReaderTest method cannotParseException.

@Test
public void cannotParseException() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "group.CANNOTPARSE;PARAM=value;VALUE=text:value\r\n" + "X-FOO:value\r\n" + "END:VCARD\r\n";
        VCardReader reader = new VCardReader(str);
        reader.registerScribe(new CannotParseScribe());
        VCardAsserter asserter = new VCardAsserter(reader);
        asserter.next(version);
        asserter.rawProperty("X-FOO").value("value").noMore();
        asserter.rawProperty("CANNOTPARSE").group("group").param("PARAM", "value").dataType(VCardDataType.TEXT).value("value").noMore();
        asserter.warnings(25);
        asserter.done();
    // @formatter:on
    }
}
Also used : CannotParseScribe(ezvcard.io.scribe.CannotParseScribe) VCardVersion(ezvcard.VCardVersion) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 57 with VCardAsserter

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

the class VCardReaderTest method type_parameter_enclosed_in_double_quotes.

/**
 * Account for an error in the 4.0 specification, which places multi-valued
 * TYPE parameters in double quotes.
 */
@Test
public void type_parameter_enclosed_in_double_quotes() throws Exception {
    VCardVersion version = V2_1;
    {
        // @formatter:off
        VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "PROP;TYPE=\"one,two,,three\";FOO=\"four,five,,six\":\r\n" + "END:VCARD\r\n");
        asserter.next(version);
        asserter.rawProperty("PROP").param("TYPE", "\"one,two,,three\"").param("FOO", "\"four,five,,six\"").value("").noMore();
        asserter.done();
    // @formatter:on
    }
    for (VCardVersion v : each(V3_0, V4_0)) {
        // @formatter:off
        VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + v + "\r\n" + "PROP;TYPE=\"one,two,,three\";FOO=\"four,five,,six\":\r\n" + "END:VCARD\r\n");
        asserter.next(v);
        asserter.rawProperty("PROP").param("TYPE", "one", "two", "", "three").param("FOO", "four,five,,six").value("").noMore();
        asserter.done();
    // @formatter:on
    }
}
Also used : VCardVersion(ezvcard.VCardVersion) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 58 with VCardAsserter

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

the class XCardDocumentTest method read_groups.

@Test
public void read_groups() throws Exception {
    // @formatter:off
    VCardAsserter asserter = readXml("<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<group name=\"item1\">" + "<fn><text>John Doe</text></fn>" + "<note><text>Hello world!</text></note>" + "</group>" + "<group>" + "<prodid><text>no name attribute</text></prodid>" + "</group>" + "<note><text>A property without a group</text></note>" + "</vcard>" + "</vcards>");
    asserter.next(V4_0);
    asserter.simpleProperty(FormattedName.class).group("item1").value("John Doe").noMore();
    asserter.simpleProperty(Note.class).group("item1").value("Hello world!").next().value("A property without a group").noMore();
    asserter.simpleProperty(ProductId.class).value("no name attribute").noMore();
    asserter.done();
// @formatter:on
}
Also used : FormattedName(ezvcard.property.FormattedName) Note(ezvcard.property.Note) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 59 with VCardAsserter

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

the class XCardDocumentTest method read_parameters.

@Test
public void read_parameters() throws Exception {
    // @formatter:off
    VCardAsserter asserter = readXml("<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + // zero params
    "<note>" + "<text>Note 1</text>" + "</note>" + // one param
    "<note>" + "<parameters>" + "<altid><text>1</text></altid>" + "</parameters>" + "<text>Hello world!</text>" + "</note>" + // one param, but doesn't have a value element, so it should be ignored
    "<note>" + "<parameters>" + "<altid>1</altid>" + "</parameters>" + "<text>Hallo Welt!</text>" + "</note>" + // two params
    "<note>" + "<parameters>" + "<altid><text>1</text></altid>" + "<language><language-tag>fr</language-tag></language>" + "</parameters>" + "<text>Bonjour tout le monde!</text>" + "</note>" + // a param with multiple values
    "<tel>" + "<parameters>" + "<type>" + "<text>work</text>" + "<text>voice</text>" + "</type>" + "</parameters>" + "<uri>tel:+1-555-555-1234</uri>" + "</tel>" + "</vcard>" + "</vcards>");
    asserter.next(V4_0);
    asserter.simpleProperty(Note.class).value("Note 1").next().value("Hello world!").param("ALTID", "1").next().value("Hallo Welt!").next().value("Bonjour tout le monde!").param("ALTID", "1").param("LANGUAGE", "fr").noMore();
    asserter.telephone().uri(new TelUri.Builder("+1-555-555-1234").build()).types(TelephoneType.WORK, TelephoneType.VOICE).noMore();
    asserter.done();
// @formatter:on
}
Also used : Note(ezvcard.property.Note) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 60 with VCardAsserter

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

the class XCardDocumentTest method readFile.

private static VCardAsserter readFile(String file) throws SAXException, IOException {
    XCardDocument document = new XCardDocument(XCardDocumentTest.class.getResourceAsStream(file));
    StreamReader reader = document.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