Search in sources :

Example 41 with FolderName

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

the class MetricServiceClientTest method listMonitoredResourceDescriptorsTest.

@Test
public void listMonitoredResourceDescriptorsTest() throws Exception {
    MonitoredResourceDescriptor responsesElement = MonitoredResourceDescriptor.newBuilder().build();
    ListMonitoredResourceDescriptorsResponse expectedResponse = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken("").addAllResourceDescriptors(Arrays.asList(responsesElement)).build();
    mockMetricService.addResponse(expectedResponse);
    FolderName name = FolderName.of("[FOLDER]");
    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<AbstractMessage> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListMonitoredResourceDescriptorsRequest actualRequest = ((ListMonitoredResourceDescriptorsRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListMonitoredResourceDescriptorsRequest(com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor) ListMonitoredResourceDescriptorsPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Example 42 with FolderName

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

the class AlertPolicyServiceClientTest method listAlertPoliciesTest.

@Test
public void listAlertPoliciesTest() throws Exception {
    AlertPolicy responsesElement = AlertPolicy.newBuilder().build();
    ListAlertPoliciesResponse expectedResponse = ListAlertPoliciesResponse.newBuilder().setNextPageToken("").addAllAlertPolicies(Arrays.asList(responsesElement)).build();
    mockAlertPolicyService.addResponse(expectedResponse);
    FolderName name = FolderName.of("[FOLDER]");
    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) AbstractMessage(com.google.protobuf.AbstractMessage) ListAlertPoliciesRequest(com.google.monitoring.v3.ListAlertPoliciesRequest) AlertPolicy(com.google.monitoring.v3.AlertPolicy) FolderName(com.google.monitoring.v3.FolderName) ListAlertPoliciesPagedResponse(com.google.cloud.monitoring.v3.AlertPolicyServiceClient.ListAlertPoliciesPagedResponse) Test(org.junit.Test)

Example 43 with FolderName

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

the class GroupServiceClientTest method createGroupTest.

@Test
public void createGroupTest() throws Exception {
    Group expectedResponse = Group.newBuilder().setName(GroupName.ofProjectGroupName("[PROJECT]", "[GROUP]").toString()).setDisplayName("displayName1714148973").setParentName("parentName-244870571").setFilter("filter-1274492040").setIsCluster(true).build();
    mockGroupService.addResponse(expectedResponse);
    FolderName name = FolderName.of("[FOLDER]");
    Group group = Group.newBuilder().build();
    Group actualResponse = client.createGroup(name, group);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockGroupService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateGroupRequest actualRequest = ((CreateGroupRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(group, actualRequest.getGroup());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Group(com.google.monitoring.v3.Group) AbstractMessage(com.google.protobuf.AbstractMessage) CreateGroupRequest(com.google.monitoring.v3.CreateGroupRequest) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Example 44 with FolderName

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

the class ServiceMonitoringServiceClientTest method listServicesTest.

@Test
public void listServicesTest() throws Exception {
    Service responsesElement = Service.newBuilder().build();
    ListServicesResponse expectedResponse = ListServicesResponse.newBuilder().setNextPageToken("").addAllServices(Arrays.asList(responsesElement)).build();
    mockServiceMonitoringService.addResponse(expectedResponse);
    FolderName parent = FolderName.of("[FOLDER]");
    ListServicesPagedResponse pagedListResponse = client.listServices(parent);
    List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListServicesRequest(com.google.monitoring.v3.ListServicesRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListServicesResponse(com.google.monitoring.v3.ListServicesResponse) ListServicesPagedResponse(com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServicesPagedResponse) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Example 45 with FolderName

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

the class ServiceMonitoringServiceClientTest method createServiceExceptionTest.

@Test
public void createServiceExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        FolderName parent = FolderName.of("[FOLDER]");
        Service service = Service.newBuilder().build();
        client.createService(parent, service);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : 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) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)50 FolderName (com.google.monitoring.v3.FolderName)30 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)25 AbstractMessage (com.google.protobuf.AbstractMessage)25 StatusRuntimeException (io.grpc.StatusRuntimeException)25 FolderName (com.google.logging.v2.FolderName)22 LogExclusion (com.google.logging.v2.LogExclusion)7 LogSink (com.google.logging.v2.LogSink)7 ArrayList (java.util.ArrayList)6 MetricDescriptor (com.google.api.MetricDescriptor)3 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)3 AlertPolicy (com.google.monitoring.v3.AlertPolicy)3 Group (com.google.monitoring.v3.Group)3 ConfigClient (com.google.cloud.logging.v2.ConfigClient)2 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 ListExclusionsRequest (com.google.logging.v2.ListExclusionsRequest)2