use of com.google.webrisk.v1beta1.SearchUrisResponse in project java-webrisk by googleapis.
the class WebRiskServiceV1Beta1ClientTest method searchUrisTest.
@Test
public void searchUrisTest() throws Exception {
SearchUrisResponse expectedResponse = SearchUrisResponse.newBuilder().setThreat(SearchUrisResponse.ThreatUri.newBuilder().build()).build();
mockWebRiskServiceV1Beta1.addResponse(expectedResponse);
String uri = "uri116076";
List<ThreatType> threatTypes = new ArrayList<>();
SearchUrisResponse actualResponse = client.searchUris(uri, threatTypes);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockWebRiskServiceV1Beta1.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.v1beta1.SearchUrisResponse in project java-webrisk by googleapis.
the class SearchUriExample method searchUriExample.
// [START webrisk_search_uri]
public static SearchUrisResponse searchUriExample(String uri) throws IOException {
// create-webrisk-client
try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) {
// Query the url for a specific threat type
SearchUrisRequest searchUrisRequest = SearchUrisRequest.newBuilder().addThreatTypes(ThreatType.MALWARE).setUri(uri).build();
SearchUrisResponse searchUrisResponse = webRiskServiceClient.searchUris(searchUrisRequest);
webRiskServiceClient.shutdownNow();
if (!searchUrisResponse.getThreat().getThreatTypesList().isEmpty()) {
System.out.println("The URL has the following threat : ");
System.out.println(searchUrisResponse);
} else {
System.out.println("The URL is safe!");
}
return searchUrisResponse;
}
}
use of com.google.webrisk.v1beta1.SearchUrisResponse 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.v1beta1.SearchUrisResponse 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.v1beta1.SearchUrisResponse in project java-webrisk by googleapis.
the class SearchUriExample method searchUriExample.
public static void searchUriExample() throws IOException {
// The URL to be searched
String uri = "http://testsafebrowsing.appspot.com/s/malware.html";
SearchUrisResponse response = searchUriExample(uri);
}
Aggregations