use of com.google.recaptchaenterprise.v1.Assessment in project pomocua-ogloszenia by coi-gov-pl.
the class CaptchaValidatorTest method validate_whenCaptchaStatusNotSuccess_expectFalse.
@Test
void validate_whenCaptchaStatusNotSuccess_expectFalse() {
// given
String recaptcha = "anytext";
Assessment response = createAssessmentResponse(false, 0);
when(recaptchaClient.createAssessment(any(CreateAssessmentRequest.class))).thenReturn(response);
// when
boolean result = captchaValidator.validate(recaptcha);
// then
assertAll(() -> assertThat(result).isFalse(), () -> verify(recaptchaClient, times(1)).createAssessment(any(CreateAssessmentRequest.class)));
}
use of com.google.recaptchaenterprise.v1.Assessment in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceClientTest method createAssessmentTest.
@Test
public void createAssessmentTest() throws Exception {
Assessment expectedResponse = Assessment.newBuilder().setName(AssessmentName.of("[PROJECT]", "[ASSESSMENT]").toString()).setEvent(Event.newBuilder().build()).setRiskAnalysis(RiskAnalysis.newBuilder().build()).setTokenProperties(TokenProperties.newBuilder().build()).setAccountDefenderAssessment(AccountDefenderAssessment.newBuilder().build()).build();
mockRecaptchaEnterpriseService.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
Assessment assessment = Assessment.newBuilder().build();
Assessment actualResponse = client.createAssessment(parent, assessment);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateAssessmentRequest actualRequest = ((CreateAssessmentRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(assessment, actualRequest.getAssessment());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.recaptchaenterprise.v1.Assessment in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceV1Beta1ClientTest method createAssessmentExceptionTest2.
@Test
public void createAssessmentExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
try {
String parent = "parent-995424086";
Assessment assessment = Assessment.newBuilder().build();
client.createAssessment(parent, assessment);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.recaptchaenterprise.v1.Assessment in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceV1Beta1ClientTest method createAssessmentExceptionTest.
@Test
public void createAssessmentExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
try {
ProjectName parent = ProjectName.of("[PROJECT]");
Assessment assessment = Assessment.newBuilder().build();
client.createAssessment(parent, assessment);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.recaptchaenterprise.v1.Assessment in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceV1Beta1ClientTest method createAssessmentTest.
@Test
public void createAssessmentTest() throws Exception {
Assessment expectedResponse = Assessment.newBuilder().setName(AssessmentName.of("[PROJECT]", "[ASSESSMENT]").toString()).setEvent(Event.newBuilder().build()).setScore(109264530).setTokenProperties(TokenProperties.newBuilder().build()).addAllReasons(new ArrayList<Assessment.ClassificationReason>()).build();
mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
Assessment assessment = Assessment.newBuilder().build();
Assessment actualResponse = client.createAssessment(parent, assessment);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateAssessmentRequest actualRequest = ((CreateAssessmentRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(assessment, actualRequest.getAssessment());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations