use of com.google.webrisk.v1.ThreatType in project java-webrisk by googleapis.
the class WebRiskServiceClientTest method computeThreatListDiffTest.
@Test
public void computeThreatListDiffTest() throws Exception {
ComputeThreatListDiffResponse expectedResponse = ComputeThreatListDiffResponse.newBuilder().setAdditions(ThreatEntryAdditions.newBuilder().build()).setRemovals(ThreatEntryRemovals.newBuilder().build()).setNewVersionToken(ByteString.EMPTY).setChecksum(ComputeThreatListDiffResponse.Checksum.newBuilder().build()).setRecommendedNextDiff(Timestamp.newBuilder().build()).build();
mockWebRiskService.addResponse(expectedResponse);
ThreatType threatType = ThreatType.forNumber(0);
ByteString versionToken = ByteString.EMPTY;
ComputeThreatListDiffRequest.Constraints constraints = ComputeThreatListDiffRequest.Constraints.newBuilder().build();
ComputeThreatListDiffResponse actualResponse = client.computeThreatListDiff(threatType, versionToken, constraints);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockWebRiskService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ComputeThreatListDiffRequest actualRequest = ((ComputeThreatListDiffRequest) actualRequests.get(0));
Assert.assertEquals(threatType, actualRequest.getThreatType());
Assert.assertEquals(versionToken, actualRequest.getVersionToken());
Assert.assertEquals(constraints, actualRequest.getConstraints());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.webrisk.v1.ThreatType in project java-webrisk by googleapis.
the class WebRiskServiceClientTest method searchUrisTest.
@Test
public void searchUrisTest() throws Exception {
SearchUrisResponse expectedResponse = SearchUrisResponse.newBuilder().setThreat(SearchUrisResponse.ThreatUri.newBuilder().build()).build();
mockWebRiskService.addResponse(expectedResponse);
String uri = "uri116076";
List<ThreatType> threatTypes = new ArrayList<>();
SearchUrisResponse actualResponse = client.searchUris(uri, threatTypes);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockWebRiskService.getRequests();
Assert.assertEquals(1, actualRequests.size());
SearchUrisRequest actualRequest = ((SearchUrisRequest) actualRequests.get(0));
Assert.assertEquals(uri, actualRequest.getUri());
Assert.assertEquals(threatTypes, actualRequest.getThreatTypesList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.webrisk.v1.ThreatType in project java-webrisk by googleapis.
the class SearchUriExampleTest method testSearchWithThreat.
@Test
public void testSearchWithThreat() throws IOException {
// The URL to be searched
String uri = "http://testsafebrowsing.appspot.com/s/malware.html";
SearchUrisResponse actualResponse = SearchUriExample.searchUriExample(uri);
List<ThreatType> type = actualResponse.getThreat().getThreatTypesList();
Truth.assertThat(type).contains(ThreatType.MALWARE);
}
use of com.google.webrisk.v1.ThreatType in project java-webrisk by googleapis.
the class WebRiskServiceV1Beta1ClientTest method searchUrisExceptionTest.
@Test
public void searchUrisExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockWebRiskServiceV1Beta1.addException(exception);
try {
String uri = "uri116076";
List<ThreatType> threatTypes = new ArrayList<>();
client.searchUris(uri, threatTypes);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations