use of com.google.monitoring.v3.AlertPolicy in project java-monitoring by googleapis.
the class AlertPolicyServiceClient method deleteAlertPolicy.
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes an alerting policy.
*
* <p>Sample code:
*
* <pre>{@code
* try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
* String name =
* AlertPolicyName.ofProjectAlertPolicyName("[PROJECT]", "[ALERT_POLICY]").toString();
* alertPolicyServiceClient.deleteAlertPolicy(name);
* }
* }</pre>
*
* @param name Required. The alerting policy to delete. The format is:
* <p>projects/[PROJECT_ID_OR_NUMBER]/alertPolicies/[ALERT_POLICY_ID]
* <p>For more information, see [AlertPolicy][google.monitoring.v3.AlertPolicy].
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteAlertPolicy(String name) {
DeleteAlertPolicyRequest request = DeleteAlertPolicyRequest.newBuilder().setName(name).build();
deleteAlertPolicy(request);
}
use of com.google.monitoring.v3.AlertPolicy in project java-monitoring by googleapis.
the class AlertPolicyServiceClientTest method getAlertPolicyTest2.
@Test
public void getAlertPolicyTest2() throws Exception {
AlertPolicy expectedResponse = AlertPolicy.newBuilder().setName(AlertPolicyName.ofProjectAlertPolicyName("[PROJECT]", "[ALERT_POLICY]").toString()).setDisplayName("displayName1714148973").setDocumentation(AlertPolicy.Documentation.newBuilder().build()).putAllUserLabels(new HashMap<String, String>()).addAllConditions(new ArrayList<AlertPolicy.Condition>()).setEnabled(BoolValue.newBuilder().build()).setValidity(Status.newBuilder().build()).addAllNotificationChannels(new ArrayList<String>()).setCreationRecord(MutationRecord.newBuilder().build()).setMutationRecord(MutationRecord.newBuilder().build()).setAlertStrategy(AlertPolicy.AlertStrategy.newBuilder().build()).build();
mockAlertPolicyService.addResponse(expectedResponse);
String name = "name3373707";
AlertPolicy actualResponse = client.getAlertPolicy(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockAlertPolicyService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetAlertPolicyRequest actualRequest = ((GetAlertPolicyRequest) actualRequests.get(0));
Assert.assertEquals(name, actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.AlertPolicy in project java-monitoring by googleapis.
the class AlertPolicyServiceClientTest method listAlertPoliciesTest.
@Test
public void listAlertPoliciesTest() throws Exception {
AlertPolicy responsesElement = AlertPolicy.newBuilder().build();
ListAlertPoliciesResponse expectedResponse = ListAlertPoliciesResponse.newBuilder().setNextPageToken("").addAllAlertPolicies(Arrays.asList(responsesElement)).build();
mockAlertPolicyService.addResponse(expectedResponse);
FolderName name = FolderName.of("[FOLDER]");
ListAlertPoliciesPagedResponse pagedListResponse = client.listAlertPolicies(name);
List<AlertPolicy> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getAlertPoliciesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAlertPolicyService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListAlertPoliciesRequest actualRequest = ((ListAlertPoliciesRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.AlertPolicy in project java-monitoring by googleapis.
the class AlertPolicyServiceClientTest method listAlertPoliciesTest4.
@Test
public void listAlertPoliciesTest4() throws Exception {
AlertPolicy responsesElement = AlertPolicy.newBuilder().build();
ListAlertPoliciesResponse expectedResponse = ListAlertPoliciesResponse.newBuilder().setNextPageToken("").addAllAlertPolicies(Arrays.asList(responsesElement)).build();
mockAlertPolicyService.addResponse(expectedResponse);
String name = "name3373707";
ListAlertPoliciesPagedResponse pagedListResponse = client.listAlertPolicies(name);
List<AlertPolicy> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getAlertPoliciesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAlertPolicyService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListAlertPoliciesRequest actualRequest = ((ListAlertPoliciesRequest) actualRequests.get(0));
Assert.assertEquals(name, actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.AlertPolicy in project java-monitoring by googleapis.
the class AlertPolicyServiceClientTest method createAlertPolicyExceptionTest3.
@Test
public void createAlertPolicyExceptionTest3() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAlertPolicyService.addException(exception);
try {
ProjectName name = ProjectName.of("[PROJECT]");
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
client.createAlertPolicy(name, alertPolicy);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations