Search in sources :

Example 1 with ListNamespacesPagedResponse

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListNamespacesPagedResponse(com.google.cloud.servicedirectory.v1beta1.RegistrationServiceClient.ListNamespacesPagedResponse) Test(org.junit.Test)

Example 2 with ListNamespacesPagedResponse

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) ListNamespacesPagedResponse(com.google.cloud.servicedirectory.v1beta1.RegistrationServiceClient.ListNamespacesPagedResponse) Test(org.junit.Test)

Example 3 with ListNamespacesPagedResponse

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());
        }
    }
}
Also used : Namespace(com.google.cloud.servicedirectory.v1.Namespace) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient) LocationName(com.google.cloud.servicedirectory.v1.LocationName) ListNamespacesPagedResponse(com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse)

Example 4 with ListNamespacesPagedResponse

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) ListNamespacesPagedResponse(com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse) Test(org.junit.Test)

Example 5 with ListNamespacesPagedResponse

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());
        }
    }
}
Also used : Namespace(com.google.cloud.servicedirectory.v1.Namespace) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient) ListNamespacesPagedResponse(com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse) After(org.junit.After)

Aggregations

ListNamespacesPagedResponse (com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse)6 Namespace (com.google.cloud.servicedirectory.v1.Namespace)4 RegistrationServiceClient (com.google.cloud.servicedirectory.v1.RegistrationServiceClient)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 Test (org.junit.Test)4 After (org.junit.After)3 ListNamespacesPagedResponse (com.google.cloud.servicedirectory.v1beta1.RegistrationServiceClient.ListNamespacesPagedResponse)2 ByteString (com.google.protobuf.ByteString)2 LocationName (com.google.cloud.servicedirectory.v1.LocationName)1