Search in sources :

Example 1 with GetProjectOptions

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

the class DiscoveryTest method testGetProjectWOptions.

@Test
public void testGetProjectWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"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, \"default_query_parameters\": {\"collection_ids\": [\"collectionIds\"], \"passages\": {\"enabled\": false, \"count\": 5, \"fields\": [\"fields\"], \"characters\": 10, \"per_document\": false, \"max_per_document\": 14}, \"table_results\": {\"enabled\": false, \"count\": 5, \"per_document\": 11}, \"aggregation\": \"aggregation\", \"suggested_refinements\": {\"enabled\": false, \"count\": 5}, \"spelling_suggestions\": false, \"highlight\": false, \"count\": 5, \"sort\": \"sort\", \"return\": [\"xReturn\"]}}";
    String getProjectPath = "/v2/projects/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetProjectOptions model
    GetProjectOptions getProjectOptionsModel = new GetProjectOptions.Builder().projectId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<ProjectDetails> response = discoveryService.getProject(getProjectOptionsModel).execute();
    assertNotNull(response);
    ProjectDetails 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, getProjectPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ProjectDetails(com.ibm.watson.discovery.v2.model.ProjectDetails) GetProjectOptions(com.ibm.watson.discovery.v2.model.GetProjectOptions) Test(org.testng.annotations.Test)

Example 2 with GetProjectOptions

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

the class Discovery method getProject.

/**
 * Get project.
 *
 * <p>Get details on the specified project.
 *
 * @param getProjectOptions the {@link GetProjectOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ProjectDetails}
 */
public ServiceCall<ProjectDetails> getProject(GetProjectOptions getProjectOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getProjectOptions, "getProjectOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", getProjectOptions.projectId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "getProject");
    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<ProjectDetails> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ProjectDetails>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : ProjectDetails(com.ibm.watson.discovery.v2.model.ProjectDetails) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Aggregations

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