Search in sources :

Example 1 with ServiceName

use of com.google.monitoring.v3.ServiceName 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 ServiceName

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

the class ServiceMonitoringServiceClientTest method getServiceExceptionTest.

@Test
public void getServiceExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
        client.getService(name);
        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) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 3 with ServiceName

use of com.google.monitoring.v3.ServiceName 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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListServiceLevelObjectivesRequest(com.google.monitoring.v3.ListServiceLevelObjectivesRequest) ServiceLevelObjective(com.google.monitoring.v3.ServiceLevelObjective) ServiceName(com.google.monitoring.v3.ServiceName) ListServiceLevelObjectivesPagedResponse(com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServiceLevelObjectivesPagedResponse) ListServiceLevelObjectivesResponse(com.google.monitoring.v3.ListServiceLevelObjectivesResponse) Test(org.junit.Test)

Example 4 with ServiceName

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

the class ServiceMonitoringServiceClient method deleteService.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Soft delete this `Service`.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (ServiceMonitoringServiceClient serviceMonitoringServiceClient =
 *     ServiceMonitoringServiceClient.create()) {
 *   ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
 *   serviceMonitoringServiceClient.deleteService(name);
 * }
 * }</pre>
 *
 * @param name Required. Resource name of the `Service` to delete. The format is:
 *     <p>projects/[PROJECT_ID_OR_NUMBER]/services/[SERVICE_ID]
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteService(ServiceName name) {
    DeleteServiceRequest request = DeleteServiceRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteService(request);
}
Also used : DeleteServiceRequest(com.google.monitoring.v3.DeleteServiceRequest)

Example 5 with ServiceName

use of com.google.monitoring.v3.ServiceName 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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ServiceLevelObjective(com.google.monitoring.v3.ServiceLevelObjective) HashMap(java.util.HashMap) ServiceName(com.google.monitoring.v3.ServiceName) CreateServiceLevelObjectiveRequest(com.google.monitoring.v3.CreateServiceLevelObjectiveRequest) Test(org.junit.Test)

Aggregations

ServiceName (com.google.monitoring.v3.ServiceName)8 Test (org.junit.Test)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 ServiceName (com.google.cloud.servicedirectory.v1.ServiceName)3 ServiceLevelObjective (com.google.monitoring.v3.ServiceLevelObjective)3 Endpoint (com.google.cloud.servicedirectory.v1.Endpoint)2 RegistrationServiceClient (com.google.cloud.servicedirectory.v1.RegistrationServiceClient)2 DeleteServiceRequest (com.google.monitoring.v3.DeleteServiceRequest)2 HashMap (java.util.HashMap)2 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)1 ListServiceLevelObjectivesPagedResponse (com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServiceLevelObjectivesPagedResponse)1 LookupServiceClient (com.google.cloud.servicedirectory.v1.LookupServiceClient)1 ResolveServiceRequest (com.google.cloud.servicedirectory.v1.ResolveServiceRequest)1 ResolveServiceResponse (com.google.cloud.servicedirectory.v1.ResolveServiceResponse)1 CreateServiceLevelObjectiveRequest (com.google.monitoring.v3.CreateServiceLevelObjectiveRequest)1 GetServiceRequest (com.google.monitoring.v3.GetServiceRequest)1 ListServiceLevelObjectivesRequest (com.google.monitoring.v3.ListServiceLevelObjectivesRequest)1 ListServiceLevelObjectivesResponse (com.google.monitoring.v3.ListServiceLevelObjectivesResponse)1