use of com.ibm.watson.discovery.v1.model.LogQueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method queryLogIsSuccessful.
/**
* Query log is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void queryLogIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(logQueryResp));
List<String> sortList = new ArrayList<>();
sortList.add("field_a");
String extraSort = "field_b";
String filter = "filter";
String naturalLanguageQuery = "Who beat Ken Jennings in Jeopardy!";
Long count = 5L;
Long offset = 5L;
Long matchingResults = 2L;
String customerId = "";
String sessionToken = "mock_session_token";
String eventType = "query";
Long resultCount = 0L;
QueryLogOptions options = new QueryLogOptions.Builder().sort(sortList).addSort(extraSort).count(count).filter(filter).offset(offset).query(naturalLanguageQuery).build();
LogQueryResponse response = discoveryService.queryLog(options).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(GET, request.getMethod());
assertEquals(matchingResults, response.getMatchingResults());
assertTrue(!response.getResults().isEmpty());
assertEquals(environmentId, response.getResults().get(0).getEnvironmentId());
assertEquals(customerId, response.getResults().get(0).getCustomerId());
assertNotNull(response.getResults().get(0).getCreatedTimestamp());
assertEquals(queryId, response.getResults().get(0).getQueryId());
assertEquals(sessionToken, response.getResults().get(0).getSessionToken());
assertEquals(eventType, response.getResults().get(0).getEventType());
assertNotNull(response.getResults().get(0).getDocumentResults().getResults());
assertEquals(resultCount, response.getResults().get(0).getDocumentResults().getCount());
}
use of com.ibm.watson.discovery.v1.model.LogQueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method queryLogNoArgsIsSuccessful.
/**
* Query log no args is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void queryLogNoArgsIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(logQueryResp));
List<String> sortList = new ArrayList<>();
sortList.add("field_a");
Long matchingResults = 2L;
String customerId = "";
String sessionToken = "mock_session_token";
String eventType = "query";
Long resultCount = 0L;
LogQueryResponse response = discoveryService.queryLog().execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(QUERY_LOG_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(matchingResults, response.getMatchingResults());
assertTrue(!response.getResults().isEmpty());
assertEquals(environmentId, response.getResults().get(0).getEnvironmentId());
assertEquals(customerId, response.getResults().get(0).getCustomerId());
assertNotNull(response.getResults().get(0).getCreatedTimestamp());
assertEquals(queryId, response.getResults().get(0).getQueryId());
assertEquals(sessionToken, response.getResults().get(0).getSessionToken());
assertEquals(eventType, response.getResults().get(0).getEventType());
assertNotNull(response.getResults().get(0).getDocumentResults().getResults());
assertEquals(resultCount, response.getResults().get(0).getDocumentResults().getCount());
}
use of com.ibm.watson.discovery.v1.model.LogQueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testQueryLogWOptions.
// Test the queryLog operation with a valid options model parameter
@Test
public void testQueryLogWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"matching_results\": 15, \"results\": [{\"environment_id\": \"environmentId\", \"customer_id\": \"customerId\", \"document_type\": \"query\", \"natural_language_query\": \"naturalLanguageQuery\", \"document_results\": {\"results\": [{\"position\": 8, \"document_id\": \"documentId\", \"score\": 5, \"confidence\": 10, \"collection_id\": \"collectionId\"}], \"count\": 5}, \"created_timestamp\": \"2019-01-01T12:00:00.000Z\", \"client_timestamp\": \"2019-01-01T12:00:00.000Z\", \"query_id\": \"queryId\", \"session_token\": \"sessionToken\", \"collection_id\": \"collectionId\", \"display_rank\": 11, \"document_id\": \"documentId\", \"event_type\": \"click\", \"result_type\": \"document\"}]}";
String queryLogPath = "/v1/logs";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the QueryLogOptions model
QueryLogOptions queryLogOptionsModel = new QueryLogOptions.Builder().filter("testString").query("testString").count(Long.valueOf("26")).offset(Long.valueOf("26")).sort(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
// Invoke queryLog() with a valid options model and verify the result
Response<LogQueryResponse> response = discoveryService.queryLog(queryLogOptionsModel).execute();
assertNotNull(response);
LogQueryResponse 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, queryLogPath);
// 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(Long.valueOf(query.get("count")), Long.valueOf("26"));
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")), ","));
}
use of com.ibm.watson.discovery.v1.model.LogQueryResponse in project java-sdk by watson-developer-cloud.
the class Discovery method queryLog.
/**
* Search the query and event log.
*
* <p>Searches the query and event log to find query sessions that match the specified criteria.
* Searching the **logs** endpoint uses the standard Discovery query syntax for the parameters
* that are supported.
*
* @param queryLogOptions the {@link QueryLogOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link LogQueryResponse}
*/
public ServiceCall<LogQueryResponse> queryLog(QueryLogOptions queryLogOptions) {
if (queryLogOptions == null) {
queryLogOptions = new QueryLogOptions.Builder().build();
}
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/logs"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "queryLog");
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 (queryLogOptions.filter() != null) {
builder.query("filter", String.valueOf(queryLogOptions.filter()));
}
if (queryLogOptions.query() != null) {
builder.query("query", String.valueOf(queryLogOptions.query()));
}
if (queryLogOptions.count() != null) {
builder.query("count", String.valueOf(queryLogOptions.count()));
}
if (queryLogOptions.offset() != null) {
builder.query("offset", String.valueOf(queryLogOptions.offset()));
}
if (queryLogOptions.sort() != null) {
builder.query("sort", RequestUtils.join(queryLogOptions.sort(), ","));
}
ResponseConverter<LogQueryResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<LogQueryResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations