public static LocationName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "LocationName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("location")); }
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); } }
@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 createDeviceRegistryExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockDeviceManager.addException(exception); try { LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); DeviceRegistry deviceRegistry = DeviceRegistry.newBuilder().build(); client.createDeviceRegistry(parent, deviceRegistry); 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())); }
@Test @SuppressWarnings("all") public void createDeviceRegistryTest() { String id = "id3355"; RegistryName name = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]"); DeviceRegistry expectedResponse = DeviceRegistry.newBuilder().setId(id).setName(name.toString()).build(); mockDeviceManager.addResponse(expectedResponse); LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); DeviceRegistry deviceRegistry = DeviceRegistry.newBuilder().build(); DeviceRegistry actualResponse = client.createDeviceRegistry(parent, deviceRegistry); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockDeviceManager.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateDeviceRegistryRequest actualRequest = (CreateDeviceRegistryRequest) actualRequests.get(0); Assert.assertEquals(parent, LocationName.parse(actualRequest.getParent())); Assert.assertEquals(deviceRegistry, actualRequest.getDeviceRegistry()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
public static LocationName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "LocationName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("location")); }