Search in sources :

Example 1 with AnnotateAssessmentRequest

use of com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceV1Beta1ClientTest method annotateAssessmentTest2.

@Test
public void annotateAssessmentTest2() throws Exception {
    AnnotateAssessmentResponse expectedResponse = AnnotateAssessmentResponse.newBuilder().build();
    mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
    String name = "name3373707";
    AnnotateAssessmentRequest.Annotation annotation = AnnotateAssessmentRequest.Annotation.forNumber(0);
    AnnotateAssessmentResponse actualResponse = client.annotateAssessment(name, annotation);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnnotateAssessmentRequest actualRequest = ((AnnotateAssessmentRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertEquals(annotation, actualRequest.getAnnotation());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AnnotateAssessmentRequest(com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest) AbstractMessage(com.google.protobuf.AbstractMessage) AnnotateAssessmentResponse(com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentResponse) Test(org.junit.Test)

Example 2 with AnnotateAssessmentRequest

use of com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceV1Beta1ClientTest method annotateAssessmentTest.

@Test
public void annotateAssessmentTest() throws Exception {
    AnnotateAssessmentResponse expectedResponse = AnnotateAssessmentResponse.newBuilder().build();
    mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
    AssessmentName name = AssessmentName.of("[PROJECT]", "[ASSESSMENT]");
    AnnotateAssessmentRequest.Annotation annotation = AnnotateAssessmentRequest.Annotation.forNumber(0);
    AnnotateAssessmentResponse actualResponse = client.annotateAssessment(name, annotation);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnnotateAssessmentRequest actualRequest = ((AnnotateAssessmentRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(annotation, actualRequest.getAnnotation());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AnnotateAssessmentRequest(com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest) AbstractMessage(com.google.protobuf.AbstractMessage) AnnotateAssessmentResponse(com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentResponse) AssessmentName(com.google.recaptchaenterprise.v1beta1.AssessmentName) Test(org.junit.Test)

Example 3 with AnnotateAssessmentRequest

use of com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method annotateAssessmentTest.

@Test
public void annotateAssessmentTest() throws Exception {
    AnnotateAssessmentResponse expectedResponse = AnnotateAssessmentResponse.newBuilder().build();
    mockRecaptchaEnterpriseService.addResponse(expectedResponse);
    AssessmentName name = AssessmentName.of("[PROJECT]", "[ASSESSMENT]");
    AnnotateAssessmentRequest.Annotation annotation = AnnotateAssessmentRequest.Annotation.forNumber(0);
    AnnotateAssessmentResponse actualResponse = client.annotateAssessment(name, annotation);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnnotateAssessmentRequest actualRequest = ((AnnotateAssessmentRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(annotation, actualRequest.getAnnotation());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AnnotateAssessmentRequest(com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest) AbstractMessage(com.google.protobuf.AbstractMessage) AnnotateAssessmentResponse(com.google.recaptchaenterprise.v1.AnnotateAssessmentResponse) AssessmentName(com.google.recaptchaenterprise.v1.AssessmentName) Test(org.junit.Test)

Example 4 with AnnotateAssessmentRequest

use of com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest in project java-recaptchaenterprise by googleapis.

the class AnnotateAssessment method annotateAssessment.

/**
 * Pre-requisite: Create an assessment before annotating.
 *
 * <p>Annotate an assessment to provide feedback on the correctness of recaptcha prediction.
 *
 * @param projectID: GCloud Project id
 * @param assessmentId: Value of the 'name' field returned from the CreateAssessment call.
 */
public static void annotateAssessment(String projectID, String assessmentId) throws IOException {
    // clean up any remaining background resources.
    try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
        // Build the annotation request.
        // For more info on when/how to annotate, see:
        // https://cloud.google.com/recaptcha-enterprise/docs/annotate-assessment#when_to_annotate
        AnnotateAssessmentRequest annotateAssessmentRequest = AnnotateAssessmentRequest.newBuilder().setName(AssessmentName.of(projectID, assessmentId).toString()).setAnnotation(Annotation.FRAUDULENT).addReasons(Reason.FAILED_TWO_FACTOR).build();
        // Empty response is sent back.
        AnnotateAssessmentResponse response = client.annotateAssessment(annotateAssessmentRequest);
        System.out.println("Annotated response sent successfully ! " + response);
    }
}
Also used : AnnotateAssessmentRequest(com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest) AnnotateAssessmentResponse(com.google.recaptchaenterprise.v1.AnnotateAssessmentResponse) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Example 5 with AnnotateAssessmentRequest

use of com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method annotateAssessmentTest2.

@Test
public void annotateAssessmentTest2() throws Exception {
    AnnotateAssessmentResponse expectedResponse = AnnotateAssessmentResponse.newBuilder().build();
    mockRecaptchaEnterpriseService.addResponse(expectedResponse);
    String name = "name3373707";
    AnnotateAssessmentRequest.Annotation annotation = AnnotateAssessmentRequest.Annotation.forNumber(0);
    AnnotateAssessmentResponse actualResponse = client.annotateAssessment(name, annotation);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnnotateAssessmentRequest actualRequest = ((AnnotateAssessmentRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertEquals(annotation, actualRequest.getAnnotation());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AnnotateAssessmentRequest(com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest) AbstractMessage(com.google.protobuf.AbstractMessage) AnnotateAssessmentResponse(com.google.recaptchaenterprise.v1.AnnotateAssessmentResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

AbstractMessage (com.google.protobuf.AbstractMessage)4 Test (org.junit.Test)4 AnnotateAssessmentRequest (com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest)3 AnnotateAssessmentResponse (com.google.recaptchaenterprise.v1.AnnotateAssessmentResponse)3 AnnotateAssessmentRequest (com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest)2 AnnotateAssessmentResponse (com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentResponse)2 RecaptchaEnterpriseServiceClient (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)1 ByteString (com.google.protobuf.ByteString)1 AssessmentName (com.google.recaptchaenterprise.v1.AssessmentName)1 AssessmentName (com.google.recaptchaenterprise.v1beta1.AssessmentName)1