Search in sources :

Example 1 with UptimeCheckConfigName

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

the class UptimeCheckServiceClient method deleteUptimeCheckConfig.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes an Uptime check configuration. Note that this method will fail if the Uptime check
 * configuration is referenced by an alert policy or other dependent configs that would be
 * rendered invalid by the deletion.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (UptimeCheckServiceClient uptimeCheckServiceClient = UptimeCheckServiceClient.create()) {
 *   UptimeCheckConfigName name =
 *       UptimeCheckConfigName.ofProjectUptimeCheckConfigName(
 *           "[PROJECT]", "[UPTIME_CHECK_CONFIG]");
 *   uptimeCheckServiceClient.deleteUptimeCheckConfig(name);
 * }
 * }</pre>
 *
 * @param name Required. The Uptime check configuration to delete. The format is:
 *     <p>projects/[PROJECT_ID_OR_NUMBER]/uptimeCheckConfigs/[UPTIME_CHECK_ID]
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteUptimeCheckConfig(UptimeCheckConfigName name) {
    DeleteUptimeCheckConfigRequest request = DeleteUptimeCheckConfigRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteUptimeCheckConfig(request);
}
Also used : DeleteUptimeCheckConfigRequest(com.google.monitoring.v3.DeleteUptimeCheckConfigRequest)

Example 2 with UptimeCheckConfigName

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

the class UptimeCheckServiceClientTest method deleteUptimeCheckConfigTest.

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

Example 3 with UptimeCheckConfigName

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

the class UptimeCheckServiceClientTest method getUptimeCheckConfigExceptionTest.

@Test
public void getUptimeCheckConfigExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockUptimeCheckService.addException(exception);
    try {
        UptimeCheckConfigName name = UptimeCheckConfigName.ofProjectUptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]");
        client.getUptimeCheckConfig(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) UptimeCheckConfigName(com.google.monitoring.v3.UptimeCheckConfigName) Test(org.junit.Test)

Example 4 with UptimeCheckConfigName

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

the class UptimeCheckServiceClientTest method getUptimeCheckConfigTest.

@Test
public void getUptimeCheckConfigTest() throws Exception {
    UptimeCheckConfig expectedResponse = UptimeCheckConfig.newBuilder().setName(UptimeCheckConfigName.ofProjectUptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]").toString()).setDisplayName("displayName1714148973").setPeriod(Duration.newBuilder().build()).setTimeout(Duration.newBuilder().build()).addAllContentMatchers(new ArrayList<UptimeCheckConfig.ContentMatcher>()).addAllSelectedRegions(new ArrayList<UptimeCheckRegion>()).setIsInternal(true).addAllInternalCheckers(new ArrayList<InternalChecker>()).build();
    mockUptimeCheckService.addResponse(expectedResponse);
    UptimeCheckConfigName name = UptimeCheckConfigName.ofProjectUptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]");
    UptimeCheckConfig actualResponse = client.getUptimeCheckConfig(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockUptimeCheckService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetUptimeCheckConfigRequest actualRequest = ((GetUptimeCheckConfigRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) GetUptimeCheckConfigRequest(com.google.monitoring.v3.GetUptimeCheckConfigRequest) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) UptimeCheckConfigName(com.google.monitoring.v3.UptimeCheckConfigName) Test(org.junit.Test)

Example 5 with UptimeCheckConfigName

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

the class UptimeCheckServiceClientTest method deleteUptimeCheckConfigExceptionTest.

@Test
public void deleteUptimeCheckConfigExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockUptimeCheckService.addException(exception);
    try {
        UptimeCheckConfigName name = UptimeCheckConfigName.ofProjectUptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]");
        client.deleteUptimeCheckConfig(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) UptimeCheckConfigName(com.google.monitoring.v3.UptimeCheckConfigName) Test(org.junit.Test)

Aggregations

UptimeCheckConfigName (com.google.monitoring.v3.UptimeCheckConfigName)4 Test (org.junit.Test)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 DeleteUptimeCheckConfigRequest (com.google.monitoring.v3.DeleteUptimeCheckConfigRequest)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 GetUptimeCheckConfigRequest (com.google.monitoring.v3.GetUptimeCheckConfigRequest)1 UptimeCheckConfig (com.google.monitoring.v3.UptimeCheckConfig)1 Empty (com.google.protobuf.Empty)1 ArrayList (java.util.ArrayList)1