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.
}
}
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()));
}
Aggregations