Search in sources :

Example 1 with ProjectName

use of com.google.devtools.clouderrorreporting.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method listMetricDescriptorsTest.

@Test
@SuppressWarnings("all")
public void listMetricDescriptorsTest() {
    String nextPageToken = "";
    MetricDescriptor metricDescriptorsElement = MetricDescriptor.newBuilder().build();
    List<MetricDescriptor> metricDescriptors = Arrays.asList(metricDescriptorsElement);
    ListMetricDescriptorsResponse expectedResponse = ListMetricDescriptorsResponse.newBuilder().setNextPageToken(nextPageToken).addAllMetricDescriptors(metricDescriptors).build();
    mockMetricService.addResponse(expectedResponse);
    ProjectName name = ProjectName.create("[PROJECT]");
    ListMetricDescriptorsPagedResponse pagedListResponse = client.listMetricDescriptors(name);
    List<MetricDescriptor> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getMetricDescriptorsList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListMetricDescriptorsRequest actualRequest = (ListMetricDescriptorsRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsProjectName());
}
Also used : MetricDescriptor(com.google.api.MetricDescriptor) ProjectName(com.google.monitoring.v3.ProjectName) ListMetricDescriptorsRequest(com.google.monitoring.v3.ListMetricDescriptorsRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) ListMetricDescriptorsResponse(com.google.monitoring.v3.ListMetricDescriptorsResponse) ListMetricDescriptorsPagedResponse(com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMetricDescriptorsPagedResponse) Test(org.junit.Test)

Example 2 with ProjectName

use of com.google.devtools.clouderrorreporting.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method listMonitoredResourceDescriptorsTest.

@Test
@SuppressWarnings("all")
public void listMonitoredResourceDescriptorsTest() {
    String nextPageToken = "";
    MonitoredResourceDescriptor resourceDescriptorsElement = MonitoredResourceDescriptor.newBuilder().build();
    List<MonitoredResourceDescriptor> resourceDescriptors = Arrays.asList(resourceDescriptorsElement);
    ListMonitoredResourceDescriptorsResponse expectedResponse = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(nextPageToken).addAllResourceDescriptors(resourceDescriptors).build();
    mockMetricService.addResponse(expectedResponse);
    ProjectName name = ProjectName.create("[PROJECT]");
    ListMonitoredResourceDescriptorsPagedResponse pagedListResponse = client.listMonitoredResourceDescriptors(name);
    List<MonitoredResourceDescriptor> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getResourceDescriptorsList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListMonitoredResourceDescriptorsRequest actualRequest = (ListMonitoredResourceDescriptorsRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsProjectName());
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse) ProjectName(com.google.monitoring.v3.ProjectName) ListMonitoredResourceDescriptorsRequest(com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor) ListMonitoredResourceDescriptorsPagedResponse(com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMonitoredResourceDescriptorsPagedResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 3 with ProjectName

use of com.google.devtools.clouderrorreporting.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method createTimeSeriesTest.

@Test
@SuppressWarnings("all")
public void createTimeSeriesTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockMetricService.addResponse(expectedResponse);
    ProjectName name = ProjectName.create("[PROJECT]");
    List<TimeSeries> timeSeries = new ArrayList<>();
    client.createTimeSeries(name, timeSeries);
    List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateTimeSeriesRequest actualRequest = (CreateTimeSeriesRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsProjectName());
    Assert.assertEquals(timeSeries, actualRequest.getTimeSeriesList());
}
Also used : Empty(com.google.protobuf.Empty) TimeSeries(com.google.monitoring.v3.TimeSeries) ProjectName(com.google.monitoring.v3.ProjectName) CreateTimeSeriesRequest(com.google.monitoring.v3.CreateTimeSeriesRequest) ArrayList(java.util.ArrayList) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 4 with ProjectName

use of com.google.devtools.clouderrorreporting.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method createMetricDescriptorExceptionTest.

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

Example 5 with ProjectName

use of com.google.devtools.clouderrorreporting.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method listMetricDescriptorsExceptionTest.

@Test
@SuppressWarnings("all")
public void listMetricDescriptorsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        ProjectName name = ProjectName.create("[PROJECT]");
        client.listMetricDescriptors(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)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