use of com.google.webrisk.v1.ThreatType in project java-webrisk by googleapis.
the class WebRiskServiceV1Beta1ClientTest 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();
mockWebRiskServiceV1Beta1.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 = mockWebRiskServiceV1Beta1.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 SearchUriExampleTest method testSearchWithoutThreat.
@Test
public void testSearchWithoutThreat() throws IOException {
// The URL to be searched
String uri = "http://testsafebrowsing.appspot.com/malware.html";
SearchUrisResponse actualResponse = SearchUriExample.searchUriExample(uri);
List<ThreatType> type = actualResponse.getThreat().getThreatTypesList();
Truth.assertThat(type).isEmpty();
}
use of com.google.webrisk.v1.ThreatType in project java-webrisk by googleapis.
the class WebRiskServiceClientTest method searchHashesTest.
@Test
public void searchHashesTest() throws Exception {
SearchHashesResponse expectedResponse = SearchHashesResponse.newBuilder().addAllThreats(new ArrayList<SearchHashesResponse.ThreatHash>()).setNegativeExpireTime(Timestamp.newBuilder().build()).build();
mockWebRiskService.addResponse(expectedResponse);
ByteString hashPrefix = ByteString.EMPTY;
List<ThreatType> threatTypes = new ArrayList<>();
SearchHashesResponse actualResponse = client.searchHashes(hashPrefix, threatTypes);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockWebRiskService.getRequests();
Assert.assertEquals(1, actualRequests.size());
SearchHashesRequest actualRequest = ((SearchHashesRequest) actualRequests.get(0));
Assert.assertEquals(hashPrefix, actualRequest.getHashPrefix());
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 WebRiskServiceClientTest method searchHashesExceptionTest.
@Test
public void searchHashesExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockWebRiskService.addException(exception);
try {
ByteString hashPrefix = ByteString.EMPTY;
List<ThreatType> threatTypes = new ArrayList<>();
client.searchHashes(hashPrefix, threatTypes);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.webrisk.v1.ThreatType in project java-webrisk by googleapis.
the class WebRiskServiceClientTest method computeThreatListDiffExceptionTest.
@Test
public void computeThreatListDiffExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockWebRiskService.addException(exception);
try {
ThreatType threatType = ThreatType.forNumber(0);
ByteString versionToken = ByteString.EMPTY;
ComputeThreatListDiffRequest.Constraints constraints = ComputeThreatListDiffRequest.Constraints.newBuilder().build();
client.computeThreatListDiff(threatType, versionToken, constraints);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations