Permalink
Browse files

Added tag test in TestInventorySystem

  • Loading branch information...
1 parent 223f201 commit 8359d78a589699b6266437bc83fc7f8f813e13c1 @wyan0220 wyan0220 committed Jan 4, 2012
@@ -40,6 +40,7 @@
import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
@@ -179,7 +180,8 @@ private Instance retrieveInstanceByServerId(String serverId)
Flavor flavor = flavorCache.getUnchecked(String.valueOf(populatedServer.getFlavor().getId()));
ServerStatus status = populatedServer.getStatus();
- Instance instance = new Instance(populatedServer.getUuid(), populatedServer.getName(), flavor.getName(), status.name(), inventorySystem.getFqdn(), inventorySystem.getTags());
+ Instance instance = new Instance(populatedServer.getUuid(), populatedServer.getName(), flavor.getName(),
+ status.name(), inventorySystem.getFqdn(), Arrays.asList(inventorySystem.getTags().split(",")));
if(status == ServerStatus.ACTIVE) {
instanceCache.put(instance.getId(), instance);
@@ -106,20 +106,20 @@ public InventorySystem setRoles(Set<String> roles)
}
@JsonProperty("tags")
- public List<String> getTags()
+ public String getTags()
{
- return tags;
+ return tags == null ? "" : Joiner.on(",").join(tags);
}
-/* public InventorySystem setTags(List<String> tags)
+ public InventorySystem setTags(List<String> tags)
{
if (tags == null)
this.tags = Lists.newArrayList();
else
this.tags = tags;
return this;
- }*/
+ }
@JsonProperty("tags")
public InventorySystem setTagsFromSerializedString(String tags)
@@ -5,6 +5,8 @@
import org.testng.Assert;
import org.testng.annotations.Test;
+import java.util.Arrays;
+
import static com.proofpoint.testing.EquivalenceTester.equivalenceTester;
public class TestInventorySystem
@@ -17,16 +19,16 @@ public void testEquivalence()
equivalenceTester()
.addEquivalentGroup(
new InventorySystem("name1"),
- new InventorySystem("name1").setSerialNumber("serial1").setPicInstance("inst1").setRoles(ImmutableSet.of("111")),
- new InventorySystem("name1").setSerialNumber("serial2").setPicInstance("inst1").setRoles(ImmutableSet.of("111")),
- new InventorySystem("name1").setSerialNumber("serial1").setPicInstance("inst2").setRoles(ImmutableSet.of("111")),
- new InventorySystem("name1").setSerialNumber("serial1").setPicInstance("inst1").setRoles(ImmutableSet.of("222")))
+ new InventorySystem("name1").setSerialNumber("serial1").setPicInstance("inst1").setRoles(ImmutableSet.of("111")).setTags(Arrays.asList("tag1")),
+ new InventorySystem("name1").setSerialNumber("serial2").setPicInstance("inst1").setRoles(ImmutableSet.of("111")).setTags(Arrays.asList("tag2")),
+ new InventorySystem("name1").setSerialNumber("serial1").setPicInstance("inst2").setRoles(ImmutableSet.of("111")).setTags(Arrays.asList("tag1")),
+ new InventorySystem("name1").setSerialNumber("serial1").setPicInstance("inst1").setRoles(ImmutableSet.of("222")).setTags(Arrays.asList("tag2")))
.addEquivalentGroup(
new InventorySystem("name2"),
- new InventorySystem("name2").setSerialNumber("serial1").setPicInstance("inst1").setRoles(ImmutableSet.of("111")),
- new InventorySystem("name2").setSerialNumber("serial2").setPicInstance("inst1").setRoles(ImmutableSet.of("111")),
- new InventorySystem("name2").setSerialNumber("serial1").setPicInstance("inst2").setRoles(ImmutableSet.of("111")),
- new InventorySystem("name2").setSerialNumber("serial1").setPicInstance("inst1").setRoles(ImmutableSet.of("222")))
+ new InventorySystem("name2").setSerialNumber("serial1").setPicInstance("inst1").setRoles(ImmutableSet.of("111")).setTags(Arrays.asList("tag1")),
+ new InventorySystem("name2").setSerialNumber("serial2").setPicInstance("inst1").setRoles(ImmutableSet.of("111")).setTags(Arrays.asList("tag2")),
+ new InventorySystem("name2").setSerialNumber("serial1").setPicInstance("inst2").setRoles(ImmutableSet.of("111")).setTags(Arrays.asList("tag1")),
+ new InventorySystem("name2").setSerialNumber("serial1").setPicInstance("inst1").setRoles(ImmutableSet.of("222")).setTags(Arrays.asList("tag2")))
.check();
}
@@ -43,13 +45,15 @@ public void testJsonRoundTrip()
new InventorySystem("test")
.setSerialNumber("serial")
.setPicInstance("instance")
- .setRoles(ImmutableSet.of("role1", "role2"));
+ .setRoles(ImmutableSet.of("role1", "role2"))
+ .setTags(Arrays.asList("tag1", "tag2"));
String encoded = CODEC.toJson(original);
InventorySystem decoded = CODEC.fromJson(encoded);
Assert.assertEquals(decoded.getFqdn(), original.getFqdn());
- Assert.assertEquals(decoded.getPicInstance(), original.getPicInstance());
+ Assert.assertEquals(decoded.getPicInstance(), original.getPicInstance());
Assert.assertEquals(decoded.getRoles(), original.getRoles());
+ Assert.assertEquals(decoded.getTags(), original.getTags());
}
}

0 comments on commit 8359d78

Please sign in to comment.