Search in sources :

Example 1 with GetSourceOptions

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

the class EventNotificationsTest method testGetSourceWOptions.

// Test the getSource operation with a valid options model parameter
@Test
public void testGetSourceWOptions() 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 getSourcePath = "/v1/instances/testString/sources/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetSourceOptions model
    GetSourceOptions getSourceOptionsModel = new GetSourceOptions.Builder().instanceId("testString").id("testString").build();
    // Invoke getSource() with a valid options model and verify the result
    Response<Source> response = eventNotificationsService.getSource(getSourceOptionsModel).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(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getSourcePath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : GetSourceOptions(com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSourceOptions) 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 GetSourceOptions

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

the class GetSourceOptionsTest method testGetSourceOptions.

@Test
public void testGetSourceOptions() throws Throwable {
    GetSourceOptions getSourceOptionsModel = new GetSourceOptions.Builder().instanceId("testString").id("testString").build();
    assertEquals(getSourceOptionsModel.instanceId(), "testString");
    assertEquals(getSourceOptionsModel.id(), "testString");
}
Also used : GetSourceOptions(com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSourceOptions) Test(org.testng.annotations.Test)

Example 3 with GetSourceOptions

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

Aggregations

GetSourceOptions (com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSourceOptions)2 Source (com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source)2 Test (org.testng.annotations.Test)2 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