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