use of com.google.monitoring.v3.NotificationChannelName in project java-monitoring by googleapis.
the class DeleteNotificationChannel method deleteNotificationChannel.
/**
* Demonstrates deleting a notification channel by name.
*
* @param channelName Name of the notification channel to delete.
*/
// [START monitoring_alert_delete_channel]
static void deleteNotificationChannel(String channelName) throws IOException {
String projectId = System.getProperty("projectId");
try (NotificationChannelServiceClient client = NotificationChannelServiceClient.create()) {
NotificationChannelName name = NotificationChannelName.of(projectId, channelName);
client.deleteNotificationChannel(channelName, false);
System.out.println("Deleted notification channel " + channelName);
}
}
use of com.google.monitoring.v3.NotificationChannelName in project java-docs-samples by GoogleCloudPlatform.
the class DeleteNotificationChannel method deleteNotificationChannel.
/**
* Demonstrates deleting a notification channel by name.
*
* @param channelName Name of the notification channel to delete.
*/
// [START monitoring_alert_delete_channel]
static void deleteNotificationChannel(String channelName) throws IOException {
String projectId = System.getProperty("projectId");
try (NotificationChannelServiceClient client = NotificationChannelServiceClient.create()) {
NotificationChannelName name = NotificationChannelName.of(projectId, channelName);
client.deleteNotificationChannel(channelName, false);
System.out.println("Deleted notification channel " + channelName);
}
}
use of com.google.monitoring.v3.NotificationChannelName in project java-monitoring by googleapis.
the class NotificationChannelServiceClientTest method getNotificationChannelExceptionTest.
@Test
public void getNotificationChannelExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockNotificationChannelService.addException(exception);
try {
NotificationChannelName name = NotificationChannelName.ofProjectNotificationChannelName("[PROJECT]", "[NOTIFICATION_CHANNEL]");
client.getNotificationChannel(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.monitoring.v3.NotificationChannelName in project java-monitoring by googleapis.
the class NotificationChannelServiceClientTest method getNotificationChannelTest.
@Test
public void getNotificationChannelTest() 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);
NotificationChannelName name = NotificationChannelName.ofProjectNotificationChannelName("[PROJECT]", "[NOTIFICATION_CHANNEL]");
NotificationChannel actualResponse = client.getNotificationChannel(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetNotificationChannelRequest actualRequest = ((GetNotificationChannelRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations