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