use of ezvcard.property.Xml in project ez-vcard by mangstadt.
the class XCardDocumentTest method add_xml_property_with_null_value.
@Test
public void add_xml_property_with_null_value() throws Throwable {
VCard vcard = new VCard();
Xml xmlProperty = new Xml((Document) null);
vcard.addXml(xmlProperty);
XCardDocument xcard = new XCardDocument();
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.write(vcard);
Document actual = xcard.getDocument();
// @formatter:off
String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard />" + "</vcards>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
assertXMLEqual(expected, actual);
}
use of ezvcard.property.Xml in project ez-vcard by mangstadt.
the class XCardDocumentTest method add_xml_property.
@Test
public void add_xml_property() throws Throwable {
VCard vcard = new VCard();
Xml xmlProperty = new Xml("<foo xmlns=\"http://example.com\" a=\"b\">bar<car/></foo>");
xmlProperty.addParameter("name", "value");
vcard.addXml(xmlProperty);
XCardDocument xcard = new XCardDocument();
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.write(vcard);
Document actual = xcard.getDocument();
// @formatter:off
String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<foo xmlns=\"http://example.com\" a=\"b\">" + "<parameters xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<name><unknown>value</unknown></name>" + "</parameters>" + "bar<car/>" + "</foo>" + "</vcard>" + "</vcards>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
/*
* When using xalan as the JAXP parser, XMLUnit thinks the <name>
* element in the "actual" DOM has the wrong namespace. But when you
* inspect the DOM yourself, the <name> element *does* have the correct
* namespace!
*
* As a workaround, let's compare the string versions of the two DOMs.
*/
assertEquals(XmlUtils.toString(expected), XmlUtils.toString(actual));
// assertXMLEqual(expected, actual);
}
use of ezvcard.property.Xml in project ez-vcard by mangstadt.
the class XCardReaderTest method read_non_standard_properties.
@Test
public void read_non_standard_properties() throws Exception {
// @formatter:off
String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + // expected: XML property
"<foo xmlns=\"http://example.com\">bar</foo>" + // expected: LuckyNumProperty
"<a:lucky-num xmlns:a=\"http://luckynum.com\"><a:num>21</a:num></a:lucky-num>" + // expected: SalaryProperty
"<x-salary><integer>1000000</integer></x-salary>" + // expected: AgeProperty (should be unmarshalled using the default parseXml implementation)
"<x-age><integer>24</integer></x-age>" + // expected: RawProperty
"<x-gender><text>m</text></x-gender>" + // expected: MyFormattedNameProperty
"<fn><name>John Doe</name></fn>" + "</vcard>" + "</vcards>";
// @formatter:on
XCardReader reader = new XCardReader(xml);
reader.registerScribe(new LuckyNumScribe());
reader.registerScribe(new SalaryScribe());
reader.registerScribe(new AgeScribe());
reader.registerScribe(new MyFormattedNameScribe());
{
VCard vcard = reader.readNext();
assertVersion(V4_0, vcard);
assertPropertyCount(6, vcard);
{
Iterator<Xml> xmlIt = vcard.getXmls().iterator();
Xml xmlType = xmlIt.next();
assertXMLEqual(XmlUtils.toDocument("<foo xmlns=\"http://example.com\">bar</foo>"), xmlType.getValue());
assertFalse(xmlIt.hasNext());
}
LuckyNumProperty luckyNum = vcard.getProperty(LuckyNumProperty.class);
assertEquals(21, luckyNum.luckyNum);
SalaryProperty salary = vcard.getProperty(SalaryProperty.class);
assertEquals(1000000, salary.salary);
AgeProperty age = vcard.getProperty(AgeProperty.class);
assertEquals(24, age.age);
RawProperty gender = vcard.getExtendedProperty("X-GENDER");
assertEquals(VCardDataType.TEXT, gender.getDataType());
assertEquals("m", gender.getValue());
MyFormattedNameProperty fn = vcard.getProperty(MyFormattedNameProperty.class);
assertEquals("JOHN DOE", fn.value);
assertParseWarnings(reader);
}
assertNoMoreVCards(reader);
}
use of ezvcard.property.Xml in project ez-vcard by mangstadt.
the class XCardWriterTest method write_xml_property.
@Test
public void write_xml_property() throws Exception {
VCard vcard = new VCard();
Xml xml = new Xml("<foo xmlns=\"http://example.com\" a=\"b\">bar<car/></foo>");
xml.setParameter("x-foo", "bar");
vcard.addXml(xml);
writer.write(vcard);
writer.close();
// @formatter:off
String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<foo xmlns=\"http://example.com\" a=\"b\">" + "<parameters xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<x-foo><unknown>bar</unknown></x-foo>" + "</parameters>" + "bar<car/>" + "</foo>" + "</vcard>" + "</vcards>";
// @formatter:on
assertOutput(expected);
}
use of ezvcard.property.Xml in project ez-vcard by mangstadt.
the class XCardWriterTest method write_xml_property_null_value.
@Test
public void write_xml_property_null_value() throws Exception {
VCard vcard = new VCard();
vcard.addXml(new Xml((Document) null));
writer.write(vcard);
writer.close();
// @formatter:off
String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard />" + "</vcards>";
// @formatter:on
assertOutput(expected);
}
Aggregations