use of com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse in project java-servicedirectory by googleapis.
the class RegistrationServiceClientTest method listNamespacesTest.
@Test
public void listNamespacesTest() throws Exception {
Namespace responsesElement = Namespace.newBuilder().build();
ListNamespacesResponse expectedResponse = ListNamespacesResponse.newBuilder().setNextPageToken("").addAllNamespaces(Arrays.asList(responsesElement)).build();
mockRegistrationService.addResponse(expectedResponse);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListNamespacesPagedResponse pagedListResponse = client.listNamespaces(parent);
List<Namespace> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getNamespacesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockRegistrationService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListNamespacesRequest actualRequest = ((ListNamespacesRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse in project java-servicedirectory by googleapis.
the class RegistrationServiceClientTest method listNamespacesTest2.
@Test
public void listNamespacesTest2() throws Exception {
Namespace responsesElement = Namespace.newBuilder().build();
ListNamespacesResponse expectedResponse = ListNamespacesResponse.newBuilder().setNextPageToken("").addAllNamespaces(Arrays.asList(responsesElement)).build();
mockRegistrationService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListNamespacesPagedResponse pagedListResponse = client.listNamespaces(parent);
List<Namespace> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getNamespacesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockRegistrationService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListNamespacesRequest actualRequest = ((ListNamespacesRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse in project java-servicedirectory by googleapis.
the class Quickstart method quickstart.
public static void quickstart(String projectId, String locationId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (RegistrationServiceClient client = RegistrationServiceClient.create()) {
// The project and location that hold the namespace to list.
LocationName parent = LocationName.of(projectId, locationId);
// Call the API.
ListNamespacesPagedResponse response = client.listNamespaces(parent);
// Iterate over each namespace and print its name.
System.out.println("Namespaces:");
for (Namespace namespace : response.iterateAll()) {
System.out.println(namespace.getName());
}
}
}
use of com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse in project java-servicedirectory by googleapis.
the class RegistrationServiceClientTest method listNamespacesTest2.
@Test
public void listNamespacesTest2() throws Exception {
Namespace responsesElement = Namespace.newBuilder().build();
ListNamespacesResponse expectedResponse = ListNamespacesResponse.newBuilder().setNextPageToken("").addAllNamespaces(Arrays.asList(responsesElement)).build();
mockRegistrationService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListNamespacesPagedResponse pagedListResponse = client.listNamespaces(parent);
List<Namespace> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getNamespacesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockRegistrationService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListNamespacesRequest actualRequest = ((ListNamespacesRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse in project java-servicedirectory by googleapis.
the class NamespacesTests method tearDown.
@After
public void tearDown() throws Exception {
System.setOut(null);
bout.reset();
// Deletes any namespaces created during these tests.
try (RegistrationServiceClient client = RegistrationServiceClient.create()) {
// List the namespaces.
String locationPath = LocationName.format(PROJECT_ID, LOCATION_ID);
ListNamespacesPagedResponse response = client.listNamespaces(locationPath);
// Delete each namespace.
for (Namespace ns : response.iterateAll()) {
client.deleteNamespace(ns.getName());
}
}
}
Aggregations