@Test public void testGivenAzWithCompulsoryTags() { List<Tag> tags = new ArrayList<>(); Tag tag = new Tag(); tag.setKey("testkey"); tag.setValue("testvalue"); tags.add(tag); List<Tag> ignoreTags = new ArrayList<>(); tag = new Tag(); tag.setKey("ignorekey"); tag.setValue("ignorevalue"); ignoreTags.add(tag); PowerMockito.when(ec2Raider.getEc2InstanceIdsWithCompulsoryTagsForAvailabilityZone("us-west-2a", ignoreTags, tags)).thenReturn(emptyList()); PowerMockito.when(ec2Raider.getEc2InstanceIdsWithCompulsoryTagsForAvailabilityZone("us-west-2b", ignoreTags, tags)).thenReturn(createSpecificInstance1()); availabilityZoneStepDefinitions.givenAzWithCompulsoryTags("us-west-2a, us-west-2b", "testkey:testvalue", "ignorekey:ignorevalue"); Assert.assertEquals(1, executionStateCache.getInstances().size()); }
@Given("^AZs \"([^\"]*)\" instance only with tags \"([^\"]*)\" ignore instances with tags \"([^\"]*)\"$") public void givenAzWithCompulsoryTags(String azs, String compulsoryTagsString, String ignoreTagsString) { String[] availabilityZones = azs.split(",\\s*"); List<Tag> compulsoryTags = CucumberHelperFunctions.tagStringToList(compulsoryTagsString); List<Tag> ignoreTags = CucumberHelperFunctions.tagStringToList(ignoreTagsString); List<EC2InstanceTO> instances = new ArrayList<>(); for (String availabilityZone : availabilityZones) { instances.addAll(ec2Raider.getEc2InstanceIdsWithCompulsoryTagsForAvailabilityZone(availabilityZone, ignoreTags, compulsoryTags)); } if (instances.isEmpty()) { throw new RuntimeException("No instances available"); } executionStateCache.setInstances(instances); }
AvailabilityZoneStepDefinitions { @Given("^AZs \"([^\"]*)\" instance only with tags \"([^\"]*)\" ignore instances with tags \"([^\"]*)\"$") public void givenAzWithCompulsoryTags(String azs, String compulsoryTagsString, String ignoreTagsString) { String[] availabilityZones = azs.split(",\\s*"); List<Tag> compulsoryTags = CucumberHelperFunctions.tagStringToList(compulsoryTagsString); List<Tag> ignoreTags = CucumberHelperFunctions.tagStringToList(ignoreTagsString); List<EC2InstanceTO> instances = new ArrayList<>(); for (String availabilityZone : availabilityZones) { instances.addAll(ec2Raider.getEc2InstanceIdsWithCompulsoryTagsForAvailabilityZone(availabilityZone, ignoreTags, compulsoryTags)); } if (instances.isEmpty()) { throw new RuntimeException("No instances available"); } executionStateCache.setInstances(instances); } }
AvailabilityZoneStepDefinitions { @Given("^AZs \"([^\"]*)\" instance only with tags \"([^\"]*)\" ignore instances with tags \"([^\"]*)\"$") public void givenAzWithCompulsoryTags(String azs, String compulsoryTagsString, String ignoreTagsString) { String[] availabilityZones = azs.split(",\\s*"); List<Tag> compulsoryTags = CucumberHelperFunctions.tagStringToList(compulsoryTagsString); List<Tag> ignoreTags = CucumberHelperFunctions.tagStringToList(ignoreTagsString); List<EC2InstanceTO> instances = new ArrayList<>(); for (String availabilityZone : availabilityZones) { instances.addAll(ec2Raider.getEc2InstanceIdsWithCompulsoryTagsForAvailabilityZone(availabilityZone, ignoreTags, compulsoryTags)); } if (instances.isEmpty()) { throw new RuntimeException("No instances available"); } executionStateCache.setInstances(instances); } AvailabilityZoneStepDefinitions(); }
AvailabilityZoneStepDefinitions { @Given("^AZs \"([^\"]*)\" instance only with tags \"([^\"]*)\" ignore instances with tags \"([^\"]*)\"$") public void givenAzWithCompulsoryTags(String azs, String compulsoryTagsString, String ignoreTagsString) { String[] availabilityZones = azs.split(",\\s*"); List<Tag> compulsoryTags = CucumberHelperFunctions.tagStringToList(compulsoryTagsString); List<Tag> ignoreTags = CucumberHelperFunctions.tagStringToList(ignoreTagsString); List<EC2InstanceTO> instances = new ArrayList<>(); for (String availabilityZone : availabilityZones) { instances.addAll(ec2Raider.getEc2InstanceIdsWithCompulsoryTagsForAvailabilityZone(availabilityZone, ignoreTags, compulsoryTags)); } if (instances.isEmpty()) { throw new RuntimeException("No instances available"); } executionStateCache.setInstances(instances); } 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); }
AvailabilityZoneStepDefinitions { @Given("^AZs \"([^\"]*)\" instance only with tags \"([^\"]*)\" ignore instances with tags \"([^\"]*)\"$") public void givenAzWithCompulsoryTags(String azs, String compulsoryTagsString, String ignoreTagsString) { String[] availabilityZones = azs.split(",\\s*"); List<Tag> compulsoryTags = CucumberHelperFunctions.tagStringToList(compulsoryTagsString); List<Tag> ignoreTags = CucumberHelperFunctions.tagStringToList(ignoreTagsString); List<EC2InstanceTO> instances = new ArrayList<>(); for (String availabilityZone : availabilityZones) { instances.addAll(ec2Raider.getEc2InstanceIdsWithCompulsoryTagsForAvailabilityZone(availabilityZone, ignoreTags, compulsoryTags)); } if (instances.isEmpty()) { throw new RuntimeException("No instances available"); } executionStateCache.setInstances(instances); } 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);  }