Search in sources :

Example 1 with MetricResponse

use of com.ibm.watson.discovery.v1.model.MetricResponse 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 MetricResponse

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

the class DiscoveryTest method testGetMetricsQueryWOptions.

// Test the getMetricsQuery operation with a valid options model parameter
@Test
public void testGetMetricsQueryWOptions() 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 getMetricsQueryPath = "/v1/metrics/number_of_queries";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetMetricsQueryOptions model
    GetMetricsQueryOptions getMetricsQueryOptionsModel = new GetMetricsQueryOptions.Builder().startTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z")).endTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z")).resultType("document").build();
    // Invoke getMetricsQuery() with a valid options model and verify the result
    Response<MetricResponse> response = discoveryService.getMetricsQuery(getMetricsQueryOptionsModel).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, getMetricsQueryPath);
    // 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) GetMetricsQueryOptions(com.ibm.watson.discovery.v1.model.GetMetricsQueryOptions) Test(org.testng.annotations.Test)

Example 3 with MetricResponse

use of com.ibm.watson.discovery.v1.model.MetricResponse 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");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) MetricResponse(com.ibm.watson.discovery.v1.model.MetricResponse) GetMetricsQueryNoResultsOptions(com.ibm.watson.discovery.v1.model.GetMetricsQueryNoResultsOptions) Test(org.testng.annotations.Test)

Example 4 with MetricResponse

use of com.ibm.watson.discovery.v1.model.MetricResponse 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 5 with MetricResponse

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

the class DiscoveryServiceTest method getMetricsEventRateNoArgsIsSuccessful.

/**
 * Gets the metrics event rate no args is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getMetricsEventRateNoArgsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(metricResp));
    String interval = "1d";
    Long key = 1533513600000L;
    Double eventRate = 0.0;
    MetricResponse response = discoveryService.getMetricsEventRate().execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(GET_METRICS_EVENT_RATE_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)

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