Open Kilda Java Documentation
LinkPropertiesSteps.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.atdd.staging.steps;
17 
18 import static java.util.Collections.singletonList;
19 import static org.hamcrest.CoreMatchers.equalTo;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertThat;
22 
30 
31 import cucumber.api.java.en.And;
32 import cucumber.api.java.en.Then;
33 import cucumber.api.java.en.When;
34 import lombok.extern.slf4j.Slf4j;
35 import org.springframework.beans.factory.annotation.Autowired;
36 
37 import java.util.Collections;
38 import java.util.List;
39 import java.util.Optional;
40 
41 @Slf4j
42 public class LinkPropertiesSteps {
43 
44  @Autowired
45  private NorthboundService northboundService;
46 
47  @Autowired
48  private TopologyDefinition topologyDefinition;
49 
50  @Autowired
51  private TopologyUnderTest topologyUnderTest;
52 
53  private LinkPropsDto linkPropsRequest;
54  private BatchResults changePropsResponse;
55  private List<LinkPropsDto> getLinkPropsResponse;
56 
57 
58  @When("^create link properties request for ISL '(.*)'$")
59  public void createLinkPropertiesRequest(String islAlias) {
60  linkPropsRequest = new LinkPropsDto();
61  Isl theIsl = topologyUnderTest.getAliasedObject(islAlias);
62  linkPropsRequest.setSrcSwitch(theIsl.getSrcSwitch().getDpId().toString());
63  linkPropsRequest.setSrcPort(theIsl.getSrcPort());
64  linkPropsRequest.setDstSwitch(theIsl.getDstSwitch().getDpId().toString());
65  linkPropsRequest.setDstPort(theIsl.getDstPort());
66  }
67 
68  @When("^update request: add link property '(.*)' with value '(.*)'$")
69  public void updateRequestProperty(String key, String value) {
70  linkPropsRequest.setProperty(key, value);
71  }
72 
73  @When("^send update link properties request$")
75  changePropsResponse = northboundService.updateLinkProps(singletonList(linkPropsRequest));
76  }
77 
78  @Then("^response has (\\d+) failures? and (\\d+) success(?:es)?$")
79  public void responseHasFailuresAndSuccess(int failures, int successes) {
80  assertEquals(changePropsResponse.getFailures(), failures);
81  assertEquals(changePropsResponse.getSuccesses(), successes);
82  }
83 
84  @When("^get all properties$")
85  public void getAllProperties() {
86  getLinkPropsResponse = northboundService.getLinkProps(null, null, null, null);
87  }
88 
89  @Then("^response has( no)? link properties from request$")
90  public void responseHasLinkPropertiesEntry(String shouldHaveStr) {
91  final boolean shouldHave = shouldHaveStr == null;
92  Optional<LinkPropsDto> wantedProps = getLinkPropsResponse.stream()
93  .filter(props -> props.equals(linkPropsRequest)).findFirst();
94  assertEquals(wantedProps.isPresent(), shouldHave);
95  }
96 
97  @Then("^response link properties from request has property '(.*)' with value '(.*)'$")
98  public void verifyResponseLinkProperties(String key, String value) {
99  LinkPropsDto props = getLinkPropsResponse.stream()
100  .filter(p -> p.equals(linkPropsRequest)).findFirst().get();
101  assertThat(value, equalTo(String.valueOf(props.getProperty(key))));
102  }
103 
104  @When("^send delete link properties request$")
106  changePropsResponse = northboundService.deleteLinkProps(singletonList(linkPropsRequest));
107  }
108 
109  @Then("^link props response has (\\d+) results?$")
110  public void responseHasResults(int resultsAmount) {
111  assertEquals(resultsAmount, getLinkPropsResponse.size());
112  }
113 
114  @When("^update request: change src_switch to '(.*)'$")
115  public void updateRequestChangeSrcSwitch(String newSrcSwitch) {
116  linkPropsRequest.setSrcSwitch(newSrcSwitch);
117  }
118 
119  @And("^update request: change src_port to '(.*)'$")
120  public void updateRequestChangeSrc_portTo(String newSrcPort) {
121  linkPropsRequest.setSrcPort(Integer.valueOf(newSrcPort));
122  }
123 
124  @When("^create empty link properties request$")
126  linkPropsRequest = new LinkPropsDto();
127  }
128 
129  @And("^get link properties for defined request$")
131  getLinkPropsResponse = northboundService.getLinkProps(
132  new SwitchId(linkPropsRequest.getSrcSwitch()), linkPropsRequest.getSrcPort(),
133  new SwitchId(linkPropsRequest.getDstSwitch()), linkPropsRequest.getDstPort());
134  }
135 
136  @And("^delete all link properties$")
137  public void deleteAllLinkProperties() {
138  List<LinkPropsDto> linkProps = northboundService.getAllLinkProps();
139  changePropsResponse = northboundService.deleteLinkProps(linkProps);
140  }
141 
142  @When("^set (.*) of '(.*)' ISL to (\\d+)$")
143  public void setCostOfIsl(String propName, String islAlias, int newCost) {
144  createLinkPropertiesRequest(islAlias);
145  linkPropsRequest.setProperty(propName, String.valueOf(newCost));
146  changePropsResponse = northboundService.updateLinkProps(Collections.singletonList(linkPropsRequest));
147  }
148 
149  @Then("^property '(.*)' of (.*) ISL equals to '(.*)'$")
150  public void verifyIslProp(String propName, String islAlias, String expectedValue) {
151  createLinkPropertiesRequest(islAlias);
153  assertEquals(expectedValue, getLinkPropsResponse.get(0).getProperty(propName));
154  }
155 }
value
Definition: nodes.py:62
List< LinkPropsDto > getLinkProps(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort)
BatchResults updateLinkProps(List< LinkPropsDto > keys)
BatchResults deleteLinkProps(List< LinkPropsDto > keys)