Open Kilda Java Documentation
FlowReinstallTest.java
Go to the documentation of this file.
1 package org.openkilda.atdd;
2 
3 import static org.awaitility.Awaitility.await;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertTrue;
7 
14 
15 import cucumber.api.java.en.Then;
16 import cucumber.api.java.en.When;
17 import org.apache.commons.lang.StringUtils;
18 import org.awaitility.Duration;
19 
20 import java.util.List;
21 import java.util.concurrent.TimeUnit;
22 
23 public class FlowReinstallTest {
24 
25  @When("^switch (.*) is turned off$")
26  public void turnOffSwitch(String switchName) throws InterruptedException {
27  TimeUnit.SECONDS.sleep(1);
28  assertTrue("Switch should be turned off", SwitchesUtils.knockoutSwitch(switchName));
29  }
30 
31  @When("^switch (.*) is turned on")
32  public void turnOnSwitch(String switchName) throws InterruptedException {
33  TimeUnit.SECONDS.sleep(1);
34  assertTrue("Switch should be turned on", SwitchesUtils.reviveSwitch(switchName));
35  }
36 
37  @Then("^flow (.*) is(.*) built through (.*) switch")
38  public void flowPathContainsSwitch(final String flow, final String shouldNotContain, final String switchIdString)
39  throws InterruptedException {
40  await().atMost(20, TimeUnit.SECONDS)
41  .pollInterval(Duration.ONE_SECOND)
42  .until(() -> {
44  assertTrue("Flow path should exist", payload != null && payload.getForwardPath() != null);
45  List<PathNodePayload> path = payload.getForwardPath();
46  SwitchId switchId = new SwitchId(switchIdString);
47  boolean contains = path.stream()
48  .anyMatch(node -> switchId.equals(node.getSwitchId()));
49 
50  if (StringUtils.isBlank(shouldNotContain)) {
51  return contains;
52  } else {
53  return !contains;
54  }
55  });
56  }
57 
58  @When("flow reroute feature is (on|off)$")
59  public void flowRerouteFeatureStatus(final String statusString) {
60  boolean status = statusString.equals("on");
61 
62  FeatureTogglePayload desired = new FeatureTogglePayload(null, status, null, null, null, null, null);
64 
65  assertNotNull(result);
66  assertEquals(status, result.getReflowOnSwitchActivationEnabled());
67  assertEquals(desired.getReflowOnSwitchActivationEnabled(), result.getReflowOnSwitchActivationEnabled());
68  }
69 }
void flowPathContainsSwitch(final String flow, final String shouldNotContain, final String switchIdString)
static boolean reviveSwitch(String switchName)
def status()
Definition: rest.py:593
static FlowPathPayload getFlowPath(final String flowId)
Definition: FlowUtils.java:275
list result
Definition: plan-d.py:72
static FeatureTogglePayload updateFeaturesStatus(FeatureTogglePayload desired)
Definition: FlowUtils.java:621
void flowRerouteFeatureStatus(final String statusString)
static String getFlowName(final String flowId)
Definition: FlowUtils.java:595
static boolean knockoutSwitch(String switchName)