Search in sources :

Example 1 with ServiceLevelObjective

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

the class ServiceMonitoringServiceClientTest method createServiceLevelObjectiveExceptionTest.

@Test
public void createServiceLevelObjectiveExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        ServiceName parent = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
        ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build();
        client.createServiceLevelObjective(parent, serviceLevelObjective);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ServiceName(com.google.monitoring.v3.ServiceName) ServiceLevelObjective(com.google.monitoring.v3.ServiceLevelObjective) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 2 with ServiceLevelObjective

use of com.google.monitoring.v3.ServiceLevelObjective 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 3 with ServiceLevelObjective

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

the class ServiceMonitoringServiceClientTest method updateServiceLevelObjectiveTest.

@Test
public void updateServiceLevelObjectiveTest() 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);
    ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build();
    ServiceLevelObjective actualResponse = client.updateServiceLevelObjective(serviceLevelObjective);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateServiceLevelObjectiveRequest actualRequest = ((UpdateServiceLevelObjectiveRequest) actualRequests.get(0));
    Assert.assertEquals(serviceLevelObjective, actualRequest.getServiceLevelObjective());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ServiceLevelObjective(com.google.monitoring.v3.ServiceLevelObjective) HashMap(java.util.HashMap) UpdateServiceLevelObjectiveRequest(com.google.monitoring.v3.UpdateServiceLevelObjectiveRequest) Test(org.junit.Test)

Example 4 with ServiceLevelObjective

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

the class ServiceMonitoringServiceClientTest method updateServiceLevelObjectiveExceptionTest.

@Test
public void updateServiceLevelObjectiveExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build();
        client.updateServiceLevelObjective(serviceLevelObjective);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ServiceLevelObjective(com.google.monitoring.v3.ServiceLevelObjective) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 5 with ServiceLevelObjective

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

the class ServiceMonitoringServiceClientTest method getServiceLevelObjectiveTest2.

@Test
public void getServiceLevelObjectiveTest2() 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);
    String name = "name3373707";
    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, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : 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)

Aggregations

ServiceLevelObjective (com.google.monitoring.v3.ServiceLevelObjective)10 Test (org.junit.Test)10 AbstractMessage (com.google.protobuf.AbstractMessage)7 HashMap (java.util.HashMap)5 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)3 ServiceName (com.google.monitoring.v3.ServiceName)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 ListServiceLevelObjectivesPagedResponse (com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServiceLevelObjectivesPagedResponse)2 CreateServiceLevelObjectiveRequest (com.google.monitoring.v3.CreateServiceLevelObjectiveRequest)2 DeleteServiceLevelObjectiveRequest (com.google.monitoring.v3.DeleteServiceLevelObjectiveRequest)2 GetServiceLevelObjectiveRequest (com.google.monitoring.v3.GetServiceLevelObjectiveRequest)2 ListServiceLevelObjectivesRequest (com.google.monitoring.v3.ListServiceLevelObjectivesRequest)2 ListServiceLevelObjectivesResponse (com.google.monitoring.v3.ListServiceLevelObjectivesResponse)2 ServiceLevelObjectiveName (com.google.monitoring.v3.ServiceLevelObjectiveName)1 UpdateServiceLevelObjectiveRequest (com.google.monitoring.v3.UpdateServiceLevelObjectiveRequest)1