1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-09 01:25:59 +01:00
Smack/test-unit/org/jivesoftware/smackx/VCardUnitTest.java

107 lines
6.7 KiB
Java

package org.jivesoftware.smackx;
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.smackx.provider.VCardProvider;
public class VCardUnitTest {
@Test
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());
}
@Test
public void testNoWorkHomeSpecifier_TEL() throws Throwable {
VCard card = VCardProvider.createVCardFromXML("<vcard><TEL><FAX/><NUMBER>3443233</NUMBER></TEL></vcard>");
assertEquals("3443233", card.getPhoneWork("FAX"));
}
@Test
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"));
}
@Test
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());
}
private final static String MIME_TYPE = "testtype";
private final static String VCARD_XML = "<vcard><PHOTO><BINVAL>" + getAvatarEncoded() + "</BINVAL><TYPE>" + MIME_TYPE + "</TYPE></PHOTO></vcard>";
@Test
public void testPhoto() throws Throwable {
VCard vc = VCardProvider.createVCardFromXML(VCARD_XML);
byte[] avatar = vc.getAvatar();
String mimeType = vc.getAvatarMimeType();
assertEquals(mimeType, MIME_TYPE);
byte[] expectedAvatar = getAvatarBinary();
assertTrue(Arrays.equals(avatar, expectedAvatar));
}
public static byte[] getAvatarBinary() {
return StringUtils.decodeBase64(getAvatarEncoded());
}
private static String getAvatarEncoded() {
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/fWUO7AwBDhhjIIPTVSsXhltF6FXlslLKGHzNLlmb9e+uC8bC\n" +
"t9muNHJa2qKeJ5eJhErFGABbA69Ppx+M6KUnR3Y/UFa17pilK8I5JSTjIIA/rqJ3TYWeve8UlH5a\n" +
"VKjzgGGCw7N+cd/wNDykNdBKI5KgD5sjI6aJW3qyueDyJI/MjIwSDlW/00vdPjMyRlVFMqoOMhjZ\n" +
"WR/5WGD/AIffUVUUoZ8EaIlDQJXVr0VTGfLlbA/8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