Search in sources :

Example 1 with TagsSubscriptionList

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

the class EventNotifications method listTagsSubscriptionsDevice.

/**
 * List all Tag Subscriptions for a device.
 *
 * List all Tag Subscriptions for a device.
 *
 * @param listTagsSubscriptionsDeviceOptions the {@link ListTagsSubscriptionsDeviceOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link TagsSubscriptionList}
 */
public ServiceCall<TagsSubscriptionList> listTagsSubscriptionsDevice(ListTagsSubscriptionsDeviceOptions listTagsSubscriptionsDeviceOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listTagsSubscriptionsDeviceOptions, "listTagsSubscriptionsDeviceOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("instance_id", listTagsSubscriptionsDeviceOptions.instanceId());
    pathParamsMap.put("id", listTagsSubscriptionsDeviceOptions.id());
    pathParamsMap.put("device_id", listTagsSubscriptionsDeviceOptions.deviceId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/destinations/{id}/tag_subscriptions/devices/{device_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "listTagsSubscriptionsDevice");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (listTagsSubscriptionsDeviceOptions.tagName() != null) {
        builder.query("tag_name", String.valueOf(listTagsSubscriptionsDeviceOptions.tagName()));
    }
    if (listTagsSubscriptionsDeviceOptions.limit() != null) {
        builder.query("limit", String.valueOf(listTagsSubscriptionsDeviceOptions.limit()));
    }
    if (listTagsSubscriptionsDeviceOptions.offset() != null) {
        builder.query("offset", String.valueOf(listTagsSubscriptionsDeviceOptions.offset()));
    }
    ResponseConverter<TagsSubscriptionList> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TagsSubscriptionList>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TagsSubscriptionList(com.ibm.cloud.eventnotifications.event_notifications.v1.model.TagsSubscriptionList)

Example 2 with TagsSubscriptionList

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

the class EventNotifications method listTagsSubscription.

/**
 * List all Tag Subscriptions.
 *
 * List all Tag Subscriptions.
 *
 * @param listTagsSubscriptionOptions the {@link ListTagsSubscriptionOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link TagsSubscriptionList}
 */
public ServiceCall<TagsSubscriptionList> listTagsSubscription(ListTagsSubscriptionOptions listTagsSubscriptionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listTagsSubscriptionOptions, "listTagsSubscriptionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("instance_id", listTagsSubscriptionOptions.instanceId());
    pathParamsMap.put("id", listTagsSubscriptionOptions.id());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/destinations/{id}/tag_subscriptions", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "listTagsSubscription");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (listTagsSubscriptionOptions.deviceId() != null) {
        builder.query("device_id", String.valueOf(listTagsSubscriptionOptions.deviceId()));
    }
    if (listTagsSubscriptionOptions.userId() != null) {
        builder.query("user_id", String.valueOf(listTagsSubscriptionOptions.userId()));
    }
    if (listTagsSubscriptionOptions.tagName() != null) {
        builder.query("tag_name", String.valueOf(listTagsSubscriptionOptions.tagName()));
    }
    if (listTagsSubscriptionOptions.limit() != null) {
        builder.query("limit", String.valueOf(listTagsSubscriptionOptions.limit()));
    }
    if (listTagsSubscriptionOptions.offset() != null) {
        builder.query("offset", String.valueOf(listTagsSubscriptionOptions.offset()));
    }
    if (listTagsSubscriptionOptions.search() != null) {
        builder.query("search", String.valueOf(listTagsSubscriptionOptions.search()));
    }
    ResponseConverter<TagsSubscriptionList> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TagsSubscriptionList>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TagsSubscriptionList(com.ibm.cloud.eventnotifications.event_notifications.v1.model.TagsSubscriptionList)

Example 3 with TagsSubscriptionList

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

the class TagsSubscriptionListTest method testTagsSubscriptionList.

@Test
public void testTagsSubscriptionList() throws Throwable {
    TagsSubscriptionList tagsSubscriptionListModel = new TagsSubscriptionList();
    assertNull(tagsSubscriptionListModel.getTotalCount());
    assertNull(tagsSubscriptionListModel.getOffset());
    assertNull(tagsSubscriptionListModel.getLimit());
    assertNull(tagsSubscriptionListModel.getTagSubscriptions());
}
Also used : TagsSubscriptionList(com.ibm.cloud.eventnotifications.event_notifications.v1.model.TagsSubscriptionList) Test(org.testng.annotations.Test)

Example 4 with TagsSubscriptionList

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

the class EventNotificationsTest method testListTagsSubscriptionWOptions.

// Test the listTagsSubscription operation with a valid options model parameter
@Test
public void testListTagsSubscriptionWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"total_count\": 10, \"offset\": 6, \"limit\": 5, \"tag_subscriptions\": [{\"id\": \"id\", \"device_id\": \"deviceId\", \"tag_name\": \"tagName\", \"user_id\": \"userId\", \"updated_at\": \"2019-01-01T12:00:00.000Z\"}]}";
    String listTagsSubscriptionPath = "/v1/instances/testString/destinations/testString/tag_subscriptions";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListTagsSubscriptionOptions model
    ListTagsSubscriptionOptions listTagsSubscriptionOptionsModel = new ListTagsSubscriptionOptions.Builder().instanceId("testString").id("testString").deviceId("testString").userId("testString").tagName("testString").limit(Long.valueOf("1")).offset(Long.valueOf("0")).search("testString").build();
    // Invoke listTagsSubscription() with a valid options model and verify the result
    Response<TagsSubscriptionList> response = eventNotificationsService.listTagsSubscription(listTagsSubscriptionOptionsModel).execute();
    assertNotNull(response);
    TagsSubscriptionList 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(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, listTagsSubscriptionPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("device_id"), "testString");
    assertEquals(query.get("user_id"), "testString");
    assertEquals(query.get("tag_name"), "testString");
    assertEquals(Long.valueOf(query.get("limit")), Long.valueOf("1"));
    assertEquals(Long.valueOf(query.get("offset")), Long.valueOf("0"));
    assertEquals(query.get("search"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListTagsSubscriptionOptions(com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListTagsSubscriptionOptions) TagsSubscriptionList(com.ibm.cloud.eventnotifications.event_notifications.v1.model.TagsSubscriptionList) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with TagsSubscriptionList

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

the class EventNotificationsTest method testListTagsSubscriptionsDeviceWOptions.

// Test the listTagsSubscriptionsDevice operation with a valid options model parameter
@Test
public void testListTagsSubscriptionsDeviceWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"total_count\": 10, \"offset\": 6, \"limit\": 5, \"tag_subscriptions\": [{\"id\": \"id\", \"device_id\": \"deviceId\", \"tag_name\": \"tagName\", \"user_id\": \"userId\", \"updated_at\": \"2019-01-01T12:00:00.000Z\"}]}";
    String listTagsSubscriptionsDevicePath = "/v1/instances/testString/destinations/testString/tag_subscriptions/devices/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListTagsSubscriptionsDeviceOptions model
    ListTagsSubscriptionsDeviceOptions listTagsSubscriptionsDeviceOptionsModel = new ListTagsSubscriptionsDeviceOptions.Builder().instanceId("testString").id("testString").deviceId("testString").tagName("testString").limit(Long.valueOf("1")).offset(Long.valueOf("0")).build();
    // Invoke listTagsSubscriptionsDevice() with a valid options model and verify the result
    Response<TagsSubscriptionList> response = eventNotificationsService.listTagsSubscriptionsDevice(listTagsSubscriptionsDeviceOptionsModel).execute();
    assertNotNull(response);
    TagsSubscriptionList 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(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, listTagsSubscriptionsDevicePath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("tag_name"), "testString");
    assertEquals(Long.valueOf(query.get("limit")), Long.valueOf("1"));
    assertEquals(Long.valueOf(query.get("offset")), Long.valueOf("0"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) TagsSubscriptionList(com.ibm.cloud.eventnotifications.event_notifications.v1.model.TagsSubscriptionList) ListTagsSubscriptionsDeviceOptions(com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListTagsSubscriptionsDeviceOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

TagsSubscriptionList (com.ibm.cloud.eventnotifications.event_notifications.v1.model.TagsSubscriptionList)5 Test (org.testng.annotations.Test)3 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)2 HashMap (java.util.HashMap)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ListTagsSubscriptionOptions (com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListTagsSubscriptionOptions)1 ListTagsSubscriptionsDeviceOptions (com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListTagsSubscriptionsDeviceOptions)1