use of co.aurasphere.botmill.fb.model.incoming.callback.EchoMessage in project fb-botmill by BotMill.
the class EchoCallbackTest method testEchoWithListTemplate.
/**
* Tests an {@link EchoMessage} containing a {@link ListTemplatePayload}.
*/
@Test
public void testEchoWithListTemplate() {
// Tests the echo with a List Template.
String echoListTemplatejson = "{\"object\":\"page\",\"entry\":[{\"id\":\"1423903854504468\",\"time\":1483578465379,\"messaging\":[{\"sender\":{\"id\":\"****\"},\"recipient\":{\"id\":\"****\"},\"timestamp\":1483578464765,\"message\":{\"is_echo\":true,\"app_id\":****,\"mid\":\"mid.1483578464765:ed1fe23f35\",\"seq\":785209,\"attachments\":[{\"title\":\"Title1, Title2, Title3, Title4\",\"url\":\"https://www.facebook.com/commerce/update/\",\"type\":\"template\",\"payload\":{\"template_type\":\"list\",\"sharable\":false,\"elements\":[{\"title\":\"Title1\",\"item_url\":\"http://www.alvinjayreyes.com/\",\"image_url\":\"http://blog.domainmonkee.com/wp-content/uploads/2014/05/url.jpg\",\"subtitle\":\"This is a sample sub title for your product\",\"buttons\":[{\"type\":\"postback\",\"title\":\"View\",\"payload\":\"view\"}],\"default_action\":{\"type\":\"web_url\",\"url\":\"http://www.alvinjayreyes.com/\"}},{\"title\":\"Title2\",\"item_url\":\"http://www.alvinjayreyes.com/\",\"image_url\":\"http://blog.domainmonkee.com/wp-content/uploads/2014/05/url.jpg\",\"subtitle\":\"This is a sample sub title for your product\",\"buttons\":[{\"type\":\"postback\",\"title\":\"View\",\"payload\":\"view\"}],\"default_action\":{\"type\":\"web_url\",\"url\":\"http://www.alvinjayreyes.com/\"}},{\"title\":\"Title3\",\"item_url\":\"http://www.alvinjayreyes.com/\",\"image_url\":\"http://blog.domainmonkee.com/wp-content/uploads/2014/05/url.jpg\",\"subtitle\":\"This is a sample sub title for your product\",\"buttons\":[{\"type\":\"postback\",\"title\":\"View\",\"payload\":\"view\"}],\"default_action\":{\"type\":\"web_url\",\"url\":\"http://www.alvinjayreyes.com/\"}},{\"title\":\"Title4\",\"item_url\":\"http://www.alvinjayreyes.com/\",\"image_url\":\"http://blog.domainmonkee.com/wp-content/uploads/2014/05/url.jpg\",\"subtitle\":\"This is a sample sub title for your product\",\"buttons\":[{\"type\":\"postback\",\"title\":\"View\",\"payload\":\"view\"}],\"default_action\":{\"type\":\"web_url\",\"url\":\"http://www.alvinjayreyes.com/\"}}],\"buttons\":[{\"type\":\"postback\",\"title\":\"Just Sample\",\"payload\":\"Yes\"}]}}]}}]}]}";
MessengerCallback callback = FbBotMillJsonUtils.fromJson(echoListTemplatejson, MessengerCallback.class);
MessageEnvelope messageEnvelope = checkCallbackWellFormed(callback);
EchoMessage echoMessage = super.assertInstanceOf(messageEnvelope.getMessage(), EchoMessage.class);
// Checks that individual fields are correctly parsed.
Assert.assertTrue(echoMessage.isEcho());
Assert.assertEquals("****", echoMessage.getAppId());
Assert.assertEquals("mid.1483578464765:ed1fe23f35", echoMessage.getMid());
Assert.assertEquals("785209", echoMessage.getSeq());
super.assertListOfSize(1, echoMessage.getAttachments());
// Checks the attachment.
Attachment attachment = echoMessage.getAttachments().get(0);
Assert.assertEquals("Title1, Title2, Title3, Title4", attachment.getTitle());
Assert.assertEquals("https://www.facebook.com/commerce/update/", attachment.getUrl());
Assert.assertEquals(AttachmentType.TEMPLATE, attachment.getType());
// Checks the payload.
ListTemplatePayload payload = super.assertInstanceOf(attachment.getPayload(), ListTemplatePayload.class);
Assert.assertEquals(PayloadType.LIST, payload.getTemplateType());
super.assertListOfSize(4, payload.getElements());
for (int i = 0; i < 4; i++) {
checkListTemplateElements(payload.getElements().get(i), i + 1);
}
// Checks the buttons.
super.assertListOfSize(1, payload.getButtons());
checkPostbackButtonWellFormed(payload.getButtons().get(0), "Just Sample", "Yes");
}
Aggregations