Search in sources :

Example 1 with Logo

use of ezvcard.property.Logo in project ez-vcard by mangstadt.

the class HCardPageTest method logic_for_displaying_a_photo.

@Test
public void logic_for_displaying_a_photo() throws Exception {
    VCard vcard = new VCard();
    Document document = generate(vcard);
    assertTrue(document.select(".vcard .photo").isEmpty());
    assertTrue(document.select(".vcard .logo").isEmpty());
    vcard = new VCard();
    Photo photo = new Photo(mockData, ImageType.JPEG);
    vcard.addPhoto(photo);
    document = generate(vcard);
    assertEquals(1, document.select(".vcard .photo").size());
    assertTrue(document.select(".vcard .logo").isEmpty());
    vcard = new VCard();
    Logo logo = new Logo(mockData, ImageType.PNG);
    vcard.addLogo(logo);
    document = generate(vcard);
    assertTrue(document.select(".vcard .photo").isEmpty());
    assertEquals(1, document.select(".vcard .logo").size());
    vcard = new VCard();
    photo = new Photo(mockData, ImageType.JPEG);
    vcard.addPhoto(photo);
    logo = new Logo(mockData, ImageType.PNG);
    vcard.addLogo(logo);
    document = generate(vcard);
    assertEquals(1, document.select(".vcard .photo").size());
    assertTrue(document.select(".vcard .logo").isEmpty());
}
Also used : Photo(ezvcard.property.Photo) Document(org.jsoup.nodes.Document) VCard(ezvcard.VCard) Logo(ezvcard.property.Logo) Test(org.junit.Test)

Example 2 with Logo

use of ezvcard.property.Logo in project ez-vcard by mangstadt.

the class VCardWriterTest method setTargetApplication_outlook.

@Test
public void setTargetApplication_outlook() throws Throwable {
    VCard vcard = new VCard();
    byte[] data = "foobar".getBytes();
    vcard.addKey(new Key(data, KeyType.X509));
    vcard.addPhoto(new Photo(data, ImageType.JPEG));
    vcard.addLogo(new Logo("http://www.company.com/logo.png", ImageType.PNG));
    vcard.addNote("note");
    {
        StringWriter sw = new StringWriter();
        VCardWriter writer = new VCardWriter(sw, VCardVersion.V2_1);
        writer.setAddProdId(false);
        writer.write(vcard);
        writer.setTargetApplication(TargetApplication.OUTLOOK);
        writer.write(vcard);
        String actual = sw.toString();
        // @formatter:off
        String expected = "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "KEY;ENCODING=BASE64;TYPE=x509:Zm9vYmFy\r\n" + "PHOTO;ENCODING=BASE64;TYPE=jpeg:Zm9vYmFy\r\n" + "LOGO;TYPE=png;VALUE=url:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "KEY;ENCODING=BASE64;TYPE=x509:Zm9vYmFy\r\n" + "\r\n" + "PHOTO;ENCODING=BASE64;TYPE=jpeg:Zm9vYmFy\r\n" + "\r\n" + "LOGO;TYPE=png;VALUE=url:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
    {
        StringWriter sw = new StringWriter();
        VCardWriter writer = new VCardWriter(sw, VCardVersion.V3_0);
        writer.setAddProdId(false);
        writer.write(vcard);
        writer.setTargetApplication(TargetApplication.OUTLOOK);
        writer.write(vcard);
        String actual = sw.toString();
        // @formatter:off
        String expected = "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "KEY;ENCODING=b;TYPE=x509:Zm9vYmFy\r\n" + "PHOTO;ENCODING=b;TYPE=jpeg:Zm9vYmFy\r\n" + "LOGO;TYPE=png;VALUE=uri:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "KEY;ENCODING=b;TYPE=x509:Zm9vYmFy\r\n" + "\r\n" + "PHOTO;ENCODING=b;TYPE=jpeg:Zm9vYmFy\r\n" + "\r\n" + "LOGO;TYPE=png;VALUE=uri:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
    {
        StringWriter sw = new StringWriter();
        VCardWriter writer = new VCardWriter(sw, VCardVersion.V4_0);
        writer.setAddProdId(false);
        writer.write(vcard);
        writer.setTargetApplication(TargetApplication.OUTLOOK);
        writer.write(vcard);
        String actual = sw.toString();
        // @formatter:off
        String expected = "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "KEY:data:application/x509;base64,Zm9vYmFy\r\n" + "PHOTO:data:image/jpeg;base64,Zm9vYmFy\r\n" + "LOGO;MEDIATYPE=image/png:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "KEY:data:application/x509;base64,Zm9vYmFy\r\n" + "PHOTO:data:image/jpeg;base64,Zm9vYmFy\r\n" + "LOGO;MEDIATYPE=image/png:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
}
Also used : StringWriter(java.io.StringWriter) Photo(ezvcard.property.Photo) VCard(ezvcard.VCard) Key(ezvcard.property.Key) Logo(ezvcard.property.Logo) Test(org.junit.Test)

Aggregations

VCard (ezvcard.VCard)2 Logo (ezvcard.property.Logo)2 Photo (ezvcard.property.Photo)2 Test (org.junit.Test)2 Key (ezvcard.property.Key)1 StringWriter (java.io.StringWriter)1 Document (org.jsoup.nodes.Document)1