Search in sources :

Example 1 with BulkNotificationResponse

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());
}
Also used : BulkNotificationResponse(com.ibm.cloud.eventnotifications.event_notifications.v1.model.BulkNotificationResponse) Test(org.testng.annotations.Test)

Example 2 with BulkNotificationResponse

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) BulkNotificationResponse(com.ibm.cloud.eventnotifications.event_notifications.v1.model.BulkNotificationResponse) JsonObject(com.google.gson.JsonObject)

Example 3 with BulkNotificationResponse

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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ArrayList(java.util.ArrayList) SendBulkNotificationsOptions(com.ibm.cloud.eventnotifications.event_notifications.v1.model.SendBulkNotificationsOptions) BulkNotificationResponse(com.ibm.cloud.eventnotifications.event_notifications.v1.model.BulkNotificationResponse) NotificationCreate(com.ibm.cloud.eventnotifications.event_notifications.v1.model.NotificationCreate) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

BulkNotificationResponse (com.ibm.cloud.eventnotifications.event_notifications.v1.model.BulkNotificationResponse)3 Test (org.testng.annotations.Test)2 JsonObject (com.google.gson.JsonObject)1 NotificationCreate (com.ibm.cloud.eventnotifications.event_notifications.v1.model.NotificationCreate)1 SendBulkNotificationsOptions (com.ibm.cloud.eventnotifications.event_notifications.v1.model.SendBulkNotificationsOptions)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1