Search in sources :

Example 1 with MetricTokenResponse

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

the class DiscoveryTest method testGetMetricsQueryTokenEventWOptions.

// Test the getMetricsQueryTokenEvent operation with a valid options model parameter
@Test
public void testGetMetricsQueryTokenEventWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"aggregations\": [{\"event_type\": \"eventType\", \"results\": [{\"key\": \"key\", \"matching_results\": 15, \"event_rate\": 9}]}]}";
    String getMetricsQueryTokenEventPath = "/v1/metrics/top_query_tokens_with_event_rate";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetMetricsQueryTokenEventOptions model
    GetMetricsQueryTokenEventOptions getMetricsQueryTokenEventOptionsModel = new GetMetricsQueryTokenEventOptions.Builder().count(Long.valueOf("26")).build();
    // Invoke getMetricsQueryTokenEvent() with a valid options model and verify the result
    Response<MetricTokenResponse> response = discoveryService.getMetricsQueryTokenEvent(getMetricsQueryTokenEventOptionsModel).execute();
    assertNotNull(response);
    MetricTokenResponse 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, getMetricsQueryTokenEventPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Long.valueOf(query.get("count")), Long.valueOf("26"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetMetricsQueryTokenEventOptions(com.ibm.watson.discovery.v1.model.GetMetricsQueryTokenEventOptions) MetricTokenResponse(com.ibm.watson.discovery.v1.model.MetricTokenResponse) Test(org.testng.annotations.Test)

Example 2 with MetricTokenResponse

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

the class DiscoveryServiceTest method getMetricsQueryTokenEventIsSuccessful.

/**
 * Gets the metrics query token event is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getMetricsQueryTokenEventIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(metricTokenResp));
    Long count = 10L;
    String key = "beat";
    Long matchingResults = 117L;
    Double eventRate = 0.0;
    GetMetricsQueryTokenEventOptions options = new GetMetricsQueryTokenEventOptions.Builder().count(count).build();
    MetricTokenResponse response = discoveryService.getMetricsQueryTokenEvent(options).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(GET, request.getMethod());
    assertTrue(!response.getAggregations().isEmpty());
    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());
    assertEquals(matchingResults, response.getAggregations().get(0).getResults().get(0).getMatchingResults());
    assertEquals(eventRate, response.getAggregations().get(0).getResults().get(0).getEventRate());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetMetricsQueryTokenEventOptions(com.ibm.watson.discovery.v1.model.GetMetricsQueryTokenEventOptions) MetricTokenResponse(com.ibm.watson.discovery.v1.model.MetricTokenResponse) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 3 with MetricTokenResponse

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

the class DiscoveryServiceTest method getMetricsQueryTokenEventNoArgsIsSuccessful.

/**
 * Gets the metrics query token event no args is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getMetricsQueryTokenEventNoArgsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(metricTokenResp));
    String key = "beat";
    Long matchingResults = 117L;
    Double eventRate = 0.0;
    MetricTokenResponse response = discoveryService.getMetricsQueryTokenEvent().execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(GET_METRICS_QUERY_TOKEN_EVENT_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertTrue(!response.getAggregations().isEmpty());
    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());
    assertEquals(matchingResults, response.getAggregations().get(0).getResults().get(0).getMatchingResults());
    assertEquals(eventRate, response.getAggregations().get(0).getResults().get(0).getEventRate());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MetricTokenResponse(com.ibm.watson.discovery.v1.model.MetricTokenResponse) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 4 with MetricTokenResponse

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

the class Discovery method getMetricsQueryTokenEvent.

/**
 * Most frequent query tokens with an event.
 *
 * <p>The most frequent query tokens parsed from the **natural_language_query** parameter and
 * their corresponding "click" event rate within the recording period (queries and events are
 * stored for 30 days). A query token is an individual word or unigram within the query string.
 *
 * @param getMetricsQueryTokenEventOptions the {@link GetMetricsQueryTokenEventOptions} containing
 *     the options for the call
 * @return a {@link ServiceCall} with a result of type {@link MetricTokenResponse}
 */
public ServiceCall<MetricTokenResponse> getMetricsQueryTokenEvent(GetMetricsQueryTokenEventOptions getMetricsQueryTokenEventOptions) {
    if (getMetricsQueryTokenEventOptions == null) {
        getMetricsQueryTokenEventOptions = new GetMetricsQueryTokenEventOptions.Builder().build();
    }
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/metrics/top_query_tokens_with_event_rate"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getMetricsQueryTokenEvent");
    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 (getMetricsQueryTokenEventOptions.count() != null) {
        builder.query("count", String.valueOf(getMetricsQueryTokenEventOptions.count()));
    }
    ResponseConverter<MetricTokenResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<MetricTokenResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) MetricTokenResponse(com.ibm.watson.discovery.v1.model.MetricTokenResponse) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Aggregations

MetricTokenResponse (com.ibm.watson.discovery.v1.model.MetricTokenResponse)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)2 GetMetricsQueryTokenEventOptions (com.ibm.watson.discovery.v1.model.GetMetricsQueryTokenEventOptions)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.testng.annotations.Test)1