Search in sources :

Example 6 with ThreatType

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ThreatType(com.google.webrisk.v1beta1.ThreatType) ByteString(com.google.protobuf.ByteString) ComputeThreatListDiffRequest(com.google.webrisk.v1beta1.ComputeThreatListDiffRequest) ComputeThreatListDiffResponse(com.google.webrisk.v1beta1.ComputeThreatListDiffResponse) Test(org.junit.Test)

Example 7 with ThreatType

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

Example 8 with ThreatType

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

Example 9 with ThreatType

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ByteString(com.google.protobuf.ByteString) ThreatType(com.google.webrisk.v1.ThreatType) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with ThreatType

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ThreatType(com.google.webrisk.v1.ThreatType) ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) ComputeThreatListDiffRequest(com.google.webrisk.v1.ComputeThreatListDiffRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 ByteString (com.google.protobuf.ByteString)12 ThreatType (com.google.webrisk.v1.ThreatType)8 ArrayList (java.util.ArrayList)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)6 AbstractMessage (com.google.protobuf.AbstractMessage)6 ThreatType (com.google.webrisk.v1beta1.ThreatType)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 SearchUrisResponse (com.google.webrisk.v1.SearchUrisResponse)3 ComputeThreatListDiffRequest (com.google.webrisk.v1.ComputeThreatListDiffRequest)2 ComputeThreatListDiffRequest (com.google.webrisk.v1beta1.ComputeThreatListDiffRequest)2 ComputeThreatListDiffResponse (com.google.webrisk.v1.ComputeThreatListDiffResponse)1 SearchHashesRequest (com.google.webrisk.v1.SearchHashesRequest)1 SearchHashesResponse (com.google.webrisk.v1.SearchHashesResponse)1 SearchUrisRequest (com.google.webrisk.v1.SearchUrisRequest)1 ComputeThreatListDiffResponse (com.google.webrisk.v1beta1.ComputeThreatListDiffResponse)1 SearchHashesRequest (com.google.webrisk.v1beta1.SearchHashesRequest)1 SearchHashesResponse (com.google.webrisk.v1beta1.SearchHashesResponse)1 SearchUrisRequest (com.google.webrisk.v1beta1.SearchUrisRequest)1 SearchUrisResponse (com.google.webrisk.v1beta1.SearchUrisResponse)1