CommunicationTemplate implements CommunicationOperations { public void connectTo(String subject, String body, String recipientId, ConnectionAuthorization connectionAuthorization) { Map<String, Object> mailboxItem = new HashMap<String,Object>(); mailboxItem.put("recipients", new Recipients(Arrays.asList(recipientId))); mailboxItem.put("subject", subject); mailboxItem.put("body", body); String[] nameValue = connectionAuthorization.getValue().split(":"); mailboxItem.put("item-content", new ItemContent(nameValue[0], nameValue[1])); restOperations.postForLocation(MESSAGING_URL, mailboxItem); } CommunicationTemplate(RestOperations restOperations); void sendMessage(String subject, String body, List<String> recipientIds); void sendMessage(String subject, String body, String... recipientIds); void connectTo(String subject, String body, String recipientId, ConnectionAuthorization connectionAuthorization); void connectTo(String subject, String body, String email, String firstName, String lastName); static final String MESSAGING_URL; static final String PEOPLE; }
@Test public void sendInvitation() { mockServer.expect(requestTo(CommunicationTemplate.MESSAGING_URL+"?oauth2_access_token=ACCESS_TOKEN")) .andExpect(method(POST)) .andExpect(jsonPath("body", is("I'd like to add you to my professional network on LinkedIn"))) .andExpect(jsonPath("subject", is("I'd like to add you to my professional network on LinkedIn"))) .andExpect(jsonPath("recipients.values", hasSize(1))) .andExpect(jsonPath("recipients.values[0].person._path", is("/people/UB2kruYvvv"))) .andExpect(jsonPath("item-content.invitation-request.authorization.name", is("NAME_SEARCH"))) .andExpect(jsonPath("item-content.invitation-request.authorization.value", is("aaaa"))) .andExpect(jsonPath("item-content.invitation-request.connect-type", is("friend"))) .andRespond(withSuccess("", MediaType.APPLICATION_JSON)); linkedIn.communicationOperations().connectTo("I'd like to add you to my professional network on LinkedIn", "I'd like to add you to my professional network on LinkedIn", "UB2kruYvvv", new ConnectionAuthorization("blah", "NAME_SEARCH:aaaa")); }
@Test public void sendEmailInvitation() { mockServer.expect(requestTo(CommunicationTemplate.MESSAGING_URL+"?oauth2_access_token=ACCESS_TOKEN")) .andExpect(method(POST)) .andExpect(jsonPath("body", is("I'd like to add you to my professional network on LinkedIn"))) .andExpect(jsonPath("subject", is("I'd like to add you to my professional network on LinkedIn"))) .andExpect(jsonPath("recipients.values", hasSize(1))) .andExpect(jsonPath("recipients.values[0].person._path", is("/people/email=rob@test.com"))) .andExpect(jsonPath("recipients.values[0].person.first-name", is("Robert"))) .andExpect(jsonPath("recipients.values[0].person.last-name", is("Smith"))) .andExpect(jsonPath("item-content.invitation-request.connect-type", is("friend"))) .andRespond(withSuccess("", MediaType.APPLICATION_JSON)); linkedIn.communicationOperations().connectTo("I'd like to add you to my professional network on LinkedIn", "I'd like to add you to my professional network on LinkedIn", "rob@test.com", "Robert", "Smith"); }