Search in sources :

Example 1 with ComponentSettingsResponse

use of com.ibm.watson.discovery.v2.model.ComponentSettingsResponse in project java-sdk by watson-developer-cloud.

the class DiscoveryTest method testGetComponentSettingsWOptions.

@Test
public void testGetComponentSettingsWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"fields_shown\": {\"body\": {\"use_passage\": true, \"field\": \"field\"}, \"title\": {\"field\": \"field\"}}, \"autocomplete\": true, \"structured_search\": true, \"results_per_page\": 14, \"aggregations\": [{\"name\": \"name\", \"label\": \"label\", \"multiple_selections_allowed\": false, \"visualization_type\": \"auto\"}]}";
    String getComponentSettingsPath = "/v2/projects/testString/component_settings";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetComponentSettingsOptions model
    GetComponentSettingsOptions getComponentSettingsOptionsModel = new GetComponentSettingsOptions.Builder().projectId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<ComponentSettingsResponse> response = discoveryService.getComponentSettings(getComponentSettingsOptionsModel).execute();
    assertNotNull(response);
    ComponentSettingsResponse responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getComponentSettingsPath);
}
Also used : GetComponentSettingsOptions(com.ibm.watson.discovery.v2.model.GetComponentSettingsOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ComponentSettingsResponse(com.ibm.watson.discovery.v2.model.ComponentSettingsResponse) Test(org.testng.annotations.Test)

Example 2 with ComponentSettingsResponse

use of com.ibm.watson.discovery.v2.model.ComponentSettingsResponse in project java-sdk by watson-developer-cloud.

the class Discovery method getComponentSettings.

/**
 * List component settings.
 *
 * <p>Returns default configuration settings for components.
 *
 * @param getComponentSettingsOptions the {@link GetComponentSettingsOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link ComponentSettingsResponse}
 */
public ServiceCall<ComponentSettingsResponse> getComponentSettings(GetComponentSettingsOptions getComponentSettingsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getComponentSettingsOptions, "getComponentSettingsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", getComponentSettingsOptions.projectId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/component_settings", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "getComponentSettings");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<ComponentSettingsResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ComponentSettingsResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) ComponentSettingsResponse(com.ibm.watson.discovery.v2.model.ComponentSettingsResponse) HashMap(java.util.HashMap)

Aggregations

ComponentSettingsResponse (com.ibm.watson.discovery.v2.model.ComponentSettingsResponse)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 GetComponentSettingsOptions (com.ibm.watson.discovery.v2.model.GetComponentSettingsOptions)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1