use of org.infobip.mobile.messaging.api.data.UserDataReport in project mobile-messaging-sdk-android by infobip.
the class MobileApiDataTest method create_userData_success_examineResponse.
@Test
public void create_userData_success_examineResponse() throws Exception {
// someDate.toString() == "Mon Nov 07 13:13:48 CET 2016"
Date someDate = new Date();
String jsonResponse = "{" + "\"predefinedUserData\":" + "{" + "\"msisdn\" : \"1234567890\"," + "\"firstName\" : \"Firstname\"," + "\"lastName\" : \"Lastname\"," + "\"gender\" : \"Gender\"," + "\"birthdate\" : \"2016-12-31\"," + "\"email\" : \"user@mailbox.com\"" + "}," + "\"customUserData\":" + "{" + "\"SomeString\":" + "{" + "\"type\" : \"String\"," + "\"value\" : \"SomeStringValue\"" + "}," + "\"SomeDate\":" + "{" + "\"type\" : \"Date\"," + "\"value\" : " + "\"" + someDate.toString() + "\"" + "}," + "\"SomeNumber\":" + "{" + "\"type\" : \"Number\"," + "\"value\" : 1.0" + "}" + "}" + "}";
debugServer.respondWith(NanoHTTPD.Response.Status.OK, jsonResponse);
UserDataReport response = mobileApiData.reportUserData("myExternalUserId", null);
// inspect http context
assertEquals("/mobile/5/data/user", debugServer.getUri());
assertEquals(1, debugServer.getRequestCount());
assertEquals(NanoHTTPD.Method.POST, debugServer.getRequestMethod());
assertEquals(1, debugServer.getQueryParametersCount());
assertEquals("App my_API_key", debugServer.getHeader("Authorization"));
assertNull(debugServer.getBody());
// inspect parameters
assertEquals("myExternalUserId", debugServer.getQueryParameter("externalUserId"));
// inspect response
assertEquals("1234567890", response.getPredefinedUserData().get("msisdn"));
assertEquals("Firstname", response.getPredefinedUserData().get("firstName"));
assertEquals("Lastname", response.getPredefinedUserData().get("lastName"));
assertEquals("Gender", response.getPredefinedUserData().get("gender"));
assertEquals("2016-12-31", response.getPredefinedUserData().get("birthdate"));
assertEquals("user@mailbox.com", response.getPredefinedUserData().get("email"));
assertEquals("SomeStringValue", response.getCustomUserData().get("SomeString").getValue());
assertEquals(someDate.toString(), response.getCustomUserData().get("SomeDate").getValue());
assertEquals(1.0, response.getCustomUserData().get("SomeNumber").getValue());
}
Aggregations