Search in sources :

Example 6 with MetricResponse

use of com.ibm.watson.discovery.v1.model.MetricResponse 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());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MetricResponse(com.ibm.watson.discovery.v1.model.MetricResponse) GetMetricsQueryNoResultsOptions(com.ibm.watson.discovery.v1.model.GetMetricsQueryNoResultsOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 7 with MetricResponse

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

the class DiscoveryServiceTest method getMetricsQueryIsSuccessful.

/**
 * Gets the metrics query is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getMetricsQueryIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(metricResp));
    String interval = "1d";
    Long key = 1533513600000L;
    Double eventRate = 0.0;
    GetMetricsQueryOptions options = new GetMetricsQueryOptions.Builder().startTime(date).endTime(date).resultType(GetMetricsQueryOptions.ResultType.DOCUMENT).build();
    MetricResponse response = discoveryService.getMetricsQuery(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());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MetricResponse(com.ibm.watson.discovery.v1.model.MetricResponse) GetMetricsQueryOptions(com.ibm.watson.discovery.v1.model.GetMetricsQueryOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 8 with MetricResponse

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

the class DiscoveryServiceTest method getMetricsQueryEventNoArgsIsSuccessful.

/**
 * Gets the metrics query event no args is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getMetricsQueryEventNoArgsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(metricResp));
    String interval = "1d";
    Long key = 1533513600000L;
    Double eventRate = 0.0;
    MetricResponse response = discoveryService.getMetricsQueryEvent().execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(GET_METRICS_QUERY_EVENT_PATH, request.getPath());
    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());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MetricResponse(com.ibm.watson.discovery.v1.model.MetricResponse) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 9 with MetricResponse

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

the class DiscoveryServiceTest method getMetricsQueryNoResultsNoArgsIsSuccessful.

/**
 * Gets the metrics query no results no args is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getMetricsQueryNoResultsNoArgsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(metricResp));
    String interval = "1d";
    Long key = 1533513600000L;
    Double eventRate = 0.0;
    MetricResponse response = discoveryService.getMetricsQueryNoResults().execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(GET_METRICS_QUERY_NO_RESULTS_PATH, request.getPath());
    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());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MetricResponse(com.ibm.watson.discovery.v1.model.MetricResponse) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 10 with MetricResponse

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

the class Discovery method getMetricsQuery.

/**
 * Number of queries over time.
 *
 * <p>Total number of queries using the **natural_language_query** parameter over a specific time
 * window.
 *
 * @param getMetricsQueryOptions the {@link GetMetricsQueryOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link MetricResponse}
 */
public ServiceCall<MetricResponse> getMetricsQuery(GetMetricsQueryOptions getMetricsQueryOptions) {
    if (getMetricsQueryOptions == null) {
        getMetricsQueryOptions = new GetMetricsQueryOptions.Builder().build();
    }
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/metrics/number_of_queries"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getMetricsQuery");
    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 (getMetricsQueryOptions.startTime() != null) {
        builder.query("start_time", DateUtils.formatAsDateTime(getMetricsQueryOptions.startTime()));
    }
    if (getMetricsQueryOptions.endTime() != null) {
        builder.query("end_time", DateUtils.formatAsDateTime(getMetricsQueryOptions.endTime()));
    }
    if (getMetricsQueryOptions.resultType() != null) {
        builder.query("result_type", String.valueOf(getMetricsQueryOptions.resultType()));
    }
    ResponseConverter<MetricResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<MetricResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) MetricResponse(com.ibm.watson.discovery.v1.model.MetricResponse) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Aggregations

MetricResponse (com.ibm.watson.discovery.v1.model.MetricResponse)16 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)12 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)8 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 Test (org.testng.annotations.Test)4 GetMetricsEventRateOptions (com.ibm.watson.discovery.v1.model.GetMetricsEventRateOptions)2 GetMetricsQueryEventOptions (com.ibm.watson.discovery.v1.model.GetMetricsQueryEventOptions)2 GetMetricsQueryNoResultsOptions (com.ibm.watson.discovery.v1.model.GetMetricsQueryNoResultsOptions)2 GetMetricsQueryOptions (com.ibm.watson.discovery.v1.model.GetMetricsQueryOptions)2