Search in sources :

Example 1 with SourceResponse

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

the class EventNotificationsTest method testCreateSourcesWOptions.

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

Example 2 with SourceResponse

use of com.ibm.cloud.eventnotifications.event_notifications.v1.model.SourceResponse 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) SourceResponse(com.ibm.cloud.eventnotifications.event_notifications.v1.model.SourceResponse) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject)

Example 3 with SourceResponse

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

the class SourceResponseTest method testSourceResponse.

@Test
public void testSourceResponse() throws Throwable {
    SourceResponse sourceResponseModel = new SourceResponse();
    assertNull(sourceResponseModel.getId());
    assertNull(sourceResponseModel.getName());
    assertNull(sourceResponseModel.getDescription());
    assertNull(sourceResponseModel.isEnabled());
    assertNull(sourceResponseModel.getCreatedAt());
}
Also used : SourceResponse(com.ibm.cloud.eventnotifications.event_notifications.v1.model.SourceResponse) Test(org.testng.annotations.Test)

Aggregations

SourceResponse (com.ibm.cloud.eventnotifications.event_notifications.v1.model.SourceResponse)3 Test (org.testng.annotations.Test)2 JsonObject (com.google.gson.JsonObject)1 CreateSourcesOptions (com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateSourcesOptions)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