Search in sources :

Example 1 with Submission

use of com.google.webrisk.v1.Submission in project java-webrisk by googleapis.

the class WebRiskServiceClientTest method createSubmissionTest.

@Test
public void createSubmissionTest() throws Exception {
    Submission expectedResponse = Submission.newBuilder().setUri("uri116076").build();
    mockWebRiskService.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    Submission submission = Submission.newBuilder().build();
    Submission actualResponse = client.createSubmission(parent, submission);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockWebRiskService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSubmissionRequest actualRequest = ((CreateSubmissionRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(submission, actualRequest.getSubmission());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Submission(com.google.webrisk.v1.Submission) ProjectName(com.google.webrisk.v1.ProjectName) CreateSubmissionRequest(com.google.webrisk.v1.CreateSubmissionRequest) Test(org.junit.Test)

Example 2 with Submission

use of com.google.webrisk.v1.Submission in project java-webrisk by googleapis.

the class SubmitUriExample method submitUriExample.

// [START webrisk_submit_uri]
public static Submission submitUriExample(String uri) throws IOException {
    // create-webrisk-client
    try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) {
        Submission submission = Submission.newBuilder().setUri(uri).build();
        CreateSubmissionRequest submissionRequest = CreateSubmissionRequest.newBuilder().setParent("projects/your-project-id").setSubmission(submission).build();
        Submission submissionResponse = webRiskServiceClient.createSubmission(submissionRequest);
        webRiskServiceClient.shutdownNow();
        System.out.println("The submitted " + submissionResponse);
        return submissionResponse;
    }
}
Also used : Submission(com.google.webrisk.v1.Submission) WebRiskServiceClient(com.google.cloud.webrisk.v1.WebRiskServiceClient) CreateSubmissionRequest(com.google.webrisk.v1.CreateSubmissionRequest)

Example 3 with Submission

use of com.google.webrisk.v1.Submission in project java-webrisk by googleapis.

the class SubmitUriExampleTest method testSumbitUriExample.

@Test
public void testSumbitUriExample() throws IOException {
    String testUri = "http://testsafebrowsing.appspot.com/s/malware.html";
    Submission actualSubmission = SubmitUriExample.submitUriExample(testUri);
    Truth.assertThat(actualSubmission.getUri()).isEqualTo(testUri);
}
Also used : Submission(com.google.webrisk.v1.Submission) Test(org.junit.Test)

Example 4 with Submission

use of com.google.webrisk.v1.Submission in project java-webrisk by googleapis.

the class WebRiskServiceClientTest method createSubmissionExceptionTest2.

@Test
public void createSubmissionExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockWebRiskService.addException(exception);
    try {
        String parent = "parent-995424086";
        Submission submission = Submission.newBuilder().build();
        client.createSubmission(parent, submission);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Submission(com.google.webrisk.v1.Submission) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 5 with Submission

use of com.google.webrisk.v1.Submission in project java-webrisk by googleapis.

the class WebRiskServiceClientTest method createSubmissionTest2.

@Test
public void createSubmissionTest2() throws Exception {
    Submission expectedResponse = Submission.newBuilder().setUri("uri116076").build();
    mockWebRiskService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    Submission submission = Submission.newBuilder().build();
    Submission actualResponse = client.createSubmission(parent, submission);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockWebRiskService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSubmissionRequest actualRequest = ((CreateSubmissionRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(submission, actualRequest.getSubmission());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Submission(com.google.webrisk.v1.Submission) ByteString(com.google.protobuf.ByteString) CreateSubmissionRequest(com.google.webrisk.v1.CreateSubmissionRequest) Test(org.junit.Test)

Aggregations

Submission (com.google.webrisk.v1.Submission)7 Test (org.junit.Test)5 CreateSubmissionRequest (com.google.webrisk.v1.CreateSubmissionRequest)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ByteString (com.google.protobuf.ByteString)2 ProjectName (com.google.webrisk.v1.ProjectName)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 WebRiskServiceClient (com.google.cloud.webrisk.v1.WebRiskServiceClient)1