Search in sources :

Example 66 with ProjectName

use of com.google.webrisk.v1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class ErrorStatsServiceClientTest method listGroupStatsExceptionTest.

@Test
@SuppressWarnings("all")
public void listGroupStatsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockErrorStatsService.addException(exception);
    try {
        ProjectName projectName = ProjectName.create("[PROJECT]");
        QueryTimeRange timeRange = QueryTimeRange.newBuilder().build();
        client.listGroupStats(projectName, timeRange);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) QueryTimeRange(com.google.devtools.clouderrorreporting.v1beta1.QueryTimeRange) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 67 with ProjectName

use of com.google.webrisk.v1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class ErrorStatsServiceClientTest method listEventsTest.

@Test
@SuppressWarnings("all")
public void listEventsTest() {
    String nextPageToken = "";
    ErrorEvent errorEventsElement = ErrorEvent.newBuilder().build();
    List<ErrorEvent> errorEvents = Arrays.asList(errorEventsElement);
    ListEventsResponse expectedResponse = ListEventsResponse.newBuilder().setNextPageToken(nextPageToken).addAllErrorEvents(errorEvents).build();
    mockErrorStatsService.addResponse(expectedResponse);
    ProjectName projectName = ProjectName.create("[PROJECT]");
    String groupId = "groupId506361563";
    ListEventsPagedResponse pagedListResponse = client.listEvents(projectName, groupId);
    List<ErrorEvent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getErrorEventsList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockErrorStatsService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListEventsRequest actualRequest = (ListEventsRequest) actualRequests.get(0);
    Assert.assertEquals(projectName, actualRequest.getProjectNameAsProjectName());
    Assert.assertEquals(groupId, actualRequest.getGroupId());
}
Also used : ListEventsResponse(com.google.devtools.clouderrorreporting.v1beta1.ListEventsResponse) ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ListEventsRequest(com.google.devtools.clouderrorreporting.v1beta1.ListEventsRequest) ErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ErrorEvent) ListEventsPagedResponse(com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListEventsPagedResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 68 with ProjectName

use of com.google.webrisk.v1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method listSnapshotsExceptionTest.

@Test
@SuppressWarnings("all")
public void listSnapshotsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        ProjectName project = ProjectName.create("[PROJECT]");
        client.listSnapshots(project);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ProjectName(com.google.pubsub.v1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 69 with ProjectName

use of com.google.webrisk.v1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method createTimeSeriesExceptionTest.

@Test
@SuppressWarnings("all")
public void createTimeSeriesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        ProjectName name = ProjectName.create("[PROJECT]");
        List<TimeSeries> timeSeries = new ArrayList<>();
        client.createTimeSeries(name, timeSeries);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) ProjectName(com.google.monitoring.v3.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 70 with ProjectName

use of com.google.webrisk.v1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method listMonitoredResourceDescriptorsExceptionTest.

@Test
@SuppressWarnings("all")
public void listMonitoredResourceDescriptorsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        ProjectName name = ProjectName.create("[PROJECT]");
        client.listMonitoredResourceDescriptors(name);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ProjectName(com.google.monitoring.v3.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)70 StatusRuntimeException (io.grpc.StatusRuntimeException)34 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)21 ProjectName (com.google.monitoring.v3.ProjectName)21 AbstractMessage (com.google.protobuf.AbstractMessage)21 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ApiException (com.google.api.gax.rpc.ApiException)15 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)14 ProjectName (com.google.logging.v2.ProjectName)14 ApiException (com.google.api.gax.grpc.ApiException)13 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)13 ProjectName (com.google.devtools.clouderrorreporting.v1beta1.ProjectName)11 ArrayList (java.util.ArrayList)11 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)10 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)9 TimeSeries (com.google.monitoring.v3.TimeSeries)9