use of com.ibm.cloud.eventnotifications.event_notifications.v1.model.BulkNotificationResponse in project event-notifications-java-admin-sdk by IBM.
the class BulkNotificationResponseTest method testBulkNotificationResponse.
@Test
public void testBulkNotificationResponse() throws Throwable {
BulkNotificationResponse bulkNotificationResponseModel = new BulkNotificationResponse();
assertNull(bulkNotificationResponseModel.getBulkNotificationId());
assertNull(bulkNotificationResponseModel.getBulkMessages());
}
use of com.ibm.cloud.eventnotifications.event_notifications.v1.model.BulkNotificationResponse in project event-notifications-java-admin-sdk by IBM.
the class EventNotifications method sendBulkNotifications.
/**
* Send Bulk notification.
*
* @param sendBulkNotificationsOptions the {@link SendBulkNotificationsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link BulkNotificationResponse}
*/
public ServiceCall<BulkNotificationResponse> sendBulkNotifications(SendBulkNotificationsOptions sendBulkNotificationsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(sendBulkNotificationsOptions, "sendBulkNotificationsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("instance_id", sendBulkNotificationsOptions.instanceId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/notifications/bulk", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "sendBulkNotifications");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
if (sendBulkNotificationsOptions.bulkMessages() != null) {
contentJson.add("bulk_messages", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(sendBulkNotificationsOptions.bulkMessages()));
}
builder.bodyJson(contentJson);
ResponseConverter<BulkNotificationResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<BulkNotificationResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.eventnotifications.event_notifications.v1.model.BulkNotificationResponse in project event-notifications-java-admin-sdk by IBM.
the class EventNotificationsTest method testSendBulkNotificationsWOptions.
// Test the sendBulkNotifications operation with a valid options model parameter
@Test
public void testSendBulkNotificationsWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"bulk_notification_id\": \"bulkNotificationId\", \"bulk_messages\": [\"anyValue\"]}";
String sendBulkNotificationsPath = "/v1/instances/testString/notifications/bulk";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(202).setBody(mockResponseBody));
// Construct an instance of the NotificationCreate model
NotificationCreate notificationCreateModel = new NotificationCreate.Builder().data(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).ibmenseverity("testString").ibmenfcmbody("testString").ibmenapnsbody("testString").ibmensafaribody("testString").ibmenpushto("{\"fcm_devices\":[\"9c75975a-37d0-3898-905d-3b5ee0d7c172\",\"C9CACDF5-6EBF-49E1-AD60-E25BA23E954C\"],\"apns_devices\":[\"3423-37d0-3898-905d-42342\",\"432423-6EBF-49E1-AD60-4234\"],\"user_ids\":[\"user-1\",\"user-2\"],\"tags\":[\"tag-1\",\"tag-2\"],\"platforms\":[\"push_android\",\"push_ios\",\"push_chrome\",\"push_firefox\"]}").ibmenapnsheaders("testString").ibmendefaultshort("testString").ibmendefaultlong("testString").ibmenchromebody("testString").ibmenfirefoxbody("testString").ibmenchromeheaders("testString").ibmenfirefoxheaders("testString").ibmensourceid("testString").datacontenttype("application/json").subject("testString").id("testString").source("testString").type("testString").specversion("1.0").time("testString").add("foo", "testString").build();
// Construct an instance of the SendBulkNotificationsOptions model
SendBulkNotificationsOptions sendBulkNotificationsOptionsModel = new SendBulkNotificationsOptions.Builder().instanceId("testString").bulkMessages(new java.util.ArrayList<NotificationCreate>(java.util.Arrays.asList(notificationCreateModel))).build();
// Invoke sendBulkNotifications() with a valid options model and verify the result
Response<BulkNotificationResponse> response = eventNotificationsService.sendBulkNotifications(sendBulkNotificationsOptionsModel).execute();
assertNotNull(response);
BulkNotificationResponse responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, sendBulkNotificationsPath);
// Verify that there is no query string
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
}
Aggregations