16 package org.openkilda.atdd.staging.steps;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertTrue;
29 import cucumber.api.java.en.And;
30 import cucumber.api.java.en.Given;
31 import cucumber.api.java.en.Then;
32 import cucumber.api.java.en.When;
33 import lombok.extern.slf4j.Slf4j;
34 import org.apache.commons.collections4.CollectionUtils;
35 import org.junit.Assume;
36 import org.springframework.beans.factory.annotation.Autowired;
38 import java.util.List;
52 private List<SwitchInfoData> allSwitchesResponse;
55 @When(
"^request all available switches from Northbound$")
57 allSwitchesResponse = northboundService.getAllSwitches();
60 @Then(
"response has at least (\\d+) switch(?:es)?")
62 assertTrue(allSwitchesResponse.size() >= expectedSwitchesAmount);
65 @Given(
"^select a switch and alias it as '(.*)'$")
67 List<Switch> switches = getUnaliasedSwitches();
68 Assume.assumeFalse(
"All switches are already aliased", CollectionUtils.isEmpty(switches));
69 Switch theSwitch = switches.get(0);
70 log.info(
"Selected switch with id: {}", theSwitch.getDpId());
71 topologyUnderTest.
addAlias(switchAlias, theSwitch);
74 @Given(
"^select a switch with Openflow version '(.*)' and alias it as '(.*)'$")
76 List<Switch> switches = getUnaliasedSwitches();
78 for (Switch s: switches) {
79 if (ofVersion.equalsIgnoreCase(s.getOfVersion())) {
80 log.info(
"Selected switch with id: {}", s.getDpId());
81 topologyUnderTest.
addAlias(switchAlias, s);
85 Assume.assumeTrue(
"No switches found with OpenFlow version " + ofVersion,
false);
88 @When(
"^request all switch rules for switch '(.*)'$")
91 ((Switch) topologyUnderTest.getAliasedObject(switchAlias)).getDpId());
94 @Then(
"^response switch_id matches id of '(.*)'$")
96 assertEquals(((Switch) topologyUnderTest.getAliasedObject(switchAlias)).getDpId(),
97 switchRulesResponse.getSwitchId());
100 @Then(
"^response has at least (\\d+) rules? installed$")
102 assertTrue(switchRulesResponse.getFlowEntries().size() >= rulesAmount);
105 @And(
"^select a switch with direct link to '(.*)' and alias it as '(.*)'$")
107 Switch nearSwitch = topologyUnderTest.getAliasedObject(nearSwitchAlias);
109 isl.getSrcSwitch().getDpId().equals(nearSwitch.getDpId())
110 || isl.getDstSwitch().getDpId().equals(nearSwitch.getDpId())).findAny().get();
111 Switch newSwitch = link.getSrcSwitch().getDpId().equals(nearSwitch.getDpId())
112 ? link.getDstSwitch() : link.getDstSwitch();
113 topologyUnderTest.
addAlias(newSwitchAlias, newSwitch);
116 private List<Switch> getUnaliasedSwitches() {
117 List<Switch> aliasedSwitches = topologyUnderTest.getAliasedObjects(Switch.class);
118 List<Switch> switches = (List<Switch>) CollectionUtils.subtract(
120 Assume.assumeTrue(
"No unaliased switches left, unable to proceed", !switches.isEmpty());
List< Switch > getActiveSwitches()
void responseSwitch_idMatchesIdOfSwitch(String switchAlias)
void selectARandomSwitch(String switchAlias)
void responseHasAtLeastRulesInstalled(int rulesAmount)
List< Isl > getIslsForActiveSwitches()
void requestAllSwitchRulesForSwitch(String switchAlias)
void addAlias(String alias, Object obj)
void selectARandomSwitchWithSpecificOfVersion(String ofVersion, String switchAlias)
void selectSwitchWithDirectLink(String nearSwitchAlias, String newSwitchAlias)
void verifySwitchesAmount(int expectedSwitchesAmount)
SwitchFlowEntries getSwitchRules(SwitchId switchId)