@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)); }
static Tags fromPb(com.google.api.services.compute.model.Tags tagsPb) { Builder builder = newBuilder(tagsPb.getItems() != null ? tagsPb.getItems() : ImmutableList.<String>of()); return builder.setFingerprint(tagsPb.getFingerprint()).build(); } }
@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 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 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())); }
@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)); }
/** * Returns 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 Tags of(String... values) { return newBuilder(values).build(); }
/** * Returns 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 Tags of(Iterable<String> values) { return newBuilder(values).build(); }
@Test public void testToAndFromPb() { compareTags(TAGS, Tags.fromPb(TAGS.toPb())); Tags tags = Tags.newBuilder().add("tag1").add("tag2").setFingerprint("fingerprint").build(); compareTags(tags, Tags.fromPb(tags.toPb())); }
@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); }