/** * Lists device registries. * * <p>Sample code: * * <pre><code> * try (DeviceManagerClient deviceManagerClient = DeviceManagerClient.create()) { * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); * for (DeviceRegistry element : deviceManagerClient.listDeviceRegistries(parent.toString()).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param parent The project and cloud region path. For example, * `projects/example-project/locations/us-central1`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListDeviceRegistriesPagedResponse listDeviceRegistries(String parent) { ListDeviceRegistriesRequest request = ListDeviceRegistriesRequest.newBuilder().setParent(parent).build(); return listDeviceRegistries(request); }
public static void executeNoCatch(String projectId) throws Exception { try (DeviceManagerClient client = DeviceManagerClient.create()) { LocationName parent = LocationName.of(projectId, "us-central1"); ListDeviceRegistriesPagedResponse pagedResponse = client.listDeviceRegistries(parent); } }
/** * Lists device registries. * * <p>Sample code: * * <pre><code> * try (DeviceManagerClient deviceManagerClient = DeviceManagerClient.create()) { * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); * for (DeviceRegistry element : deviceManagerClient.listDeviceRegistries(parent).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param parent The project and cloud region path. For example, * `projects/example-project/locations/us-central1`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListDeviceRegistriesPagedResponse listDeviceRegistries(LocationName parent) { ListDeviceRegistriesRequest request = ListDeviceRegistriesRequest.newBuilder() .setParent(parent == null ? null : parent.toString()) .build(); return listDeviceRegistries(request); }
@Test @SuppressWarnings("all") public void listDeviceRegistriesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockDeviceManager.addException(exception); try { LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); client.listDeviceRegistries(parent); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void listDeviceRegistriesTest() { String nextPageToken = ""; DeviceRegistry deviceRegistriesElement = DeviceRegistry.newBuilder().build(); List<DeviceRegistry> deviceRegistries = Arrays.asList(deviceRegistriesElement); ListDeviceRegistriesResponse expectedResponse = ListDeviceRegistriesResponse.newBuilder() .setNextPageToken(nextPageToken) .addAllDeviceRegistries(deviceRegistries) .build(); mockDeviceManager.addResponse(expectedResponse); LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); ListDeviceRegistriesPagedResponse pagedListResponse = client.listDeviceRegistries(parent); List<DeviceRegistry> resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getDeviceRegistriesList().get(0), resources.get(0)); List<GeneratedMessageV3> actualRequests = mockDeviceManager.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListDeviceRegistriesRequest actualRequest = (ListDeviceRegistriesRequest) actualRequests.get(0); Assert.assertEquals(parent, LocationName.parse(actualRequest.getParent())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }