Search in sources :

Example 6 with NotificationChannelName

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

the class NotificationChannelServiceClientTest method sendNotificationChannelVerificationCodeTest.

@Test
public void sendNotificationChannelVerificationCodeTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockNotificationChannelService.addResponse(expectedResponse);
    NotificationChannelName name = NotificationChannelName.ofProjectNotificationChannelName("[PROJECT]", "[NOTIFICATION_CHANNEL]");
    client.sendNotificationChannelVerificationCode(name);
    List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SendNotificationChannelVerificationCodeRequest actualRequest = ((SendNotificationChannelVerificationCodeRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) SendNotificationChannelVerificationCodeRequest(com.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest) NotificationChannelName(com.google.monitoring.v3.NotificationChannelName) Test(org.junit.Test)

Example 7 with NotificationChannelName

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

the class NotificationChannelServiceClientTest method verifyNotificationChannelExceptionTest.

@Test
public void verifyNotificationChannelExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockNotificationChannelService.addException(exception);
    try {
        NotificationChannelName name = NotificationChannelName.ofProjectNotificationChannelName("[PROJECT]", "[NOTIFICATION_CHANNEL]");
        String code = "code3059181";
        client.verifyNotificationChannel(name, code);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) NotificationChannelName(com.google.monitoring.v3.NotificationChannelName) Test(org.junit.Test)

Example 8 with NotificationChannelName

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

the class NotificationChannelServiceClientTest method deleteNotificationChannelExceptionTest.

@Test
public void deleteNotificationChannelExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockNotificationChannelService.addException(exception);
    try {
        NotificationChannelName name = NotificationChannelName.ofProjectNotificationChannelName("[PROJECT]", "[NOTIFICATION_CHANNEL]");
        boolean force = true;
        client.deleteNotificationChannel(name, force);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) NotificationChannelName(com.google.monitoring.v3.NotificationChannelName) Test(org.junit.Test)

Example 9 with NotificationChannelName

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

the class NotificationChannelServiceClient method sendNotificationChannelVerificationCode.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Causes a verification code to be delivered to the channel. The code can then be supplied in
 * `VerifyNotificationChannel` to verify the channel.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (NotificationChannelServiceClient notificationChannelServiceClient =
 *     NotificationChannelServiceClient.create()) {
 *   NotificationChannelName name =
 *       NotificationChannelName.ofProjectNotificationChannelName(
 *           "[PROJECT]", "[NOTIFICATION_CHANNEL]");
 *   notificationChannelServiceClient.sendNotificationChannelVerificationCode(name);
 * }
 * }</pre>
 *
 * @param name Required. The notification channel to which to send a verification code.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void sendNotificationChannelVerificationCode(NotificationChannelName name) {
    SendNotificationChannelVerificationCodeRequest request = SendNotificationChannelVerificationCodeRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    sendNotificationChannelVerificationCode(request);
}
Also used : SendNotificationChannelVerificationCodeRequest(com.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest)

Example 10 with NotificationChannelName

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

the class NotificationChannelServiceClient method deleteNotificationChannel.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a notification channel.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (NotificationChannelServiceClient notificationChannelServiceClient =
 *     NotificationChannelServiceClient.create()) {
 *   NotificationChannelName name =
 *       NotificationChannelName.ofProjectNotificationChannelName(
 *           "[PROJECT]", "[NOTIFICATION_CHANNEL]");
 *   boolean force = true;
 *   notificationChannelServiceClient.deleteNotificationChannel(name, force);
 * }
 * }</pre>
 *
 * @param name Required. The channel for which to execute the request. The format is:
 *     <p>projects/[PROJECT_ID_OR_NUMBER]/notificationChannels/[CHANNEL_ID]
 * @param force If true, the notification channel will be deleted regardless of its use in alert
 *     policies (the policies will be updated to remove the channel). If false, channels that are
 *     still referenced by an existing alerting policy will fail to be deleted in a delete
 *     operation.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteNotificationChannel(NotificationChannelName name, boolean force) {
    DeleteNotificationChannelRequest request = DeleteNotificationChannelRequest.newBuilder().setName(name == null ? null : name.toString()).setForce(force).build();
    deleteNotificationChannel(request);
}
Also used : DeleteNotificationChannelRequest(com.google.monitoring.v3.DeleteNotificationChannelRequest)

Aggregations

NotificationChannelName (com.google.monitoring.v3.NotificationChannelName)12 Test (org.junit.Test)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 NotificationChannelServiceClient (com.google.cloud.monitoring.v3.NotificationChannelServiceClient)2 DeleteNotificationChannelRequest (com.google.monitoring.v3.DeleteNotificationChannelRequest)2 NotificationChannel (com.google.monitoring.v3.NotificationChannel)2 SendNotificationChannelVerificationCodeRequest (com.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest)2 Empty (com.google.protobuf.Empty)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 GetNotificationChannelRequest (com.google.monitoring.v3.GetNotificationChannelRequest)1 GetNotificationChannelVerificationCodeRequest (com.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest)1 GetNotificationChannelVerificationCodeResponse (com.google.monitoring.v3.GetNotificationChannelVerificationCodeResponse)1 VerifyNotificationChannelRequest (com.google.monitoring.v3.VerifyNotificationChannelRequest)1