From: Gilles Thouenon Date: Sat, 25 Feb 2023 18:40:28 +0000 (+0100) Subject: Migrate common module to JUnit5 X-Git-Tag: 7.0.0~21 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=transportpce.git;a=commitdiff_plain;h=1b2f9f488bdd54e577c88c230c4875daccc0b93c Migrate common module to JUnit5 JIRA: TRNSPRTPCE-730 Signed-off-by: Gilles Thouenon Change-Id: Iaeb49f9d2f36ec2e2ba143b1802f4a877063a23d --- diff --git a/common/src/test/java/org/opendaylight/transportpce/common/NodeIdPairTest.java b/common/src/test/java/org/opendaylight/transportpce/common/NodeIdPairTest.java index bc02b76c9..f3f07db72 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/NodeIdPairTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/NodeIdPairTest.java @@ -8,50 +8,37 @@ package org.opendaylight.transportpce.common; -import java.util.Arrays; -import java.util.Collection; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(Parameterized.class) -public class NodeIdPairTest { - - private NodeIdPair firstPair; - private Object secondPair; - private boolean equality; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; - public NodeIdPairTest(NodeIdPair firstPair, Object secondPair, boolean equality) { - this.firstPair = firstPair; - this.secondPair = secondPair; - this.equality = equality; - } +public class NodeIdPairTest { - @Parameterized.Parameters - public static Collection nodes() { + private static Stream provideNodeSamples() { NodeIdPair same = new NodeIdPair("nodeS", "CLIENT"); - return Arrays.asList(new Object[][] { - { new NodeIdPair("",""), null, false }, - { new NodeIdPair("",""), "", false }, - { new NodeIdPair("node1","PP"), new NodeIdPair("node2","PP"), false }, - { new NodeIdPair("node1","PP"), new NodeIdPair("node1","TTP"), false }, - { new NodeIdPair(null,"PP"), new NodeIdPair(null,"TTP"), false }, - { new NodeIdPair(null,"PP"), new NodeIdPair("node2","TTP"), false }, - { new NodeIdPair("node1",null), new NodeIdPair("node1","NETWORK"), false }, - { new NodeIdPair("node1",null), new NodeIdPair("node1",null), true }, - { new NodeIdPair("node1","TTP"), new NodeIdPair("node1","TTP"), true }, - { new NodeIdPair(null,null), new NodeIdPair(null,null), true }, - {same, same, true} - }); + return Stream.of( + Arguments.of(new NodeIdPair("",""), null, false), + Arguments.of(new NodeIdPair("",""), "", false), + Arguments.of(new NodeIdPair("node1","PP"), new NodeIdPair("node2","PP"), false), + Arguments.of(new NodeIdPair("node1","PP"), new NodeIdPair("node1","TTP"), false), + Arguments.of(new NodeIdPair(null,"PP"), new NodeIdPair(null,"TTP"), false), + Arguments.of(new NodeIdPair(null,"PP"), new NodeIdPair("node2","TTP"), false), + Arguments.of(new NodeIdPair("node1",null), new NodeIdPair("node1","NETWORK"), false), + Arguments.of(new NodeIdPair("node1",null), new NodeIdPair("node1",null), true), + Arguments.of(new NodeIdPair("node1","TTP"), new NodeIdPair("node1","TTP"), true), + Arguments.of(new NodeIdPair(null,null), new NodeIdPair(null,null), true), + Arguments.of(same, same, true)); } - @Test - public void equalityTest() { - Assert.assertEquals(this.equality, firstPair.equals(this.secondPair)); - if ((this.secondPair != null) && this.firstPair.getClass().equals(this.secondPair.getClass())) { - Assert.assertEquals(this.equality, this.firstPair.hashCode() == this.secondPair.hashCode()); + @ParameterizedTest + @MethodSource("provideNodeSamples") + void equalityTest(NodeIdPair firstPair, Object secondPair, boolean equality) { + assertEquals(equality, firstPair.equals(secondPair)); + if ((secondPair != null) && firstPair.getClass().equals(secondPair.getClass())) { + assertEquals(equality, firstPair.hashCode() == secondPair.hashCode()); } } - } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/catalog/CatalogUtilsTest.java b/common/src/test/java/org/opendaylight/transportpce/common/catalog/CatalogUtilsTest.java index d7421e8e9..10377c2e7 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/catalog/CatalogUtilsTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/catalog/CatalogUtilsTest.java @@ -8,8 +8,9 @@ package org.opendaylight.transportpce.common.catalog; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.FileReader; import java.io.IOException; @@ -19,8 +20,8 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; import org.eclipse.jdt.annotation.NonNull; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.opendaylight.mdsal.binding.api.WriteTransaction; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.transportpce.common.StringConstants; @@ -39,12 +40,12 @@ import org.slf4j.LoggerFactory; public class CatalogUtilsTest extends AbstractTest { private static final Logger LOG = LoggerFactory.getLogger(CatalogUtilsTest.class); private static final String CATALOG_FILE = "src/test/resources/apidocCatalog10_1OptSpecV5_1.json"; + private static OperationalModeCatalog omCatalog; private static Map outputImpairments = new HashMap<>(); - // - @BeforeClass - public static void setUp() throws InterruptedException, + @BeforeAll + static void setUp() throws InterruptedException, ExecutionException { DataObjectConverter dataObjectConverter = JSONDataObjectConverter .createWithDataStoreUtil(getDataStoreContextUtil()); @@ -69,178 +70,267 @@ public class CatalogUtilsTest extends AbstractTest { } @Test - public void catalogPrimitivesTest() { + void catalogPrimitivesTest() { NetworkTransactionService netTransServ = new NetworkTransactionImpl(getDataBroker()); CatalogUtils catalogUtils = new CatalogUtils(netTransServ); - assertEquals("Checking retrieval of Operational Mode from Node Type ADD", + assertEquals( CatalogConstant.MWWRCORE, catalogUtils.getPceOperationalModeFromServiceType(CatalogConstant.CatalogNodeType.ADD, - StringConstants.SERVICE_TYPE_100GE_T)); - assertEquals("Checking retrieval of Operational Mode from Node Type DROP", + StringConstants.SERVICE_TYPE_100GE_T), + "Checking retrieval of Operational Mode from Node Type ADD"); + assertEquals( CatalogConstant.MWWRCORE, catalogUtils.getPceOperationalModeFromServiceType(CatalogConstant.CatalogNodeType.DROP, - StringConstants.SERVICE_TYPE_100GE_T)); - assertEquals("Checking retrieval of Operational Mode from Node Type EXPRESS", + StringConstants.SERVICE_TYPE_100GE_T), + "Checking retrieval of Operational Mode from Node Type DROP"); + assertEquals( CatalogConstant.MWMWCORE, catalogUtils.getPceOperationalModeFromServiceType(CatalogConstant.CatalogNodeType.EXPRESS, - StringConstants.SERVICE_TYPE_100GE_T)); - assertEquals("Checking retrieval of Operational Mode from Node Type AMP", + StringConstants.SERVICE_TYPE_100GE_T), + "Checking retrieval of Operational Mode from Node Type EXPRESS"); + assertEquals( CatalogConstant.MWISTANDARD, catalogUtils.getPceOperationalModeFromServiceType(CatalogConstant.CatalogNodeType.AMP, - StringConstants.SERVICE_TYPE_100GE_T)); - assertEquals("Checking retrieval of Operational Mode from Node Type and service Type 100GE", + StringConstants.SERVICE_TYPE_100GE_T), + "Checking retrieval of Operational Mode from Node Type AMP"); + assertEquals( CatalogConstant.ORW100GSC, catalogUtils.getPceOperationalModeFromServiceType(CatalogConstant.CatalogNodeType.TSP, - StringConstants.SERVICE_TYPE_100GE_T)); - assertEquals("Checking retrieval of Operational Mode from Node Type and service Type OTU4", + StringConstants.SERVICE_TYPE_100GE_T), + "Checking retrieval of Operational Mode from Node Type and service Type 100GE"); + assertEquals( CatalogConstant.ORW100GSC, catalogUtils.getPceOperationalModeFromServiceType(CatalogConstant.CatalogNodeType.TSP, - StringConstants.SERVICE_TYPE_OTU4)); - assertEquals("Checking retrieval of Operational Mode from Node Type and service Type OTUC2", + StringConstants.SERVICE_TYPE_OTU4), + "Checking retrieval of Operational Mode from Node Type and service Type OTU4"); + assertEquals( CatalogConstant.ORW200GOFEC316GBD, catalogUtils.getPceOperationalModeFromServiceType(CatalogConstant.CatalogNodeType.TSP, - StringConstants.SERVICE_TYPE_OTUC2)); - assertEquals("Checking retrieval of Operational Mode from Node Type and service Type OTUC3", + StringConstants.SERVICE_TYPE_OTUC2), + "Checking retrieval of Operational Mode from Node Type and service Type OTUC2"); + assertEquals( CatalogConstant.ORW300GOFEC631GBD, catalogUtils.getPceOperationalModeFromServiceType(CatalogConstant.CatalogNodeType.TSP, - StringConstants.SERVICE_TYPE_OTUC3)); - assertEquals("Checking retrieval of Operational Mode from Node Type and service Type 400GE", + StringConstants.SERVICE_TYPE_OTUC3), + "Checking retrieval of Operational Mode from Node Type and service Type OTUC3"); + assertEquals( CatalogConstant.ORW400GOFEC631GBD, catalogUtils.getPceOperationalModeFromServiceType(CatalogConstant.CatalogNodeType.TSP, - StringConstants.SERVICE_TYPE_400GE)); - assertEquals("Checking retrieval of Operational Mode from Node Type and service Type OTUC4", + StringConstants.SERVICE_TYPE_400GE), + "Checking retrieval of Operational Mode from Node Type and service Type 400GE"); + assertEquals( CatalogConstant.ORW400GOFEC631GBD, catalogUtils.getPceOperationalModeFromServiceType(CatalogConstant.CatalogNodeType.TSP, - StringConstants.SERVICE_TYPE_OTUC4)); - assertEquals("Checking retrieval of channel spacing from Operational Mode 100G SC FEC", + StringConstants.SERVICE_TYPE_OTUC4), + "Checking retrieval of Operational Mode from Node Type and service Type OTUC4"); + assertEquals( 50.0, - catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW100GSC),0.005); - assertEquals("Checking retrieval of channel spacing from Operational Mode 100G OFEC 31.6", + catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW100GSC), + 0.005, + "Checking retrieval of channel spacing from Operational Mode 100G SC FEC"); + assertEquals( 50.0, - catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW100GOFEC316GBD),0.005); - assertEquals("Checking retrieval of channel spacing from Operational Mode 200G OFEC 31.6", + catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW100GOFEC316GBD), + 0.005, + "Checking retrieval of channel spacing from Operational Mode 100G OFEC 31.6"); + assertEquals( 50.0, - catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW200GOFEC316GBD),0.005); - assertEquals("Checking retrieval of channel spacing from Operational Mode 200G OFEC 63.1", + catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW200GOFEC316GBD), + 0.005, + "Checking retrieval of channel spacing from Operational Mode 200G OFEC 31.6"); + assertEquals( 87.5, - catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW200GOFEC631GBD),0.005); - assertEquals("Checking retrieval of channel spacing from Operational Mode 300G OFEC 63.1 GBd", + catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW200GOFEC631GBD), + 0.005, + "Checking retrieval of channel spacing from Operational Mode 200G OFEC 63.1"); + assertEquals( 87.5, - catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW300GOFEC631GBD),0.005); - assertEquals("Checking retrieval of channel spacing from Operational Mode 400G OFEC 63.1 Gbd", + catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW300GOFEC631GBD), + 0.005, + "Checking retrieval of channel spacing from Operational Mode 300G OFEC 63.1 GBd"); + assertEquals( 87.5, - catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW400GOFEC631GBD),0.005); - assertEquals("Checking 100GSCFEC ONSR Lin", + catalogUtils.getPceTxTspChannelSpacing(CatalogConstant.ORW400GOFEC631GBD), + 0.005, + "Checking retrieval of channel spacing from Operational Mode 400G OFEC 63.1 Gbd"); + assertEquals( 1345.6, catalogUtils.getPceTxTspParameters(CatalogConstant.ORW100GSC, CatalogConstant.MWWRCORE) * 1000000.0, - 0.5); - assertEquals("Checking 100G OFEC 31.6 Gbauds ONSR Lin", + 0.5, + "Checking 100GSCFEC ONSR Lin"); + assertEquals( 450.7, catalogUtils.getPceTxTspParameters(CatalogConstant.ORW100GOFEC316GBD, CatalogConstant.MWWRCORE) * 1000000.0, - 0.5); - assertEquals("Checking 200G OFEC 31.6 Gbauds ONSR Lin", + 0.5, + "Checking 100G OFEC 31.6 Gbauds ONSR Lin"); + assertEquals( 450.7, catalogUtils.getPceTxTspParameters(CatalogConstant.ORW200GOFEC316GBD, CatalogConstant.MWWRCORE) * 1000000.0, - 0.5); - assertEquals("Checking 200G OFEC 63.1 Gbauds ONSR Lin", + 0.5, + "Checking 200G OFEC 31.6 Gbauds ONSR Lin"); + assertEquals( 450.7, catalogUtils.getPceTxTspParameters(CatalogConstant.ORW200GOFEC631GBD, CatalogConstant.MWWRCORE) * 1000000.0, - 0.5); - assertEquals("Checking 300G OFEC 63.1 Gbauds ONSR Lin", + 0.5, + "Checking 200G OFEC 63.1 Gbauds ONSR Lin"); + assertEquals( 450.7, catalogUtils.getPceTxTspParameters(CatalogConstant.ORW300GOFEC631GBD, CatalogConstant.MWWRCORE) * 1000000.0, - 0.5); - assertEquals("Checking 400G OFEC 63.1 Gbauds ONSR Lin", + 0.5, + "Checking 300G OFEC 63.1 Gbauds ONSR Lin"); + assertEquals( 450.7, catalogUtils.getPceTxTspParameters(CatalogConstant.ORW400GOFEC631GBD, CatalogConstant.MWWRCORE) * 1000000.0, - 0.5); - assertEquals("Checking ONSR Lin = 0 for non valid OM", + 0.5, + "Checking 400G OFEC 63.1 Gbauds ONSR Lin"); + assertEquals( 0.0, catalogUtils.getPceTxTspParameters("SPE-non-existing-mode", CatalogConstant.MWWRCORE) * 1000000.0, - 0.0); - assertEquals("Checking 100GSCFEC RX margin OOR due to CD", - -9996.9, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GSC, 18001.0, 0.0, 0.0, 20.0), 0.5); - assertEquals("Checking 100GSCFEC RX margin OOR due to PMD", - -9996.9, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GSC, 0.0, 30.1, 0.0, 20.0), 0.5); - assertEquals("Checking 100GSCFEC RX margin OOR due to PDL", - 0.0, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GSC, 0.0, 0.0, 6.0, 20.0), 0.5); - assertEquals("Checking 100GSCFEC RX margin in Range at max tolerated penalty", - 0.0, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GSC, 17999.0, 29.9, 6.0, 20.0), 0.05); - assertEquals("Checking 400G OFEC 63.1 Gbauds RX margin OOR due to CD", - -9996.9, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 12001.0, 0.0, 0.0, 27.0), - 0.5); - assertEquals("Checking 400G OFEC 63.1 Gbauds RX margin OOR due to PMD", - -9996.9, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 0.0, 20.1, 0.0, 27.0), - 0.5); - assertEquals("Checking 400G OFEC 63.1 Gbauds RX margin OOR due to PDL", - 0.0, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 0.0, 0.0, 6.0, 27.0), - 0.5); - assertEquals("Checking 400G OFEC 63.1 Gbauds RX margin in Range at max tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 11999.0, 19.9, 5.0, 28.0), - 0.05); - assertEquals("Checking 400G OFEC 63.1 Gbauds RX margin in Range at intermediate tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 3999.0, 9.9, 2.0, 25.5), - 0.05); - assertEquals("Checking 400G OFEC 63.1 Gbauds RX margin in Range at min tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 3999.0, 9.9, 1.0, 25.0), - 0.05); - assertEquals("Checking 300G OFEC 63.1 Gbauds RX margin in Range at max tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW300GOFEC631GBD, 17999.0, 24.9, 5.0, 25.0), - 0.05); - assertEquals("Checking 300G OFEC 63.1 Gbauds RX margin in Range at min tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW300GOFEC631GBD, 3999.0, 9.9, 1.0, 22.0), - 0.05); - assertEquals("Checking 200G OFEC 63.1 Gbauds RX margin in Range at max tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW200GOFEC631GBD, 23999.0, 24.9, 5.0, 21.0), - 0.05); - assertEquals("Checking 200G OFEC 63.1 Gbauds RX margin in Range at min tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW200GOFEC631GBD, 3999.0, 9.9, 1.0, 18.0), - 0.05); - assertEquals("Checking 200G OFEC 31.6 Gbauds RX margin in Range at max tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW200GOFEC316GBD, 23999.0, 29.9, 5.0, 24.5), - 0.05); - assertEquals("Checking 200G OFEC 31.6 Gbauds RX margin in Range at min tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW200GOFEC316GBD, 3999.0, 9.9, 1.0, 21.5), - 0.05); - assertEquals("Checking 100G OFEC 31.6 Gbauds RX margin in Range at max tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GOFEC316GBD, 47999.0, 29.9, 5.0, 16.0), - 0.05); - assertEquals("Checking 100G OFEC 31.6 Gbauds RX margin in Range at min tolerated penalty", - 0.5, catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GOFEC316GBD, 3999.0, 9.9, 1.0, 13.0), - 0.05); - assertEquals("Checking Margin negative for non valid OM", - -9999.9, catalogUtils.getPceRxTspParameters("SPE-non-existing-mode", 0.0, 0.0, 0.0, 30.0), 0.05); + 0.0, + "Checking ONSR Lin = 0 for non valid OM"); + assertEquals( + -9996.9, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GSC, 18001.0, 0.0, 0.0, 20.0), + 0.5, + "Checking 100GSCFEC RX margin OOR due to CD"); + assertEquals( + -9996.9, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GSC, 0.0, 30.1, 0.0, 20.0), + 0.5, + "Checking 100GSCFEC RX margin OOR due to PMD"); + assertEquals( + 0.0, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GSC, 0.0, 0.0, 6.0, 20.0), + 0.5, + "Checking 100GSCFEC RX margin OOR due to PDL"); + assertEquals( + 0.0, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GSC, 17999.0, 29.9, 6.0, 20.0), + 0.05, + "Checking 100GSCFEC RX margin in Range at max tolerated penalty"); + assertEquals( + -9996.9, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 12001.0, 0.0, 0.0, 27.0), + 0.5, + "Checking 400G OFEC 63.1 Gbauds RX margin OOR due to CD"); + assertEquals( + -9996.9, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 0.0, 20.1, 0.0, 27.0), + 0.5, + "Checking 400G OFEC 63.1 Gbauds RX margin OOR due to PMD"); + assertEquals( + 0.0, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 0.0, 0.0, 6.0, 27.0), + 0.5, + "Checking 400G OFEC 63.1 Gbauds RX margin OOR due to PDL"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 11999.0, 19.9, 5.0, 28.0), + 0.05, + "Checking 400G OFEC 63.1 Gbauds RX margin in Range at max tolerated penalty"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 3999.0, 9.9, 2.0, 25.5), + 0.05, + "Checking 400G OFEC 63.1 Gbauds RX margin in Range at intermediate tolerated penalty"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW400GOFEC631GBD, 3999.0, 9.9, 1.0, 25.0), + 0.05, + "Checking 400G OFEC 63.1 Gbauds RX margin in Range at min tolerated penalty"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW300GOFEC631GBD, 17999.0, 24.9, 5.0, 25.0), + 0.05, + "Checking 300G OFEC 63.1 Gbauds RX margin in Range at max tolerated penalty"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW300GOFEC631GBD, 3999.0, 9.9, 1.0, 22.0), + 0.05, + "Checking 300G OFEC 63.1 Gbauds RX margin in Range at min tolerated penalty"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW200GOFEC631GBD, 23999.0, 24.9, 5.0, 21.0), + 0.05, + "Checking 200G OFEC 63.1 Gbauds RX margin in Range at max tolerated penalty"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW200GOFEC631GBD, 3999.0, 9.9, 1.0, 18.0), + 0.05, + "Checking 200G OFEC 63.1 Gbauds RX margin in Range at min tolerated penalty"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW200GOFEC316GBD, 23999.0, 29.9, 5.0, 24.5), + 0.05, + "Checking 200G OFEC 31.6 Gbauds RX margin in Range at max tolerated penalty"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW200GOFEC316GBD, 3999.0, 9.9, 1.0, 21.5), + 0.05, + "Checking 200G OFEC 31.6 Gbauds RX margin in Range at min tolerated penalty"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GOFEC316GBD, 47999.0, 29.9, 5.0, 16.0), + 0.05, + "Checking 100G OFEC 31.6 Gbauds RX margin in Range at max tolerated penalty"); + assertEquals( + 0.5, + catalogUtils.getPceRxTspParameters(CatalogConstant.ORW100GOFEC316GBD, 3999.0, 9.9, 1.0, 13.0), + 0.05, + "Checking 100G OFEC 31.6 Gbauds RX margin in Range at min tolerated penalty"); + assertEquals( + -9999.9, + catalogUtils.getPceRxTspParameters("SPE-non-existing-mode", 0.0, 0.0, 0.0, 30.0), + 0.05, + "Checking Margin negative for non valid OM"); outputImpairments.put("CD", 1025.0); outputImpairments.put("DGD2", 18.0); outputImpairments.put("PDL2", 4.4); outputImpairments.put("ONSRLIN", 0.0016307685044580757); // check how to add Delta on an object - assertEquals("Checking ROADM Express path contribution to impairments ", - outputImpairments, catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.EXPRESS, - CatalogConstant.MWMWCORE,-15.0, 1000.0, 9.0, 4.0, 0.001000, 50.0)); + assertEquals( + outputImpairments, + catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.EXPRESS, CatalogConstant.MWMWCORE, + -15.0, 1000.0, 9.0, 4.0, 0.001000, 50.0), + "Checking ROADM Express path contribution to impairments "); outputImpairments.put("ONSRLIN", 0.0014729700859390747); - assertEquals("Checking ROADM Express path contribution to impairments with 87.5 GHz spacing ", - outputImpairments, catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.EXPRESS, - CatalogConstant.MWMWCORE,-15.0, 1000.0, 9.0, 4.0, 0.001000, 87.5)); + assertEquals( + outputImpairments, + catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.EXPRESS, CatalogConstant.MWMWCORE, + -15.0, 1000.0, 9.0, 4.0, 0.001000, 87.5), + "Checking ROADM Express path contribution to impairments with 87.5 GHz spacing"); outputImpairments.put("ONSRLIN", 0.0015011872336272727); - assertEquals("Checking ROADM Add path contribution to impairments ", - outputImpairments, catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.ADD, - CatalogConstant.MWWRCORE, -15.0, 1000.0, 9.0, 4.2, 0.001, 50.0)); + assertEquals( + outputImpairments, + catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.ADD, CatalogConstant.MWWRCORE, + -15.0, 1000.0, 9.0, 4.2, 0.001, 50.0), + "Checking ROADM Add path contribution to impairments"); outputImpairments.put("ONSRLIN", 0.0016307685044580757); - assertEquals("Checking ROADM Drop path contribution to impairments ", - outputImpairments, catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.DROP, - CatalogConstant.MWWRCORE, -15.0, 1000.0, 9.0, 4.2, 0.001, 50.0)); + assertEquals( + outputImpairments, + catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.DROP, CatalogConstant.MWWRCORE, + -15.0, 1000.0, 9.0, 4.2, 0.001, 50.0), + "Checking ROADM Drop path contribution to impairments"); outputImpairments.put("ONSRLIN", 0.0015010372326658581); - assertEquals("Checking Amp path contribution to impairments ", - outputImpairments, catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.AMP, - CatalogConstant.MWISTANDARD, -15.0, 1025.0, 9.0, 4.36, 0.001, 50.0)); - assertEquals("Checking empty map returned in case wrong Operational mode provided ", - true, catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.AMP, - "ThisIsNotAValidMode", -15.0,1000.0, 0.0, 0.0, 0.001, 50.0).isEmpty()); + assertEquals( + outputImpairments, + catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.AMP, CatalogConstant.MWISTANDARD, + -15.0, 1025.0, 9.0, 4.36, 0.001, 50.0), + "Checking Amp path contribution to impairments"); + assertEquals( + true, + catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.AMP, "ThisIsNotAValidMode", + -15.0,1000.0, 0.0, 0.0, 0.001, 50.0).isEmpty(), + "Checking empty map returned in case wrong Operational mode provided "); outputImpairments.put("ONSRLIN", 1.0); - assertEquals("Checking empty map returned in case wrong Operational mode provided ", - true, catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.AMP, - "OR-InvalidMode", -15.0, 1025.0, 18.0, 6.25, 0.001, 50.0).isEmpty()); - assertEquals("Checking Non Linear contribution calculation ", 0.000114266642501745, - catalogUtils.calculateNLonsrContribution(2, 70, 87.5), 0.000000005); + assertEquals( + true, + catalogUtils.getPceRoadmAmpParameters(CatalogConstant.CatalogNodeType.AMP, "OR-InvalidMode", + -15.0, 1025.0, 18.0, 6.25, 0.001, 50.0).isEmpty(), + "Checking empty map returned in case wrong Operational mode provided"); + assertEquals( + 0.000114266642501745, + catalogUtils.calculateNLonsrContribution(2, 70, 87.5), + 0.000000005, + "Checking Non Linear contribution calculation"); } } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/converter/JsonStringConverterTest.java b/common/src/test/java/org/opendaylight/transportpce/common/converter/JsonStringConverterTest.java index 085f57e40..d448a0aaf 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/converter/JsonStringConverterTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/converter/JsonStringConverterTest.java @@ -7,9 +7,10 @@ */ package org.opendaylight.transportpce.common.converter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import java.io.FileReader; import java.io.IOException; @@ -17,7 +18,7 @@ import java.io.Reader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.transportpce.test.AbstractTest; import org.opendaylight.transportpce.test.converter.JSONDataObjectConverter; import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.Request; @@ -28,10 +29,9 @@ import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier; public class JsonStringConverterTest extends AbstractTest { @Test - public void createJsonStringFromDataObjectTest() { + void createJsonStringFromDataObjectTest() { try (Reader reader = new FileReader("src/test/resources/gnpy_request.json", StandardCharsets.UTF_8)) { assertEquals( - "Should be a valid request", Files.readString(Paths.get("src/test/resources/expected_string.json")), new JsonStringConverter(getDataStoreContextUtil().getBindingDOMCodecServices()) .createJsonStringFromDataObject( @@ -46,20 +46,21 @@ public class JsonStringConverterTest extends AbstractTest { .transformIntoNormalizedNode(reader) .get()) .getValue(), - JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02)); + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02), + "Should be a valid request"); } catch (IOException e) { fail("Cannot load path description "); } } @Test - public void createDataObjectFromJsonStringTest() throws IOException { + void createDataObjectFromJsonStringTest() throws IOException { assertNotNull( - "Should not be null", new JsonStringConverter(getDataStoreContextUtil().getBindingDOMCodecServices()) .createDataObjectFromJsonString( YangInstanceIdentifier.of(Request.QNAME), Files.readString(Paths.get("src/test/resources/expected_string.json")), - JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02)); + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02), + "Should not be null"); } } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl121Test.java b/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl121Test.java index 4d6663f8e..839027a13 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl121Test.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl121Test.java @@ -8,16 +8,19 @@ package org.opendaylight.transportpce.common.crossconnect; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.opendaylight.mdsal.common.api.CommitInfo.emptyFluentFuture; import java.util.Optional; import java.util.concurrent.CompletableFuture; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.MountPoint; import org.opendaylight.mdsal.binding.api.MountPointService; @@ -32,12 +35,14 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.Op import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceData; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey; import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.Decimal64; import org.opendaylight.yangtools.yang.common.Uint32; + public class CrossConnectImpl121Test { private CrossConnectImpl121 crossConnectImpl121 = null; private DeviceTransactionManager deviceTransactionManager = null; @@ -46,9 +51,10 @@ public class CrossConnectImpl121Test { private MountPoint mountPointMock = mock(MountPoint.class); private DataBroker dataBrokerMock = mock(DataBroker.class); private ReadWriteTransaction rwTransactionMock = mock(ReadWriteTransaction.class); + private DeviceTransaction deviceTransaction = mock(DeviceTransaction.class); - @Before - public void setup() { + @BeforeEach + void setup() { deviceTransactionManager = mock(DeviceTransactionManager.class); crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager); @@ -64,18 +70,18 @@ public class CrossConnectImpl121Test { } @Test - public void getCrossConnectTest() { + void getCrossConnectTest() { Optional res = crossConnectImpl121.getCrossConnect("deviceId", "1"); - Assert.assertTrue("Optional object should have a value", res.isPresent()); + assertTrue(res.isPresent(), "Optional object should have a value"); } @Test - public void postCrossConnectTest() { - Mockito.when(mountPointServiceMock.getMountPoint(any())).thenReturn(Optional.of(mountPointMock)); - Mockito.when(mountPointMock.getService(any())).thenReturn(Optional.of(dataBrokerMock)); - Mockito.when(dataBrokerMock.newReadWriteTransaction()).thenReturn(rwTransactionMock); - Mockito.when(rwTransactionMock.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); + void postCrossConnectTest() { + when(mountPointServiceMock.getMountPoint(any())).thenReturn(Optional.of(mountPointMock)); + when(mountPointMock.getService(any())).thenReturn(Optional.of(dataBrokerMock)); + when(dataBrokerMock.newReadWriteTransaction()).thenReturn(rwTransactionMock); + when(rwTransactionMock.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointServiceMock, 3000); crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager); SpectrumInformation spectrumInformation = new SpectrumInformation(); @@ -83,12 +89,11 @@ public class CrossConnectImpl121Test { spectrumInformation.setLowerSpectralSlotNumber(761); spectrumInformation.setHigherSpectralSlotNumber(768); Optional res = crossConnectImpl121.postCrossConnect("deviceId", "srcTp", "destTp", spectrumInformation); - Assert.assertEquals(res.get(), "srcTp-destTp-761:768"); + assertEquals(res.get(), "srcTp-destTp-761:768"); } - // TODO : fix commit - @Test(expected = NullPointerException.class) - public void setPowerLevelTest() { + @Test + void setPowerLevelTest() { InstanceIdentifier deviceIID = InstanceIdentifier .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class) .child(RoadmConnections.class, new RoadmConnectionsKey("1")) @@ -96,12 +101,11 @@ public class CrossConnectImpl121Test { when(deviceTransactionManager.getDataFromDevice("deviceId", LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT)) - .thenReturn(Optional.of(mock(RoadmConnections.class))); - - Mockito.when(deviceTransactionManager.getDeviceTransaction("deviceId")) - .thenReturn(CompletableFuture.completedFuture(Optional.of(mock(DeviceTransaction.class)))); + .thenReturn(Optional.of(new RoadmConnectionsBuilder().setConnectionNumber("1").build())); + when(deviceTransactionManager.getDeviceTransaction("deviceId")) + .thenReturn(CompletableFuture.completedFuture(Optional.of(deviceTransaction))); + doReturn(emptyFluentFuture()).when(deviceTransaction).commit(anyLong(), any()); crossConnectImpl121.setPowerLevel("deviceId", OpticalControlMode.Power, Decimal64.valueOf("100"), "1"); - - Assert.assertTrue("set Level should be true", true); + assertTrue(true, "set Level should be true"); } } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl221Test.java b/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl221Test.java index b92095cba..89ff463bc 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl221Test.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl221Test.java @@ -8,15 +8,20 @@ package org.opendaylight.transportpce.common.crossconnect; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.opendaylight.mdsal.common.api.CommitInfo.emptyFluentFuture; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.MountPoint; @@ -32,6 +37,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.Op import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OrgOpenroadmDeviceData; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.OrgOpenroadmDevice; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.RoadmConnections; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey; import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.otn.renderer.nodes.Nodes; import org.opendaylight.yangtools.util.concurrent.FluentFutures; @@ -47,9 +53,10 @@ public class CrossConnectImpl221Test { private MountPoint mountPointMock = mock(MountPoint.class); private DataBroker dataBrokerMock = mock(DataBroker.class); private ReadWriteTransaction rwTransactionMock = mock(ReadWriteTransaction.class); + private DeviceTransaction deviceTransaction = mock(DeviceTransaction.class); - @Before - public void setup() { + @BeforeEach + void setup() { deviceTransactionManager = mock(DeviceTransactionManager.class); crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager); @@ -59,25 +66,25 @@ public class CrossConnectImpl221Test { .child(RoadmConnections.class, new RoadmConnectionsKey("1")) .build(); - Mockito.when(deviceTransactionManager.getDataFromDevice("deviceId", + when(deviceTransactionManager.getDataFromDevice("deviceId", LogicalDatastoreType.CONFIGURATION, deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT)) .thenReturn(Optional.of(mock(RoadmConnections.class))); } @Test - public void getCrossConnectTest() { + void getCrossConnectTest() { Optional res = crossConnectImpl221.getCrossConnect("deviceId", "1"); - Assert.assertTrue("Optional object should have a value", res.isPresent()); + assertTrue(res.isPresent(), "Optional object should have a value"); } @Test - public void postCrossConnectTest() { - Mockito.when(mountPointServiceMock.getMountPoint(any())).thenReturn(Optional.of(mountPointMock)); - Mockito.when(mountPointMock.getService(any())).thenReturn(Optional.of(dataBrokerMock)); - Mockito.when(dataBrokerMock.newReadWriteTransaction()).thenReturn(rwTransactionMock); - Mockito.when(rwTransactionMock.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); + void postCrossConnectTest() { + when(mountPointServiceMock.getMountPoint(any())).thenReturn(Optional.of(mountPointMock)); + when(mountPointMock.getService(any())).thenReturn(Optional.of(dataBrokerMock)); + when(dataBrokerMock.newReadWriteTransaction()).thenReturn(rwTransactionMock); + when(rwTransactionMock.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointServiceMock, 3000); crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager); SpectrumInformation spectrumInformation = new SpectrumInformation(); @@ -85,34 +92,35 @@ public class CrossConnectImpl221Test { spectrumInformation.setLowerSpectralSlotNumber(761); spectrumInformation.setHigherSpectralSlotNumber(768); Optional res = crossConnectImpl221.postCrossConnect("deviceId", "srcTp", "destTp", spectrumInformation); - Assert.assertEquals(res.get(), "srcTp-destTp-761:768"); + assertEquals(res.get(), "srcTp-destTp-761:768"); } - @Test(expected = NullPointerException.class) - public void setPowerLevelTest() { + @Test + void setPowerLevelTest() { InstanceIdentifier deviceIID = InstanceIdentifier .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class) .child(RoadmConnections.class, new RoadmConnectionsKey("1")) .build(); - Mockito.when(deviceTransactionManager.getDataFromDevice("deviceId", - LogicalDatastoreType.OPERATIONAL, deviceIID, + when(deviceTransactionManager.getDataFromDevice("deviceId", + LogicalDatastoreType.CONFIGURATION, deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT)) - .thenReturn(Optional.of(mock(RoadmConnections.class))); + .thenReturn(Optional.of(new RoadmConnectionsBuilder().setConnectionName("1").build())); - Mockito.when(deviceTransactionManager.getDeviceTransaction("deviceId")) - .thenReturn(CompletableFuture.completedFuture(Optional.of(mock(DeviceTransaction.class)))); + when(deviceTransactionManager.getDeviceTransaction("deviceId")) + .thenReturn(CompletableFuture.completedFuture(Optional.of(deviceTransaction))); + doReturn(emptyFluentFuture()).when(deviceTransaction).commit(anyLong(), any()); crossConnectImpl221.setPowerLevel("deviceId", OpticalControlMode.GainLoss, Decimal64.valueOf("100"), "1"); - - Assert.assertTrue("set Level should be true", true); + assertTrue(true, "set Level should be true"); } - @Test(expected = NullPointerException.class) - public void postOtnCrossConnect() { + @Test + void postOtnCrossConnect() { Nodes nodes = Mockito.mock(Nodes.class); - Mockito.when(nodes.getNodeId()).thenReturn("nodeId"); - Mockito.when(deviceTransactionManager.getDeviceTransaction(any())) - .thenReturn(CompletableFuture.completedFuture(Optional.of(mock(DeviceTransaction.class)))); + when(nodes.getNodeId()).thenReturn("nodeId"); + when(deviceTransactionManager.getDeviceTransaction(any())) + .thenReturn(CompletableFuture.completedFuture(Optional.of(deviceTransaction))); + doReturn(emptyFluentFuture()).when(deviceTransaction).commit(anyLong(), any()); Optional res = crossConnectImpl221.postOtnCrossConnect(List.of("src1", "src2"), nodes); - Assert.assertTrue("Optional value should have a value", res.isPresent()); + assertTrue(res.isPresent(), "Optional value should have a value"); } } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImplTest.java b/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImplTest.java index e5cb18b84..d3b2f9637 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImplTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImplTest.java @@ -8,104 +8,93 @@ package org.opendaylight.transportpce.common.crossconnect; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.opendaylight.transportpce.common.StringConstants.OPENROADM_DEVICE_VERSION_1_2_1; +import static org.opendaylight.transportpce.common.StringConstants.OPENROADM_DEVICE_VERSION_2_2_1; import java.util.List; import java.util.Optional; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.opendaylight.transportpce.common.device.DeviceTransactionManager; import org.opendaylight.transportpce.common.fixedflex.SpectrumInformation; import org.opendaylight.transportpce.common.mapping.MappingUtils; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.RoadmConnections; import org.opendaylight.yangtools.yang.common.Decimal64; -import org.opendaylight.yangtools.yang.common.Uint32; -@Ignore public class CrossConnectImplTest { private CrossConnectImpl crossConnectImpl = null; - private static DeviceTransactionManager deviceTransactionManager; - private CrossConnectImpl121 crossConnectImpl121 = null; - private CrossConnectImpl221 crossConnectImpl221 = null; - private CrossConnectImpl710 crossConnectImpl710 = null; - private MappingUtils mappingUtils = null; - - @Before - public void setUp() { - deviceTransactionManager = mock(DeviceTransactionManager.class); - crossConnectImpl121 = mock(CrossConnectImpl121.class); - crossConnectImpl221 = mock(CrossConnectImpl221.class); - crossConnectImpl710 = mock(CrossConnectImpl710.class); - mappingUtils = mock(MappingUtils.class); - crossConnectImpl = - new CrossConnectImpl(deviceTransactionManager, mappingUtils, crossConnectImpl121, - crossConnectImpl221, crossConnectImpl710); - } - - @Before - public void init() { - + private static DeviceTransactionManager deviceTransactionManager = mock(DeviceTransactionManager.class); + private CrossConnectImpl121 crossConnectImpl121 = mock(CrossConnectImpl121.class); + private CrossConnectImpl221 crossConnectImpl221 = mock(CrossConnectImpl221.class); + private CrossConnectImpl710 crossConnectImpl710 = mock(CrossConnectImpl710.class); + private MappingUtils mappingUtils = mock(MappingUtils.class); + private SpectrumInformation spectrumInfo = mock(SpectrumInformation.class); + + @BeforeEach + void setUp() { + crossConnectImpl = new CrossConnectImpl(deviceTransactionManager, mappingUtils, crossConnectImpl121, + crossConnectImpl221, crossConnectImpl710); } @Test - public void getCrossConnect() { - Optional res = crossConnectImpl.getCrossConnect("100", "122"); - Assert.assertFalse("Optional object should be empty",res.isPresent()); - - String devV121 = "(http://org/openroadm/device?revision=2017-02-06)org-openroadm-device"; - when(mappingUtils.getOpenRoadmVersion(any())).thenReturn(devV121); - when(crossConnectImpl121.getCrossConnect(any(), any())).thenReturn(Optional.of(mock(RoadmConnections.class))); - res = crossConnectImpl.getCrossConnect("100", "122"); - Assert.assertTrue("Optional object should have a value",res.isPresent()); + void getCrossConnect() { + when(mappingUtils.getOpenRoadmVersion("NodeId")).thenReturn(OPENROADM_DEVICE_VERSION_2_2_1); + when(crossConnectImpl221.getCrossConnect(any(), any())).thenReturn(Optional.empty()); + Optional res = crossConnectImpl.getCrossConnect("NodeId", "122"); + assertFalse(res.isPresent(), "Optional object should be empty"); + + when(mappingUtils.getOpenRoadmVersion(any())).thenReturn(OPENROADM_DEVICE_VERSION_2_2_1); + when(crossConnectImpl221.getCrossConnect(any(), any())).thenReturn(Optional.of(mock(RoadmConnections.class))); + res = crossConnectImpl.getCrossConnect("NodeId", "122"); + assertTrue(res.isPresent(), "Optional object should have a value"); } @Test - public void postCrossConnect() { - SpectrumInformation spectrumInformation = new SpectrumInformation(); - spectrumInformation.setWaveLength(Uint32.valueOf(1)); - spectrumInformation.setLowerSpectralSlotNumber(761); - spectrumInformation.setHigherSpectralSlotNumber(768); - Optional res = crossConnectImpl.postCrossConnect("100", "srcTp", "destTp", spectrumInformation); - Assert.assertFalse("Optional object should be empty",res.isPresent()); - - String devV121 = "(http://org/openroadm/device?revision=2017-02-06)org-openroadm-device"; - when(mappingUtils.getOpenRoadmVersion(any())).thenReturn(devV121); - when(crossConnectImpl121.postCrossConnect(any(), any(), any(), any())) - .thenReturn(Optional.of("Value")); - res = crossConnectImpl.postCrossConnect("100", "srcTp", "destTp", spectrumInformation); - Assert.assertTrue("Optional object should have a value",res.isPresent()); + void postCrossConnect() { + when(mappingUtils.getOpenRoadmVersion(anyString())).thenReturn("bad node version"); + Optional res = crossConnectImpl.postCrossConnect("nodeId", "srcTp", "destTp", spectrumInfo); + assertFalse(res.isPresent(), "Optional object should be empty"); + + when(mappingUtils.getOpenRoadmVersion(any())).thenReturn(OPENROADM_DEVICE_VERSION_2_2_1); + when(crossConnectImpl221.postCrossConnect(any(), any(), any(), any())) + .thenReturn(Optional.of("Connection Number")); + res = crossConnectImpl.postCrossConnect("100", "srcTp", "destTp", spectrumInfo); + assertTrue(res.isPresent(), "Optional object should have a value"); } @Test - public void deleteCrossConnect() { - List res = crossConnectImpl.deleteCrossConnect("100", "srcTp", true); - Assert.assertNull(res); + void deleteCrossConnect() { + when(mappingUtils.getOpenRoadmVersion(anyString())).thenReturn("bad node version"); + List res = crossConnectImpl.deleteCrossConnect("nodeId", "100", false); + assertNull(res); - String devV121 = "(http://org/openroadm/device?revision=2017-02-06)org-openroadm-device"; - when(mappingUtils.getOpenRoadmVersion(any())).thenReturn(devV121); + when(mappingUtils.getOpenRoadmVersion(any())).thenReturn(OPENROADM_DEVICE_VERSION_1_2_1); when(crossConnectImpl121.deleteCrossConnect(any(), any())) - .thenReturn(List.of("val1")); - res = crossConnectImpl.deleteCrossConnect("100", "srcTp", true); - Assert.assertEquals(res.size(), 1); + .thenReturn(List.of("interface1", "interface2")); + res = crossConnectImpl.deleteCrossConnect("nodeId", "100", false); + assertEquals(res.size(), 2); } @Test - public void setPowerLevel() { - boolean res = crossConnectImpl.setPowerLevel("100", "srcTp", Decimal64.valueOf("100"), "power"); - Assert.assertFalse("Power Level sgould be false",res); + void setPowerLevel() { + when(mappingUtils.getOpenRoadmVersion(anyString())).thenReturn(OPENROADM_DEVICE_VERSION_1_2_1); + boolean res = crossConnectImpl.setPowerLevel("nodeId", "bad mode", Decimal64.valueOf("1"), "connection number"); + assertFalse(res, "Power Level sgould be false"); - String devV121 = "(http://org/openroadm/device?revision=2017-02-06)org-openroadm-device"; - when(mappingUtils.getOpenRoadmVersion(any())).thenReturn(devV121); + when(mappingUtils.getOpenRoadmVersion(any())).thenReturn(OPENROADM_DEVICE_VERSION_1_2_1); when(crossConnectImpl121.setPowerLevel(any(), any(), any(), any())) .thenReturn(true); - //FIXME: this part of the test needs to be reviewed - crossConnectImpl.setPowerLevel("100", "srcTp", Decimal64.valueOf("100"), "power"); - Assert.assertTrue(true); + crossConnectImpl.setPowerLevel("nodeId", "power", Decimal64.valueOf("1"), "connection number"); + assertTrue(true); } } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/device/DeviceTransactionManagerTest.java b/common/src/test/java/org/opendaylight/transportpce/common/device/DeviceTransactionManagerTest.java index b423d4bbc..885de6d24 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/device/DeviceTransactionManagerTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/device/DeviceTransactionManagerTest.java @@ -8,7 +8,12 @@ package org.opendaylight.transportpce.common.device; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.when; import java.util.LinkedList; import java.util.List; @@ -17,15 +22,13 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.MountPoint; import org.opendaylight.mdsal.binding.api.MountPointService; @@ -39,8 +42,7 @@ import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DeviceTransactionManagerTest { @Mock @@ -62,28 +64,28 @@ public class DeviceTransactionManagerTest { private long defaultTimeout = 1000; private TimeUnit defaultTimeUnit = TimeUnit.MILLISECONDS; - @Before - public void before() { - Mockito.when(mountPointServiceMock.getMountPoint(any())).thenReturn(Optional.of(mountPointMock)); - Mockito.when(mountPointMock.getService(any())).thenReturn(Optional.of(dataBrokerMock)); - Mockito.when(dataBrokerMock.newReadWriteTransaction()).thenReturn(rwTransactionMock); - Mockito.when(rwTransactionMock.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); + @BeforeEach + void before() { + when(mountPointServiceMock.getMountPoint(any())).thenReturn(Optional.of(mountPointMock)); + when(mountPointMock.getService(any())).thenReturn(Optional.of(dataBrokerMock)); + when(dataBrokerMock.newReadWriteTransaction()).thenReturn(rwTransactionMock); + lenient().when(rwTransactionMock.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); NetworkId networkId = new NetworkId("NETWORK1"); defaultData = new NetworkBuilder().setNetworkId(networkId).build(); this.transactionManager = new DeviceTransactionManagerImpl(mountPointServiceMock, 3000); } - @After - public void after() { + @AfterEach + void after() { transactionManager.preDestroy(); } @Test - public void basicPositiveTransactionTest() { + void basicPositiveTransactionTest() { try { putAndSubmit(transactionManager, defaultDeviceId, defaultDatastore, defaultIid, defaultData); } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); return; } @@ -92,8 +94,7 @@ public class DeviceTransactionManagerTest { } @Test - @Ignore - public void advancedPositiveTransactionTest() { + void advancedPositiveTransactionTest() { try { Future> firstDeviceTxFuture = transactionManager.getDeviceTransaction(defaultDeviceId); @@ -101,36 +102,37 @@ public class DeviceTransactionManagerTest { Future> secondDeviceTxFuture = transactionManager.getDeviceTransaction(defaultDeviceId); - Assert.assertFalse(secondDeviceTxFuture.isDone()); + assertFalse(secondDeviceTxFuture.isDone()); Future> thirdDeviceTxFuture = transactionManager.getDeviceTransaction(defaultDeviceId); - Assert.assertFalse(thirdDeviceTxFuture.isDone()); + assertFalse(thirdDeviceTxFuture.isDone()); firstDeviceTx.put(defaultDatastore, defaultIid, defaultData); - Assert.assertFalse(secondDeviceTxFuture.isDone()); - Assert.assertFalse(thirdDeviceTxFuture.isDone()); + assertFalse(secondDeviceTxFuture.isDone()); + assertFalse(thirdDeviceTxFuture.isDone()); Thread.sleep(200); - Assert.assertFalse(secondDeviceTxFuture.isDone()); - Assert.assertFalse(thirdDeviceTxFuture.isDone()); + assertFalse(secondDeviceTxFuture.isDone()); + assertFalse(thirdDeviceTxFuture.isDone()); Future> anotherDeviceTxFuture = transactionManager.getDeviceTransaction("another-id"); - Assert.assertTrue(anotherDeviceTxFuture.isDone()); + Thread.sleep(50); + assertTrue(anotherDeviceTxFuture.isDone()); anotherDeviceTxFuture.get().get().commit(defaultTimeout, defaultTimeUnit); firstDeviceTx.commit(defaultTimeout, defaultTimeUnit); Thread.sleep(200); - Assert.assertTrue(secondDeviceTxFuture.isDone()); - Assert.assertFalse(thirdDeviceTxFuture.isDone()); + assertTrue(secondDeviceTxFuture.isDone()); + assertFalse(thirdDeviceTxFuture.isDone()); DeviceTransaction secondDeviceTx = secondDeviceTxFuture.get().get(); secondDeviceTx.put(defaultDatastore, defaultIid, defaultData); - Assert.assertFalse(thirdDeviceTxFuture.isDone()); + assertFalse(thirdDeviceTxFuture.isDone()); secondDeviceTx.commit(defaultTimeout, defaultTimeUnit); Thread.sleep(200); - Assert.assertTrue(thirdDeviceTxFuture.isDone()); + assertTrue(thirdDeviceTxFuture.isDone()); DeviceTransaction thirdDeviceTx = thirdDeviceTxFuture.get().get(); thirdDeviceTx.put(defaultDatastore, defaultIid, defaultData); @@ -139,12 +141,12 @@ public class DeviceTransactionManagerTest { Mockito.verify(rwTransactionMock, Mockito.times(3)).put(defaultDatastore, defaultIid, defaultData); Mockito.verify(rwTransactionMock, Mockito.times(4)).commit(); } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); } } @Test - public void bigAmountOfTransactionsOnSameDeviceTest() { + void bigAmountOfTransactionsOnSameDeviceTest() { int numberOfTxs = 100; List>> deviceTransactionFutures = new LinkedList<>(); List deviceTransactions = new LinkedList<>(); @@ -160,16 +162,16 @@ public class DeviceTransactionManagerTest { deviceTransactions.add(deviceTx); } } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); } for (DeviceTransaction deviceTx : deviceTransactions) { - Assert.assertTrue(deviceTx.wasSubmittedOrCancelled().get()); + assertTrue(deviceTx.wasSubmittedOrCancelled().get()); } } @Test - public void bigAmountOfTransactionsOnDifferentDevicesTest() { + void bigAmountOfTransactionsOnDifferentDevicesTest() { int numberOfTxs = 1000; List deviceTransactions = new LinkedList<>(); @@ -178,18 +180,18 @@ public class DeviceTransactionManagerTest { deviceTransactions.add(transactionManager.getDeviceTransaction(defaultDeviceId + " " + i).get().get()); } } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); } deviceTransactions.parallelStream() .forEach(deviceTransaction -> deviceTransaction.commit(defaultTimeout, defaultTimeUnit)); deviceTransactions.parallelStream() - .forEach(deviceTransaction -> Assert.assertTrue(deviceTransaction.wasSubmittedOrCancelled().get())); + .forEach(deviceTransaction -> assertTrue(deviceTransaction.wasSubmittedOrCancelled().get())); } @Test - public void bigAmountOfTransactionsOnDifferentDevicesWithoutSubmitTest() { + void bigAmountOfTransactionsOnDifferentDevicesWithoutSubmitTest() { int numberOfTxs = 1000; List deviceTransactions = new LinkedList<>(); @@ -198,34 +200,34 @@ public class DeviceTransactionManagerTest { deviceTransactions.add(transactionManager.getDeviceTransaction(defaultDeviceId + " " + i).get().get()); } } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); } try { Thread.sleep(transactionManager.getMaxDurationToSubmitTransaction() + 1000); } catch (InterruptedException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); } deviceTransactions.parallelStream() - .forEach(deviceTransaction -> Assert.assertTrue(deviceTransaction.wasSubmittedOrCancelled().get())); + .forEach(deviceTransaction -> assertTrue(deviceTransaction.wasSubmittedOrCancelled().get())); } @Test - public void notSubmittedTransactionTest() { + void notSubmittedTransactionTest() { Future> deviceTxFuture = transactionManager.getDeviceTransaction(defaultDeviceId); try { deviceTxFuture.get(); Thread.sleep(transactionManager.getMaxDurationToSubmitTransaction() + 1000); } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); } Mockito.verify(rwTransactionMock, Mockito.times(1)).cancel(); try { putAndSubmit(transactionManager, defaultDeviceId, defaultDatastore, defaultIid, defaultData); } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); return; } @@ -235,7 +237,7 @@ public class DeviceTransactionManagerTest { } @Test - public void dataBrokerTimeoutTransactionTest() { + void dataBrokerTimeoutTransactionTest() { Mockito.when(dataBrokerMock.newReadWriteTransaction()).then(invocation -> { Thread.sleep(transactionManager.getMaxDurationToSubmitTransaction() + 1000); return rwTransactionMock; @@ -244,7 +246,7 @@ public class DeviceTransactionManagerTest { try { putAndSubmit(transactionManager, defaultDeviceId, defaultDatastore, defaultIid, defaultData); } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); } Mockito.verify(rwTransactionMock, Mockito.times(1)).commit(); @@ -254,7 +256,7 @@ public class DeviceTransactionManagerTest { try { putAndSubmit(transactionManager, defaultDeviceId, defaultDatastore, defaultIid, defaultData); } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); return; } @@ -263,7 +265,7 @@ public class DeviceTransactionManagerTest { } @Test - public void getFutureTimeoutTransactionTest() { + void getFutureTimeoutTransactionTest() { Mockito.when(dataBrokerMock.newReadWriteTransaction()).then(invocation -> { Thread.sleep(3000); return rwTransactionMock; @@ -276,13 +278,13 @@ public class DeviceTransactionManagerTest { try { deviceTxFuture.get(1000, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); } catch (TimeoutException e) { throwedException = e; } if (throwedException == null) { - Assert.fail("TimeoutException should be thrown!"); + fail("TimeoutException should be thrown!"); return; } @@ -291,7 +293,7 @@ public class DeviceTransactionManagerTest { try { putAndSubmit(transactionManager, defaultDeviceId, defaultDatastore, defaultIid, defaultData); } catch (InterruptedException | ExecutionException e) { - Assert.fail("Exception catched! " + e); + fail("Exception catched! " + e); return; } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/fixedflex/GridUtilsTest.java b/common/src/test/java/org/opendaylight/transportpce/common/fixedflex/GridUtilsTest.java index 9ce4b3fac..00df8dbfa 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/fixedflex/GridUtilsTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/fixedflex/GridUtilsTest.java @@ -8,13 +8,15 @@ package org.opendaylight.transportpce.common.fixedflex; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; import java.util.Arrays; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.transportpce.common.ServiceRateConstant; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInputBuilder; @@ -29,98 +31,108 @@ import org.opendaylight.yangtools.yang.common.Uint32; public class GridUtilsTest { @Test - public void getWaveLengthIndexFromSpectrumAssigmentTest() { - assertEquals("Wavelength index should be 15", 15, GridUtils.getWaveLengthIndexFromSpectrumAssigment(647)); + void getWaveLengthIndexFromSpectrumAssigmentTest() { + assertEquals(15, GridUtils.getWaveLengthIndexFromSpectrumAssigment(647), "Wavelength index should be 15"); } @Test - public void getFrequencyFromIndexTest() { + void getFrequencyFromIndexTest() { BigDecimal[] expectedFrequencies = new BigDecimal[768]; BigDecimal frequency = BigDecimal.valueOf(191.325); for (int i = 0; i < expectedFrequencies.length; i++) { expectedFrequencies[i] = frequency; frequency = frequency.add(BigDecimal.valueOf(0.00625)); } - assertEquals("Frequency should be 191.325", 0, expectedFrequencies[0] - .compareTo(GridUtils.getStartFrequencyFromIndex(0))); - assertEquals("Frequency should be 193.1", 0, expectedFrequencies[284] - .compareTo(GridUtils.getStartFrequencyFromIndex(284))); - assertEquals("Frequency should be 196.1188", 0, expectedFrequencies[767] - .compareTo(GridUtils.getStartFrequencyFromIndex(767))); + assertEquals(0, expectedFrequencies[0].compareTo(GridUtils.getStartFrequencyFromIndex(0)), + "Frequency should be 191.325"); + assertEquals(0, expectedFrequencies[284].compareTo(GridUtils.getStartFrequencyFromIndex(284)), + "Frequency should be 193.1"); + assertEquals(0, expectedFrequencies[767].compareTo(GridUtils.getStartFrequencyFromIndex(767)), + "Frequency should be 196.1188"); } @Test - public void initFreqMaps4FixedGrid2AvailableTest() { + void initFreqMaps4FixedGrid2AvailableTest() { AvailFreqMapsKey key = new AvailFreqMapsKey(GridConstant.C_BAND); byte[] byteArray = new byte[GridConstant.NB_OCTECTS]; Arrays.fill(byteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE); Map availFreqMaps = GridUtils.initFreqMaps4FixedGrid2Available(); - assertEquals("Should contains 1 element", 1, availFreqMaps.size()); - assertTrue("should contains cband key", availFreqMaps.containsKey(key)); - assertTrue("Should have available freq map", Arrays.equals(byteArray, availFreqMaps.get(key).getFreqMap())); + assertEquals(1, availFreqMaps.size(), "Should contains 1 element"); + assertTrue(availFreqMaps.containsKey(key), "should contains cband key"); + assertTrue(Arrays.equals(byteArray, availFreqMaps.get(key).getFreqMap()), "Should have available freq map"); } @Test - public void getIndexFromFrequencyTest() { - assertEquals("Index should be 693", 693, GridUtils.getIndexFromFrequency(Decimal64.valueOf("195.65625"))); - assertEquals("Index should be 0", 0, GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.325"))); - assertEquals("Index should be 767", 767, GridUtils.getIndexFromFrequency(Decimal64.valueOf("196.11875"))); - assertEquals("Index should be 8", 8, GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.375"))); - assertEquals("Index should be 15", 15, GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.41875"))); - assertEquals("Index should be 768", 768, GridUtils.getIndexFromFrequency(Decimal64.valueOf("196.125"))); + void getIndexFromFrequencyTest() { + assertEquals(693, GridUtils.getIndexFromFrequency(Decimal64.valueOf("195.65625")), "Index should be 693"); + assertEquals(0, GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.325")), "Index should be 0"); + assertEquals(767, GridUtils.getIndexFromFrequency(Decimal64.valueOf("196.11875")), "Index should be 767"); + assertEquals(8, GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.375")), "Index should be 8"); + assertEquals(15, GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.41875")), "Index should be 15"); + assertEquals(768, GridUtils.getIndexFromFrequency(Decimal64.valueOf("196.125")), "Index should be 768"); } - @Test(expected = IllegalArgumentException.class) - public void getIndexFromFrequencyExceptionTest() { - GridUtils.getIndexFromFrequency(Decimal64.valueOf("196.13125")); + @Test + void getIndexFromFrequencyExceptionTest() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { + GridUtils.getIndexFromFrequency(Decimal64.valueOf("196.13125")); + }); + assertEquals("Frequency not in range 196.13125", exception.getMessage()); } - @Test(expected = IllegalArgumentException.class) - public void getIndexFromFrequencyException2Test() { - GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.31875")); + @Test + void getIndexFromFrequencyException2Test() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { + GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.31875")); + }); + assertEquals("Frequency not in range 191.31875", exception.getMessage()); } @Test - public void getWidthFromRateAndModulationFormatTest() { - assertEquals("Width should be 75", new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_75)), - GridUtils.getWidthFromRateAndModulationFormat(ServiceRateConstant.RATE_400, - ModulationFormat.DpQam16)); + void getWidthFromRateAndModulationFormatTest() { + assertEquals( + new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_75)), + GridUtils.getWidthFromRateAndModulationFormat(ServiceRateConstant.RATE_400, ModulationFormat.DpQam16), + "Width should be 75"); } @Test - public void getWidthFromRateAndModulationFormatNotFoundTest() { - assertEquals("As not found width should be 40", new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)), - GridUtils.getWidthFromRateAndModulationFormat(ServiceRateConstant.RATE_100, - ModulationFormat.DpQam16)); + void getWidthFromRateAndModulationFormatNotFoundTest() { + assertEquals( + new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)), + GridUtils.getWidthFromRateAndModulationFormat(ServiceRateConstant.RATE_100, ModulationFormat.DpQam16), + "As not found width should be 40"); } @Test - public void getCentralFrequencyTest() { - assertEquals("Central frequency should be 191.350", - new FrequencyTHz(Decimal64.valueOf(BigDecimal.valueOf(191.35).setScale(3))), - GridUtils.getCentralFrequency(BigDecimal.valueOf(191.325), BigDecimal.valueOf(191.375))); + void getCentralFrequencyTest() { + assertEquals( + new FrequencyTHz(Decimal64.valueOf(BigDecimal.valueOf(191.35).setScale(3))), + GridUtils.getCentralFrequency(BigDecimal.valueOf(191.325), BigDecimal.valueOf(191.375)), + "Central frequency should be 191.350"); } @Test - public void getCentralFrequencyWithPrecisionTest() { - assertEquals("Central frequency should be 191.3500", - new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz( - Decimal64.valueOf(BigDecimal.valueOf(191.35).setScale(4))), - GridUtils.getCentralFrequencyWithPrecision(BigDecimal.valueOf(191.325), - BigDecimal.valueOf(191.375), 4)); + void getCentralFrequencyWithPrecisionTest() { + assertEquals( + new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz( + Decimal64.valueOf(BigDecimal.valueOf(191.35).setScale(4))), + GridUtils.getCentralFrequencyWithPrecision(BigDecimal.valueOf(191.325), BigDecimal.valueOf(191.375), 4), + "Central frequency should be 191.3500"); } @Test - public void getCentralFrequencyWithPrecisionAndRoundTest() { - assertEquals("Central frequency should be 191.3499", - new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz( + void getCentralFrequencyWithPrecisionAndRoundTest() { + assertEquals( + new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz( Decimal64.valueOf("191.3499")), - GridUtils.getCentralFrequencyWithPrecision(BigDecimal.valueOf(191.3244445), - BigDecimal.valueOf(191.3754457788), 4)); + GridUtils.getCentralFrequencyWithPrecision( + BigDecimal.valueOf(191.3244445), BigDecimal.valueOf(191.3754457788), 4), + "Central frequency should be 191.3499"); } @Test - public void initSpectrumInformationFromServicePathInputTest() { + void initSpectrumInformationFromServicePathInputTest() { ServicePathInput input = new ServicePathInputBuilder() .setWaveNumber(Uint32.valueOf(1)) .setCenterFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019 @@ -135,20 +147,20 @@ public class GridUtilsTest { .FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40))) .build(); SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input); - assertEquals("Width should be 40", BigDecimal.valueOf(40), spectrumInformation.getWidth()); - assertEquals("Wavelength should be 1", Uint32.valueOf(1), spectrumInformation.getWaveLength()); - assertEquals("Center freq should be 196.1", BigDecimal.valueOf(196.1).setScale(4), - spectrumInformation.getCenterFrequency()); - assertEquals("Lower slot number should be 761", 761, spectrumInformation.getLowerSpectralSlotNumber()); - assertEquals("Higher slot number should be 768", 768, spectrumInformation.getHigherSpectralSlotNumber()); - assertEquals("Min freq should be 196.075", BigDecimal.valueOf(196.075).setScale(4), - spectrumInformation.getMinFrequency()); - assertEquals("Max freq should be 196.125", BigDecimal.valueOf(196.125).setScale(4), - spectrumInformation.getMaxFrequency()); + assertEquals(BigDecimal.valueOf(40), spectrumInformation.getWidth(), "Width should be 40"); + assertEquals(Uint32.valueOf(1), spectrumInformation.getWaveLength(), "Wavelength should be 1"); + assertEquals(BigDecimal.valueOf(196.1).setScale(4), spectrumInformation.getCenterFrequency(), + "Center freq should be 196.1"); + assertEquals(761, spectrumInformation.getLowerSpectralSlotNumber(), "Lower slot number should be 761"); + assertEquals(768, spectrumInformation.getHigherSpectralSlotNumber(), "Higher slot number should be 768"); + assertEquals(BigDecimal.valueOf(196.075).setScale(4), spectrumInformation.getMinFrequency(), + "Min freq should be 196.075"); + assertEquals(BigDecimal.valueOf(196.125).setScale(4), spectrumInformation.getMaxFrequency(), + "Max freq should be 196.125"); } @Test - public void initSpectrumInformationFromServicePathInputNoCenterFreqTest() { + void initSpectrumInformationFromServicePathInputNoCenterFreqTest() { ServicePathInput input = new ServicePathInputBuilder() .setWaveNumber(Uint32.valueOf(1)) .setHigherSpectralSlotNumber(Uint32.valueOf(768)) @@ -161,20 +173,20 @@ public class GridUtilsTest { .FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40))) .build(); SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input); - assertEquals("Width should be 40", BigDecimal.valueOf(40), spectrumInformation.getWidth()); - assertEquals("Wavelength should be 1", Uint32.valueOf(1), spectrumInformation.getWaveLength()); - assertEquals("Center freq should be 196.1", BigDecimal.valueOf(196.1).setScale(4), - spectrumInformation.getCenterFrequency()); - assertEquals("Lower slot number should be 761", 761, spectrumInformation.getLowerSpectralSlotNumber()); - assertEquals("Higher slot number should be 768", 768, spectrumInformation.getHigherSpectralSlotNumber()); - assertEquals("Min freq should be 196.075", BigDecimal.valueOf(196.075).setScale(4), - spectrumInformation.getMinFrequency()); - assertEquals("Max freq should be 196.125", BigDecimal.valueOf(196.125).setScale(4), - spectrumInformation.getMaxFrequency()); + assertEquals(BigDecimal.valueOf(40), spectrumInformation.getWidth(), "Width should be 40"); + assertEquals(Uint32.valueOf(1), spectrumInformation.getWaveLength(), "Wavelength should be 1"); + assertEquals(BigDecimal.valueOf(196.1).setScale(4), spectrumInformation.getCenterFrequency(), + "Center freq should be 196.1"); + assertEquals(761, spectrumInformation.getLowerSpectralSlotNumber(), "Lower slot number should be 761"); + assertEquals(768, spectrumInformation.getHigherSpectralSlotNumber(), "Higher slot number should be 768"); + assertEquals(BigDecimal.valueOf(196.075).setScale(4), spectrumInformation.getMinFrequency(), + "Min freq should be 196.075"); + assertEquals(BigDecimal.valueOf(196.125).setScale(4), spectrumInformation.getMaxFrequency(), + "Max freq should be 196.125"); } @Test - public void initSpectrumInformationFromServicePathInputNoFreqTest() { + void initSpectrumInformationFromServicePathInputNoFreqTest() { ServicePathInput input = new ServicePathInputBuilder() .setWaveNumber(Uint32.valueOf(1)) .setHigherSpectralSlotNumber(Uint32.valueOf(768)) @@ -183,20 +195,23 @@ public class GridUtilsTest { .FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40))) .build(); SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input); - assertEquals("Width should be 40", BigDecimal.valueOf(40), spectrumInformation.getWidth()); - assertEquals("Wavelength should be 1", Uint32.valueOf(1), spectrumInformation.getWaveLength()); - assertEquals("Center freq should be 196.1", BigDecimal.valueOf(196.1).setScale(4), - spectrumInformation.getCenterFrequency()); - assertEquals("Lower slot number should be 761", 761, spectrumInformation.getLowerSpectralSlotNumber()); - assertEquals("Higher slot number should be 768", 768, spectrumInformation.getHigherSpectralSlotNumber()); - assertEquals("Min freq should be 196.075", BigDecimal.valueOf(196.075).setScale(4), - spectrumInformation.getMinFrequency()); - assertEquals("Max freq should be 196.125", BigDecimal.valueOf(196.125).setScale(4), - spectrumInformation.getMaxFrequency()); + assertEquals(BigDecimal.valueOf(40), spectrumInformation.getWidth(), "Width should be 40"); + assertEquals(Uint32.valueOf(1), spectrumInformation.getWaveLength(), "Wavelength should be 1"); + assertEquals(BigDecimal.valueOf(196.1).setScale(4), spectrumInformation.getCenterFrequency(), + "Center freq should be 196.1"); + assertEquals(761, spectrumInformation.getLowerSpectralSlotNumber(), "Lower slot number should be 761"); + assertEquals(768, spectrumInformation.getHigherSpectralSlotNumber(), "Higher slot number should be 768"); + assertEquals(BigDecimal.valueOf(196.075).setScale(4), spectrumInformation.getMinFrequency(), + "Min freq should be 196.075"); + assertEquals(BigDecimal.valueOf(196.125).setScale(4), spectrumInformation.getMaxFrequency(), + "Max freq should be 196.125"); } - @Test(expected = IllegalArgumentException.class) - public void initSpectrumInformationFromServicePathInputNoSlotTest() { - GridUtils.initSpectrumInformationFromServicePathInput(new ServicePathInputBuilder().build()); + @Test + void initSpectrumInformationFromServicePathInputNoSlotTest() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { + GridUtils.initSpectrumInformationFromServicePathInput(new ServicePathInputBuilder().build()); + }); + assertEquals("low and higher spectral slot numbers cannot be null", exception.getMessage()); } } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/mapping/MappingUtilsImplTest.java b/common/src/test/java/org/opendaylight/transportpce/common/mapping/MappingUtilsImplTest.java index a9a72c51e..acbb77d70 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/mapping/MappingUtilsImplTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/mapping/MappingUtilsImplTest.java @@ -8,10 +8,11 @@ package org.opendaylight.transportpce.common.mapping; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.FileNotFoundException; import java.io.FileReader; @@ -19,8 +20,8 @@ import java.io.IOException; import java.io.Reader; import java.nio.charset.StandardCharsets; import java.util.concurrent.ExecutionException; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.opendaylight.mdsal.binding.api.WriteTransaction; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.transportpce.common.StringConstants; @@ -38,8 +39,8 @@ public class MappingUtilsImplTest extends AbstractTest { private static final Logger LOG = LoggerFactory.getLogger(MappingUtilsImplTest.class); private static MappingUtils mappingUtils; - @BeforeClass - public static void setUp() throws InterruptedException, ExecutionException, FileNotFoundException { + @BeforeAll + static void setUp() throws InterruptedException, ExecutionException, FileNotFoundException { DataObjectConverter dataObjectConverter = JSONDataObjectConverter .createWithDataStoreUtil(getDataStoreContextUtil()); try (Reader reader = new FileReader("src/test/resources/network.json", StandardCharsets.UTF_8)) { @@ -60,23 +61,19 @@ public class MappingUtilsImplTest extends AbstractTest { } @Test - public void getOpenRoadmVersionTest() throws ExecutionException, InterruptedException { - assertEquals("NodeInfo with ROADM-C1 as id should be 1.2.1 version", - StringConstants.OPENROADM_DEVICE_VERSION_1_2_1, - mappingUtils.getOpenRoadmVersion("ROADM-C1")); - assertEquals("NodeInfo with ROADM-A1 as id should be 2.2.1 version", - StringConstants.OPENROADM_DEVICE_VERSION_2_2_1, - mappingUtils.getOpenRoadmVersion("ROADM-A1")); - assertNull("NodeInfo with nodes3 as id should not exist", mappingUtils.getOpenRoadmVersion("nodes3")); + void getOpenRoadmVersionTest() throws ExecutionException, InterruptedException { + assertEquals(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1, mappingUtils.getOpenRoadmVersion("ROADM-C1"), + "NodeInfo with ROADM-C1 as id should be 1.2.1 version"); + assertEquals(StringConstants.OPENROADM_DEVICE_VERSION_2_2_1, mappingUtils.getOpenRoadmVersion("ROADM-A1"), + "NodeInfo with ROADM-A1 as id should be 2.2.1 version"); + assertNull(mappingUtils.getOpenRoadmVersion("nodes3"), "NodeInfo with nodes3 as id should not exist"); } @Test - public void getMcCapabilitiesForNodeTest() { - assertEquals("Mc capabilities list size should be 2", 2, - mappingUtils.getMcCapabilitiesForNode("ROADM-A1").size()); - assertTrue("Mc capabilities list size should be empty", - mappingUtils.getMcCapabilitiesForNode("ROADM-A2").isEmpty()); + void getMcCapabilitiesForNodeTest() { + assertEquals(2, mappingUtils.getMcCapabilitiesForNode("ROADM-A1").size(), + "Mc capabilities list size should be 2"); + assertTrue(mappingUtils.getMcCapabilitiesForNode("ROADM-A2").isEmpty(), + "Mc capabilities list size should be empty"); } - - } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/mapping/PortMappingImplTest.java b/common/src/test/java/org/opendaylight/transportpce/common/mapping/PortMappingImplTest.java index 68dcb9706..132b3d45c 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/mapping/PortMappingImplTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/mapping/PortMappingImplTest.java @@ -8,19 +8,19 @@ package org.opendaylight.transportpce.common.mapping; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.opendaylight.transportpce.common.StringConstants.OPENROADM_DEVICE_VERSION_1_2_1; import static org.opendaylight.transportpce.common.StringConstants.OPENROADM_DEVICE_VERSION_2_2_1; import java.util.concurrent.ExecutionException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.WriteTransaction; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; @@ -46,8 +46,8 @@ public class PortMappingImplTest { private PortMappingVersion121 portMappingVersion121; private PortMapping portMapping; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { DataStoreContext dataStoreContext = new DataStoreContextImpl(); dataBroker = dataStoreContext.getDataBroker(); portMappingVersion710 = mock(PortMappingVersion710.class); @@ -58,7 +58,7 @@ public class PortMappingImplTest { } @Test - public void createMappingDataTest() { + void createMappingDataTest() { //test create mapping version 1 when(portMappingVersion121.createMappingData("node")).thenReturn(true); assertTrue(portMapping.createMappingData("node", OPENROADM_DEVICE_VERSION_1_2_1)); @@ -71,9 +71,8 @@ public class PortMappingImplTest { assertFalse(portMapping.createMappingData("node", "test")); } - @Test - public void updateMappingTest() throws ExecutionException, InterruptedException { + void updateMappingTest() throws ExecutionException, InterruptedException { Mapping mapping = new MappingBuilder().setLogicalConnectionPoint("logicalConnectionPoint") .setPortDirection("1").setConnectionMapLcp("1").setPartnerLcp("1") .setPortQual("1").setSupportingCircuitPackName("1").setSupportingOms("1") @@ -97,7 +96,7 @@ public class PortMappingImplTest { wr.commit().get(); //test update port mapping version 2 when(portMappingVersion221.updateMapping("node", mapping)).thenReturn(true); - assertTrue("Update sould be ok", portMapping.updateMapping("node", mapping)); + assertTrue(portMapping.updateMapping("node", mapping), "Update sould be ok"); //replace node nodefino version 1 instead of version 2 WriteTransaction wr2 = dataBroker.newWriteOnlyTransaction(); @@ -115,15 +114,12 @@ public class PortMappingImplTest { assertNull(portMapping.getNode("node2")); //test get portmapping for existing node - assertEquals(portMapping - .getMapping("node", "logicalConnectionPoint"), mapping); + assertEquals(portMapping.getMapping("node", "logicalConnectionPoint"), mapping); //test delete portmapping for existing node portMapping.deletePortMappingNode("node"); //test get portmapping that was deleted above and doesn't exist anymore assertNull(portMapping.getMapping("node", "logicalConnectionPoint")); - } - } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121Test.java b/common/src/test/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121Test.java index 872214436..366c9fc66 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121Test.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121Test.java @@ -8,10 +8,10 @@ package org.opendaylight.transportpce.common.mapping; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -25,8 +25,8 @@ import java.util.Optional; import java.util.Random; import java.util.concurrent.ExecutionException; import org.eclipse.jdt.annotation.NonNull; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.ReadTransaction; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; @@ -99,8 +99,8 @@ public class PortMappingVersion121Test { private static PortMappingVersion121 portMappingVersion121; private Random ran = new Random(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { // test createMappingData for a xpdr node with 3 network + 1 client + bidirectional & unidirectional ports DataStoreContext dataStoreContext = new DataStoreContextImpl(); dataBroker = dataStoreContext.getDataBroker(); @@ -109,7 +109,7 @@ public class PortMappingVersion121Test { } @Test - public void createMappingDataTestRdm() { + void createMappingDataTestRdm() { // mock node info final Info info = getInfo2(); @@ -449,8 +449,8 @@ public class PortMappingVersion121Test { .thenReturn(Optional.of(ordmSrgObject6)); // test createMappingData with a node with 3 dgree + 3 srg + bidirectional & unidirectional ports - assertTrue("creating mappingdata for existed node returns true", - portMappingVersion121.createMappingData("node")); + assertTrue(portMappingVersion121.createMappingData("node"), + "creating mappingdata for existed node returns true"); // assert all portmappings have been created for the roadm node ReadTransaction rr = dataBroker.newReadOnlyTransaction(); @@ -465,7 +465,6 @@ public class PortMappingVersion121Test { } catch (ExecutionException | InterruptedException e) { LOG.error("Failed to read mapping.", e); fail(); - } List testMappings = Arrays.asList("SRG2-PP1-RX", "SRG3-PP1-RX", "SRG1-PP1-TXRX", "SRG3-PP1-TX", "DEG1-TTP-TXRX", "SRG2-PP1-TX", "DEG2-TTP-RX", "DEG2-TTP-TX", "DEG3-TTP-RX", "DEG3-TTP-TX"); @@ -477,23 +476,23 @@ public class PortMappingVersion121Test { } Collections.sort(testMappings); Collections.sort(mappings); - assertEquals("test mapping are equals to mapping", testMappings, mappings); + assertEquals(testMappings, mappings, "test mapping are equals to mapping"); // test updateMapping - assertTrue("update mapping for node returns true", - portMappingVersion121.updateMapping("node", mappingValues.get(0))); + assertTrue(portMappingVersion121.updateMapping("node", mappingValues.get(0)), + "update mapping for node returns true"); // test createMapping for non-existent roadm node - assertFalse("create non existed roadm node returns false", portMappingVersion121.createMappingData("node2")); + assertFalse(portMappingVersion121.createMappingData("node2"), "create non existed roadm node returns false"); // test updateMapping for null roadm node - assertFalse("updating null roadm node returns false", - portMappingVersion121.updateMapping(null, mappingValues.get(0))); + assertFalse(portMappingVersion121.updateMapping(null, mappingValues.get(0)), + "updating null roadm node returns false"); } @Test - public void createMappingDataTestXpdr() { + void createMappingDataTestXpdr() { // mock node info final Info info = getInfo(); @@ -619,7 +618,7 @@ public class PortMappingVersion121Test { Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT)).thenReturn(Optional.of(deviceObject)); // test createMappingData for xpdr node with 2 network + 1 client + unidirectional & bidirectional ports - assertTrue("returns true when create mapping ", portMappingVersion121.createMappingData("node")); + assertTrue(portMappingVersion121.createMappingData("node"), "returns true when create mapping"); // assert all portmappings have been created for the xpdr node ReadTransaction rr = dataBroker.newReadOnlyTransaction(); @@ -645,7 +644,7 @@ public class PortMappingVersion121Test { } Collections.sort(testMappings); Collections.sort(mappings); - assertEquals("test mapping are equals to mapping", testMappings, mappings); + assertEquals(testMappings, mappings, "test mapping are equals to mapping"); } @NonNull @@ -708,5 +707,4 @@ public class PortMappingVersion121Test { private Interfaces getInterfaces(String i1) { return new InterfacesBuilder().setInterfaceName(i1).build(); } - } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/mapping/SortPort121ByNameTest.java b/common/src/test/java/org/opendaylight/transportpce/common/mapping/SortPort121ByNameTest.java index 646184645..3c5fe3318 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/mapping/SortPort121ByNameTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/mapping/SortPort121ByNameTest.java @@ -8,17 +8,17 @@ package org.opendaylight.transportpce.common.mapping; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.Port; public class SortPort121ByNameTest { @Test - public void compareTest() { + void compareTest() { Port port1 = mock(Port.class); Port port2 = mock(Port.class); when(port1.getPortName()).thenReturn("port1"); diff --git a/common/src/test/java/org/opendaylight/transportpce/common/mapping/SortPort221ByNameTest.java b/common/src/test/java/org/opendaylight/transportpce/common/mapping/SortPort221ByNameTest.java index ceb55557b..dec91c671 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/mapping/SortPort221ByNameTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/mapping/SortPort221ByNameTest.java @@ -8,17 +8,17 @@ package org.opendaylight.transportpce.common.mapping; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.Port; public class SortPort221ByNameTest { @Test - public void compareTest() { + void compareTest() { Port port1 = mock(Port.class); Port port2 = mock(Port.class); when(port1.getPortName()).thenReturn("port1"); diff --git a/common/src/test/java/org/opendaylight/transportpce/common/service/ServiceTypeTest.java b/common/src/test/java/org/opendaylight/transportpce/common/service/ServiceTypeTest.java index 3eeca57e0..b2fa4d60f 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/service/ServiceTypeTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/service/ServiceTypeTest.java @@ -8,10 +8,11 @@ package org.opendaylight.transportpce.common.service; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.MappingBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.PortQual; @@ -21,42 +22,42 @@ import org.opendaylight.yangtools.yang.common.Uint32; public class ServiceTypeTest { @Test - public void getServiceTypeForServiceFormatUnknownTest() { + void getServiceTypeForServiceFormatUnknownTest() { String serviceType = ServiceTypes.getServiceType("toto", null, null); - assertNull("service-type should be null", serviceType); + assertNull(serviceType, "service-type should be null"); } @Test - public void getServiceTypeForServiceFormatOCTest() { + void getServiceTypeForServiceFormatOCTest() { String serviceType = ServiceTypes.getServiceType("OC", Uint32.valueOf(100), null); - assertEquals("service-type should be 100GEt", "100GEt", serviceType); + assertEquals("100GEt", serviceType, "service-type should be 100GEt"); serviceType = ServiceTypes.getServiceType("OC", null, null); - assertNull("service-type should be null", serviceType); + assertNull(serviceType, "service-type should be null"); } @Test - public void getServiceTypeForServiceFormatEthernetTest() { + void getServiceTypeForServiceFormatEthernetTest() { String serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(400), null); - assertEquals("service-type should be 400GE", "400GE", serviceType); + assertEquals("400GE", serviceType, "service-type should be 400GE"); serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(100), null); - assertEquals("service-type should be 100GEt", "100GEt", serviceType); + assertEquals("100GEt", serviceType, "service-type should be 100GEt"); Mapping mapping = new MappingBuilder() .setLogicalConnectionPoint("logicalConnectionPoint") .setPortQual(PortQual.XpdrClient.getName()) .build(); serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(100), mapping); - assertEquals("service-type should be 100GEt", "100GEt", serviceType); + assertEquals("100GEt", serviceType, "service-type should be 100GEt"); mapping = new MappingBuilder() .setLogicalConnectionPoint("logicalConnectionPoint") .setPortQual(PortQual.SwitchClient.getName()) .build(); serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(100), mapping); - assertEquals("service-type should be 100GEm", "100GEm", serviceType); + assertEquals("100GEm", serviceType, "service-type should be 100GEm"); serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(10), mapping); - assertEquals("service-type should be 10GE", "10GE", serviceType); + assertEquals("10GE", serviceType, "service-type should be 10GE"); serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(1), mapping); - assertEquals("service-type should be 1GE", "1GE", serviceType); + assertEquals("1GE", serviceType, "service-type should be 1GE"); mapping = new MappingBuilder() .setLogicalConnectionPoint("logicalConnectionPoint") @@ -64,31 +65,30 @@ public class ServiceTypeTest { .setXponderType(XpdrNodeTypes.Switch) .build(); serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(100), mapping); - assertEquals("service-type should be 100GEs", "100GEs", serviceType); + assertEquals("100GEs", serviceType, "service-type should be 100GEs"); } @Test - public void getOtnServiceTypeForServiceFormatEthernetTest() { + void getOtnServiceTypeForServiceFormatEthernetTest() { String serviceType = ServiceTypes.getOtnServiceType("toto", Uint32.valueOf(123)); - assertNull("service-type should be null", serviceType); + assertNull(serviceType, "service-type should be null"); serviceType = ServiceTypes.getOtnServiceType("Ethernet", Uint32.valueOf(123)); - assertNull("service-type should be null", serviceType); + assertNull(serviceType, "service-type should be null"); serviceType = ServiceTypes.getOtnServiceType("Ethernet", Uint32.valueOf(1)); - assertEquals("service-type should be 1GE", "1GE", serviceType); + assertEquals("1GE", serviceType, "service-type should be 1GE"); serviceType = ServiceTypes.getOtnServiceType("Ethernet", Uint32.valueOf(10)); - assertEquals("service-type should be 10GE", "10GE", serviceType); + assertEquals("10GE", serviceType, "service-type should be 10GE"); serviceType = ServiceTypes.getOtnServiceType("Ethernet", Uint32.valueOf(100)); - assertEquals("service-type should be 100GEm", "100GEm", serviceType); + assertEquals("100GEm", serviceType, "service-type should be 100GEm"); serviceType = ServiceTypes.getOtnServiceType("OTU", Uint32.valueOf(100)); - assertEquals("service-type should be OTU4", "OTU4", serviceType); + assertEquals("OTU4", serviceType, "service-type should be OTU4"); serviceType = ServiceTypes.getOtnServiceType("OTU", Uint32.valueOf(400)); - assertEquals("service-type should be OTUC4", "OTUC4", serviceType); + assertEquals("OTUC4", serviceType, "service-type should be OTUC4"); serviceType = ServiceTypes.getOtnServiceType("ODU", Uint32.valueOf(100)); - assertEquals("service-type should be ODU4", "ODU4", serviceType); + assertEquals("ODU4", serviceType, "service-type should be ODU4"); serviceType = ServiceTypes.getOtnServiceType("ODU", Uint32.valueOf(400)); - assertEquals("service-type should be ODUC4", "ODUC4", serviceType); + assertEquals("ODUC4", serviceType, "service-type should be ODUC4"); } - } \ No newline at end of file