use of com.google.monitoring.v3.Service in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method createServiceTest.
@Test
public void createServiceTest() throws Exception {
Service expectedResponse = Service.newBuilder().setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()).setDisplayName("displayName1714148973").setTelemetry(Service.Telemetry.newBuilder().build()).putAllUserLabels(new HashMap<String, String>()).build();
mockServiceMonitoringService.addResponse(expectedResponse);
FolderName parent = FolderName.of("[FOLDER]");
Service service = Service.newBuilder().build();
Service actualResponse = client.createService(parent, service);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateServiceRequest actualRequest = ((CreateServiceRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(service, actualRequest.getService());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.Service 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.
}
}
use of com.google.monitoring.v3.Service in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method createServiceExceptionTest2.
@Test
public void createServiceExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockServiceMonitoringService.addException(exception);
try {
OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
Service service = Service.newBuilder().build();
client.createService(parent, service);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.monitoring.v3.Service 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()));
}
use of com.google.monitoring.v3.Service 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()));
}
Aggregations