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);
}
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);
}
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);
}
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);
}
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");
}
Aggregations