Search in sources :

Example 6 with ProjectName

use of com.google.monitoring.v3.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method listTimeSeriesExceptionTest.

@Test
@SuppressWarnings("all")
public void listTimeSeriesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        ProjectName name = ProjectName.create("[PROJECT]");
        String filter = "filter-1274492040";
        TimeInterval interval = TimeInterval.newBuilder().build();
        ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
        client.listTimeSeries(name, filter, interval, view);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : TimeInterval(com.google.monitoring.v3.TimeInterval) ProjectName(com.google.monitoring.v3.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) TimeSeriesView(com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 7 with ProjectName

use of com.google.monitoring.v3.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method createMetricDescriptorTest.

@Test
@SuppressWarnings("all")
public void createMetricDescriptorTest() {
    String name2 = "name2-1052831874";
    String type = "type3575610";
    String unit = "unit3594628";
    String description = "description-1724546052";
    String displayName = "displayName1615086568";
    MetricDescriptor expectedResponse = MetricDescriptor.newBuilder().setName(name2).setType(type).setUnit(unit).setDescription(description).setDisplayName(displayName).build();
    mockMetricService.addResponse(expectedResponse);
    ProjectName name = ProjectName.create("[PROJECT]");
    MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
    MetricDescriptor actualResponse = client.createMetricDescriptor(name, metricDescriptor);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateMetricDescriptorRequest actualRequest = (CreateMetricDescriptorRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsProjectName());
    Assert.assertEquals(metricDescriptor, actualRequest.getMetricDescriptor());
}
Also used : MetricDescriptor(com.google.api.MetricDescriptor) ProjectName(com.google.monitoring.v3.ProjectName) CreateMetricDescriptorRequest(com.google.monitoring.v3.CreateMetricDescriptorRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 8 with ProjectName

use of com.google.monitoring.v3.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method listSubscriptionsTest.

@Test
@SuppressWarnings("all")
public void listSubscriptionsTest() {
    String nextPageToken = "";
    Subscription subscriptionsElement = Subscription.newBuilder().build();
    List<Subscription> subscriptions = Arrays.asList(subscriptionsElement);
    ListSubscriptionsResponse expectedResponse = ListSubscriptionsResponse.newBuilder().setNextPageToken(nextPageToken).addAllSubscriptions(subscriptions).build();
    mockSubscriber.addResponse(expectedResponse);
    ProjectName project = ProjectName.create("[PROJECT]");
    ListSubscriptionsPagedResponse pagedListResponse = client.listSubscriptions(project);
    List<Subscription> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSubscriptionsList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSubscriptionsRequest actualRequest = (ListSubscriptionsRequest) actualRequests.get(0);
    Assert.assertEquals(project, actualRequest.getProjectAsProjectName());
}
Also used : ListSubscriptionsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse) ListSubscriptionsResponse(com.google.pubsub.v1.ListSubscriptionsResponse) ProjectName(com.google.pubsub.v1.ProjectName) ListSubscriptionsRequest(com.google.pubsub.v1.ListSubscriptionsRequest) ByteString(com.google.protobuf.ByteString) Subscription(com.google.pubsub.v1.Subscription) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 9 with ProjectName

use of com.google.monitoring.v3.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class ErrorStatsServiceClientTest method listGroupStatsTest.

@Test
@SuppressWarnings("all")
public void listGroupStatsTest() {
    String nextPageToken = "";
    ErrorGroupStats errorGroupStatsElement = ErrorGroupStats.newBuilder().build();
    List<ErrorGroupStats> errorGroupStats = Arrays.asList(errorGroupStatsElement);
    ListGroupStatsResponse expectedResponse = ListGroupStatsResponse.newBuilder().setNextPageToken(nextPageToken).addAllErrorGroupStats(errorGroupStats).build();
    mockErrorStatsService.addResponse(expectedResponse);
    ProjectName projectName = ProjectName.create("[PROJECT]");
    QueryTimeRange timeRange = QueryTimeRange.newBuilder().build();
    ListGroupStatsPagedResponse pagedListResponse = client.listGroupStats(projectName, timeRange);
    List<ErrorGroupStats> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getErrorGroupStatsList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockErrorStatsService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListGroupStatsRequest actualRequest = (ListGroupStatsRequest) actualRequests.get(0);
    Assert.assertEquals(projectName, actualRequest.getProjectNameAsProjectName());
    Assert.assertEquals(timeRange, actualRequest.getTimeRange());
}
Also used : ErrorGroupStats(com.google.devtools.clouderrorreporting.v1beta1.ErrorGroupStats) ListGroupStatsRequest(com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsRequest) ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ListGroupStatsResponse(com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsResponse) ListGroupStatsPagedResponse(com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListGroupStatsPagedResponse) QueryTimeRange(com.google.devtools.clouderrorreporting.v1beta1.QueryTimeRange) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 10 with ProjectName

use of com.google.monitoring.v3.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class ReportErrorsServiceClientTest method reportErrorEventTest.

@Test
@SuppressWarnings("all")
public void reportErrorEventTest() {
    ReportErrorEventResponse expectedResponse = ReportErrorEventResponse.newBuilder().build();
    mockReportErrorsService.addResponse(expectedResponse);
    ProjectName projectName = ProjectName.create("[PROJECT]");
    ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
    ReportErrorEventResponse actualResponse = client.reportErrorEvent(projectName, event);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockReportErrorsService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ReportErrorEventRequest actualRequest = (ReportErrorEventRequest) actualRequests.get(0);
    Assert.assertEquals(projectName, actualRequest.getProjectNameAsProjectName());
    Assert.assertEquals(event, actualRequest.getEvent());
}
Also used : ReportErrorEventRequest(com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventRequest) ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ReportErrorEventResponse(com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)26 ApiException (com.google.api.gax.grpc.ApiException)13 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)13 StatusRuntimeException (io.grpc.StatusRuntimeException)13 ProjectName (com.google.monitoring.v3.ProjectName)12 ProjectName (com.google.devtools.clouderrorreporting.v1beta1.ProjectName)8 ProjectName (com.google.pubsub.v1.ProjectName)6 MetricDescriptor (com.google.api.MetricDescriptor)3 TimeSeries (com.google.monitoring.v3.TimeSeries)3 ByteString (com.google.protobuf.ByteString)3 QueryTimeRange (com.google.devtools.clouderrorreporting.v1beta1.QueryTimeRange)2 ReportedErrorEvent (com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent)2 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)2 Group (com.google.monitoring.v3.Group)2 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)2 TimeSeriesView (com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView)2 TimeInterval (com.google.monitoring.v3.TimeInterval)2 ArrayList (java.util.ArrayList)2 MonitoredResourceDescriptor (com.google.api.MonitoredResourceDescriptor)1 ListEventsPagedResponse (com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListEventsPagedResponse)1