Search in sources :

Example 1 with MetricsName

use of com.google.recaptchaenterprise.v1.MetricsName in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method getMetricsExceptionTest.

@Test
public void getMetricsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockRecaptchaEnterpriseService.addException(exception);
    try {
        MetricsName name = MetricsName.of("[PROJECT]", "[KEY]");
        client.getMetrics(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) MetricsName(com.google.recaptchaenterprise.v1.MetricsName) Test(org.junit.Test)

Example 2 with MetricsName

use of com.google.recaptchaenterprise.v1.MetricsName in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method getMetricsTest.

@Test
public void getMetricsTest() throws Exception {
    Metrics expectedResponse = Metrics.newBuilder().setName(MetricsName.of("[PROJECT]", "[KEY]").toString()).setStartTime(Timestamp.newBuilder().build()).addAllScoreMetrics(new ArrayList<ScoreMetrics>()).addAllChallengeMetrics(new ArrayList<ChallengeMetrics>()).build();
    mockRecaptchaEnterpriseService.addResponse(expectedResponse);
    MetricsName name = MetricsName.of("[PROJECT]", "[KEY]");
    Metrics actualResponse = client.getMetrics(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetMetricsRequest actualRequest = ((GetMetricsRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ChallengeMetrics(com.google.recaptchaenterprise.v1.ChallengeMetrics) ScoreMetrics(com.google.recaptchaenterprise.v1.ScoreMetrics) Metrics(com.google.recaptchaenterprise.v1.Metrics) ScoreMetrics(com.google.recaptchaenterprise.v1.ScoreMetrics) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) GetMetricsRequest(com.google.recaptchaenterprise.v1.GetMetricsRequest) MetricsName(com.google.recaptchaenterprise.v1.MetricsName) Test(org.junit.Test)

Aggregations

MetricsName (com.google.recaptchaenterprise.v1.MetricsName)2 Test (org.junit.Test)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 ChallengeMetrics (com.google.recaptchaenterprise.v1.ChallengeMetrics)1 GetMetricsRequest (com.google.recaptchaenterprise.v1.GetMetricsRequest)1 Metrics (com.google.recaptchaenterprise.v1.Metrics)1 ScoreMetrics (com.google.recaptchaenterprise.v1.ScoreMetrics)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ArrayList (java.util.ArrayList)1