mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-04 20:22:07 +01:00
1f8cb4452b
2 - Throw exception if parsing of vCard fails. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7217 b35dd754-fafc-0310-a699-88a17e54d16e
187 lines
9.1 KiB
Java
187 lines
9.1 KiB
Java
package org.jivesoftware.smackx;
|
|
|
|
import org.jivesoftware.smack.XMPPException;
|
|
import org.jivesoftware.smack.test.SmackTestCase;
|
|
import org.jivesoftware.smack.util.StringUtils;
|
|
import org.jivesoftware.smackx.packet.VCard;
|
|
import org.jivesoftware.smackx.provider.VCardProvider;
|
|
|
|
/**
|
|
* Created by IntelliJ IDEA.
|
|
* User: Gaston
|
|
* Date: Jun 18, 2005
|
|
* Time: 1:29:30 AM
|
|
* To change this template use File | Settings | File Templates.
|
|
*/
|
|
public class VCardTest extends SmackTestCase {
|
|
|
|
public VCardTest(String arg0) {
|
|
super(arg0);
|
|
}
|
|
|
|
public void testBigFunctional() throws XMPPException {
|
|
VCard origVCard = new VCard();
|
|
|
|
origVCard.setFirstName("kir");
|
|
origVCard.setLastName("max");
|
|
origVCard.setEmailHome("foo@fee.bar");
|
|
origVCard.setEmailWork("foo@fee.www.bar");
|
|
|
|
origVCard.setJabberId("jabber@id.org");
|
|
origVCard.setOrganization("Jetbrains, s.r.o");
|
|
origVCard.setNickName("KIR");
|
|
|
|
origVCard.setField("TITLE", "Mr");
|
|
origVCard.setAddressFieldHome("STREET", "Some street & House");
|
|
origVCard.setAddressFieldWork("STREET", "Some street work");
|
|
|
|
origVCard.setPhoneWork("FAX", "3443233");
|
|
origVCard.setPhoneHome("VOICE", "3443233");
|
|
|
|
origVCard.save(getConnection(0));
|
|
|
|
VCard loaded = new VCard();
|
|
try {
|
|
loaded.load(getConnection(0));
|
|
} catch (XMPPException e) {
|
|
e.printStackTrace();
|
|
fail(e.getMessage());
|
|
}
|
|
|
|
assertEquals("Should load own VCard successfully", origVCard.toString(), loaded.toString());
|
|
|
|
loaded = new VCard();
|
|
try {
|
|
loaded.load(getConnection(1), getBareJID(0));
|
|
} catch (XMPPException e) {
|
|
e.printStackTrace();
|
|
fail(e.getMessage());
|
|
}
|
|
|
|
assertEquals("Should load another user's VCard successfully", origVCard.toString(), loaded.toString());
|
|
}
|
|
|
|
public void testNoWorkHomeSpecifier_EMAIL() throws Throwable {
|
|
VCard card = VCardProvider.createVCardFromXML("<vcard><EMAIL><USERID>foo@fee.www.bar</USERID></EMAIL></vcard>");
|
|
assertEquals("foo@fee.www.bar", card.getEmailHome());
|
|
}
|
|
|
|
public void testNoWorkHomeSpecifier_TEL() throws Throwable {
|
|
VCard card = VCardProvider.createVCardFromXML("<vcard><TEL><FAX/><NUMBER>3443233</NUMBER></TEL></vcard>");
|
|
assertEquals("3443233", card.getPhoneWork("FAX"));
|
|
}
|
|
|
|
public void testNoWorkHomeSpecifier_ADDR() throws Throwable {
|
|
VCard card = VCardProvider.createVCardFromXML("<vcard><ADR><STREET>Some street</STREET><FF>ddss</FF></ADR></vcard>");
|
|
assertEquals("Some street", card.getAddressFieldWork("STREET"));
|
|
assertEquals("ddss", card.getAddressFieldWork("FF"));
|
|
}
|
|
|
|
public void testFN() throws Throwable {
|
|
VCard card = VCardProvider.createVCardFromXML("<vcard><FN>kir max</FN></vcard>");
|
|
assertEquals("kir max", card.getField("FN"));
|
|
// assertEquals("kir max", card.getFullName());
|
|
}
|
|
|
|
public void testBinaryAvatar() throws Throwable {
|
|
VCard card = new VCard();
|
|
card.setAvatar(getAvatarBinary());
|
|
card.save(getConnection(0));
|
|
System.out.println(card.getChildElementXML());
|
|
|
|
VCard loaded = new VCard();
|
|
try {
|
|
loaded.load(getConnection(0));
|
|
}
|
|
catch (XMPPException e) {
|
|
e.printStackTrace();
|
|
fail(e.getMessage());
|
|
}
|
|
System.out.println(StringUtils.encodeBase64(loaded.getAvatar()));
|
|
assertEquals("Should load own Avatar successfully", card.getAvatar(), loaded.getAvatar());
|
|
|
|
loaded = new VCard();
|
|
try {
|
|
loaded.load(getConnection(1), getBareJID(0));
|
|
}
|
|
catch (XMPPException e) {
|
|
e.printStackTrace();
|
|
fail(e.getMessage());
|
|
}
|
|
|
|
assertEquals("Should load avatar successfully", card.getAvatar(), loaded.getAvatar());
|
|
}
|
|
|
|
private byte[] getAvatarBinary() {
|
|
return StringUtils.decodeBase64(getAvatarEnconded());
|
|
}
|
|
|
|
private String getAvatarEnconded() {
|
|
return "/9j/4AAQSkZJRgABAQEASABIAAD/4QAWRXhpZgAATU0AKgAAAAgAAAAAAAD/2wBDAAUDBAQEAwUE\n" +
|
|
"BAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/\n" +
|
|
"2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e\n" +
|
|
"Hh4eHh4eHh4eHh7/wAARCABQAFADASIAAhEBAxEB/8QAHAAAAgIDAQEAAAAAAAAAAAAABwgFBgID\n" +
|
|
"BAkB/8QAORAAAgEDAwIDBwIDBwUAAAAAAQIDBAURAAYSITEHE0EIFBUiMlFxYbEjUqEkQoGR0eHw\n" +
|
|
"M0NicsH/xAAZAQADAQEBAAAAAAAAAAAAAAACAwQBAAX/xAAgEQACAgMAAwADAAAAAAAAAAAAAQIR\n" +
|
|
"AxIhBBMxMmGR/9oADAMBAAIRAxEAPwDOor6ir6RqwhH0hfX9fx++t1FbGmYRUyEg4A6k5Ot9staw\n" +
|
|
"ny4FP8R+RDNkE9s6s1TR2yzW0190QVGOiq/0k/bj21Ko2/0Miv6bKSOKyW1aeAqzjq5B+pvXXKdy\n" +
|
|
"BRyYkYOqVd9xw1crSQWiCKnXIXCDl/nj9tUu80016u8dPPdKyC3ypzMMT4ZmGAUz9hkHJz3xqlTa\n" +
|
|
"4ilRk/oYJd8WunJjlr6NJT2RplB/fWUO7AwBDhhjIIPTVSsXhltF6FXlslLKGHzN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UdPtnXTNUBLlTQR4xHlj+gHT/7pjw8oTsf/9k=";
|
|
}
|
|
|
|
/*
|
|
public void testFullName() throws Throwable {
|
|
VCard card = new VCard();
|
|
card.setFirstName("kir");
|
|
// assertEquals("kir", card.getFullName());
|
|
|
|
card.setLastName("maximov");
|
|
// assertEquals("kir maximov", card.getFullName());
|
|
|
|
card.setField("FN", "some name");
|
|
// assertEquals("some name", card.getFullName());
|
|
}
|
|
*/
|
|
|
|
protected int getMaxConnections() {
|
|
return 2;
|
|
}
|
|
}
|