public static List<String> toStringList(List<InstanceName> values) { List<String> list = new ArrayList<String>(values.size()); for (InstanceName value : values) { if (value == null) { list.add(""); } else { list.add(value.toString()); } } return list; }
public static InstanceName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "InstanceName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("instance")); }
public static List<InstanceName> parseList(List<String> formattedStrings) { List<InstanceName> list = new ArrayList<>(formattedStrings.size()); for (String formattedString : formattedStrings) { list.add(parse(formattedString)); } return list; }
public static String format(String project, String instance) { return newBuilder().setProject(project).setInstance(instance).build().toString(); }
@Test @SuppressWarnings("all") public void getInstanceTest() { InstanceName name2 = InstanceName.of("[PROJECT]", "[INSTANCE]"); InstanceConfigName config = InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]"); String displayName = "displayName1615086568"; int nodeCount = 1539922066; Instance expectedResponse = Instance.newBuilder() .setName(name2.toString()) .setConfig(config.toString()) .setDisplayName(displayName) .setNodeCount(nodeCount) .build(); mockInstanceAdmin.addResponse(expectedResponse); InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); Instance actualResponse = client.getInstance(name); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockInstanceAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetInstanceRequest actualRequest = (GetInstanceRequest) actualRequests.get(0); Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void updateInstanceTest() throws Exception { InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); InstanceConfigName config = InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]"); String displayName = "displayName1615086568"; Instance expectedResponse = Instance.newBuilder() .setName(name.toString()) .setConfig(config.toString()) .setDisplayName(displayName)
@Test @SuppressWarnings("all") public void deleteInstanceTest() { Empty expectedResponse = Empty.newBuilder().build(); mockInstanceAdmin.addResponse(expectedResponse); InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); client.deleteInstance(name); List<GeneratedMessageV3> actualRequests = mockInstanceAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteInstanceRequest actualRequest = (DeleteInstanceRequest) actualRequests.get(0); Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void testIamPermissionsExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockInstanceAdmin.addException(exception); try { String formattedResource = InstanceName.format("[PROJECT]", "[INSTANCE]"); List<String> permissions = new ArrayList<>(); client.testIamPermissions(formattedResource, permissions); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } } }
public static InstanceName of(String project, String instance) { return newBuilder().setProject(project).setInstance(instance).build(); }
public InstanceName build() { return new InstanceName(this); } }
public String getFieldValue(String fieldName) { return getFieldValuesMap().get(fieldName); }
@Test @SuppressWarnings("all") public void createInstanceTest() throws Exception { InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); InstanceConfigName config = InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]"); String displayName = "displayName1615086568"; Instance expectedResponse = Instance.newBuilder() .setName(name.toString()) .setConfig(config.toString()) .setDisplayName(displayName) InstanceName instanceId = InstanceName.of("[PROJECT]", "[INSTANCE]"); Instance instance = Instance.newBuilder().build(); Assert.assertEquals(instanceId, InstanceName.parse(actualRequest.getInstanceId())); Assert.assertEquals(instance, actualRequest.getInstance()); Assert.assertTrue(
public static String format(String project, String instance) { return newBuilder().setProject(project).setInstance(instance).build().toString(); }
@Test @SuppressWarnings("all") public void getIamPolicyExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockInstanceAdmin.addException(exception); try { String formattedResource = InstanceName.format("[PROJECT]", "[INSTANCE]"); client.getIamPolicy(formattedResource); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
public static InstanceName of(String project, String instance) { return newBuilder().setProject(project).setInstance(instance).build(); }
public InstanceName build() { return new InstanceName(this); } }
public String getFieldValue(String fieldName) { return getFieldValuesMap().get(fieldName); }
/** * Gets information about a particular instance. * * <p>Sample code: * * <pre><code> * try (InstanceAdminClient instanceAdminClient = InstanceAdminClient.create()) { * InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); * Instance response = instanceAdminClient.getInstance(name); * } * </code></pre> * * @param name Required. The name of the requested instance. Values are of the form * `projects/<project>/instances/<instance>`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Instance getInstance(InstanceName name) { GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return getInstance(request); }
@Test @SuppressWarnings("all") public void getInstanceExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockInstanceAdmin.addException(exception); try { InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); client.getInstance(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
public static List<InstanceName> parseList(List<String> formattedStrings) { List<InstanceName> list = new ArrayList<>(formattedStrings.size()); for (String formattedString : formattedStrings) { list.add(parse(formattedString)); } return list; }