Search in sources :

Example 1 with Pid

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

the class XCardWriterTest method write_parameters.

@Test
public void write_parameters() throws Exception {
    writer.registerParameterDataType("X-INT", VCardDataType.INTEGER);
    VCard vcard = new VCard();
    Note note = new Note("This is a\nnote.");
    note.setParameter(VCardParameters.ALTID, "value");
    note.setParameter(VCardParameters.CALSCALE, "value");
    note.setParameter(VCardParameters.GEO, "geo:123.456,234.567");
    note.setParameter(VCardParameters.LABEL, "value");
    note.setParameter(VCardParameters.LANGUAGE, "en");
    note.setParameter(VCardParameters.MEDIATYPE, "text/plain");
    note.getPids().add(new Pid(1, 1));
    note.setParameter(VCardParameters.PREF, "1");
    note.setParameter(VCardParameters.SORT_AS, "value");
    note.setParameter(VCardParameters.TYPE, "home");
    note.setParameter(VCardParameters.TZ, "America/New_York");
    note.setParameter("X-CUSTOM", "xxx");
    note.setParameter("X-INT", "11");
    vcard.addNote(note);
    writer.write(vcard);
    writer.close();
    // @formatter:off
    String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<note>" + "<parameters>" + "<altid><text>value</text></altid>" + "<calscale><text>value</text></calscale>" + "<geo><uri>geo:123.456,234.567</uri></geo>" + "<label><text>value</text></label>" + "<language><language-tag>en</language-tag></language>" + "<mediatype><text>text/plain</text></mediatype>" + "<pid><text>1.1</text></pid>" + "<pref><integer>1</integer></pref>" + "<sort-as><text>value</text></sort-as>" + "<type><text>home</text></type>" + "<tz><uri>America/New_York</uri></tz>" + "<x-custom><unknown>xxx</unknown></x-custom>" + "<x-int><integer>11</integer></x-int>" + "</parameters>" + "<text>This is a\nnote.</text>" + "</note>" + "</vcard>" + "</vcards>";
    // @formatter:on
    assertOutput(expected);
}
Also used : Note(ezvcard.property.Note) Pid(ezvcard.parameter.Pid) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 2 with Pid

use of ezvcard.parameter.Pid 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)

Example 3 with Pid

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

the class XCardDocumentTest method add_parameters.

@Test
public void add_parameters() throws Throwable {
    VCard vcard = new VCard();
    Note note = new Note("This is a\nnote.");
    note.setParameter(VCardParameters.ALTID, "value");
    note.setParameter(VCardParameters.CALSCALE, "value");
    note.setParameter(VCardParameters.GEO, "geo:123.456,234.567");
    note.setParameter(VCardParameters.LABEL, "value");
    note.setParameter(VCardParameters.LANGUAGE, "en");
    note.setParameter(VCardParameters.MEDIATYPE, "text/plain");
    note.getPids().add(new Pid(1, 1));
    note.setParameter(VCardParameters.PREF, "1");
    note.setParameter(VCardParameters.SORT_AS, "value");
    note.setParameter(VCardParameters.TYPE, "home");
    note.setParameter(VCardParameters.TZ, "America/New_York");
    note.setParameter("X-CUSTOM", "xxx");
    note.setParameter("X-INT", "11");
    vcard.addNote(note);
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.registerParameterDataType("X-INT", VCardDataType.INTEGER);
    writer.registerParameterDataType("X-CUSTOM", VCardDataType.BOOLEAN);
    writer.registerParameterDataType("X-CUSTOM", null);
    writer.write(vcard);
    Document actual = xcard.getDocument();
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<note>" + "<parameters>" + "<altid><text>value</text></altid>" + "<calscale><text>value</text></calscale>" + "<geo><uri>geo:123.456,234.567</uri></geo>" + "<label><text>value</text></label>" + "<language><language-tag>en</language-tag></language>" + "<mediatype><text>text/plain</text></mediatype>" + "<pid><text>1.1</text></pid>" + "<pref><integer>1</integer></pref>" + "<sort-as><text>value</text></sort-as>" + "<type><text>home</text></type>" + "<tz><uri>America/New_York</uri></tz>" + "<x-custom><unknown>xxx</unknown></x-custom>" + "<x-int><integer>11</integer></x-int>" + "</parameters>" + "<text>This is a\nnote.</text>" + "</note>" + "</vcard>" + "</vcards>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(expected, actual);
}
Also used : Note(ezvcard.property.Note) XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) Pid(ezvcard.parameter.Pid) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 4 with Pid

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

the class PidParameterListTest method invalid_value.

@Test
public void invalid_value() {
    PidParameterListProperty property = new PidParameterListProperty();
    VCardParameters parameters = property.getParameters();
    List<Pid> pids = property.getPids();
    parameters.put(VCardParameters.PID, "foobar");
    try {
        pids.get(0);
        fail();
    } catch (IllegalStateException e) {
        assertTrue(e.getCause() instanceof NumberFormatException);
    }
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) Pid(ezvcard.parameter.Pid) Test(org.junit.Test)

Aggregations

Pid (ezvcard.parameter.Pid)4 Test (org.junit.Test)4 VCard (ezvcard.VCard)2 VCardParameters (ezvcard.parameter.VCardParameters)2 Note (ezvcard.property.Note)2 XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)1 Document (org.w3c.dom.Document)1