@Test(expected = ApiException.class) public void messagesPostTestFailsIfBodyIsInvalid() throws ApiException { MessageJSON body = new MessageJSON(); From sender = new From(); sender.userId(null); List<To> receivers = new ArrayList<>(); Text text = new Text(); text.plain("TEST MESSAGE"); body.from(sender); body.to(receivers); body.text(text); api.messagesPost(accessToken, body); }
@Test(expected = ApiException.class) public void messagesPostTestFailsIfAccessTokenIsInvalid() throws ApiException { String accessToken = "123ABC"; MessageJSON body = new MessageJSON(); From sender = new From(); sender.userId(null); List<To> receivers = new ArrayList<>(); To receiver = new To(); receiver.userId(null); receiver.siteId("MLA"); receiver.resource("orders"); receiver.resourceId(null); receivers.add(0, receiver); Text text = new Text(); text.plain("TEST MESSAGE"); body.from(sender); body.to(receivers); body.text(text); api.messagesPost(accessToken, body); }
/** * Send a message. * * @throws ApiException if the Api call fails */ @Test public void messagesPostTest() throws ApiException { MessageJSON body = new MessageJSON(); From sender = new From(); sender.userId(null); List<To> receivers = new ArrayList<>(); To receiver = new To(); receiver.userId(null); receiver.siteId("MLA"); receiver.resource("orders"); receiver.resourceId(null); receivers.add(0, receiver); Text text = new Text(); text.plain("TEST MESSAGE"); body.from(sender); body.to(receivers); body.text(text); MessageCreated response = api.messagesPost(accessToken, body); assertNotNull(response); assertEquals(body.getFrom().getUserId(), response.get(0).getFrom().getUserId()); assertEquals(body.getTo(), response.get(0).getTo()); assertEquals(body.getText().getPlain(), response.get(0).getText().getPlain()); }