Search in sources :

Example 1 with SearchUrisResponse

use of com.google.webrisk.v1.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()));
}
Also used : SearchUrisRequest(com.google.webrisk.v1beta1.SearchUrisRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ThreatType(com.google.webrisk.v1beta1.ThreatType) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) SearchUrisResponse(com.google.webrisk.v1beta1.SearchUrisResponse) Test(org.junit.Test)

Example 2 with SearchUrisResponse

use of com.google.webrisk.v1.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;
    }
}
Also used : SearchUrisRequest(com.google.webrisk.v1.SearchUrisRequest) WebRiskServiceClient(com.google.cloud.webrisk.v1.WebRiskServiceClient) SearchUrisResponse(com.google.webrisk.v1.SearchUrisResponse)

Example 3 with SearchUrisResponse

use of com.google.webrisk.v1.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();
}
Also used : ThreatType(com.google.webrisk.v1.ThreatType) SearchUrisResponse(com.google.webrisk.v1.SearchUrisResponse) Test(org.junit.Test)

Example 4 with SearchUrisResponse

use of com.google.webrisk.v1.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()));
}
Also used : SearchUrisRequest(com.google.webrisk.v1.SearchUrisRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ThreatType(com.google.webrisk.v1.ThreatType) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) SearchUrisResponse(com.google.webrisk.v1.SearchUrisResponse) Test(org.junit.Test)

Example 5 with SearchUrisResponse

use of com.google.webrisk.v1.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);
}
Also used : SearchUrisResponse(com.google.webrisk.v1.SearchUrisResponse)

Aggregations

SearchUrisResponse (com.google.webrisk.v1.SearchUrisResponse)5 Test (org.junit.Test)4 ThreatType (com.google.webrisk.v1.ThreatType)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 ByteString (com.google.protobuf.ByteString)2 SearchUrisRequest (com.google.webrisk.v1.SearchUrisRequest)2 ArrayList (java.util.ArrayList)2 WebRiskServiceClient (com.google.cloud.webrisk.v1.WebRiskServiceClient)1 SearchUrisRequest (com.google.webrisk.v1beta1.SearchUrisRequest)1 SearchUrisResponse (com.google.webrisk.v1beta1.SearchUrisResponse)1 ThreatType (com.google.webrisk.v1beta1.ThreatType)1