Search in sources :

Example 1 with UpdateProjectOptions

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

the class DiscoveryTest method testUpdateProjectWOptions.

@Test
public void testUpdateProjectWOptions() 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 updateProjectPath = "/v2/projects/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the UpdateProjectOptions model
    UpdateProjectOptions updateProjectOptionsModel = new UpdateProjectOptions.Builder().projectId("testString").name("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<ProjectDetails> response = discoveryService.updateProject(updateProjectOptionsModel).execute();
    assertNotNull(response);
    ProjectDetails responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // 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, updateProjectPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ProjectDetails(com.ibm.watson.discovery.v2.model.ProjectDetails) UpdateProjectOptions(com.ibm.watson.discovery.v2.model.UpdateProjectOptions) Test(org.testng.annotations.Test)

Example 2 with UpdateProjectOptions

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

the class Discovery method updateProject.

/**
 * Update a project.
 *
 * <p>Update the specified project's name.
 *
 * @param updateProjectOptions the {@link UpdateProjectOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link ProjectDetails}
 */
public ServiceCall<ProjectDetails> updateProject(UpdateProjectOptions updateProjectOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateProjectOptions, "updateProjectOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", updateProjectOptions.projectId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "updateProject");
    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));
    final JsonObject contentJson = new JsonObject();
    if (updateProjectOptions.name() != null) {
        contentJson.addProperty("name", updateProjectOptions.name());
    }
    builder.bodyJson(contentJson);
    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) JsonObject(com.google.gson.JsonObject)

Aggregations

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