use of com.ibm.watson.discovery.v2.model.QueryNoticesOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testQueryNoticesWOptions.
// Test the queryNotices operation with a valid options model parameter
@Test
public void testQueryNoticesWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"matching_results\": 15, \"results\": [{\"id\": \"id\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"collection_id\": \"collectionId\", \"result_metadata\": {\"score\": 5, \"confidence\": 10}, \"code\": 4, \"filename\": \"filename\", \"file_type\": \"pdf\", \"sha1\": \"sha1\", \"notices\": [{\"notice_id\": \"noticeId\", \"created\": \"2019-01-01T12:00:00.000Z\", \"document_id\": \"documentId\", \"query_id\": \"queryId\", \"severity\": \"warning\", \"step\": \"step\", \"description\": \"description\"}]}], \"aggregations\": [{\"type\": \"filter\", \"match\": \"match\", \"matching_results\": 15}], \"passages\": [{\"document_id\": \"documentId\", \"passage_score\": 12, \"passage_text\": \"passageText\", \"start_offset\": 11, \"end_offset\": 9, \"field\": \"field\"}], \"duplicates_removed\": 17}";
String queryNoticesPath = "/v1/environments/testString/collections/testString/notices";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the QueryNoticesOptions model
QueryNoticesOptions queryNoticesOptionsModel = new QueryNoticesOptions.Builder().environmentId("testString").collectionId("testString").filter("testString").query("testString").naturalLanguageQuery("testString").passages(true).aggregation("testString").count(Long.valueOf("26")).xReturn(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).offset(Long.valueOf("26")).sort(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).highlight(false).passagesFields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).passagesCount(Long.valueOf("100")).passagesCharacters(Long.valueOf("50")).deduplicateField("testString").similar(false).similarDocumentIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).similarFields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
// Invoke queryNotices() with a valid options model and verify the result
Response<QueryNoticesResponse> response = discoveryService.queryNotices(queryNoticesOptionsModel).execute();
assertNotNull(response);
QueryNoticesResponse responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, queryNoticesPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(query.get("filter"), "testString");
assertEquals(query.get("query"), "testString");
assertEquals(query.get("natural_language_query"), "testString");
assertEquals(Boolean.valueOf(query.get("passages")), Boolean.valueOf(true));
assertEquals(query.get("aggregation"), "testString");
assertEquals(Long.valueOf(query.get("count")), Long.valueOf("26"));
assertEquals(query.get("return"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
assertEquals(Long.valueOf(query.get("offset")), Long.valueOf("26"));
assertEquals(query.get("sort"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
assertEquals(Boolean.valueOf(query.get("highlight")), Boolean.valueOf(false));
assertEquals(query.get("passages.fields"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
assertEquals(Long.valueOf(query.get("passages.count")), Long.valueOf("100"));
assertEquals(Long.valueOf(query.get("passages.characters")), Long.valueOf("50"));
assertEquals(query.get("deduplicate.field"), "testString");
assertEquals(Boolean.valueOf(query.get("similar")), Boolean.valueOf(false));
assertEquals(query.get("similar.document_ids"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
assertEquals(query.get("similar.fields"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
}
use of com.ibm.watson.discovery.v2.model.QueryNoticesOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testQueryNoticesWOptions.
@Test
public void testQueryNoticesWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"matching_results\": 15, \"notices\": [{\"notice_id\": \"noticeId\", \"created\": \"2019-01-01T12:00:00.000Z\", \"document_id\": \"documentId\", \"collection_id\": \"collectionId\", \"query_id\": \"queryId\", \"severity\": \"warning\", \"step\": \"step\", \"description\": \"description\"}]}";
String queryNoticesPath = "/v2/projects/testString/notices";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the QueryNoticesOptions model
QueryNoticesOptions queryNoticesOptionsModel = new QueryNoticesOptions.Builder().projectId("testString").filter("testString").query("testString").naturalLanguageQuery("testString").count(Long.valueOf("26")).offset(Long.valueOf("26")).build();
// Invoke operation with valid options model (positive test)
Response<QueryNoticesResponse> response = discoveryService.queryNotices(queryNoticesOptionsModel).execute();
assertNotNull(response);
QueryNoticesResponse 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");
assertEquals(query.get("filter"), "testString");
assertEquals(query.get("query"), "testString");
assertEquals(query.get("natural_language_query"), "testString");
assertEquals(Long.valueOf(query.get("count")), Long.valueOf("26"));
assertEquals(Long.valueOf(query.get("offset")), Long.valueOf("26"));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, queryNoticesPath);
}
use of com.ibm.watson.discovery.v2.model.QueryNoticesOptions in project java-sdk by watson-developer-cloud.
the class Discovery method queryNotices.
/**
* Query project notices.
*
* <p>Finds project-level notices (errors and warnings). Currently, project-level notices are
* generated by relevancy training.
*
* @param queryNoticesOptions the {@link QueryNoticesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link QueryNoticesResponse}
*/
public ServiceCall<QueryNoticesResponse> queryNotices(QueryNoticesOptions queryNoticesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(queryNoticesOptions, "queryNoticesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("project_id", queryNoticesOptions.projectId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/notices", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "queryNotices");
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));
if (queryNoticesOptions.filter() != null) {
builder.query("filter", String.valueOf(queryNoticesOptions.filter()));
}
if (queryNoticesOptions.query() != null) {
builder.query("query", String.valueOf(queryNoticesOptions.query()));
}
if (queryNoticesOptions.naturalLanguageQuery() != null) {
builder.query("natural_language_query", String.valueOf(queryNoticesOptions.naturalLanguageQuery()));
}
if (queryNoticesOptions.count() != null) {
builder.query("count", String.valueOf(queryNoticesOptions.count()));
}
if (queryNoticesOptions.offset() != null) {
builder.query("offset", String.valueOf(queryNoticesOptions.offset()));
}
ResponseConverter<QueryNoticesResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<QueryNoticesResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations