AvailabilityZoneStepDefinitions { @Given("^AZs \"([^\"]*)\" ignore instances with tags \"([^\"]*)\"$") public AvailabilityZoneStepDefinitions givenAzWithIgnoreTags(String azs, String instanceIgnoreTags) { String[] availabilityZones = azs.split(",\\s*"); List<Tag> tags = CucumberHelperFunctions.tagStringToList(instanceIgnoreTags); List<String> instanceIdsToIgnore = new ArrayList<>(ec2Raider.getInstancesFromAnyTags(tags).stream().map(EC2InstanceTO::getInstanceId).collect(Collectors.toList())); for (String availabilityZone : availabilityZones) { executionStateCache.addInstances(ec2Raider.getEc2InstancesForAvailabilityZone(availabilityZone, instanceIdsToIgnore)); } return this; } AvailabilityZoneStepDefinitions(); ExecutionStateCache getExecutionStateCache(); void setExecutionStateCache(ExecutionStateCache executionStateCache); @Given("^AZs \"([^\"]*)\" ignore instances with tags \"([^\"]*)\"$") AvailabilityZoneStepDefinitions givenAzWithIgnoreTags(String azs, String instanceIgnoreTags); @Given("^AZs \"([^\"]*)\" instance only with tags \"([^\"]*)\" ignore instances with tags \"([^\"]*)\"$") void givenAzWithCompulsoryTags(String azs, String compulsoryTagsString, String ignoreTagsString); @When("^terminate (\\d+) instance in AZ$") AvailabilityZoneStepDefinitions terminateInstanceOnNumInstances(int numInstances ); @When("^terminate (\\d+) instance in AZ only with tags \\\"([^\\\"]*)\\\"$") AvailabilityZoneStepDefinitions terminateInstanceOnNumInstancesWithTags(int numInstances, String compulsoryTagsString); @Then("^assertEC2 healthy host count in AZ$") void confirmHealthyHostCount(); boolean confirmHealthyHostCount(int expected);  }
@Test public void testGivenAzWithIgnoreTags() { executionStateCache.clearInstances(); PowerMockito.when(ec2Raider.getInstancesFromAnyTags(Mockito.anyList())).thenReturn(createInstances()); PowerMockito.when(ec2Raider.getEc2InstancesForAvailabilityZone(Mockito.anyString(), Mockito.anyList())).thenReturn(createInstances()); Assert.assertEquals(0, executionStateCache.getInstances().size()); availabilityZoneStepDefinitions.givenAzWithIgnoreTags("us-west-2a, us-west-2b", "testkey:testvalue"); Assert.assertTrue(executionStateCache.getInstances().size() > 0); }