Search in sources :

Example 21 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class JCardRawReaderTest method data_type_unrecognized.

@Test
public void data_type_unrecognized() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"foo\", \"value\"]" + "]" + "]";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    reader.readNext(listener);
    verify(listener).beginVCard();
    verify(listener).readProperty(null, "prop", new VCardParameters(), VCardDataType.get("foo"), JCardValue.single("value"));
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 22 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class JCardRawReaderTest method basic.

@Test
public void basic() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"prop1\", {}, \"text\", \"one\"]," + "[\"prop2\", {}, \"integer\", 2]" + "]" + "]";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    reader.readNext(listener);
    verify(listener).beginVCard();
    verify(listener).readProperty(null, "prop1", new VCardParameters(), VCardDataType.TEXT, JCardValue.single("one"));
    verify(listener).readProperty(null, "prop2", new VCardParameters(), VCardDataType.INTEGER, JCardValue.single(2L));
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 23 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class JCardRawReaderTest method multi_value.

@Test
public void multi_value() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"text\", \"one\", \"two\", \"three\" ]," + "[\"prop\", {}, \"text\", \"one\" ]" + "]" + "]";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    reader.readNext(listener);
    verify(listener).beginVCard();
    verify(listener).readProperty(null, "prop", new VCardParameters(), VCardDataType.TEXT, JCardValue.multi("one", "two", "three"));
    verify(listener).readProperty(null, "prop", new VCardParameters(), VCardDataType.TEXT, JCardValue.multi("one"));
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 24 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class JCardRawReaderTest method parameters.

@Test
public void parameters() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"prop\", { \"a\": \"one\", \"b\": [\"two\"], \"c\": [\"three\", \"four\"] }, \"text\", \"value\"]" + "]" + "]";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    reader.readNext(listener);
    VCardParameters expected = new VCardParameters();
    expected.put("a", "one");
    expected.put("b", "two");
    expected.put("c", "three");
    expected.put("c", "four");
    verify(listener).beginVCard();
    verify(listener).readProperty(null, "prop", expected, VCardDataType.TEXT, JCardValue.single("value"));
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 25 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class JCardRawReaderTest method bad_snytax.

@Test
public void bad_snytax() throws Throwable {
    // @formatter:off
    String json = "[" + "[\"vcard\"," + "[" + "[\"prop1\", {}, \"text\", \"one\"]," + "[\"prop2\", {}, []]" + "]" + "]," + "[\"vcard\"," + "[" + "[\"prop1\", {}, \"text\", \"one\"]," + "[\"prop2\", {}, \"integer\", 2]" + "]" + "]" + "]";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    try {
        reader.readNext(listener);
        fail("JCardParseException expected.");
    } catch (JCardParseException e) {
        assertEquals(JsonToken.VALUE_STRING, e.getExpectedToken());
        assertEquals(JsonToken.START_ARRAY, e.getActualToken());
    }
    reader.readNext(listener);
    verify(listener, times(2)).beginVCard();
    verify(listener, times(2)).readProperty(null, "prop1", new VCardParameters(), VCardDataType.TEXT, JCardValue.single("one"));
    verify(listener).readProperty(null, "prop2", new VCardParameters(), VCardDataType.INTEGER, JCardValue.single(2L));
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Aggregations

VCardParameters (ezvcard.parameter.VCardParameters)32 Test (org.junit.Test)24 JCardDataStreamListener (ezvcard.io.json.JCardRawReader.JCardDataStreamListener)12 VCard (ezvcard.VCard)5 VCardVersion (ezvcard.VCardVersion)5 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)4 VCardDataType (ezvcard.VCardDataType)3 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)3 SkipMeException (ezvcard.io.SkipMeException)3 VCardProperty (ezvcard.property.VCardProperty)3 StringWriter (java.io.StringWriter)3 Pid (ezvcard.parameter.Pid)2 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)1 ParseContext (ezvcard.io.ParseContext)1 JCardValue (ezvcard.io.json.JCardValue)1 Xml (ezvcard.property.Xml)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1