Search in sources :

Example 11 with VCardVersion

use of ezvcard.VCardVersion 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 12 with VCardVersion

use of ezvcard.VCardVersion in project ez-vcard by mangstadt.

the class VCardReaderTest method embedded_vcard.

@Test
public void embedded_vcard() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        /*
			 * Test against all versions, even though embedded vCards are only
			 * supported by 3.0.
			 */
        // @formatter:off
        String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "AGENT:" + "BEGIN:VCARD\\n" + "VERSION:" + version + "\\n" + "FN:Agent 007\\n" + "AGENT:" + "BEGIN:VCARD\\\\n" + "VERSION:" + version + "\\\\n" + "FN:Agent 009\\\\n" + "END:VCARD\\\\n" + "END:VCARD\r\n" + "FN:John Doe\r\n" + "END:VCARD\r\n";
        // @formatter:on
        VCardReader reader = new VCardReader(str);
        VCard vcard = reader.readNext();
        assertVersion(version, vcard);
        assertPropertyCount(2, vcard);
        assertEquals("John Doe", vcard.getFormattedName().getValue());
        {
            VCard agentVCard = vcard.getAgent().getVCard();
            assertVersion(version, agentVCard);
            assertPropertyCount(2, agentVCard);
            assertEquals("Agent 007", agentVCard.getFormattedName().getValue());
            {
                VCard agentAgentVCard = agentVCard.getAgent().getVCard();
                assertVersion(version, agentAgentVCard);
                assertPropertyCount(1, agentAgentVCard);
                assertEquals("Agent 009", agentAgentVCard.getFormattedName().getValue());
            }
        }
        assertParseWarnings(reader);
        assertNoMoreVCards(reader);
    }
}
Also used : VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 13 with VCardVersion

use of ezvcard.VCardVersion 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 14 with VCardVersion

use of ezvcard.VCardVersion in project ez-vcard by mangstadt.

the class VCardParameterTest method isSupportedBy.

@Test
public void isSupportedBy() {
    assertTrue(VCardParameterImpl.ONE.isSupportedBy(VCardVersion.V2_1));
    assertFalse(VCardParameterImpl.ONE.isSupportedBy(VCardVersion.V3_0));
    assertFalse(VCardParameterImpl.ONE.isSupportedBy(VCardVersion.V4_0));
    for (VCardVersion version : VCardVersion.values()) {
        assertTrue(VCardParameterImpl.TWO.isSupportedBy(version));
    }
    VCardParameterImpl three = new VCardParameterImpl("three");
    for (VCardVersion version : VCardVersion.values()) {
        assertTrue(three.isSupportedBy(version));
    }
}
Also used : VCardVersion(ezvcard.VCardVersion) Test(org.junit.Test)

Example 15 with VCardVersion

use of ezvcard.VCardVersion in project ez-vcard by mangstadt.

the class AgentScribeTest method writeText.

@Test
public void writeText() {
    sensei.assertWriteText(withUrl).run(url);
    for (VCardVersion version : values()) {
        try {
            scribe.writeText(withVCard, new WriteContext(version, null, false));
            fail();
        } catch (EmbeddedVCardException e) {
            assertEquals(vcard, e.getVCard());
        }
    }
    sensei.assertWriteText(empty).skipMe();
}
Also used : EmbeddedVCardException(ezvcard.io.EmbeddedVCardException) VCardVersion(ezvcard.VCardVersion) WriteContext(ezvcard.io.text.WriteContext) Test(org.junit.Test)

Aggregations

VCardVersion (ezvcard.VCardVersion)36 Test (org.junit.Test)30 VCard (ezvcard.VCard)14 VCardAsserter (ezvcard.property.asserter.VCardAsserter)10 VCardParameters (ezvcard.parameter.VCardParameters)5 Label (ezvcard.property.Label)4 RawProperty (ezvcard.property.RawProperty)4 VCardProperty (ezvcard.property.VCardProperty)4 Address (ezvcard.property.Address)3 ProductId (ezvcard.property.ProductId)3 VCardDataType (ezvcard.VCardDataType)2 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)2 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)2 ArrayList (java.util.ArrayList)2 SyntaxStyle (com.github.mangstadt.vinnie.SyntaxStyle)1 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)1 AllowedCharacters (com.github.mangstadt.vinnie.validate.AllowedCharacters)1 ValidationWarning (ezvcard.ValidationWarning)1 LuckyNumProperty (ezvcard.io.LuckyNumProperty)1 LuckyNumScribe (ezvcard.io.LuckyNumProperty.LuckyNumScribe)1