use of org.openkilda.testing.service.floodlight.model.MeterBand in project open-kilda by telstra.
the class StubServiceFactory method getFloodlightStub.
/**
* Get a stub for {@link FloodlightService}. The instance is tied to the factory state.
*/
public FloodlightService getFloodlightStub() {
FloodlightService serviceMock = mock(FloodlightService.class);
when(serviceMock.getFlows(any())).thenAnswer(invocation -> {
SwitchId switchId = (SwitchId) invocation.getArguments()[0];
String switchVersion = topologyDefinition.getActiveSwitches().stream().filter(sw -> sw.getDpId().equals(switchId)).map(Switch::getOfVersion).findAny().orElse("OF_13");
return buildFlowEntries(switchId, switchVersion);
});
when(serviceMock.getMeters(any())).then((Answer<MetersEntriesMap>) invocation -> {
SwitchId switchId = (SwitchId) invocation.getArguments()[0];
MetersEntriesMap result = new MetersEntriesMap();
flows.values().forEach(flowPair -> {
if (flowPair.getLeft().getSourceSwitch().equals(switchId) || flowPair.getRight().getSourceSwitch().equals(switchId)) {
MeterEntry entry = new MeterEntry(emptyList(), flowPair.getLeft().getMeterId(), singletonList(new MeterBand(flowPair.getLeft().getBandwidth(), 0, "", 1)), "");
result.put(entry.getMeterId(), entry);
}
});
return result;
});
when(serviceMock.getSwitches()).then((Answer<List<SwitchEntry>>) invocation -> topologyDefinition.getActiveSwitches().stream().map(sw -> SwitchEntry.builder().switchId(sw.getDpId()).ofVersion(sw.getOfVersion()).build()).collect(toList()));
return serviceMock;
}
Aggregations