use of com.ibm.watson.discovery.v1.model.GetMetricsQueryNoResultsOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testGetMetricsQueryNoResultsWOptions.
// Test the getMetricsQueryNoResults operation with a valid options model parameter
@Test
public void testGetMetricsQueryNoResultsWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"aggregations\": [{\"interval\": \"interval\", \"event_type\": \"eventType\", \"results\": [{\"key_as_string\": \"2019-01-01T12:00:00.000Z\", \"key\": 3, \"matching_results\": 15, \"event_rate\": 9}]}]}";
String getMetricsQueryNoResultsPath = "/v1/metrics/number_of_queries_with_no_search_results";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the GetMetricsQueryNoResultsOptions model
GetMetricsQueryNoResultsOptions getMetricsQueryNoResultsOptionsModel = new GetMetricsQueryNoResultsOptions.Builder().startTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z")).endTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z")).resultType("document").build();
// Invoke getMetricsQueryNoResults() with a valid options model and verify the result
Response<MetricResponse> response = discoveryService.getMetricsQueryNoResults(getMetricsQueryNoResultsOptionsModel).execute();
assertNotNull(response);
MetricResponse 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, getMetricsQueryNoResultsPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(query.get("result_type"), "document");
}
use of com.ibm.watson.discovery.v1.model.GetMetricsQueryNoResultsOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method getMetricsQueryNoResultsIsSuccessful.
/**
* Gets the metrics query no results is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void getMetricsQueryNoResultsIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(metricResp));
String interval = "1d";
Long key = 1533513600000L;
Double eventRate = 0.0;
GetMetricsQueryNoResultsOptions options = new GetMetricsQueryNoResultsOptions.Builder().startTime(date).endTime(date).resultType(GetMetricsQueryEventOptions.ResultType.DOCUMENT).build();
MetricResponse response = discoveryService.getMetricsQueryNoResults(options).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(GET, request.getMethod());
assertTrue(!response.getAggregations().isEmpty());
assertEquals(interval, response.getAggregations().get(0).getInterval());
assertEquals(CreateEventOptions.Type.CLICK, response.getAggregations().get(0).getEventType());
assertTrue(!response.getAggregations().get(0).getResults().isEmpty());
assertEquals(key, response.getAggregations().get(0).getResults().get(0).getKey());
assertNotNull(response.getAggregations().get(0).getResults().get(0).getKeyAsString());
assertEquals(eventRate, response.getAggregations().get(0).getResults().get(0).getEventRate());
}
use of com.ibm.watson.discovery.v1.model.GetMetricsQueryNoResultsOptions in project java-sdk by watson-developer-cloud.
the class Discovery method getMetricsQueryNoResults.
/**
* Number of queries with no search results over time.
*
* <p>Total number of queries using the **natural_language_query** parameter that have no results
* returned over a specified time window.
*
* @param getMetricsQueryNoResultsOptions the {@link GetMetricsQueryNoResultsOptions} containing
* the options for the call
* @return a {@link ServiceCall} with a result of type {@link MetricResponse}
*/
public ServiceCall<MetricResponse> getMetricsQueryNoResults(GetMetricsQueryNoResultsOptions getMetricsQueryNoResultsOptions) {
if (getMetricsQueryNoResultsOptions == null) {
getMetricsQueryNoResultsOptions = new GetMetricsQueryNoResultsOptions.Builder().build();
}
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/metrics/number_of_queries_with_no_search_results"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getMetricsQueryNoResults");
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 (getMetricsQueryNoResultsOptions.startTime() != null) {
builder.query("start_time", DateUtils.formatAsDateTime(getMetricsQueryNoResultsOptions.startTime()));
}
if (getMetricsQueryNoResultsOptions.endTime() != null) {
builder.query("end_time", DateUtils.formatAsDateTime(getMetricsQueryNoResultsOptions.endTime()));
}
if (getMetricsQueryNoResultsOptions.resultType() != null) {
builder.query("result_type", String.valueOf(getMetricsQueryNoResultsOptions.resultType()));
}
ResponseConverter<MetricResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<MetricResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations