Search in sources :

Example 1 with UpdateSourceOptions

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

the class EventNotificationsTest method testUpdateSourceWOptions.

// Test the updateSource operation with a valid options model parameter
@Test
public void testUpdateSourceWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"id\": \"id\", \"name\": \"name\", \"description\": \"description\", \"enabled\": false, \"type\": \"type\", \"updated_at\": \"2019-01-01T12:00:00.000Z\", \"topic_count\": 10, \"topic_names\": [\"topicNames\"]}";
    String updateSourcePath = "/v1/instances/testString/sources/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the UpdateSourceOptions model
    UpdateSourceOptions updateSourceOptionsModel = new UpdateSourceOptions.Builder().instanceId("testString").id("testString").name("testString").description("testString").enabled(true).build();
    // Invoke updateSource() with a valid options model and verify the result
    Response<Source> response = eventNotificationsService.updateSource(updateSourceOptionsModel).execute();
    assertNotNull(response);
    Source 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(), "PATCH");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, updateSourcePath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : UpdateSourceOptions(com.ibm.cloud.eventnotifications.event_notifications.v1.model.UpdateSourceOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Source(com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with UpdateSourceOptions

use of com.ibm.cloud.eventnotifications.event_notifications.v1.model.UpdateSourceOptions 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 3 with UpdateSourceOptions

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

the class UpdateSourceOptionsTest method testUpdateSourceOptions.

@Test
public void testUpdateSourceOptions() throws Throwable {
    UpdateSourceOptions updateSourceOptionsModel = new UpdateSourceOptions.Builder().instanceId("testString").id("testString").name("testString").description("testString").enabled(true).build();
    assertEquals(updateSourceOptionsModel.instanceId(), "testString");
    assertEquals(updateSourceOptionsModel.id(), "testString");
    assertEquals(updateSourceOptionsModel.name(), "testString");
    assertEquals(updateSourceOptionsModel.description(), "testString");
    assertEquals(updateSourceOptionsModel.enabled(), Boolean.valueOf(true));
}
Also used : UpdateSourceOptions(com.ibm.cloud.eventnotifications.event_notifications.v1.model.UpdateSourceOptions) Test(org.testng.annotations.Test)

Aggregations

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