Search in sources :

Example 1 with SwitchDto

use of org.openkilda.northbound.dto.v1.switches.SwitchDto in project open-kilda by telstra.

the class SwitchMapperTest method testSwitchToSwitchDto.

@Test
public void testSwitchToSwitchDto() {
    Switch sw = getSwitch();
    SwitchDto switchDto = switchMapper.toSwitchDto(sw);
    assertEquals(sw.getSwitchId(), switchDto.getSwitchId());
    assertEquals("127.0.0.1", switchDto.getAddress());
    assertEquals(sw.getSocketAddress().getPort(), switchDto.getPort());
    assertEquals(sw.getHostname(), switchDto.getHostname());
    assertEquals(sw.getDescription(), switchDto.getDescription());
    assertEquals(switchMapper.convertStatus(sw.getStatus()), switchDto.getState());
    assertEquals(sw.isUnderMaintenance(), switchDto.isUnderMaintenance());
    assertEquals(sw.getOfVersion(), switchDto.getOfVersion());
    assertEquals(sw.getOfDescriptionManufacturer(), switchDto.getManufacturer());
    assertEquals(sw.getOfDescriptionHardware(), switchDto.getHardware());
    assertEquals(sw.getOfDescriptionSoftware(), switchDto.getSoftware());
    assertEquals(sw.getOfDescriptionSerialNumber(), switchDto.getSerialNumber());
    assertEquals(sw.getPop(), switchDto.getPop());
    assertEquals((Double) sw.getLatitude(), switchDto.getLocation().getLatitude());
    assertEquals((Double) sw.getLongitude(), switchDto.getLocation().getLongitude());
    assertEquals(sw.getStreet(), switchDto.getLocation().getStreet());
    assertEquals(sw.getCity(), switchDto.getLocation().getCity());
    assertEquals(sw.getCountry(), switchDto.getLocation().getCountry());
}
Also used : Switch(org.openkilda.model.Switch) SwitchDto(org.openkilda.northbound.dto.v1.switches.SwitchDto) Test(org.junit.Test)

Example 2 with SwitchDto

use of org.openkilda.northbound.dto.v1.switches.SwitchDto in project open-kilda by telstra.

the class JsonSerializationTest method switchDtoTest.

@Test
public void switchDtoTest() throws IOException {
    SwitchDto dto = new SwitchDto(new SwitchId(SWITCH_ID), "address-test", 37040, "host", "desc", SwitchChangeType.ACTIVATED, false, "of_version", "manufacturer", "hardware", "software", "serial_number", "pop", new SwitchLocationDto(48.860611, 2.337633, "street", "city", "country"));
    assertEquals(dto, pass(dto, SwitchDto.class));
}
Also used : SwitchDto(org.openkilda.northbound.dto.v1.switches.SwitchDto) SwitchId(org.openkilda.model.SwitchId) SwitchLocationDto(org.openkilda.northbound.dto.v1.switches.SwitchLocationDto) Test(org.junit.Test)

Example 3 with SwitchDto

use of org.openkilda.northbound.dto.v1.switches.SwitchDto 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;
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) RulesValidationResult(org.openkilda.northbound.dto.v1.switches.RulesValidationResult) SwitchDto(org.openkilda.northbound.dto.v1.switches.SwitchDto) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) NorthboundService(org.openkilda.testing.service.northbound.NorthboundService) SwitchLocationDto(org.openkilda.northbound.dto.v1.switches.SwitchLocationDto) PathNode(org.openkilda.messaging.info.event.PathNode) RulesSyncResult(org.openkilda.northbound.dto.v1.switches.RulesSyncResult)

Aggregations

SwitchDto (org.openkilda.northbound.dto.v1.switches.SwitchDto)3 Test (org.junit.Test)2 SwitchLocationDto (org.openkilda.northbound.dto.v1.switches.SwitchLocationDto)2 PathNode (org.openkilda.messaging.info.event.PathNode)1 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)1 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)1 Switch (org.openkilda.model.Switch)1 SwitchId (org.openkilda.model.SwitchId)1 RulesSyncResult (org.openkilda.northbound.dto.v1.switches.RulesSyncResult)1 RulesValidationResult (org.openkilda.northbound.dto.v1.switches.RulesValidationResult)1 NorthboundService (org.openkilda.testing.service.northbound.NorthboundService)1