Search in sources :

Example 1 with OrganizationName

use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.

the class GroupServiceClientTest method createGroupExceptionTest2.

@Test
public void createGroupExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockGroupService.addException(exception);
    try {
        OrganizationName name = OrganizationName.of("[ORGANIZATION]");
        Group group = Group.newBuilder().build();
        client.createGroup(name, group);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) Group(com.google.monitoring.v3.Group) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 2 with OrganizationName

use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.

the class MetricServiceClientTest method listTimeSeriesTest2.

@Test
public void listTimeSeriesTest2() throws Exception {
    TimeSeries responsesElement = TimeSeries.newBuilder().build();
    ListTimeSeriesResponse expectedResponse = ListTimeSeriesResponse.newBuilder().setNextPageToken("").addAllTimeSeries(Arrays.asList(responsesElement)).build();
    mockMetricService.addResponse(expectedResponse);
    OrganizationName name = OrganizationName.of("[ORGANIZATION]");
    String filter = "filter-1274492040";
    TimeInterval interval = TimeInterval.newBuilder().build();
    ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.forNumber(0);
    ListTimeSeriesPagedResponse pagedListResponse = client.listTimeSeries(name, filter, interval, view);
    List<TimeSeries> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTimeSeriesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTimeSeriesRequest actualRequest = ((ListTimeSeriesRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertEquals(interval, actualRequest.getInterval());
    Assert.assertEquals(view, actualRequest.getView());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) TimeSeries(com.google.monitoring.v3.TimeSeries) AbstractMessage(com.google.protobuf.AbstractMessage) TimeInterval(com.google.monitoring.v3.TimeInterval) ListTimeSeriesResponse(com.google.monitoring.v3.ListTimeSeriesResponse) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest) Test(org.junit.Test)

Example 3 with OrganizationName

use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.

the class MetricServiceClientTest method listTimeSeriesExceptionTest2.

@Test
public void listTimeSeriesExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        OrganizationName name = OrganizationName.of("[ORGANIZATION]");
        String filter = "filter-1274492040";
        TimeInterval interval = TimeInterval.newBuilder().build();
        ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.forNumber(0);
        client.listTimeSeries(name, filter, interval, view);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) TimeInterval(com.google.monitoring.v3.TimeInterval) StatusRuntimeException(io.grpc.StatusRuntimeException) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest) Test(org.junit.Test)

Example 4 with OrganizationName

use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.

the class AlertPolicyServiceClientTest method listAlertPoliciesTest2.

@Test
public void listAlertPoliciesTest2() throws Exception {
    AlertPolicy responsesElement = AlertPolicy.newBuilder().build();
    ListAlertPoliciesResponse expectedResponse = ListAlertPoliciesResponse.newBuilder().setNextPageToken("").addAllAlertPolicies(Arrays.asList(responsesElement)).build();
    mockAlertPolicyService.addResponse(expectedResponse);
    OrganizationName name = OrganizationName.of("[ORGANIZATION]");
    ListAlertPoliciesPagedResponse pagedListResponse = client.listAlertPolicies(name);
    List<AlertPolicy> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAlertPoliciesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAlertPolicyService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAlertPoliciesRequest actualRequest = ((ListAlertPoliciesRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListAlertPoliciesResponse(com.google.monitoring.v3.ListAlertPoliciesResponse) OrganizationName(com.google.monitoring.v3.OrganizationName) AbstractMessage(com.google.protobuf.AbstractMessage) ListAlertPoliciesRequest(com.google.monitoring.v3.ListAlertPoliciesRequest) AlertPolicy(com.google.monitoring.v3.AlertPolicy) ListAlertPoliciesPagedResponse(com.google.cloud.monitoring.v3.AlertPolicyServiceClient.ListAlertPoliciesPagedResponse) Test(org.junit.Test)

Example 5 with OrganizationName

use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.

the class ServiceMonitoringServiceClientTest method createServiceExceptionTest2.

@Test
public void createServiceExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
        Service service = Service.newBuilder().build();
        client.createService(parent, service);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)62 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)31 AbstractMessage (com.google.protobuf.AbstractMessage)31 StatusRuntimeException (io.grpc.StatusRuntimeException)31 OrganizationName (com.google.monitoring.v3.OrganizationName)30 OrganizationName (com.google.logging.v2.OrganizationName)20 OrganizationName (com.google.privacy.dlp.v2.OrganizationName)12 ArrayList (java.util.ArrayList)7 LogExclusion (com.google.logging.v2.LogExclusion)6 LogSink (com.google.logging.v2.LogSink)6 MetricDescriptor (com.google.api.MetricDescriptor)3 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)3 AlertPolicy (com.google.monitoring.v3.AlertPolicy)3 UptimeCheckConfig (com.google.monitoring.v3.UptimeCheckConfig)3 InspectTemplate (com.google.privacy.dlp.v2.InspectTemplate)3 ListExclusionsPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse)2 ListSinksPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse)2 ListLogsPagedResponse (com.google.cloud.logging.v2.LoggingClient.ListLogsPagedResponse)2 CreateExclusionRequest (com.google.logging.v2.CreateExclusionRequest)2 CreateSinkRequest (com.google.logging.v2.CreateSinkRequest)2