Search in sources :

Example 6 with AlertPolicy

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

the class AlertPolicyServiceClientTest method listAlertPoliciesTest2.

@Test
public void listAlertPoliciesTest2() throws Exception {
    AlertPolicy responsesElement = AlertPolicy.newBuilder().build();
    ListAlertPoliciesResponse expectedResponse = ListAlertPoliciesResponse.newBuilder().setNextPageToken("").addAllAlertPolicies(Arrays.asList(responsesElement)).build();
    mockAlertPolicyService.addResponse(expectedResponse);
    OrganizationName name = OrganizationName.of("[ORGANIZATION]");
    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()));
}
Also used : ListAlertPoliciesResponse(com.google.monitoring.v3.ListAlertPoliciesResponse) OrganizationName(com.google.monitoring.v3.OrganizationName) AbstractMessage(com.google.protobuf.AbstractMessage) ListAlertPoliciesRequest(com.google.monitoring.v3.ListAlertPoliciesRequest) AlertPolicy(com.google.monitoring.v3.AlertPolicy) ListAlertPoliciesPagedResponse(com.google.cloud.monitoring.v3.AlertPolicyServiceClient.ListAlertPoliciesPagedResponse) Test(org.junit.Test)

Example 7 with AlertPolicy

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

the class AlertPolicyServiceClientTest method updateAlertPolicyExceptionTest.

@Test
public void updateAlertPolicyExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockAlertPolicyService.addException(exception);
    try {
        FieldMask updateMask = FieldMask.newBuilder().build();
        AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
        client.updateAlertPolicy(updateMask, alertPolicy);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) AlertPolicy(com.google.monitoring.v3.AlertPolicy) StatusRuntimeException(io.grpc.StatusRuntimeException) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 8 with AlertPolicy

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

the class AlertPolicyServiceClientTest method createAlertPolicyTest4.

@Test
public void createAlertPolicyTest4() 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 alertPolicy = AlertPolicy.newBuilder().build();
    AlertPolicy actualResponse = client.createAlertPolicy(name, alertPolicy);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockAlertPolicyService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateAlertPolicyRequest actualRequest = ((CreateAlertPolicyRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertEquals(alertPolicy, actualRequest.getAlertPolicy());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) CreateAlertPolicyRequest(com.google.monitoring.v3.CreateAlertPolicyRequest) AlertPolicy(com.google.monitoring.v3.AlertPolicy) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with AlertPolicy

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

the class AlertPolicyServiceClientTest method listAlertPoliciesTest3.

@Test
public void listAlertPoliciesTest3() throws Exception {
    AlertPolicy responsesElement = AlertPolicy.newBuilder().build();
    ListAlertPoliciesResponse expectedResponse = ListAlertPoliciesResponse.newBuilder().setNextPageToken("").addAllAlertPolicies(Arrays.asList(responsesElement)).build();
    mockAlertPolicyService.addResponse(expectedResponse);
    ProjectName name = ProjectName.of("[PROJECT]");
    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()));
}
Also used : ListAlertPoliciesResponse(com.google.monitoring.v3.ListAlertPoliciesResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListAlertPoliciesRequest(com.google.monitoring.v3.ListAlertPoliciesRequest) ProjectName(com.google.monitoring.v3.ProjectName) AlertPolicy(com.google.monitoring.v3.AlertPolicy) ListAlertPoliciesPagedResponse(com.google.cloud.monitoring.v3.AlertPolicyServiceClient.ListAlertPoliciesPagedResponse) Test(org.junit.Test)

Example 10 with AlertPolicy

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()) {
 *   AlertPolicyName name =
 *       AlertPolicyName.ofProjectAlertPolicyName("[PROJECT]", "[ALERT_POLICY]");
 *   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(AlertPolicyName name) {
    DeleteAlertPolicyRequest request = DeleteAlertPolicyRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteAlertPolicy(request);
}
Also used : DeleteAlertPolicyRequest(com.google.monitoring.v3.DeleteAlertPolicyRequest)

Aggregations

AlertPolicy (com.google.monitoring.v3.AlertPolicy)33 Test (org.junit.Test)16 AbstractMessage (com.google.protobuf.AbstractMessage)11 AlertPolicyServiceClient (com.google.cloud.monitoring.v3.AlertPolicyServiceClient)9 ListAlertPoliciesPagedResponse (com.google.cloud.monitoring.v3.AlertPolicyServiceClient.ListAlertPoliciesPagedResponse)8 ArrayList (java.util.ArrayList)7 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)5 ListAlertPoliciesRequest (com.google.monitoring.v3.ListAlertPoliciesRequest)5 NotificationChannel (com.google.monitoring.v3.NotificationChannel)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 JsonObject (com.google.gson.JsonObject)4 CreateAlertPolicyRequest (com.google.monitoring.v3.CreateAlertPolicyRequest)4 ListAlertPoliciesResponse (com.google.monitoring.v3.ListAlertPoliciesResponse)4 ProjectName (com.google.monitoring.v3.ProjectName)4 Aggregation (com.google.monitoring.v3.Aggregation)3 FolderName (com.google.monitoring.v3.FolderName)3 OrganizationName (com.google.monitoring.v3.OrganizationName)3 UpdateAlertPolicyRequest (com.google.monitoring.v3.UpdateAlertPolicyRequest)3 Duration (com.google.protobuf.Duration)3 JsonArray (com.google.gson.JsonArray)2