@Test
    public void testProfileCrud() {
        Gateway beanstream = new Gateway("v1", 300200578,
                "4BaD82D9197b4cc4b70a221911eE9f70", // payments API passcode
                "D97D3BE1EE964A6193D17A571D9FBC80", // profiles API passcode
                "4e6Ff318bee64EA391609de89aD4CF5d");// reporting API passcode

        String profileId = null;

        try {
            Address billing = getTestCardValidAddress();
            Card card = new Card().setName("John Doe")
                    .setNumber("5100000010001004")
                    .setExpiryMonth("12")
                    .setExpiryYear("18")
                    .setCvd("123");

            // test create profile
            ProfileResponse createdProfile = beanstream.profiles().createProfile(card, billing);
            profileId = createdProfile.getId();
            System.out.println(createdProfile);
            
            // test get profile by id
            PaymentProfile paymentProfile = beanstream.profiles().getProfileById(profileId);
            System.out.println(paymentProfile);
            Assert.assertNotNull(paymentProfile);
            
            // update the profile to francais
            paymentProfile.setLanguage("fr");
            paymentProfile.setComments("test updating profile sending billing info only");
            // update profile
            beanstream.profiles().updateProfile(paymentProfile);

            // refresh the updated profile
            paymentProfile = beanstream.profiles().getProfileById(profileId);
            System.out.println(paymentProfile);
            Assert.assertNotNull(paymentProfile);
            Assert.assertEquals("fr", paymentProfile.getLanguage());
            
            // add a new card
            Card newCard = new Card()
                .setCvd("123")
                .setName("Tester Doe")
                .setNumber("4030000010001234")
                .setExpiryMonth("01")
                .setExpiryYear("19");
            ProfileResponse newCardResp = beanstream.profiles().addCard(profileId, newCard);
            System.out.println(newCardResp);
            
            // get all cards
            List<Card> profileCards = beanstream.profiles().getCards(profileId);
            Assert.assertNotNull(profileCards);
            Assert.assertEquals("Number of cards not expected.", 2, profileCards.size());
            
            // update card
            Card cardUpdated = beanstream.profiles().getCard(profileId, "1");
            cardUpdated.setExpiryMonth("04");
            beanstream.profiles().updateCard(profileId, cardUpdated);
            
            // delete card
            ProfileResponse result = beanstream.profiles().removeCard(profileId, "2");
            
            // delete the payment profile
            beanstream.profiles().deleteProfileById(profileId);
            boolean notFound = false;
            try {
                beanstream.profiles().getProfileById(profileId);
                System.out.println("This profile was deleted, therefore should throw an exception");
            } catch (BeanstreamApiException e) {
                profileId = null;
                notFound = true;
            }
            Assert.assertTrue("Profile should not have been found", notFound);
            
        } catch (Exception ex) {
            System.out.println("unexpected exception occurred, test can not continue : "+ ex.getMessage());
            Assert.fail(ex.getMessage());
        } finally {
            if (profileId != null) {
                try {
                    beanstream.profiles().deleteProfileById(profileId);
                } catch (BeanstreamApiException e) {
                    e.printStackTrace();
                    Assert.fail(e.getMessage());
                }
            }
        }

    }