/* * 1. create a new Contact (OP: createContact) 2. retrieve contact by email (OP: getContactByEmail) 3. update the contact (OP: updateContact) 4. retrieve contact by id (OP: * getContactById) 5. delete contact by id (OP: */ @Test public void createRetrieveDeleteContact() throws HubSpotConnectorException, HubSpotConnectorNoAccessTokenException, HubSpotConnectorAccessTokenExpiredException { // 1. Create a new contact ContactProperties cp; final String email = createNewContact(); // 2. Retrieve the contact by email and check that all the properties setted are stablished Contact c = connector.getContactByEmail(USER_ID, email); Assert.assertNotNull(c); cp = c.getContactProperties(); Assert.assertNotNull(cp); Assert.assertFalse(StringUtils.isEmpty(c.getVid())); Assert.assertEquals(cp.getFirstname(), "theFirstName"); Assert.assertEquals(cp.getLastname(), "theLastName"); Assert.assertEquals(cp.getNumemployees(), ContactPropertiesNumberOfEmployees._25_50); Assert.assertEquals(cp.getLifecyclestage(), ContactPropertiesLifecycleStage.LEAD); Assert.assertEquals(cp.getCity(), "beautifulCity"); // 3. Update the lastname of the contact cp = new ContactProperties(); cp.setLastname("lastNameModified"); connector.updateContact(USER_ID, c.getVid(), cp); // 4. Retrieve again the same contact but this time by ID, and check that the lastname holds the // modified value c = connector.getContactById(USER_ID, c.getVid()); Assert.assertNotNull(c); cp = c.getContactProperties(); Assert.assertNotNull(cp); Assert.assertEquals(cp.getLastname(), "lastNameModified"); // 5. Delete the contact by his ID and check the response final ContactDeleted cd = connector.deleteContact(USER_ID, c.getVid()); Assert.assertNotNull(cd); Assert.assertTrue(cd.getDeleted()); Assert.assertEquals(cd.getVid(), c.getVid()); }
@Test public void addAndRemoveContactFromLists() throws HubSpotConnectorException, HubSpotConnectorNoAccessTokenException, HubSpotConnectorAccessTokenExpiredException { // Create a new contact final String email = createNewContact(); // Retrieve the contact by email and check that all the properties setted are stablished final Contact c = connector.getContactByEmail(USER_ID, email); Assert.assertNotNull(c); // Retrieve all the email lists and use one that is not dynamic final HubSpotListLists hsll = connector.getContactsLists(USER_ID, null, null); Assert.assertNotNull(hsll); for (final HubSpotList hbl : hsll.getLists()) { // It must be a non dynamic list if (!hbl.getDynamic()) { final String listId = hbl.getListId(); final HubSpotListAddContactToListResponse hslactlr = connector.addExistingContactInAList(USER_ID, listId, c.getVid()); Assert.assertNotNull(hslactlr); Assert.assertNotNull(hslactlr.getUpdated()); Assert.assertEquals(1, hslactlr.getUpdated().size()); Assert.assertEquals(Integer.valueOf(c.getVid()), hslactlr.getUpdated().get(0)); break; } } // Delete the contact by his ID and check the response final ContactDeleted cd = connector.deleteContact(USER_ID, c.getVid()); Assert.assertNotNull(cd); Assert.assertTrue(cd.getDeleted()); Assert.assertEquals(cd.getVid(), c.getVid()); }