use of com.google.monitoring.v3.ServiceLevelObjective in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method listServiceLevelObjectivesTest.
@Test
public void listServiceLevelObjectivesTest() throws Exception {
ServiceLevelObjective responsesElement = ServiceLevelObjective.newBuilder().build();
ListServiceLevelObjectivesResponse expectedResponse = ListServiceLevelObjectivesResponse.newBuilder().setNextPageToken("").addAllServiceLevelObjectives(Arrays.asList(responsesElement)).build();
mockServiceMonitoringService.addResponse(expectedResponse);
ServiceName parent = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
ListServiceLevelObjectivesPagedResponse pagedListResponse = client.listServiceLevelObjectives(parent);
List<ServiceLevelObjective> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getServiceLevelObjectivesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListServiceLevelObjectivesRequest actualRequest = ((ListServiceLevelObjectivesRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.ServiceLevelObjective in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method listServiceLevelObjectivesTest2.
@Test
public void listServiceLevelObjectivesTest2() throws Exception {
ServiceLevelObjective responsesElement = ServiceLevelObjective.newBuilder().build();
ListServiceLevelObjectivesResponse expectedResponse = ListServiceLevelObjectivesResponse.newBuilder().setNextPageToken("").addAllServiceLevelObjectives(Arrays.asList(responsesElement)).build();
mockServiceMonitoringService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListServiceLevelObjectivesPagedResponse pagedListResponse = client.listServiceLevelObjectives(parent);
List<ServiceLevelObjective> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getServiceLevelObjectivesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListServiceLevelObjectivesRequest actualRequest = ((ListServiceLevelObjectivesRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.ServiceLevelObjective in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClient method deleteServiceLevelObjective.
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Delete the given `ServiceLevelObjective`.
*
* <p>Sample code:
*
* <pre>{@code
* try (ServiceMonitoringServiceClient serviceMonitoringServiceClient =
* ServiceMonitoringServiceClient.create()) {
* String name =
* ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName(
* "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]")
* .toString();
* serviceMonitoringServiceClient.deleteServiceLevelObjective(name);
* }
* }</pre>
*
* @param name Required. Resource name of the `ServiceLevelObjective` to delete. The format is:
* <p>projects/[PROJECT_ID_OR_NUMBER]/services/[SERVICE_ID]/serviceLevelObjectives/[SLO_NAME]
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteServiceLevelObjective(String name) {
DeleteServiceLevelObjectiveRequest request = DeleteServiceLevelObjectiveRequest.newBuilder().setName(name).build();
deleteServiceLevelObjective(request);
}
use of com.google.monitoring.v3.ServiceLevelObjective in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method createServiceLevelObjectiveTest.
@Test
public void createServiceLevelObjectiveTest() throws Exception {
ServiceLevelObjective expectedResponse = ServiceLevelObjective.newBuilder().setName(ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName("[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]").toString()).setDisplayName("displayName1714148973").setServiceLevelIndicator(ServiceLevelIndicator.newBuilder().build()).setGoal(3178259).putAllUserLabels(new HashMap<String, String>()).build();
mockServiceMonitoringService.addResponse(expectedResponse);
ServiceName parent = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build();
ServiceLevelObjective actualResponse = client.createServiceLevelObjective(parent, serviceLevelObjective);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateServiceLevelObjectiveRequest actualRequest = ((CreateServiceLevelObjectiveRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(serviceLevelObjective, actualRequest.getServiceLevelObjective());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.ServiceLevelObjective in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method createServiceLevelObjectiveExceptionTest2.
@Test
public void createServiceLevelObjectiveExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockServiceMonitoringService.addException(exception);
try {
String parent = "parent-995424086";
ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build();
client.createServiceLevelObjective(parent, serviceLevelObjective);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations