Search in sources :

Example 11 with VCardParameters

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

the class VCardPropertyScribeTest method parseXml.

@Test
public void parseXml() {
    final VCardParameters params = new VCardParameters();
    // @formatter:off
    sensei.assertParseXml("<ignore xmlns=\"http://example.com\">ignore-me</ignore>" + "<integer>value</integer>" + "<text>ignore-me</text>").params(params).warnings((Integer) null).run(new Check<TestProperty>() {

        public void check(TestProperty property) {
            assertEquals("value", property.value);
            assertEquals(VCardDataType.INTEGER, property.parsedDataType);
            assertSame(params, property.getParameters());
        }
    });
// @formatter:on
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) Test(org.junit.Test)

Example 12 with VCardParameters

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

the class VCardPropertyScribeTest method handlePrefParam_from_4.

@Test
public void handlePrefParam_from_4() {
    VCard vcard = new VCard();
    TestProperty two = new TestProperty("");
    two.getParameters().setPref(2);
    vcard.addProperty(two);
    TestProperty nullPref = new TestProperty("");
    vcard.addProperty(nullPref);
    TestProperty invalidPref = new TestProperty("");
    invalidPref.getParameters().replace("PREF", "invalid");
    vcard.addProperty(invalidPref);
    TestProperty one = new TestProperty("");
    one.getParameters().setPref(1);
    vcard.addProperty(one);
    TestProperty three = new TestProperty("");
    three.getParameters().setPref(3);
    vcard.addProperty(three);
    // no change
    {
        VCardVersion version = V4_0;
        for (TestProperty p : vcard.getProperties(TestProperty.class)) {
            VCardParameters copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertEquals(p.getParameters(), copy);
        }
    }
    for (VCardVersion version : each(V2_1, V3_0)) {
        VCardParameters copy = new VCardParameters(one.getParameters());
        VCardPropertyScribe.handlePrefParam(one, copy, version, vcard);
        assertEquals("pref", copy.getType());
        assertNull(copy.getPref());
        for (TestProperty p : each(nullPref, invalidPref, two, three)) {
            copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertNull(copy.getType());
            assertNull(copy.getPref());
        }
    }
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 13 with VCardParameters

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

the class VCardPropertyScribeTest method handlePrefParam_to_4.

@Test
public void handlePrefParam_to_4() {
    VCard vcard = new VCard();
    TestProperty two = new TestProperty("");
    two.getParameters().setType("HOME");
    vcard.addProperty(two);
    TestProperty one = new TestProperty("");
    one.getParameters().setType("PREF");
    vcard.addProperty(one);
    TestProperty three = new TestProperty("");
    vcard.addProperty(three);
    // no change
    for (VCardVersion version : each(V2_1, V3_0)) {
        for (TestProperty p : vcard.getProperties(TestProperty.class)) {
            VCardParameters copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertEquals(p.getParameters(), copy);
        }
    }
    {
        VCardVersion version = V4_0;
        VCardParameters copy = new VCardParameters(one.getParameters());
        VCardPropertyScribe.handlePrefParam(one, copy, version, vcard);
        assertIntEquals(1, copy.getPref());
        assertNull(copy.getType());
        for (TestProperty p : each(two, three)) {
            copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertEquals(p.getParameters(), copy);
        }
    }
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 14 with VCardParameters

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

the class VCardPropertyTest method parameters.

@Test
public void parameters() {
    VCardPropertyImpl property = new VCardPropertyImpl();
    assertEquals(new VCardParameters(), property.getParameters());
    try {
        property.setParameters(null);
        fail("NPE expected.");
    } catch (NullPointerException e) {
    // expected
    }
    VCardParameters parameters = new VCardParameters();
    property.setParameters(parameters);
    assertSame(parameters, property.getParameters());
    property.addParameter("PARAM", "value");
    property.addParameter("PARAM", "value2");
    assertEquals("value", property.getParameter("PARAM"));
    assertEquals(Arrays.asList("value", "value2"), property.getParameters("PARAM"));
    VCardParameters expected = new VCardParameters();
    expected.put("PARAM", "value");
    expected.put("PARAM", "value2");
    assertEquals(expected, property.getParameters());
    property.setParameter("PARAM", "one");
    assertEquals("one", property.getParameter("PARAM"));
    assertEquals(Arrays.asList("one"), property.getParameters("PARAM"));
    expected = new VCardParameters();
    expected.put("PARAM", "one");
    assertEquals(expected, property.getParameters());
    property.removeParameter("PARAM");
    assertNull(property.getParameter("PARAM"));
    assertEquals(Arrays.asList(), property.getParameters("PARAM"));
    expected = new VCardParameters();
    assertEquals(expected, property.getParameters());
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) Test(org.junit.Test)

Example 15 with VCardParameters

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

the class PidParameterListTest method get_set.

@Test
public void get_set() {
    PidParameterListProperty property = new PidParameterListProperty();
    VCardParameters parameters = property.getParameters();
    List<Pid> pids = property.getPids();
    pids.add(new Pid(1, 1));
    parameters.put(VCardParameters.PID, "2");
    assertEquals(Arrays.asList("1.1", "2"), parameters.get(VCardParameters.PID));
    assertEquals(Arrays.asList(new Pid(1, 1), new Pid(2)), pids);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) Pid(ezvcard.parameter.Pid) 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