EC2Context { public Map<String, String> getInstanceTags() { Map<String, String> map = new HashMap<>(); Instance instance = this.getInstance(); for (Tag tag : instance.getTags()) { map.put(tag.getKey(), tag.getValue()); } return map; }  String getInstanceId(); Map<String, String> getInstanceTags(); String getAutoScalingGroup(); List<String> getAutoScalingMembers(String autoScalingGroupName); List<String> getPrivateAutoScalingMemberIPs(String autoScalingGroupName); AutoScalingGroup getAutoScalingGroup(String autoScalingGroupName); Map<String, String> getAutoScalingGroupTags(String autoScalingGroupName); Instance getInstance();  }
@Test public void getHostTags() { String tagName = "foo"; String tagValue = "bar"; DescribeInstancesResult res = new DescribeInstancesResult(); Instance instance = new Instance().withInstanceId(this.instanceId).withTags(new Tag(tagName, tagValue)); res.withReservations(new Reservation().withInstances(instance)); Mockito.when(this.ec2Mock.describeInstances(Mockito.any(DescribeInstancesRequest.class))).thenReturn(res); Map<String, String> tags = this.context.getInstanceTags(); Assert.assertEquals(1, tags.size()); Assert.assertTrue(tags.containsKey(tagName)); Assert.assertEquals(tagValue, tags.get(tagName)); }
@Test(expected = IllegalStateException.class) public void testInvalidResponsesWithMultipleReservations() { DescribeInstancesResult res = new DescribeInstancesResult(); Instance instance = new Instance().withInstanceId(this.instanceId); res.withReservations(new Reservation().withInstances(instance), new Reservation().withInstances(instance)); Mockito.when(this.ec2Mock.describeInstances(Mockito.any(DescribeInstancesRequest.class))).thenReturn(res); this.context.getInstanceTags(); }
@Test(expected = IllegalStateException.class) public void testInvalidResponsesWithMissingReservations() { DescribeInstancesResult res = new DescribeInstancesResult(); Mockito.when(this.ec2Mock.describeInstances(Mockito.any(DescribeInstancesRequest.class))).thenReturn(res); this.context.getInstanceTags(); }
@Test(expected = IllegalStateException.class) public void testInvalidResponsesWithMultipleInstances() { DescribeInstancesResult res = new DescribeInstancesResult(); Instance instance = new Instance().withInstanceId("instanceId"); Instance instance2 = new Instance().withInstanceId("instanceId2"); res.withReservations(new Reservation().withInstances(instance, instance2)); Mockito.when(this.ec2Mock.describeInstances(Mockito.any(DescribeInstancesRequest.class))).thenReturn(res); this.context.getInstanceTags(); }
@Test(expected = IllegalStateException.class) public void testInvalidResponsesWithMissingInstances() { DescribeInstancesResult res = new DescribeInstancesResult(); res.withReservations(new Reservation().withInstances()); Mockito.when(this.ec2Mock.describeInstances(Mockito.any(DescribeInstancesRequest.class))).thenReturn(res); this.context.getInstanceTags(); }