Search in sources :

Example 1 with ListProjectsResponse

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

the class DiscoveryTest method testListProjectsWOptions.

@Test
public void testListProjectsWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"projects\": [{\"project_id\": \"projectId\", \"name\": \"name\", \"type\": \"document_retrieval\", \"relevancy_training_status\": {\"data_updated\": \"dataUpdated\", \"total_examples\": 13, \"sufficient_label_diversity\": true, \"processing\": true, \"minimum_examples_added\": true, \"successfully_trained\": \"successfullyTrained\", \"available\": false, \"notices\": 7, \"minimum_queries_added\": false}, \"collection_count\": 15}]}";
    String listProjectsPath = "/v2/projects";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ListProjectsOptions model
    ListProjectsOptions listProjectsOptionsModel = new ListProjectsOptions();
    // Invoke operation with valid options model (positive test)
    Response<ListProjectsResponse> response = discoveryService.listProjects(listProjectsOptionsModel).execute();
    assertNotNull(response);
    ListProjectsResponse 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, listProjectsPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListProjectsOptions(com.ibm.watson.discovery.v2.model.ListProjectsOptions) ListProjectsResponse(com.ibm.watson.discovery.v2.model.ListProjectsResponse) Test(org.testng.annotations.Test)

Example 2 with ListProjectsResponse

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

the class Discovery method listProjects.

/**
 * List projects.
 *
 * <p>Lists existing projects for this instance.
 *
 * @param listProjectsOptions the {@link ListProjectsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ListProjectsResponse}
 */
public ServiceCall<ListProjectsResponse> listProjects(ListProjectsOptions listProjectsOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "listProjects");
    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<ListProjectsResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ListProjectsResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) ListProjectsResponse(com.ibm.watson.discovery.v2.model.ListProjectsResponse)

Aggregations

ListProjectsResponse (com.ibm.watson.discovery.v2.model.ListProjectsResponse)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 ListProjectsOptions (com.ibm.watson.discovery.v2.model.ListProjectsOptions)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1