use of ezvcard.io.SalaryProperty 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);
}
use of ezvcard.io.SalaryProperty 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.io.SalaryProperty in project ez-vcard by mangstadt.
the class XCardWriterTest method write_extended_properties.
@Test
public void write_extended_properties() throws Exception {
writer.registerScribe(new LuckyNumScribe());
writer.registerScribe(new SalaryScribe());
writer.registerScribe(new AgeScribe());
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);
writer.write(vcard);
writer.close();
// @formatter:off
String expected = "<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>";
// @formatter:on
assertOutput(expected);
}
Aggregations