Search in sources :

Example 1 with CreateProjectOptions

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

the class DiscoveryTest method testCreateProjectWOptions.

@Test
public void testCreateProjectWOptions() 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 createProjectPath = "/v2/projects";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the DefaultQueryParamsPassages model
    DefaultQueryParamsPassages defaultQueryParamsPassagesModel = new DefaultQueryParamsPassages.Builder().enabled(true).count(Long.valueOf("26")).fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).characters(Long.valueOf("26")).perDocument(true).maxPerDocument(Long.valueOf("26")).build();
    // Construct an instance of the DefaultQueryParamsTableResults model
    DefaultQueryParamsTableResults defaultQueryParamsTableResultsModel = new DefaultQueryParamsTableResults.Builder().enabled(true).count(Long.valueOf("26")).perDocument(Long.valueOf("26")).build();
    // Construct an instance of the DefaultQueryParamsSuggestedRefinements model
    DefaultQueryParamsSuggestedRefinements defaultQueryParamsSuggestedRefinementsModel = new DefaultQueryParamsSuggestedRefinements.Builder().enabled(true).count(Long.valueOf("26")).build();
    // Construct an instance of the DefaultQueryParams model
    DefaultQueryParams defaultQueryParamsModel = new DefaultQueryParams.Builder().collectionIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).passages(defaultQueryParamsPassagesModel).tableResults(defaultQueryParamsTableResultsModel).aggregation("testString").suggestedRefinements(defaultQueryParamsSuggestedRefinementsModel).spellingSuggestions(true).highlight(true).count(Long.valueOf("26")).sort("testString").xReturn(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the CreateProjectOptions model
    CreateProjectOptions createProjectOptionsModel = new CreateProjectOptions.Builder().name("testString").type("document_retrieval").defaultQueryParameters(defaultQueryParamsModel).build();
    // Invoke operation with valid options model (positive test)
    Response<ProjectDetails> response = discoveryService.createProject(createProjectOptionsModel).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, createProjectPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ProjectDetails(com.ibm.watson.discovery.v2.model.ProjectDetails) DefaultQueryParamsSuggestedRefinements(com.ibm.watson.discovery.v2.model.DefaultQueryParamsSuggestedRefinements) CreateProjectOptions(com.ibm.watson.discovery.v2.model.CreateProjectOptions) DefaultQueryParams(com.ibm.watson.discovery.v2.model.DefaultQueryParams) DefaultQueryParamsPassages(com.ibm.watson.discovery.v2.model.DefaultQueryParamsPassages) DefaultQueryParamsTableResults(com.ibm.watson.discovery.v2.model.DefaultQueryParamsTableResults) Test(org.testng.annotations.Test)

Example 2 with CreateProjectOptions

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

the class Discovery method createProject.

/**
 * Create a Project.
 *
 * <p>Create a new project for this instance.
 *
 * @param createProjectOptions the {@link CreateProjectOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link ProjectDetails}
 */
public ServiceCall<ProjectDetails> createProject(CreateProjectOptions createProjectOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createProjectOptions, "createProjectOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "createProject");
    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();
    contentJson.addProperty("name", createProjectOptions.name());
    contentJson.addProperty("type", createProjectOptions.type());
    if (createProjectOptions.defaultQueryParameters() != null) {
        contentJson.add("default_query_parameters", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createProjectOptions.defaultQueryParameters()));
    }
    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) 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 CreateProjectOptions (com.ibm.watson.discovery.v2.model.CreateProjectOptions)1 DefaultQueryParams (com.ibm.watson.discovery.v2.model.DefaultQueryParams)1 DefaultQueryParamsPassages (com.ibm.watson.discovery.v2.model.DefaultQueryParamsPassages)1 DefaultQueryParamsSuggestedRefinements (com.ibm.watson.discovery.v2.model.DefaultQueryParamsSuggestedRefinements)1 DefaultQueryParamsTableResults (com.ibm.watson.discovery.v2.model.DefaultQueryParamsTableResults)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1