Search in sources :

Example 21 with ProjectName

use of com.google.privacy.dlp.v2.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class ErrorStatsServiceClientTest method listEventsExceptionTest.

@Test
@SuppressWarnings("all")
public void listEventsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockErrorStatsService.addException(exception);
    try {
        ProjectName projectName = ProjectName.create("[PROJECT]");
        String groupId = "groupId506361563";
        client.listEvents(projectName, groupId);
        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) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 22 with ProjectName

use of com.google.privacy.dlp.v2.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 23 with ProjectName

use of com.google.privacy.dlp.v2.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 24 with ProjectName

use of com.google.privacy.dlp.v2.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 25 with ProjectName

use of com.google.privacy.dlp.v2.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)

Aggregations

Test (org.junit.Test)26 ProjectName (com.google.monitoring.v3.ProjectName)21 ApiException (com.google.api.gax.grpc.ApiException)13 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)13 StatusRuntimeException (io.grpc.StatusRuntimeException)13 ProjectName (com.google.devtools.clouderrorreporting.v1beta1.ProjectName)10 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)9 TimeSeries (com.google.monitoring.v3.TimeSeries)9 TimeInterval (com.google.monitoring.v3.TimeInterval)8 ProjectName (com.google.pubsub.v1.ProjectName)7 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)6 MetricDescriptor (com.google.api.MetricDescriptor)5 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse)4 ReportedErrorEvent (com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent)4 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)3 ByteString (com.google.protobuf.ByteString)3 ArrayList (java.util.ArrayList)3 Metric (com.google.api.Metric)2 MonitoredResource (com.google.api.MonitoredResource)2 MonitoredResourceDescriptor (com.google.api.MonitoredResourceDescriptor)2