Search in sources :

Example 1 with NotificationChannelName

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

the class NotificationChannelServiceClientTest method getNotificationChannelVerificationCodeTest.

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

Example 2 with NotificationChannelName

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

the class NotificationChannelServiceClientTest method deleteNotificationChannelTest.

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

Example 3 with NotificationChannelName

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

the class NotificationChannelServiceClientTest method getNotificationChannelVerificationCodeExceptionTest.

@Test
public void getNotificationChannelVerificationCodeExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockNotificationChannelService.addException(exception);
    try {
        NotificationChannelName name = NotificationChannelName.ofProjectNotificationChannelName("[PROJECT]", "[NOTIFICATION_CHANNEL]");
        client.getNotificationChannelVerificationCode(name);
        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 4 with NotificationChannelName

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

the class NotificationChannelServiceClientTest method sendNotificationChannelVerificationCodeExceptionTest.

@Test
public void sendNotificationChannelVerificationCodeExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockNotificationChannelService.addException(exception);
    try {
        NotificationChannelName name = NotificationChannelName.ofProjectNotificationChannelName("[PROJECT]", "[NOTIFICATION_CHANNEL]");
        client.sendNotificationChannelVerificationCode(name);
        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 5 with NotificationChannelName

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

the class NotificationChannelServiceClientTest method verifyNotificationChannelTest.

@Test
public void verifyNotificationChannelTest() 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]");
    String code = "code3059181";
    NotificationChannel actualResponse = client.verifyNotificationChannel(name, code);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    VerifyNotificationChannelRequest actualRequest = ((VerifyNotificationChannelRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(code, actualRequest.getCode());
    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) VerifyNotificationChannelRequest(com.google.monitoring.v3.VerifyNotificationChannelRequest) NotificationChannelName(com.google.monitoring.v3.NotificationChannelName) Test(org.junit.Test)

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