Open Kilda Java Documentation
NorthboundSteps.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 com.nitorcreations.Matchers.reflectEquals;
19 import static org.hamcrest.MatcherAssert.assertThat;
20 import static org.junit.Assert.assertTrue;
21 
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.Map.Entry;
38 
39 @Slf4j
40 public class NorthboundSteps {
41 
42  private FeatureTogglePayload featureToggleRequest;
43 
44  @Autowired
45  private NorthboundService northboundService;
46 
47  @Autowired
48  private TopologyDefinition topologyDefinition;
49 
50  @Autowired
51  private TopologyUnderTest topologyUnderTest;
52 
53  private HealthCheck healthCheckResponse;
54  private FeatureTogglePayload featureTogglesResponse;
55  private DeleteMeterResult deleteMeterResponse;
56 
57  @When("^request Northbound health check$")
59  healthCheckResponse = northboundService.getHealthCheck();
60  }
61 
62  @Then("^all healthcheck components are (.*)")
63  public void allHealthcheckComponentsAreOperational(String componentStatus) {
64  assertTrue(healthCheckResponse.getComponents().values().stream().allMatch(c -> c.equals(componentStatus)));
65  }
66 
67  @When("^get all feature toggles$")
68  public void getAllFeatureToggles() {
69  featureTogglesResponse = northboundService.getFeatureToggles();
70  }
71 
72  @When("^create feature toggles request based on the response$")
74  featureToggleRequest = new FeatureTogglePayload(featureTogglesResponse);
75  }
76 
77  @When("^update request: switch each toggle to an opposite state$")
79  featureToggleRequest.setCreateFlowEnabled(!featureToggleRequest.getCreateFlowEnabled());
80  featureToggleRequest.setDeleteFlowEnabled(!featureToggleRequest.getDeleteFlowEnabled());
81  featureToggleRequest.setPushFlowEnabled(!featureToggleRequest.getPushFlowEnabled());
82  featureToggleRequest.setReflowOnSwitchActivationEnabled(
83  !featureToggleRequest.getReflowOnSwitchActivationEnabled());
84  featureToggleRequest.setSyncRulesEnabled(!featureToggleRequest.getSyncRulesEnabled());
85  featureToggleRequest.setUnpushFlowEnabled(!featureToggleRequest.getUnpushFlowEnabled());
86  featureToggleRequest.setUpdateFlowEnabled(!featureToggleRequest.getUpdateFlowEnabled());
87  }
88 
89  @When("^send update request to feature toggles$")
91  featureTogglesResponse = northboundService.toggleFeature(featureToggleRequest);
92  }
93 
94  @Then("^feature toggles response matches request$")
96  assertThat(featureToggleRequest, reflectEquals(featureTogglesResponse));
97  }
98 
99  @And("^remove '(.*)' from '(.*)'$")
100  public void removeMeter(String meterAlias, String switchAlias) {
101  Entry<Integer, MeterEntry> meter = topologyUnderTest.getAliasedObject(meterAlias);
102  Switch sw = topologyUnderTest.getAliasedObject(switchAlias);
103  deleteMeterResponse = northboundService.deleteMeter(sw.getDpId(), meter.getKey());
104  }
105 
106  @Then("^remove meter response is successful$")
108  assertTrue(deleteMeterResponse.isDeleted());
109  }
110 }
void removeMeter(String meterAlias, String switchAlias)
Definition: MeterEntry.java:26
FeatureTogglePayload toggleFeature(FeatureTogglePayload request)
void allHealthcheckComponentsAreOperational(String componentStatus)
DeleteMeterResult deleteMeter(SwitchId switchId, Integer meterId)