Search in sources :

Example 11 with Assessment

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)));
}
Also used : Assessment(com.google.recaptchaenterprise.v1beta1.Assessment) CreateAssessmentRequest(com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest) Test(org.junit.jupiter.api.Test)

Example 12 with Assessment

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.recaptchaenterprise.v1.ProjectName) Assessment(com.google.recaptchaenterprise.v1.Assessment) AccountDefenderAssessment(com.google.recaptchaenterprise.v1.AccountDefenderAssessment) CreateAssessmentRequest(com.google.recaptchaenterprise.v1.CreateAssessmentRequest) Test(org.junit.Test)

Example 13 with Assessment

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Assessment(com.google.recaptchaenterprise.v1beta1.Assessment) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 14 with Assessment

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.recaptchaenterprise.v1beta1.ProjectName) Assessment(com.google.recaptchaenterprise.v1beta1.Assessment) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 15 with Assessment

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.recaptchaenterprise.v1beta1.ProjectName) Assessment(com.google.recaptchaenterprise.v1beta1.Assessment) ArrayList(java.util.ArrayList) CreateAssessmentRequest(com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 Assessment (com.google.recaptchaenterprise.v1beta1.Assessment)8 Assessment (com.google.recaptchaenterprise.v1.Assessment)6 CreateAssessmentRequest (com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 AccountDefenderAssessment (com.google.recaptchaenterprise.v1.AccountDefenderAssessment)4 AnnotateAssessmentRequest (com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest)3 CreateAssessmentRequest (com.google.recaptchaenterprise.v1.CreateAssessmentRequest)3 ProjectName (com.google.recaptchaenterprise.v1beta1.ProjectName)3 Test (org.junit.jupiter.api.Test)3 RecaptchaEnterpriseServiceClient (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)2 ByteString (com.google.protobuf.ByteString)2 AnnotateAssessmentResponse (com.google.recaptchaenterprise.v1.AnnotateAssessmentResponse)2 AssessmentName (com.google.recaptchaenterprise.v1.AssessmentName)2 Event (com.google.recaptchaenterprise.v1.Event)2 ProjectName (com.google.recaptchaenterprise.v1.ProjectName)2 ArrayList (java.util.ArrayList)2 RecaptchaEnterpriseServiceV1Beta1Client (com.google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client)1