16 package org.openkilda.atdd.staging.steps;
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;
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;
37 import java.util.Collections;
38 import java.util.List;
39 import java.util.Optional;
55 private List<LinkPropsDto> getLinkPropsResponse;
58 @When(
"^create link properties request for ISL '(.*)'$")
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());
68 @When(
"^update request: add link property '(.*)' with value '(.*)'$")
73 @When(
"^send update link properties request$")
75 changePropsResponse = northboundService.
updateLinkProps(singletonList(linkPropsRequest));
78 @Then(
"^response has (\\d+) failures? and (\\d+) success(?:es)?$")
80 assertEquals(changePropsResponse.getFailures(), failures);
81 assertEquals(changePropsResponse.getSuccesses(), successes);
84 @When(
"^get all properties$")
86 getLinkPropsResponse = northboundService.
getLinkProps(null, null, null, null);
89 @Then(
"^response has( no)? link properties from request$")
91 final boolean shouldHave = shouldHaveStr == null;
92 Optional<LinkPropsDto> wantedProps = getLinkPropsResponse.stream()
93 .filter(props -> props.equals(linkPropsRequest)).findFirst();
94 assertEquals(wantedProps.isPresent(), shouldHave);
97 @Then(
"^response link properties from request has property '(.*)' with value '(.*)'$")
100 .filter(
p ->
p.equals(linkPropsRequest)).findFirst().get();
104 @When(
"^send delete link properties request$")
106 changePropsResponse = northboundService.
deleteLinkProps(singletonList(linkPropsRequest));
109 @Then(
"^link props response has (\\d+) results?$")
111 assertEquals(resultsAmount, getLinkPropsResponse.size());
114 @When(
"^update request: change src_switch to '(.*)'$")
116 linkPropsRequest.setSrcSwitch(newSrcSwitch);
119 @And(
"^update request: change src_port to '(.*)'$")
121 linkPropsRequest.setSrcPort(Integer.valueOf(newSrcPort));
124 @When(
"^create empty link properties request$")
129 @And(
"^get link properties for defined request$")
132 new SwitchId(linkPropsRequest.getSrcSwitch()), linkPropsRequest.getSrcPort(),
133 new SwitchId(linkPropsRequest.getDstSwitch()), linkPropsRequest.getDstPort());
136 @And(
"^delete all link properties$")
142 @When(
"^set (.*) of '(.*)' ISL to (\\d+)$")
143 public
void setCostOfIsl(String propName, String islAlias,
int newCost) {
145 linkPropsRequest.
setProperty(propName, String.valueOf(newCost));
146 changePropsResponse = northboundService.
updateLinkProps(Collections.singletonList(linkPropsRequest));
149 @Then(
"^property '(.*)' of (.*) ISL equals to '(.*)'$")
150 public
void verifyIslProp(String propName, String islAlias, String expectedValue) {
153 assertEquals(expectedValue, getLinkPropsResponse.get(0).getProperty(propName));
String getProperty(String key)
void verifyResponseLinkProperties(String key, String value)
void responseHasLinkPropertiesEntry(String shouldHaveStr)
void sendDeleteLinkPropertiesRequest()
void createLinkPropertiesRequest(String islAlias)
void updateRequestChangeSrc_portTo(String newSrcPort)
void updateRequestProperty(String key, String value)
List< LinkPropsDto > getAllLinkProps()
void getLinkPropertiesForDefinedRequest()
List< LinkPropsDto > getLinkProps(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort)
void verifyIslProp(String propName, String islAlias, String expectedValue)
void sendUpdateLinkPropertiesRequest()
void setCostOfIsl(String propName, String islAlias, int newCost)
void responseHasResults(int resultsAmount)
BatchResults updateLinkProps(List< LinkPropsDto > keys)
void setProperty(String key, String value)
void createEmptyLinkPropertiesRequest()
BatchResults deleteLinkProps(List< LinkPropsDto > keys)
void responseHasFailuresAndSuccess(int failures, int successes)
void updateRequestChangeSrcSwitch(String newSrcSwitch)
void deleteAllLinkProperties()