Search in sources :

Example 56 with ProjectName

use of com.google.containeranalysis.v1beta1.ProjectName in project java-webrisk by googleapis.

the class WebRiskServiceClientTest method createSubmissionTest.

@Test
public void createSubmissionTest() throws Exception {
    Submission expectedResponse = Submission.newBuilder().setUri("uri116076").build();
    mockWebRiskService.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    Submission submission = Submission.newBuilder().build();
    Submission actualResponse = client.createSubmission(parent, submission);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockWebRiskService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSubmissionRequest actualRequest = ((CreateSubmissionRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(submission, actualRequest.getSubmission());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Submission(com.google.webrisk.v1.Submission) ProjectName(com.google.webrisk.v1.ProjectName) CreateSubmissionRequest(com.google.webrisk.v1.CreateSubmissionRequest) Test(org.junit.Test)

Example 57 with ProjectName

use of com.google.containeranalysis.v1beta1.ProjectName in project java-containeranalysis by googleapis.

the class ContainerAnalysisV1Beta1ClientTest method listScanConfigsExceptionTest.

@Test
@SuppressWarnings("all")
public void listScanConfigsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockContainerAnalysisV1Beta1.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        String filter = "filter-1274492040";
        client.listScanConfigs(parent, filter);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.containeranalysis.v1beta1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 58 with ProjectName

use of com.google.containeranalysis.v1beta1.ProjectName in project java-containeranalysis by googleapis.

the class GrafeasV1Beta1ClientTest method createOccurrenceExceptionTest.

@Test
@SuppressWarnings("all")
public void createOccurrenceExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockGrafeasV1Beta1.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        Occurrence occurrence = Occurrence.newBuilder().build();
        client.createOccurrence(parent, occurrence);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.containeranalysis.v1beta1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) Occurrence(io.grafeas.v1beta1.Occurrence) Test(org.junit.Test)

Example 59 with ProjectName

use of com.google.containeranalysis.v1beta1.ProjectName in project java-containeranalysis by googleapis.

the class GrafeasV1Beta1ClientTest method batchCreateOccurrencesExceptionTest.

@Test
@SuppressWarnings("all")
public void batchCreateOccurrencesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockGrafeasV1Beta1.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        List<Occurrence> occurrences = new ArrayList<>();
        client.batchCreateOccurrences(parent, occurrences);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.containeranalysis.v1beta1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) Occurrence(io.grafeas.v1beta1.Occurrence) Test(org.junit.Test)

Example 60 with ProjectName

use of com.google.containeranalysis.v1beta1.ProjectName in project java-containeranalysis by googleapis.

the class GrafeasV1Beta1ClientTest method listOccurrencesTest.

@Test
@SuppressWarnings("all")
public void listOccurrencesTest() {
    String nextPageToken = "";
    Occurrence occurrencesElement = Occurrence.newBuilder().build();
    List<Occurrence> occurrences = Arrays.asList(occurrencesElement);
    ListOccurrencesResponse expectedResponse = ListOccurrencesResponse.newBuilder().setNextPageToken(nextPageToken).addAllOccurrences(occurrences).build();
    mockGrafeasV1Beta1.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    String filter = "filter-1274492040";
    ListOccurrencesPagedResponse pagedListResponse = client.listOccurrences(parent, filter);
    List<Occurrence> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getOccurrencesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockGrafeasV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListOccurrencesRequest actualRequest = (ListOccurrencesRequest) actualRequests.get(0);
    Assert.assertEquals(parent, ProjectName.parse(actualRequest.getParent()));
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListOccurrencesRequest(io.grafeas.v1beta1.ListOccurrencesRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.containeranalysis.v1beta1.ProjectName) ListOccurrencesResponse(io.grafeas.v1beta1.ListOccurrencesResponse) Occurrence(io.grafeas.v1beta1.Occurrence) ListOccurrencesPagedResponse(com.google.cloud.devtools.containeranalysis.v1beta1.GrafeasV1Beta1Client.ListOccurrencesPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)146 StatusRuntimeException (io.grpc.StatusRuntimeException)73 ProjectName (com.google.monitoring.v3.ProjectName)62 AbstractMessage (com.google.protobuf.AbstractMessage)60 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)58 ProjectName (com.google.pubsub.v1.ProjectName)30 ArrayList (java.util.ArrayList)29 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 ByteString (com.google.protobuf.ByteString)18 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 IOException (java.io.IOException)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)16 ApiException (com.google.api.gax.rpc.ApiException)15 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)15 TimeSeries (com.google.monitoring.v3.TimeSeries)15 ProjectName (com.google.logging.v2.ProjectName)14