Search in sources :

Example 36 with FolderName

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

the class NotificationChannelServiceClientTest method createNotificationChannelExceptionTest.

@Test
public void createNotificationChannelExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockNotificationChannelService.addException(exception);
    try {
        FolderName name = FolderName.of("[FOLDER]");
        NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
        client.createNotificationChannel(name, notificationChannel);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : NotificationChannel(com.google.monitoring.v3.NotificationChannel) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Example 37 with FolderName

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

the class NotificationChannelServiceClientTest method listNotificationChannelsTest.

@Test
public void listNotificationChannelsTest() throws Exception {
    NotificationChannel responsesElement = NotificationChannel.newBuilder().build();
    ListNotificationChannelsResponse expectedResponse = ListNotificationChannelsResponse.newBuilder().setNextPageToken("").addAllNotificationChannels(Arrays.asList(responsesElement)).build();
    mockNotificationChannelService.addResponse(expectedResponse);
    FolderName name = FolderName.of("[FOLDER]");
    ListNotificationChannelsPagedResponse pagedListResponse = client.listNotificationChannels(name);
    List<NotificationChannel> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getNotificationChannelsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListNotificationChannelsRequest actualRequest = ((ListNotificationChannelsRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : NotificationChannel(com.google.monitoring.v3.NotificationChannel) ListNotificationChannelsResponse(com.google.monitoring.v3.ListNotificationChannelsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListNotificationChannelsRequest(com.google.monitoring.v3.ListNotificationChannelsRequest) ListNotificationChannelsPagedResponse(com.google.cloud.monitoring.v3.NotificationChannelServiceClient.ListNotificationChannelsPagedResponse) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Example 38 with FolderName

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

the class MetricServiceClientTest method createMetricDescriptorTest.

@Test
public void createMetricDescriptorTest() throws Exception {
    MetricDescriptor expectedResponse = MetricDescriptor.newBuilder().setName("name3373707").setType("type3575610").addAllLabels(new ArrayList<LabelDescriptor>()).setUnit("unit3594628").setDescription("description-1724546052").setDisplayName("displayName1714148973").setMetadata(MetricDescriptor.MetricDescriptorMetadata.newBuilder().build()).setLaunchStage(LaunchStage.forNumber(0)).addAllMonitoredResourceTypes(new ArrayList<String>()).build();
    mockMetricService.addResponse(expectedResponse);
    FolderName name = FolderName.of("[FOLDER]");
    MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
    MetricDescriptor actualResponse = client.createMetricDescriptor(name, metricDescriptor);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateMetricDescriptorRequest actualRequest = ((CreateMetricDescriptorRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(metricDescriptor, actualRequest.getMetricDescriptor());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : MetricDescriptor(com.google.api.MetricDescriptor) AbstractMessage(com.google.protobuf.AbstractMessage) CreateMetricDescriptorRequest(com.google.monitoring.v3.CreateMetricDescriptorRequest) ArrayList(java.util.ArrayList) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Example 39 with FolderName

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

the class MetricServiceClientTest method createMetricDescriptorExceptionTest.

@Test
public void createMetricDescriptorExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        FolderName name = FolderName.of("[FOLDER]");
        MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
        client.createMetricDescriptor(name, metricDescriptor);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : MetricDescriptor(com.google.api.MetricDescriptor) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Example 40 with FolderName

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

the class MetricServiceClientTest method listMetricDescriptorsExceptionTest.

@Test
public void listMetricDescriptorsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        FolderName name = FolderName.of("[FOLDER]");
        client.listMetricDescriptors(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) 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