Search in sources :

Example 16 with Source

use of com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source 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)

Example 17 with Source

use of com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source in project event-notifications-java-admin-sdk by IBM.

the class EventNotifications method createSources.

/**
 * Create a new API Source.
 *
 * Create a new API Source.
 *
 * @param createSourcesOptions the {@link CreateSourcesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link SourceResponse}
 */
public ServiceCall<SourceResponse> createSources(CreateSourcesOptions createSourcesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createSourcesOptions, "createSourcesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("instance_id", createSourcesOptions.instanceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/sources", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "createSources");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", createSourcesOptions.name());
    contentJson.addProperty("description", createSourcesOptions.description());
    if (createSourcesOptions.enabled() != null) {
        contentJson.addProperty("enabled", createSourcesOptions.enabled());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<SourceResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SourceResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) SourceResponse(com.ibm.cloud.eventnotifications.event_notifications.v1.model.SourceResponse) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject)

Example 18 with Source

use of com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source in project event-notifications-java-admin-sdk by IBM.

the class EventNotifications method getSource.

/**
 * Get a Source.
 *
 * Get a Sources.
 *
 * @param getSourceOptions the {@link GetSourceOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Source}
 */
public ServiceCall<Source> getSource(GetSourceOptions getSourceOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getSourceOptions, "getSourceOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("instance_id", getSourceOptions.instanceId());
    pathParamsMap.put("id", getSourceOptions.id());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/sources/{id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "getSource");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Source> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Source>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Source(com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source)

Example 19 with Source

use of com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source in project event-notifications-java-admin-sdk by IBM.

the class EventNotifications method updateSource.

/**
 * Update details of a Source.
 *
 * Update details of a Source.
 *
 * @param updateSourceOptions the {@link UpdateSourceOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Source}
 */
public ServiceCall<Source> updateSource(UpdateSourceOptions updateSourceOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateSourceOptions, "updateSourceOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("instance_id", updateSourceOptions.instanceId());
    pathParamsMap.put("id", updateSourceOptions.id());
    RequestBuilder builder = RequestBuilder.patch(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/sources/{id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "updateSource");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    if (updateSourceOptions.name() != null) {
        contentJson.addProperty("name", updateSourceOptions.name());
    }
    if (updateSourceOptions.description() != null) {
        contentJson.addProperty("description", updateSourceOptions.description());
    }
    if (updateSourceOptions.enabled() != null) {
        contentJson.addProperty("enabled", updateSourceOptions.enabled());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Source> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Source>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Source(com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source)

Example 20 with Source

use of com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source in project event-notifications-java-admin-sdk by IBM.

the class NotificationCreateTest method testNotificationCreate.

@Test
public void testNotificationCreate() throws Throwable {
    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();
    assertEquals(notificationCreateModel.getData(), new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    });
    assertEquals(notificationCreateModel.getIbmenseverity(), "testString");
    assertEquals(notificationCreateModel.getIbmenfcmbody(), "testString");
    assertEquals(notificationCreateModel.getIbmenapnsbody(), "testString");
    assertEquals(notificationCreateModel.getIbmensafaribody(), "testString");
    assertEquals(notificationCreateModel.getIbmenpushto(), "{\"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\"]}");
    assertEquals(notificationCreateModel.getIbmenapnsheaders(), "testString");
    assertEquals(notificationCreateModel.getIbmendefaultshort(), "testString");
    assertEquals(notificationCreateModel.getIbmendefaultlong(), "testString");
    assertEquals(notificationCreateModel.getIbmenchromebody(), "testString");
    assertEquals(notificationCreateModel.getIbmenfirefoxbody(), "testString");
    assertEquals(notificationCreateModel.getIbmenchromeheaders(), "testString");
    assertEquals(notificationCreateModel.getIbmenfirefoxheaders(), "testString");
    assertEquals(notificationCreateModel.getIbmensourceid(), "testString");
    assertEquals(notificationCreateModel.getDatacontenttype(), "application/json");
    assertEquals(notificationCreateModel.getSubject(), "testString");
    assertEquals(notificationCreateModel.getId(), "testString");
    assertEquals(notificationCreateModel.getSource(), "testString");
    assertEquals(notificationCreateModel.getType(), "testString");
    assertEquals(notificationCreateModel.getSpecversion(), "1.0");
    assertEquals(notificationCreateModel.getTime(), "testString");
    assertEquals(notificationCreateModel.get("foo"), "testString");
    String json = TestUtilities.serialize(notificationCreateModel);
    NotificationCreate notificationCreateModelNew = TestUtilities.deserialize(json, NotificationCreate.class);
    assertTrue(notificationCreateModelNew instanceof NotificationCreate);
    assertEquals(notificationCreateModelNew.getIbmenseverity(), "testString");
    assertEquals(notificationCreateModelNew.getIbmenfcmbody(), "testString");
    assertEquals(notificationCreateModelNew.getIbmenapnsbody(), "testString");
    assertEquals(notificationCreateModelNew.getIbmensafaribody(), "testString");
    assertEquals(notificationCreateModelNew.getIbmenpushto(), "{\"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\"]}");
    assertEquals(notificationCreateModelNew.getIbmenapnsheaders(), "testString");
    assertEquals(notificationCreateModelNew.getIbmendefaultshort(), "testString");
    assertEquals(notificationCreateModelNew.getIbmendefaultlong(), "testString");
    assertEquals(notificationCreateModelNew.getIbmenchromebody(), "testString");
    assertEquals(notificationCreateModelNew.getIbmenfirefoxbody(), "testString");
    assertEquals(notificationCreateModelNew.getIbmenchromeheaders(), "testString");
    assertEquals(notificationCreateModelNew.getIbmenfirefoxheaders(), "testString");
    assertEquals(notificationCreateModelNew.getIbmensourceid(), "testString");
    assertEquals(notificationCreateModelNew.getDatacontenttype(), "application/json");
    assertEquals(notificationCreateModelNew.getSubject(), "testString");
    assertEquals(notificationCreateModelNew.getId(), "testString");
    assertEquals(notificationCreateModelNew.getSource(), "testString");
    assertEquals(notificationCreateModelNew.getType(), "testString");
    assertEquals(notificationCreateModelNew.getSpecversion(), "1.0");
    assertEquals(notificationCreateModelNew.getTime(), "testString");
    assertEquals(notificationCreateModelNew.get("foo"), "testString");
}
Also used : NotificationCreate(com.ibm.cloud.eventnotifications.event_notifications.v1.model.NotificationCreate) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)10 FieldMetadata (com.google.api.services.people.v1.model.FieldMetadata)6 Name (com.google.api.services.people.v1.model.Name)6 Source (com.google.api.services.people.v1.model.Source)6 StructuredName (ezvcard.property.StructuredName)6 MockResponse (okhttp3.mockwebserver.MockResponse)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 NotificationCreate (com.ibm.cloud.eventnotifications.event_notifications.v1.model.NotificationCreate)5 Source (com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source)4 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)3 Person (com.google.api.services.people.v1.model.Person)3 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Pair (com.google.gdata.util.common.base.Pair)3 BulkNotificationResponse (com.ibm.cloud.eventnotifications.event_notifications.v1.model.BulkNotificationResponse)3 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 Conversions (com.ibm.watson.discovery.v1.model.Conversions)3 Enrichment (com.ibm.watson.discovery.v1.model.Enrichment)3 NormalizationOperation (com.ibm.watson.discovery.v1.model.NormalizationOperation)3 Source (com.ibm.watson.discovery.v1.model.Source)3