Search in sources :

Example 6 with XCardDocumentStreamWriter

use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.

the class XCardDocumentTest method write_prettyPrint_invalid_value.

@Test
public void write_prettyPrint_invalid_value() throws Throwable {
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.write(vcard);
    String actual = xcard.write();
    String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\"><vcard><fn><text>John Doe</text></fn></vcard></vcards>";
    // use "String.contains()" to ignore the XML declaration at the top
    assertTrue("Expected:" + NEWLINE + expected + NEWLINE + NEWLINE + "Actual:" + NEWLINE + actual, actual.contains(expected));
}
Also used : XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 7 with XCardDocumentStreamWriter

use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.

the class XCardDocumentTest method add_embedded_vcards_not_supported.

@Test
public void add_embedded_vcards_not_supported() throws Throwable {
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    vcard.addProperty(new EmbeddedProperty());
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.registerScribe(new EmbeddedScribe());
    writer.write(vcard);
    VCard parsedVCard = Ezvcard.parseXml(xcard.write()).first();
    assertTrue(parsedVCard.getExtendedProperties().isEmpty());
}
Also used : XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 8 with XCardDocumentStreamWriter

use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.

the class XCardDocumentTest method add_extendedTypes.

@Test
public void add_extendedTypes() throws Throwable {
    VCard vcard = new VCard();
    // contains marshal methods and QName
    LuckyNumProperty num = new LuckyNumProperty(24);
    vcard.addProperty(num);
    // contains marshal methods, but does not have a QName
    SalaryProperty salary = new SalaryProperty(1000000);
    vcard.addProperty(salary);
    // does not contain marshal methods nor QName
    AgeProperty age = new AgeProperty(22);
    vcard.addProperty(age);
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.registerScribe(new LuckyNumScribe());
    writer.registerScribe(new SalaryScribe());
    writer.registerScribe(new AgeScribe());
    writer.write(vcard);
    Document actual = xcard.getDocument();
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<a:lucky-num xmlns:a=\"http://luckynum.com\">24</a:lucky-num>" + "<x-salary>1000000</x-salary>" + "<x-age><unknown>22</unknown></x-age>" + "</vcard>" + "</vcards>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(XmlUtils.toString(actual), expected, actual);
}
Also used : AgeScribe(ezvcard.io.AgeProperty.AgeScribe) AgeProperty(ezvcard.io.AgeProperty) SalaryProperty(ezvcard.io.SalaryProperty) XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) LuckyNumScribe(ezvcard.io.LuckyNumProperty.LuckyNumScribe) SalaryScribe(ezvcard.io.SalaryProperty.SalaryScribe) LuckyNumProperty(ezvcard.io.LuckyNumProperty) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 9 with XCardDocumentStreamWriter

use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.

the class XCardDocumentTest method add_skipMeException.

@Test
public void add_skipMeException() throws Throwable {
    VCard vcard = new VCard();
    vcard.addProperty(new SkipMeProperty());
    vcard.addExtendedProperty("x-foo", "value");
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.registerScribe(new SkipMeScribe());
    writer.write(vcard);
    Document actual = xcard.getDocument();
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<x-foo><unknown>value</unknown></x-foo>" + "</vcard>" + "</vcards>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(expected, actual);
}
Also used : XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) SkipMeScribe(ezvcard.io.scribe.SkipMeScribe) SkipMeProperty(ezvcard.property.SkipMeProperty) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 10 with XCardDocumentStreamWriter

use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.

the class XCardDocumentTest method assertExample.

private static void assertExample(VCard vcard, String exampleFileName) throws IOException, SAXException {
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.write(vcard);
    Document expected = XmlUtils.toDocument(new InputStreamReader(XCardDocumentTest.class.getResourceAsStream(exampleFileName)));
    Document actual = xcard.getDocument();
    assertXMLEqual(XmlUtils.toString(actual), expected, actual);
}
Also used : InputStreamReader(java.io.InputStreamReader) XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) Document(org.w3c.dom.Document)

Aggregations

XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)15 VCard (ezvcard.VCard)14 Test (org.junit.Test)13 Document (org.w3c.dom.Document)11 Note (ezvcard.property.Note)2 Xml (ezvcard.property.Xml)2 VCardDataType (ezvcard.VCardDataType)1 AgeProperty (ezvcard.io.AgeProperty)1 AgeScribe (ezvcard.io.AgeProperty.AgeScribe)1 LuckyNumProperty (ezvcard.io.LuckyNumProperty)1 LuckyNumScribe (ezvcard.io.LuckyNumProperty.LuckyNumScribe)1 SalaryProperty (ezvcard.io.SalaryProperty)1 SalaryScribe (ezvcard.io.SalaryProperty.SalaryScribe)1 SkipMeScribe (ezvcard.io.scribe.SkipMeScribe)1 XCardDocument (ezvcard.io.xml.XCardDocument)1 Pid (ezvcard.parameter.Pid)1 Photo (ezvcard.property.Photo)1 SkipMeProperty (ezvcard.property.SkipMeProperty)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1