EC2Context { public String getAutoScalingGroup() { DescribeAutoScalingInstancesRequest req = new DescribeAutoScalingInstancesRequest(); req.setInstanceIds(Collections.singleton(this.getInstanceId())); DescribeAutoScalingInstancesResult result = this.autoScalingClient.describeAutoScalingInstances(req); if (result.getAutoScalingInstances().size() != 1) { throw new IllegalStateException("Found multiple auto scaling instances"); } return result.getAutoScalingInstances().get(0).getAutoScalingGroupName(); }  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 getServerGroupName() { AutoScalingInstanceDetails inst = new AutoScalingInstanceDetails().withAutoScalingGroupName("awsGroup"); DescribeAutoScalingInstancesResult res = new DescribeAutoScalingInstancesResult(); res.withAutoScalingInstances(inst); Mockito.when(this.asgMock.describeAutoScalingInstances(Mockito.any(DescribeAutoScalingInstancesRequest.class))).thenReturn(res); Assert.assertEquals("awsGroup", this.context.getAutoScalingGroup()); }
@Test(expected = IllegalStateException.class) public void getServerGroupNameWithInvalidResponseMultipleInstances() { AutoScalingInstanceDetails inst = new AutoScalingInstanceDetails().withAutoScalingGroupName("awsGroup"); AutoScalingInstanceDetails inst2 = new AutoScalingInstanceDetails().withAutoScalingGroupName("awsGroup"); DescribeAutoScalingInstancesResult res = new DescribeAutoScalingInstancesResult(); res.withAutoScalingInstances(inst, inst2); Mockito.when(this.asgMock.describeAutoScalingInstances(Mockito.any(DescribeAutoScalingInstancesRequest.class))).thenReturn(res); this.context.getAutoScalingGroup(); }
@Test(expected = IllegalStateException.class) public void getServerGroupNameWithInvalidResponseMissingInstance() throws Exception { DescribeAutoScalingInstancesResult res = new DescribeAutoScalingInstancesResult(); res.withAutoScalingInstances(); Mockito.when(this.asgMock.describeAutoScalingInstances(Mockito.any(DescribeAutoScalingInstancesRequest.class))).thenReturn(res); this.context.getAutoScalingGroup(); }