use of com.google.cloud.servicedirectory.v1.Service in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method listServicesTest.
@Test
public void listServicesTest() throws Exception {
Service responsesElement = Service.newBuilder().build();
ListServicesResponse expectedResponse = ListServicesResponse.newBuilder().setNextPageToken("").addAllServices(Arrays.asList(responsesElement)).build();
mockServiceMonitoringService.addResponse(expectedResponse);
FolderName parent = FolderName.of("[FOLDER]");
ListServicesPagedResponse pagedListResponse = client.listServices(parent);
List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.servicedirectory.v1.Service in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method createServiceExceptionTest.
@Test
public void createServiceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockServiceMonitoringService.addException(exception);
try {
FolderName parent = FolderName.of("[FOLDER]");
Service service = Service.newBuilder().build();
client.createService(parent, service);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.cloud.servicedirectory.v1.Service in project yakc by manusa.
the class ServiceIT method patchNamespacedService.
@Test
@DisplayName("patchNamespacedService, should patch labels of Service")
void patchNamespacedService() throws IOException {
// When
final Service result = KC.create(CoreV1Api.class).patchNamespacedService(serviceName, NAMESPACE, Service.builder().metadata(ObjectMeta.builder().putInLabels("patched", "label").build()).build()).get();
// Then
assertThat(result).isNotNull().extracting(Service::getMetadata).hasFieldOrPropertyWithValue("name", serviceName).extracting(ObjectMeta::getLabels).asInstanceOf(InstanceOfAssertFactories.MAP).hasSize(2).containsEntry("patched", "label");
}
use of com.google.cloud.servicedirectory.v1.Service in project yakc by manusa.
the class ServiceIT method replaceNamespacedService.
@Test
@DisplayName("replaceNamespacedService, should replace existing Service's port")
void replaceNamespacedService() throws IOException {
// Given
final Service existingService = KC.create(CoreV1Api.class).readNamespacedService(serviceName, NAMESPACE).get();
existingService.getSpec().getPorts().get(0).setTargetPort("http");
// When
final Service result = KC.create(CoreV1Api.class).replaceNamespacedService(serviceName, NAMESPACE, existingService).get();
// Then
assertThat(result).isNotNull().hasFieldOrPropertyWithValue("metadata.name", serviceName).extracting(Service::getSpec).extracting(ServiceSpec::getPorts).asList().hasSize(2).element(0).hasFieldOrPropertyWithValue("targetPort", "http");
}
use of com.google.cloud.servicedirectory.v1.Service in project yakc by manusa.
the class ServiceIT method awaitCreateWatch.
@Test
@DisplayName("listNamespacedService.watch, should await for notification of newly created Service")
void awaitCreateWatch() throws IOException {
// Given
final AtomicBoolean hasError = new AtomicBoolean(false);
final AtomicBoolean hasCompleted = new AtomicBoolean(false);
// When
final Disposable d = KC.create(CoreV1Api.class).listNamespacedService(NAMESPACE).watch().filter(we -> we.getObject().getMetadata().getName().equals(serviceName)).takeUntil(we -> we.getType() == Type.ADDED).timeout(20, TimeUnit.SECONDS).subscribe(we -> hasCompleted.set(true), we -> hasError.set(true));
// Then
assertThat(d).isNotNull();
assertThat(hasError.get()).as("Watch subscribe ended with an error").isFalse();
assertThat(hasCompleted.get()).as("Watch subscribe did not complete").isTrue();
}
Aggregations