Search in sources :

Example 1 with ServiceLevelObjectiveName

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

the class ServiceMonitoringServiceClientTest method getServiceLevelObjectiveTest.

@Test
public void getServiceLevelObjectiveTest() 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);
    ServiceLevelObjectiveName name = ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName("[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]");
    ServiceLevelObjective actualResponse = client.getServiceLevelObjective(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetServiceLevelObjectiveRequest actualRequest = ((GetServiceLevelObjectiveRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ServiceLevelObjectiveName(com.google.monitoring.v3.ServiceLevelObjectiveName) AbstractMessage(com.google.protobuf.AbstractMessage) ServiceLevelObjective(com.google.monitoring.v3.ServiceLevelObjective) HashMap(java.util.HashMap) GetServiceLevelObjectiveRequest(com.google.monitoring.v3.GetServiceLevelObjectiveRequest) Test(org.junit.Test)

Example 2 with ServiceLevelObjectiveName

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

the class ServiceMonitoringServiceClientTest method deleteServiceLevelObjectiveTest.

@Test
public void deleteServiceLevelObjectiveTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockServiceMonitoringService.addResponse(expectedResponse);
    ServiceLevelObjectiveName name = ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName("[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]");
    client.deleteServiceLevelObjective(name);
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteServiceLevelObjectiveRequest actualRequest = ((DeleteServiceLevelObjectiveRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) ServiceLevelObjectiveName(com.google.monitoring.v3.ServiceLevelObjectiveName) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteServiceLevelObjectiveRequest(com.google.monitoring.v3.DeleteServiceLevelObjectiveRequest) Test(org.junit.Test)

Example 3 with ServiceLevelObjectiveName

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

the class ServiceMonitoringServiceClientTest method deleteServiceLevelObjectiveExceptionTest.

@Test
public void deleteServiceLevelObjectiveExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        ServiceLevelObjectiveName name = ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName("[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]");
        client.deleteServiceLevelObjective(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : ServiceLevelObjectiveName(com.google.monitoring.v3.ServiceLevelObjectiveName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 4 with ServiceLevelObjectiveName

use of com.google.monitoring.v3.ServiceLevelObjectiveName 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()) {
 *   ServiceLevelObjectiveName name =
 *       ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName(
 *           "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]");
 *   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(ServiceLevelObjectiveName name) {
    DeleteServiceLevelObjectiveRequest request = DeleteServiceLevelObjectiveRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteServiceLevelObjective(request);
}
Also used : DeleteServiceLevelObjectiveRequest(com.google.monitoring.v3.DeleteServiceLevelObjectiveRequest)

Example 5 with ServiceLevelObjectiveName

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

the class ServiceMonitoringServiceClientTest method getServiceLevelObjectiveExceptionTest.

@Test
public void getServiceLevelObjectiveExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        ServiceLevelObjectiveName name = ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName("[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]");
        client.getServiceLevelObjective(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : ServiceLevelObjectiveName(com.google.monitoring.v3.ServiceLevelObjectiveName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

ServiceLevelObjectiveName (com.google.monitoring.v3.ServiceLevelObjectiveName)4 Test (org.junit.Test)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 DeleteServiceLevelObjectiveRequest (com.google.monitoring.v3.DeleteServiceLevelObjectiveRequest)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 GetServiceLevelObjectiveRequest (com.google.monitoring.v3.GetServiceLevelObjectiveRequest)1 ServiceLevelObjective (com.google.monitoring.v3.ServiceLevelObjective)1 Empty (com.google.protobuf.Empty)1 HashMap (java.util.HashMap)1