@Test public void testSetTagsFromList_Null() throws Exception { initializeExpectedInstance(2); expect(compute.getOptions()).andReturn(mockOptions); List<String> tagList = ImmutableList.of("v1", "v2"); Tags tags = Tags.newBuilder().setValues(tagList).setFingerprint("fingerprint").build(); expect(compute.setTags(INSTANCE_ID, tags)).andReturn(null); replay(compute); initializeInstance(); assertNull(instance.setTags(tagList)); }
@Test public void testSetTags_Null() throws Exception { initializeExpectedInstance(2); expect(compute.getOptions()).andReturn(mockOptions); Tags tags = Tags.newBuilder().setValues("v1", "v2").setFingerprint("fingerprint").build(); expect(compute.setTags(INSTANCE_ID, tags)).andReturn(null); replay(compute); initializeInstance(); assertNull(instance.setTags(tags)); }
@Test public void testSetTagsFromList() throws Exception { initializeExpectedInstance(2); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(ZoneOperationId.of("project", "op")) .build(); List<String> tagList = ImmutableList.of("v1", "v2"); Tags tags = Tags.newBuilder().setValues(tagList).setFingerprint("fingerprint").build(); expect(compute.setTags(INSTANCE_ID, tags)).andReturn(operation); replay(compute); initializeInstance(); assertSame(operation, instance.setTags(tagList)); }
@Test public void testSetTagsFromListWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(ZoneOperationId.of("project", "op")) .build(); List<String> tagList = ImmutableList.of("v1", "v2"); Tags tags = Tags.newBuilder().setValues(tagList).setFingerprint("fingerprint").build(); expect(compute.setTags(INSTANCE_ID, tags, Compute.OperationOption.fields())) .andReturn(operation); replay(compute); initializeInstance(); assertSame(operation, instance.setTags(tagList, Compute.OperationOption.fields())); }
@Test public void testSetTags() throws Exception { initializeExpectedInstance(2); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(ZoneOperationId.of("project", "op")) .build(); Tags tags = Tags.newBuilder().setValues("v1", "v2").setFingerprint("fingerprint").build(); expect(compute.setTags(INSTANCE_ID, tags)).andReturn(operation); replay(compute); initializeInstance(); assertSame(operation, instance.setTags(tags)); }
@Test public void testSetTagsWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(ZoneOperationId.of("project", "op")) .build(); Tags tags = Tags.newBuilder().setValues("v1", "v2").setFingerprint("fingerprint").build(); expect(compute.setTags(INSTANCE_ID, tags, Compute.OperationOption.fields())) .andReturn(operation); replay(compute); initializeInstance(); assertSame(operation, instance.setTags(tags, Compute.OperationOption.fields())); }
/** * Returns a builder for a {@code Tags} object given the tags to apply to the instance. Each tag * within the list must comply with RFC1035. * * @see <a href="https://www.ietf.org/rfc/rfc1035.txt">RFC1035</a> */ public static Builder newBuilder(Iterable<String> values) { return new Builder().setValues(values); }
@Test public void testBuilder() { Tags tags = Tags.newBuilder().setValues(ImmutableList.of("tag1", "tag2")).build(); assertEquals(ImmutableList.of("tag1", "tag2"), tags.getValues()); assertNull(tags.getFingerprint()); tags = Tags.newBuilder().add("tag1").add("tag2").build(); assertEquals(ImmutableList.of("tag1", "tag2"), tags.getValues()); assertNull(tags.getFingerprint()); tags = Tags.newBuilder().add("tag1").add("tag2").setFingerprint("fingerprint").build(); assertEquals(ImmutableList.of("tag1", "tag2"), tags.getValues()); assertEquals("fingerprint", tags.getFingerprint()); }
/** * Sets the tags for this instance, fingerprint value is taken from this instance's {@code * tags().fingerprint()}. * * @return a zone operation if the set request was issued correctly, {@code null} if the instance * was not found * @throws ComputeException upon failure */ public Operation setTags(Iterable<String> tags, OperationOption... options) { return setTags(getTags().toBuilder().setValues(tags).build(), options); }
/** * Returns a builder for a {@code Tags} object given the tags to apply to the instance. Each tag * within the list must comply with RFC1035. * * @see <a href="https://www.ietf.org/rfc/rfc1035.txt">RFC1035</a> */ public static Builder newBuilder(String... values) { return new Builder().setValues(values); }