Search in sources :

Example 46 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class StreamReader method readAll.

/**
 * Reads all vCards from the data stream.
 * @return the vCards
 * @throws IOException if there's a problem reading from the stream
 */
public List<VCard> readAll() throws IOException {
    List<VCard> vcards = new ArrayList<VCard>();
    VCard vcard = null;
    while ((vcard = readNext()) != null) {
        vcards.add(vcard);
    }
    return vcards;
}
Also used : ArrayList(java.util.ArrayList) VCard(ezvcard.VCard)

Example 47 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class VCardPropertyScribeTest method handlePrefParam_from_4.

@Test
public void handlePrefParam_from_4() {
    VCard vcard = new VCard();
    TestProperty two = new TestProperty("");
    two.getParameters().setPref(2);
    vcard.addProperty(two);
    TestProperty nullPref = new TestProperty("");
    vcard.addProperty(nullPref);
    TestProperty invalidPref = new TestProperty("");
    invalidPref.getParameters().replace("PREF", "invalid");
    vcard.addProperty(invalidPref);
    TestProperty one = new TestProperty("");
    one.getParameters().setPref(1);
    vcard.addProperty(one);
    TestProperty three = new TestProperty("");
    three.getParameters().setPref(3);
    vcard.addProperty(three);
    // no change
    {
        VCardVersion version = V4_0;
        for (TestProperty p : vcard.getProperties(TestProperty.class)) {
            VCardParameters copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertEquals(p.getParameters(), copy);
        }
    }
    for (VCardVersion version : each(V2_1, V3_0)) {
        VCardParameters copy = new VCardParameters(one.getParameters());
        VCardPropertyScribe.handlePrefParam(one, copy, version, vcard);
        assertEquals("pref", copy.getType());
        assertNull(copy.getPref());
        for (TestProperty p : each(nullPref, invalidPref, two, three)) {
            copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertNull(copy.getType());
            assertNull(copy.getPref());
        }
    }
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 48 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class VCardPropertyScribeTest method handlePrefParam_to_4.

@Test
public void handlePrefParam_to_4() {
    VCard vcard = new VCard();
    TestProperty two = new TestProperty("");
    two.getParameters().setType("HOME");
    vcard.addProperty(two);
    TestProperty one = new TestProperty("");
    one.getParameters().setType("PREF");
    vcard.addProperty(one);
    TestProperty three = new TestProperty("");
    vcard.addProperty(three);
    // no change
    for (VCardVersion version : each(V2_1, V3_0)) {
        for (TestProperty p : vcard.getProperties(TestProperty.class)) {
            VCardParameters copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertEquals(p.getParameters(), copy);
        }
    }
    {
        VCardVersion version = V4_0;
        VCardParameters copy = new VCardParameters(one.getParameters());
        VCardPropertyScribe.handlePrefParam(one, copy, version, vcard);
        assertIntEquals(1, copy.getPref());
        assertNull(copy.getType());
        for (TestProperty p : each(two, three)) {
            copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertEquals(p.getParameters(), copy);
        }
    }
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 49 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class SampleVCardsTest method macAddressBookVCard.

@Test
public void macAddressBookVCard() throws Throwable {
    VCardAsserter asserter = read("John_Doe_MAC_ADDRESS_BOOK.vcf");
    asserter.next(V3_0);
    // @formatter:off
    asserter.structuredName().family("Doe").given("John").additional("Richter,James").prefixes("Mr.").suffixes("Sr.").noMore();
    asserter.simpleProperty(FormattedName.class).value("Mr. John Richter,James Doe Sr.").noMore();
    asserter.listProperty(Nickname.class).values("Johny").noMore();
    asserter.listProperty(Organization.class).values("IBM", "Accounting").noMore();
    asserter.simpleProperty(Title.class).value("Money Counter").noMore();
    asserter.email().types(EmailType.INTERNET, EmailType.WORK, EmailType.PREF).value("john.doe@ibm.com").noMore();
    asserter.telephone().types(TelephoneType.WORK, TelephoneType.PREF).text("905-777-1234").next().types(TelephoneType.HOME).text("905-666-1234").next().types(TelephoneType.CELL).text("905-555-1234").next().types(TelephoneType.HOME, TelephoneType.FAX).text("905-888-1234").next().types(TelephoneType.WORK, TelephoneType.FAX).text("905-999-1234").next().types(TelephoneType.PAGER).text("905-111-1234").next().group("item1").text("905-222-1234").noMore();
    asserter.address().group("item2").streetAddress("Silicon Alley 5,").locality("New York").region("New York").postalCode("12345").country("United States of America").types(AddressType.HOME, AddressType.PREF).next().group("item3").streetAddress("Street4" + NEWLINE + "Building 6" + NEWLINE + "Floor 8").locality("New York").postalCode("12345").country("USA").types(AddressType.WORK).noMore();
    asserter.simpleProperty(Note.class).value("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + NEWLINE + "Favotire Color: Blue").noMore();
    asserter.simpleProperty(Url.class).group("item4").value("http://www.ibm.com").param("TYPE", "pref").noMore();
    asserter.dateProperty(Birthday.class).date("2012-06-06").noMore();
    asserter.binaryProperty(Photo.class).param("ENCODING", "BASE64").dataLength(18242).noMore();
    asserter.rawProperty("X-PHONETIC-FIRST-NAME").value("Jon").noMore();
    asserter.rawProperty("X-PHONETIC-LAST-NAME").value("Dow").noMore();
    asserter.rawProperty("X-ABLABEL").group("item1").value("AssistantPhone").next().group("item4").value("_$!<HomePage>!$_").next().group("item5").value("Spouse").noMore();
    asserter.rawProperty("X-ABADR").group("item2").value("Silicon Alley").next().group("item3").value("Street 4, Building 6,\\nFloor 8\\nNew York\\nUSA").noMore();
    asserter.rawProperty("X-ABRELATEDNAMES").group("item5").value("Jenny").param("TYPE", "pref").noMore();
    asserter.rawProperty("X-ABUID").value("6B29A774-D124-4822-B8D0-2780EC117F60\\:ABPerson").noMore();
    VCard vcard = asserter.getVCard();
    asserter.validate().prop(vcard.getEmails().get(0), // "TYPE=WORK" not valid in vCard 3.0
    9).prop(vcard.getPhotos().get(0), // "BASE64" not valid parameter
    4).run();
    // @formatter:on
    asserter.done();
}
Also used : Photo(ezvcard.property.Photo) VCardAsserter(ezvcard.property.asserter.VCardAsserter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 50 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class SampleVCardsTest method evolutionVCard.

@Test
public void evolutionVCard() throws Throwable {
    VCardAsserter asserter = read("John_Doe_EVOLUTION.vcf");
    asserter.next(V3_0);
    // @formatter:off
    asserter.simpleProperty(Url.class).value("http://www.ibm.com").param("X-COUCHDB-UUID", "0abc9b8d-0845-47d0-9a91-3db5bb74620d").noMore();
    asserter.telephone().types(TelephoneType.CELL).text("905-666-1234").param("X-COUCHDB-UUID", "c2fa1caa-2926-4087-8971-609cfc7354ce").next().types(TelephoneType.WORK, TelephoneType.VOICE).text("905-555-1234").param("X-COUCHDB-UUID", "fbfb2722-4fd8-4dbf-9abd-eeb24072fd8e").noMore();
    asserter.simpleProperty(Uid.class).value("477343c8e6bf375a9bac1f96a5000837").noMore();
    asserter.structuredName().family("Doe").given("John").additional("Richter, James").prefixes("Mr.").suffixes("Sr.").noMore();
    asserter.simpleProperty(FormattedName.class).value("Mr. John Richter, James Doe Sr.").noMore();
    asserter.listProperty(Nickname.class).values("Johny").noMore();
    asserter.listProperty(Organization.class).values("IBM", "Accounting", "Dungeon").noMore();
    asserter.simpleProperty(Title.class).value("Money Counter").noMore();
    asserter.listProperty(Categories.class).values("VIP").noMore();
    asserter.simpleProperty(Note.class).value("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.").noMore();
    asserter.email().types(EmailType.WORK).value("john.doe@ibm.com").param("X-COUCHDB-UUID", "83a75a5d-2777-45aa-bab5-76a4bd972490").noMore();
    asserter.address().poBox("ASB-123").streetAddress("15 Crescent moon drive").locality("Albaney").region("New York").postalCode("12345").country("United States of America").types(AddressType.HOME).noMore();
    asserter.dateProperty(Birthday.class).date("1980-03-22").noMore();
    asserter.simpleProperty(Revision.class).value(utc("2012-03-05 13:32:54")).noMore();
    asserter.rawProperty("X-COUCHDB-APPLICATION-ANNOTATIONS").value("{\"Evolution\":{\"revision\":\"2012-03-05T13:32:54Z\"}}").noMore();
    asserter.rawProperty("X-AIM").value("johnny5@aol.com").param("TYPE", "HOME").param("X-COUCHDB-UUID", "cb9e11fc-bb97-4222-9cd8-99820c1de454").noMore();
    asserter.rawProperty("X-EVOLUTION-FILE-AS").value("Doe\\, John").noMore();
    asserter.rawProperty("X-EVOLUTION-SPOUSE").value("Maria").noMore();
    asserter.rawProperty("X-EVOLUTION-MANAGER").value("Big Blue").noMore();
    asserter.rawProperty("X-EVOLUTION-ASSISTANT").value("Little Red").noMore();
    asserter.rawProperty("X-EVOLUTION-ANNIVERSARY").value("1980-03-22").noMore();
    VCard vcard = asserter.getVCard();
    asserter.validate().prop(vcard.getEmails().get(0), // "TYPE=WORK" not valid in vCard 3.0
    9).run();
    // @formatter:on
    asserter.done();
}
Also used : VCardAsserter(ezvcard.property.asserter.VCardAsserter) VCard(ezvcard.VCard) FreeBusyUrl(ezvcard.property.FreeBusyUrl) Url(ezvcard.property.Url) Test(org.junit.Test)

Aggregations

VCard (ezvcard.VCard)191 Test (org.junit.Test)134 StringWriter (java.io.StringWriter)29 StructuredName (ezvcard.property.StructuredName)23 Person (com.google.api.services.people.v1.model.Person)22 Telephone (ezvcard.property.Telephone)21 Photo (ezvcard.property.Photo)17 Email (ezvcard.property.Email)16 List (java.util.List)16 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)15 Document (org.w3c.dom.Document)15 VCardVersion (ezvcard.VCardVersion)14 XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)14 Address (ezvcard.property.Address)14 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)13 Collectors (java.util.stream.Collectors)12 Name (com.google.api.services.people.v1.model.Name)11 File (java.io.File)11 Truth.assertThat (com.google.common.truth.Truth.assertThat)10 Pair (com.google.gdata.util.common.base.Pair)10