Search in sources :

Example 1 with GetMetricsQueryEventOptions

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

the class DiscoveryServiceTest method getMetricsQueryEventIsSuccessful.

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

Example 2 with GetMetricsQueryEventOptions

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

the class DiscoveryTest method testGetMetricsQueryEventWOptions.

// Test the getMetricsQueryEvent operation with a valid options model parameter
@Test
public void testGetMetricsQueryEventWOptions() 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 getMetricsQueryEventPath = "/v1/metrics/number_of_queries_with_event";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetMetricsQueryEventOptions model
    GetMetricsQueryEventOptions getMetricsQueryEventOptionsModel = new GetMetricsQueryEventOptions.Builder().startTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z")).endTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z")).resultType("document").build();
    // Invoke getMetricsQueryEvent() with a valid options model and verify the result
    Response<MetricResponse> response = discoveryService.getMetricsQueryEvent(getMetricsQueryEventOptionsModel).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, getMetricsQueryEventPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(query.get("result_type"), "document");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) MetricResponse(com.ibm.watson.discovery.v1.model.MetricResponse) GetMetricsQueryEventOptions(com.ibm.watson.discovery.v1.model.GetMetricsQueryEventOptions) Test(org.testng.annotations.Test)

Example 3 with GetMetricsQueryEventOptions

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

the class Discovery method getMetricsQueryEvent.

/**
 * Number of queries with an event over time.
 *
 * <p>Total number of queries using the **natural_language_query** parameter that have a
 * corresponding "click" event over a specified time window. This metric requires having
 * integrated event tracking in your application using the **Events** API.
 *
 * @param getMetricsQueryEventOptions the {@link GetMetricsQueryEventOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link MetricResponse}
 */
public ServiceCall<MetricResponse> getMetricsQueryEvent(GetMetricsQueryEventOptions getMetricsQueryEventOptions) {
    if (getMetricsQueryEventOptions == null) {
        getMetricsQueryEventOptions = new GetMetricsQueryEventOptions.Builder().build();
    }
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/metrics/number_of_queries_with_event"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getMetricsQueryEvent");
    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 (getMetricsQueryEventOptions.startTime() != null) {
        builder.query("start_time", DateUtils.formatAsDateTime(getMetricsQueryEventOptions.startTime()));
    }
    if (getMetricsQueryEventOptions.endTime() != null) {
        builder.query("end_time", DateUtils.formatAsDateTime(getMetricsQueryEventOptions.endTime()));
    }
    if (getMetricsQueryEventOptions.resultType() != null) {
        builder.query("result_type", String.valueOf(getMetricsQueryEventOptions.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)3 GetMetricsQueryEventOptions (com.ibm.watson.discovery.v1.model.GetMetricsQueryEventOptions)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.testng.annotations.Test)1