use of org.openkilda.northbound.dto.v1.switches.RulesValidationResult in project open-kilda by telstra.
the class JsonSerializationTest method rulesValidationResultTest.
@Test
public void rulesValidationResultTest() throws IOException {
RulesValidationResult dto = new RulesValidationResult(singletonList(0L), singletonList(1L), singletonList(2L));
assertEquals(dto, pass(dto, RulesValidationResult.class));
}
use of org.openkilda.northbound.dto.v1.switches.RulesValidationResult in project open-kilda by telstra.
the class StubServiceFactory method getNorthboundStub.
/**
* Get a stub for {@link NorthboundService}. The instance is tied to the factory state.
*/
public NorthboundService getNorthboundStub() {
NorthboundService serviceMock = mock(NorthboundService.class);
when(serviceMock.getActiveSwitches()).thenAnswer(invocation -> topologyDefinition.getActiveSwitches().stream().map(sw -> new SwitchDto(sw.getDpId(), "", 0, "", "", SwitchChangeType.ACTIVATED, false, "", "", "", "", "", "", new SwitchLocationDto(0.0, 0.0, "", "", ""))).collect(toList()));
when(serviceMock.getActiveLinks()).thenAnswer(invocation -> topologyDefinition.getIslsForActiveSwitches().stream().flatMap(link -> Stream.of(IslInfoData.builder().latency(0).source(new PathNode(link.getSrcSwitch().getDpId(), link.getSrcPort(), 0)).destination(new PathNode(link.getDstSwitch().getDpId(), link.getDstPort(), 1)).speed(link.getMaxBandwidth()).state(IslChangeType.DISCOVERED).availableBandwidth(0).build(), IslInfoData.builder().latency(0).source(new PathNode(link.getDstSwitch().getDpId(), link.getDstPort(), 0)).destination(new PathNode(link.getSrcSwitch().getDpId(), link.getSrcPort(), 1)).speed(link.getMaxBandwidth()).state(IslChangeType.DISCOVERED).availableBandwidth(0).build())).collect(toList()));
when(serviceMock.getAllFlows()).thenReturn(new ArrayList<>(flowPayloads.values()));
when(serviceMock.getFlow(any())).thenAnswer(invocation -> {
String flowId = (String) invocation.getArguments()[0];
return flowPayloads.containsKey(flowId) ? SerializationUtils.clone(flowPayloads.get(flowId)) : null;
});
when(serviceMock.getFlowStatus(any())).thenAnswer(invocation -> {
String flowId = (String) invocation.getArguments()[0];
return flows.containsKey(flowId) ? new FlowIdStatusPayload(flowId, FlowState.UP) : null;
});
when(serviceMock.addFlow(any())).thenAnswer(invocation -> {
FlowPayload result = SerializationUtils.clone(((FlowPayload) invocation.getArguments()[0]));
result.setLastUpdated(LocalTime.now().toString());
result.setStatus(FlowState.IN_PROGRESS.toString());
putFlow(result.getId(), result);
return result;
});
when(serviceMock.updateFlow(any(), any())).thenAnswer(invocation -> {
String flowId = (String) invocation.getArguments()[0];
FlowPayload result = SerializationUtils.clone(((FlowPayload) invocation.getArguments()[1]));
result.setLastUpdated(LocalTime.now().toString());
putFlow(flowId, result);
return result;
});
when(serviceMock.deleteFlow(any())).thenAnswer(invocation -> {
String flowId = (String) invocation.getArguments()[0];
flows.remove(flowId);
return flowPayloads.remove(flowId);
});
when(serviceMock.synchronizeSwitchRules(any())).thenReturn(new RulesSyncResult(emptyList(), emptyList(), emptyList(), emptyList()));
when(serviceMock.validateSwitchRules(any())).thenReturn(new RulesValidationResult(emptyList(), emptyList(), emptyList()));
return serviceMock;
}
use of org.openkilda.northbound.dto.v1.switches.RulesValidationResult in project open-kilda by telstra.
the class TopologyVerificationSteps method validateSwitchRules.
@And("^all active switches have correct rules installed per Northbound validation")
public void validateSwitchRules() {
actualSwitches.forEach(sw -> {
SwitchId switchId = sw.getSwitchId();
RulesValidationResult validationResult = northboundService.validateSwitchRules(switchId);
assertTrue(format("The switch '%s' is missing rules: %s", switchId, validationResult.getMissingRules()), validationResult.getMissingRules().isEmpty());
assertTrue(format("The switch '%s' has excess rules: %s", switchId, validationResult.getExcessRules()), validationResult.getExcessRules().isEmpty());
});
}
Aggregations