Search in sources :

Example 1 with VCardParameters

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

the class JCardRawReaderTest method structured_value.

@Test
public void structured_value() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"text\", [\"one\", [\"two\", \"three\"], \"four\"] ]," + "[\"prop\", {}, \"text\", [] ]" + "]" + "]";
    // @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.structured("one", Arrays.asList("two", "three"), "four"));
    verify(listener).readProperty(null, "prop", new VCardParameters(), VCardDataType.TEXT, JCardValue.structured());
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 2 with VCardParameters

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

the class JCardRawReaderTest method read_multiple.

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

Example 3 with VCardParameters

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

the class JCardRawReaderTest method data_type_unknown.

@Test
public void data_type_unknown() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"unknown\", \"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(), null, JCardValue.single("value"));
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 4 with VCardParameters

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

the class JCardRawReaderTest method complex_value.

@Test
public void complex_value() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"text\", {" + "\"a\":[\"one\",\"two\"]," + "\"b\":{" + "\"c\":[\"three\"]," + "\"d\":{}" + "}" + "}, \"four\" ]" + "]" + "]";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    reader.readNext(listener);
    List<JsonValue> expectedValues = new ArrayList<JsonValue>();
    Map<String, JsonValue> m = new HashMap<String, JsonValue>();
    {
        // @formatter:off
        m.put("a", new JsonValue(Arrays.asList(new JsonValue("one"), new JsonValue("two"))));
        Map<String, JsonValue> m2 = new HashMap<String, JsonValue>();
        {
            m2.put("c", new JsonValue(Arrays.asList(new JsonValue("three"))));
            m2.put("d", new JsonValue(new HashMap<String, JsonValue>()));
        }
        m.put("b", new JsonValue(m2));
    // @formatter:on
    }
    expectedValues.add(new JsonValue(m));
    expectedValues.add(new JsonValue("four"));
    JCardValue expected = new JCardValue(expectedValues);
    verify(listener).beginVCard();
    verify(listener).readProperty(null, "prop", new VCardParameters(), VCardDataType.TEXT, expected);
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) HashMap(java.util.HashMap) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with VCardParameters

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

the class JCardRawWriterTest method parameters.

@Test
public void parameters() throws Throwable {
    StringWriter sw = new StringWriter();
    JCardRawWriter writer = new JCardRawWriter(sw, false);
    writer.writeStartVCard();
    VCardParameters parameters = new VCardParameters();
    parameters.put("a", "value1");
    parameters.put("b", "value2");
    parameters.put("b", "value3");
    writer.writeProperty(null, "prop", parameters, VCardDataType.TEXT, JCardValue.single("value"));
    writer.close();
    String actual = sw.toString();
    // @formatter:off
    String expected = "[\"vcard\"," + "[" + "[\"prop\",{\"a\":\"value1\",\"b\":[\"value2\",\"value3\"]},\"text\",\"value\"]" + "]" + "]";
    // @formatter:on
    assertEquals(expected, actual);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) StringWriter(java.io.StringWriter) 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