Search in sources :

Example 6 with FolderName

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

the class AlertPolicyServiceClientTest method createAlertPolicyExceptionTest.

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

Example 7 with FolderName

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

the class ServiceMonitoringServiceClientTest method createServiceTest.

@Test
public void createServiceTest() throws Exception {
    Service expectedResponse = Service.newBuilder().setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()).setDisplayName("displayName1714148973").setTelemetry(Service.Telemetry.newBuilder().build()).putAllUserLabels(new HashMap<String, String>()).build();
    mockServiceMonitoringService.addResponse(expectedResponse);
    FolderName parent = FolderName.of("[FOLDER]");
    Service service = Service.newBuilder().build();
    Service actualResponse = client.createService(parent, service);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateServiceRequest actualRequest = ((CreateServiceRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(service, actualRequest.getService());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) CreateServiceRequest(com.google.monitoring.v3.CreateServiceRequest) 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 8 with FolderName

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

the class ServiceMonitoringServiceClientTest method listServicesExceptionTest.

@Test
public void listServicesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        FolderName parent = FolderName.of("[FOLDER]");
        client.listServices(parent);
        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)

Example 9 with FolderName

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

the class NotificationChannelServiceClientTest method createNotificationChannelTest.

@Test
public void createNotificationChannelTest() throws Exception {
    NotificationChannel expectedResponse = NotificationChannel.newBuilder().setType("type3575610").setName(NotificationChannelName.ofProjectNotificationChannelName("[PROJECT]", "[NOTIFICATION_CHANNEL]").toString()).setDisplayName("displayName1714148973").setDescription("description-1724546052").putAllLabels(new HashMap<String, String>()).putAllUserLabels(new HashMap<String, String>()).setEnabled(BoolValue.newBuilder().build()).setCreationRecord(MutationRecord.newBuilder().build()).addAllMutationRecords(new ArrayList<MutationRecord>()).build();
    mockNotificationChannelService.addResponse(expectedResponse);
    FolderName name = FolderName.of("[FOLDER]");
    NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
    NotificationChannel actualResponse = client.createNotificationChannel(name, notificationChannel);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateNotificationChannelRequest actualRequest = ((CreateNotificationChannelRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(notificationChannel, actualRequest.getNotificationChannel());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : NotificationChannel(com.google.monitoring.v3.NotificationChannel) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FolderName(com.google.monitoring.v3.FolderName) CreateNotificationChannelRequest(com.google.monitoring.v3.CreateNotificationChannelRequest) Test(org.junit.Test)

Example 10 with FolderName

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

the class NotificationChannelServiceClientTest method listNotificationChannelsExceptionTest.

@Test
public void listNotificationChannelsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockNotificationChannelService.addException(exception);
    try {
        FolderName name = FolderName.of("[FOLDER]");
        client.listNotificationChannels(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