Search in sources :

Example 1 with SearchUrisRequest

use of com.google.webrisk.v1beta1.SearchUrisRequest 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 SearchUrisRequest

use of com.google.webrisk.v1beta1.SearchUrisRequest 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 SearchUrisRequest

use of com.google.webrisk.v1beta1.SearchUrisRequest 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)

Aggregations

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