Search in sources :

Example 1 with TrainingQuerySet

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

the class DiscoveryTest method testListTrainingQueriesWOptions.

@Test
public void testListTrainingQueriesWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"queries\": [{\"query_id\": \"queryId\", \"natural_language_query\": \"naturalLanguageQuery\", \"filter\": \"filter\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"examples\": [{\"document_id\": \"documentId\", \"collection_id\": \"collectionId\", \"relevance\": 9, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}]}";
    String listTrainingQueriesPath = "/v2/projects/testString/training_data/queries";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ListTrainingQueriesOptions model
    ListTrainingQueriesOptions listTrainingQueriesOptionsModel = new ListTrainingQueriesOptions.Builder().projectId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<TrainingQuerySet> response = discoveryService.listTrainingQueries(listTrainingQueriesOptionsModel).execute();
    assertNotNull(response);
    TrainingQuerySet 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, listTrainingQueriesPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListTrainingQueriesOptions(com.ibm.watson.discovery.v2.model.ListTrainingQueriesOptions) TrainingQuerySet(com.ibm.watson.discovery.v2.model.TrainingQuerySet) Test(org.testng.annotations.Test)

Example 2 with TrainingQuerySet

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

the class Discovery method listTrainingQueries.

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

Aggregations

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