X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=olm%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Folm%2Fservice%2FOlmPowerServiceImplSpanLossBaseTest.java;h=765716c3dd655d19d177a53aec70036a426e66f8;hb=213a09651d6a2a0a32fd92e743e3606473edabd9;hp=7237f33f83a77112159bc8038547c7e715e21886;hpb=2e7347dac70ba667dcfc8b4d35bc45faf09a5d46;p=transportpce.git diff --git a/olm/src/test/java/org/opendaylight/transportpce/olm/service/OlmPowerServiceImplSpanLossBaseTest.java b/olm/src/test/java/org/opendaylight/transportpce/olm/service/OlmPowerServiceImplSpanLossBaseTest.java index 7237f33f8..765716c3d 100644 --- a/olm/src/test/java/org/opendaylight/transportpce/olm/service/OlmPowerServiceImplSpanLossBaseTest.java +++ b/olm/src/test/java/org/opendaylight/transportpce/olm/service/OlmPowerServiceImplSpanLossBaseTest.java @@ -8,14 +8,16 @@ package org.opendaylight.transportpce.olm.service; -import java.math.BigDecimal; -import java.util.Optional; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.transportpce.common.NetworkUtils; @@ -32,14 +34,16 @@ import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfa import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl; import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121; import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221; +import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710; import org.opendaylight.transportpce.olm.power.PowerMgmt; import org.opendaylight.transportpce.olm.power.PowerMgmtImpl; import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil; import org.opendaylight.transportpce.olm.util.OlmTransactionUtils; import org.opendaylight.transportpce.test.AbstractTest; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossBaseInput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossBaseOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.RatioDB; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OrgOpenroadmDeviceData; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceKey; @@ -55,10 +59,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.Decimal64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class OlmPowerServiceImplSpanLossBaseTest extends AbstractTest { private static final Logger LOG = LoggerFactory.getLogger(OlmPowerServiceImplSpanLossBaseTest.class); @@ -69,74 +73,76 @@ public class OlmPowerServiceImplSpanLossBaseTest extends AbstractTest { private MappingUtils mappingUtils; private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221; private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121; + private OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710; private OlmPowerService olmPowerService; private DataBroker dataBroker; - @Before - public void setUp() throws OpenRoadmInterfaceException { - this.openRoadmInterfacesImpl121 = Mockito.mock(OpenRoadmInterfacesImpl121.class); - this.openRoadmInterfacesImpl221 = Mockito.mock(OpenRoadmInterfacesImpl221.class); - this.mappingUtils = Mockito.mock(MappingUtilsImpl.class); - this.portMapping = Mockito.mock(PortMappingImpl.class); - this.deviceTransactionManager = Mockito.mock(DeviceTransactionManagerImpl.class); - this.powerMgmt = Mockito.mock(PowerMgmtImpl.class); + @BeforeEach + void setUp() throws OpenRoadmInterfaceException { + this.openRoadmInterfacesImpl121 = mock(OpenRoadmInterfacesImpl121.class); + this.openRoadmInterfacesImpl221 = mock(OpenRoadmInterfacesImpl221.class); + this.mappingUtils = mock(MappingUtilsImpl.class); + this.portMapping = mock(PortMappingImpl.class); + this.deviceTransactionManager = mock(DeviceTransactionManagerImpl.class); + this.powerMgmt = mock(PowerMgmtImpl.class); this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(this.deviceTransactionManager, this.mappingUtils, - this.openRoadmInterfacesImpl121, this.openRoadmInterfacesImpl221); - this.olmPowerService = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmt, + this.openRoadmInterfacesImpl121, this.openRoadmInterfacesImpl221, this.openRoadmInterfacesImpl710); + this.olmPowerService = new OlmPowerServiceImpl(getDataBroker(), this.powerMgmt, this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces); - this.dataBroker = this.getDataBroker(); - MockitoAnnotations.initMocks(this); - Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_2_2_1).when(this.mappingUtils) - .getOpenRoadmVersion(Mockito.anyString()); + this.dataBroker = getDataBroker(); + doReturn(StringConstants.OPENROADM_DEVICE_VERSION_2_2_1) + .when(this.mappingUtils).getOpenRoadmVersion(anyString()); - Mockito.when(this.portMapping.getMapping("ROADM-A1", "DEG2-TTP-TXRX")) - .thenReturn(OlmTransactionUtils.getMapping1()); - Mockito.when(this.portMapping.getMapping("ROADM-C1", "DEG1-TTP-TXRX")) - .thenReturn(OlmTransactionUtils.getMapping2()); + when(this.portMapping.getMapping("ROADM-A1", "DEG2-TTP-TXRX")).thenReturn(OlmTransactionUtils.getMapping1()); + when(this.portMapping.getMapping("ROADM-C1", "DEG1-TTP-TXRX")).thenReturn(OlmTransactionUtils.getMapping2()); InstanceIdentifier iidCurrentPmList = InstanceIdentifier.create(CurrentPmList.class); - Mockito.when(this.deviceTransactionManager.getDataFromDevice("ROADM-A1", LogicalDatastoreType.OPERATIONAL, - iidCurrentPmList, Timeouts.DEVICE_READ_TIMEOUT, - Timeouts.DEVICE_READ_TIMEOUT_UNIT)).thenReturn(OlmTransactionUtils.getCurrentPmListA()); - Mockito.when(this.deviceTransactionManager.getDataFromDevice("ROADM-C1", LogicalDatastoreType.OPERATIONAL, - iidCurrentPmList, Timeouts.DEVICE_READ_TIMEOUT, - Timeouts.DEVICE_READ_TIMEOUT_UNIT)).thenReturn(OlmTransactionUtils.getCurrentPmListC()); - - InstanceIdentifier interfacesIIDA = InstanceIdentifier.create(OrgOpenroadmDevice.class) - .child(Interface.class, new InterfaceKey("OTS-DEG2-TTP-TXRX")); - InstanceIdentifier interfacesIIDC = InstanceIdentifier.create(OrgOpenroadmDevice.class) - .child(Interface.class, new InterfaceKey("OTS-DEG1-TTP-TXRX")); + when(this.deviceTransactionManager.getDataFromDevice("ROADM-A1", LogicalDatastoreType.OPERATIONAL, + iidCurrentPmList, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT)) + .thenReturn(OlmTransactionUtils.getCurrentPmListA()); + when(this.deviceTransactionManager.getDataFromDevice("ROADM-C1", LogicalDatastoreType.OPERATIONAL, + iidCurrentPmList, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT)) + .thenReturn(OlmTransactionUtils.getCurrentPmListC()); + + InstanceIdentifier interfacesIIDA = InstanceIdentifier + .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class) + .child(Interface.class, new InterfaceKey("OTS-DEG2-TTP-TXRX")) + .build(); + InstanceIdentifier interfacesIIDC = InstanceIdentifier + .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class) + .child(Interface.class, new InterfaceKey("OTS-DEG1-TTP-TXRX")) + .build(); Optional interfaceA = Optional.of(new InterfaceBuilder().setName("OTS-DEG2-TTP-TXRX").build()); Optional interfaceC = Optional.of(new InterfaceBuilder().setName("OTS-DEG1-TTP-TXRX").build()); - Mockito.when(this.deviceTransactionManager.getDataFromDevice("ROADM-A1", LogicalDatastoreType.CONFIGURATION, - interfacesIIDA, Timeouts.DEVICE_READ_TIMEOUT, - Timeouts.DEVICE_READ_TIMEOUT_UNIT)).thenReturn(interfaceA); - Mockito.when(this.deviceTransactionManager.getDataFromDevice("ROADM-C1", LogicalDatastoreType.CONFIGURATION, - interfacesIIDC, Timeouts.DEVICE_READ_TIMEOUT, - Timeouts.DEVICE_READ_TIMEOUT_UNIT)).thenReturn(interfaceC); - - Ots otsValue = new OtsBuilder().setSpanLossTransmit(new RatioDB(new BigDecimal(25))) - .setSpanLossReceive(new RatioDB(new BigDecimal(25))).build(); + when(this.deviceTransactionManager.getDataFromDevice("ROADM-A1", LogicalDatastoreType.CONFIGURATION, + interfacesIIDA, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT)) + .thenReturn(interfaceA); + when(this.deviceTransactionManager.getDataFromDevice("ROADM-C1", LogicalDatastoreType.CONFIGURATION, + interfacesIIDC, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT)) + .thenReturn(interfaceC); + + Ots otsValue = new OtsBuilder() + .setSpanLossTransmit(new RatioDB(Decimal64.valueOf("25"))) + .setSpanLossReceive(new RatioDB(Decimal64.valueOf("25"))) + .build(); Interface1 ots = new Interface1Builder().setOts(otsValue).build(); - Interface interA = new InterfaceBuilder().setName("OTS-DEG2-TTP-TXRX").setType(OpticalTransport.class) - .addAugmentation(Interface1.class, ots).build(); - Interface interC = new InterfaceBuilder().setName("OTS-DEG1-TTP-TXRX").setType(OpticalTransport.class) - .addAugmentation(Interface1.class, ots).build(); + Interface interA = new InterfaceBuilder().setName("OTS-DEG2-TTP-TXRX").setType(OpticalTransport.VALUE) + .addAugmentation(ots).build(); + Interface interC = new InterfaceBuilder().setName("OTS-DEG1-TTP-TXRX").setType(OpticalTransport.VALUE) + .addAugmentation(ots).build(); Optional interOptA = Optional.of(interA); Optional interOptC = Optional.of(interC); - Mockito.when(this.openRoadmInterfacesImpl221.getInterface("ROADM-A1", "OTS-DEG2-TTP-TXRX")) - .thenReturn(interOptA); - Mockito.when(this.openRoadmInterfacesImpl221.getInterface("ROADM-C1", "OTS-DEG1-TTP-TXRX")) - .thenReturn(interOptC); + when(this.openRoadmInterfacesImpl221.getInterface("ROADM-A1", "OTS-DEG2-TTP-TXRX")).thenReturn(interOptA); + when(this.openRoadmInterfacesImpl221.getInterface("ROADM-C1", "OTS-DEG1-TTP-TXRX")).thenReturn(interOptC); InterfaceBuilder ifABldr = new InterfaceBuilder(); - Mockito.doNothing().when(this.openRoadmInterfacesImpl221).postInterface("ROADM-A1", ifABldr); - Mockito.doNothing().when(this.openRoadmInterfacesImpl221).postInterface("ROADM-C1", ifABldr); + doNothing().when(this.openRoadmInterfacesImpl221).postInterface("ROADM-A1", ifABldr); + doNothing().when(this.openRoadmInterfacesImpl221).postInterface("ROADM-C1", ifABldr); } @Test - public void testCalculateSpanlossBaseLink() { + void testCalculateSpanlossBaseLink() { // initialise and store openroadm-topology in datastore NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)); InstanceIdentifier ietfNetworkIID = InstanceIdentifier.builder(Networks.class) @@ -152,13 +158,13 @@ public class OlmPowerServiceImplSpanLossBaseTest extends AbstractTest { CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInputLink(); CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input); - Assert.assertEquals("Success", output.getResult()); - Assert.assertEquals("ROADM-A1-to-ROADM-C1", output.getSpans().get(0).getLinkId().getValue()); - Assert.assertEquals("15", output.getSpans().get(0).getSpanloss()); + assertEquals("Success", output.getResult()); + assertEquals("ROADM-A1-to-ROADM-C1", output.getSpans().get(0).getLinkId().getValue()); + assertEquals("14.6", output.getSpans().get(0).getSpanloss()); } @Test - public void testCalculateSpanlossBaseAll() { + void testCalculateSpanlossBaseAll() { // initialise and store openroadm-topology in datastore NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)); @@ -175,8 +181,8 @@ public class OlmPowerServiceImplSpanLossBaseTest extends AbstractTest { CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInputAll(); CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input); - Assert.assertEquals("Success", output.getResult()); - Assert.assertEquals("ROADM-A1-to-ROADM-C1", output.getSpans().get(0).getLinkId().getValue()); - Assert.assertEquals("15", output.getSpans().get(0).getSpanloss()); + assertEquals("Success", output.getResult()); + assertEquals("ROADM-A1-to-ROADM-C1", output.getSpans().get(0).getLinkId().getValue()); + assertEquals("14.6", output.getSpans().get(0).getSpanloss()); } }