use of com.google.monitoring.v3.AlertPolicy in project java-monitoring by googleapis.
the class AlertPolicyServiceClientTest method createAlertPolicyTest.
@Test
public void createAlertPolicyTest() 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);
FolderName name = FolderName.of("[FOLDER]");
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.toString(), actualRequest.getName());
Assert.assertEquals(alertPolicy, actualRequest.getAlertPolicy());
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 createAlertPolicyExceptionTest4.
@Test
public void createAlertPolicyExceptionTest4() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAlertPolicyService.addException(exception);
try {
String name = "name3373707";
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
client.createAlertPolicy(name, alertPolicy);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.monitoring.v3.AlertPolicy in project java-monitoring by googleapis.
the class AlertPolicyServiceClientTest method createAlertPolicyExceptionTest.
@Test
public void createAlertPolicyExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAlertPolicyService.addException(exception);
try {
FolderName name = FolderName.of("[FOLDER]");
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
client.createAlertPolicy(name, alertPolicy);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.monitoring.v3.AlertPolicy in project java-monitoring by googleapis.
the class AlertPolicyServiceClientTest method createAlertPolicyTest3.
@Test
public void createAlertPolicyTest3() 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);
ProjectName name = ProjectName.of("[PROJECT]");
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.toString(), actualRequest.getName());
Assert.assertEquals(alertPolicy, actualRequest.getAlertPolicy());
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 updateAlertPolicyTest.
@Test
public void updateAlertPolicyTest() 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);
FieldMask updateMask = FieldMask.newBuilder().build();
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
AlertPolicy actualResponse = client.updateAlertPolicy(updateMask, alertPolicy);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockAlertPolicyService.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateAlertPolicyRequest actualRequest = ((UpdateAlertPolicyRequest) actualRequests.get(0));
Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
Assert.assertEquals(alertPolicy, actualRequest.getAlertPolicy());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations