From: Gilles Thouenon Date: Mon, 27 Feb 2023 15:22:03 +0000 (+0100) Subject: Migrate servicehandler module to JUnit5 X-Git-Tag: 7.0.0~13 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=inline;h=82da799bdb2bcb570109af94a9099741ede8bdb6;p=transportpce.git Migrate servicehandler module to JUnit5 JIRA: TRNSPRTPCE-730 Signed-off-by: Gilles Thouenon Change-Id: Ib08d8e77f1bc436b176ffed7f7b76d46eae426d3 --- diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraintsTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraintsTest.java index abc8d502a..300b11697 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraintsTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraintsTest.java @@ -11,16 +11,16 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildHardConstraint; import static org.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildSoftConstraint; import java.util.Set; import org.hamcrest.collection.IsMapContaining; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType; import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.DiversityConstraints.DiversityType; import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.common.constraints.LinkIdentifierKey; @@ -37,7 +37,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev21 public class DowngradeConstraintsTest { @Test - public void testUpdateSoftConstraintsForCustomerCode() { + void testUpdateSoftConstraintsForCustomerCode() { // test no addition when hard customer-code is null or empty HardConstraints initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, null, null); @@ -45,8 +45,8 @@ public class DowngradeConstraintsTest { buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertNull("updated soft constraints should contain no customer code", - generatedSoftConstraints.getCustomerCode()); + assertNull(generatedSoftConstraints.getCustomerCode(), + "updated soft constraints should contain no customer code"); Set softCustomerCode = Set.of("soft-customer-code 3", "soft-customer-code 4"); initialSoftConstraints = buildSoftConstraint(softCustomerCode, false, null, null, null, null, false, false, null, null); @@ -61,14 +61,13 @@ public class DowngradeConstraintsTest { initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should contain the customer code of hard constraint", - generatedSoftConstraints.getCustomerCode(), - initialHardConstraints.getCustomerCode()); + assertEquals(generatedSoftConstraints.getCustomerCode(),initialHardConstraints.getCustomerCode(), + "updated soft constraints should contain the customer code of hard constraint"); // test addition of hard customer-code when existing soft customer-code initialSoftConstraints = buildSoftConstraint(softCustomerCode, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( - initialHardConstraints, initialSoftConstraints); + initialHardConstraints, initialSoftConstraints); assertThat("updated soft constraints should contain 4 customer code", generatedSoftConstraints.getCustomerCode(), hasSize(4)); assertThat(generatedSoftConstraints.getCustomerCode(), @@ -77,15 +76,15 @@ public class DowngradeConstraintsTest { } @Test - public void testUpdateSoftConstraintsForDiversity() { + void testUpdateSoftConstraintsForDiversity() { HardConstraints initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertNull("updated soft constraints should contain no diversity constraint", - generatedSoftConstraints.getDiversity()); + assertNull(generatedSoftConstraints.getDiversity(), + "updated soft constraints should contain no diversity constraint"); Set softDiversityServiceid = Set.of("soft-service 3"); initialSoftConstraints = buildSoftConstraint(null, false, softDiversityServiceid, null, null, null, false, false, null, null); @@ -100,9 +99,8 @@ public class DowngradeConstraintsTest { initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should contain the diversity of hard constraint", - generatedSoftConstraints.getDiversity(), - initialHardConstraints.getDiversity()); + assertEquals(generatedSoftConstraints.getDiversity(), initialHardConstraints.getDiversity(), + "updated soft constraints should contain the diversity of hard constraint"); // test addition of hard diversity when existing soft diversity initialSoftConstraints = @@ -111,9 +109,8 @@ public class DowngradeConstraintsTest { initialHardConstraints, initialSoftConstraints); assertThat("updated soft constraints should contain diversity with 3 services", generatedSoftConstraints.getDiversity().getServiceIdentifierList().size(), is(3)); - assertEquals("updated soft constraints should have diversity type of serial", - DiversityType.Serial, - generatedSoftConstraints.getDiversity().getDiversityType()); + assertEquals(DiversityType.Serial, generatedSoftConstraints.getDiversity().getDiversityType(), + "updated soft constraints should have diversity type of serial"); assertThat(generatedSoftConstraints.getDiversity().getServiceIdentifierList(), IsMapContaining.hasKey(new ServiceIdentifierListKey("hard-service 1"))); assertThat(generatedSoftConstraints.getDiversity().getServiceIdentifierList(), @@ -123,21 +120,21 @@ public class DowngradeConstraintsTest { } @Test - public void testUpdateSoftConstraintsForExclude() { + void testUpdateSoftConstraintsForExclude() { HardConstraints initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertNull("updated soft constraints should contain no exclude constraint", - generatedSoftConstraints.getExclude()); + assertNull(generatedSoftConstraints.getExclude(), + "updated soft constraints should contain no exclude constraint"); initialSoftConstraints = buildSoftConstraint(null, false, null, "link", null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should not be changed", - initialSoftConstraints.getExclude(), generatedSoftConstraints.getExclude()); + assertEquals(initialSoftConstraints.getExclude(), generatedSoftConstraints.getExclude(), + "updated soft constraints should not be changed"); // test addition of hard exclude with fiber list when no soft exclude initialHardConstraints = @@ -145,8 +142,8 @@ public class DowngradeConstraintsTest { initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should contain the exclude constraint of hard constraint", - generatedSoftConstraints.getExclude(), initialHardConstraints.getExclude()); + assertEquals(generatedSoftConstraints.getExclude(), initialHardConstraints.getExclude(), + "updated soft constraints should contain the exclude constraint of hard constraint"); // test addition of hard exclude with fiber list when existing soft // exclude with fiber list @@ -164,8 +161,8 @@ public class DowngradeConstraintsTest { initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should contain the exclude constraint of hard constraint", - generatedSoftConstraints.getExclude(), initialHardConstraints.getExclude()); + assertEquals(generatedSoftConstraints.getExclude(), initialHardConstraints.getExclude(), + "updated soft constraints should contain the exclude constraint of hard constraint"); // test addition of hard exclude with link list when existing soft // exclude with link list @@ -183,21 +180,21 @@ public class DowngradeConstraintsTest { } @Test - public void testUpdateSoftConstraintsForInclude() { + void testUpdateSoftConstraintsForInclude() { HardConstraints initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertNull("updated soft constraints should contain no include constraint", - generatedSoftConstraints.getInclude()); + assertNull(generatedSoftConstraints.getInclude(), + "updated soft constraints should contain no include constraint"); initialSoftConstraints = buildSoftConstraint(null, false, null, null, "link", null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should not be changed", - initialSoftConstraints.getInclude(), generatedSoftConstraints.getInclude()); + assertEquals(initialSoftConstraints.getInclude(), generatedSoftConstraints.getInclude(), + "updated soft constraints should not be changed"); // test addition of hard include with fiber list when no soft include initialHardConstraints = @@ -205,8 +202,8 @@ public class DowngradeConstraintsTest { initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should contain the include constraint of hard constraint", - generatedSoftConstraints.getInclude(), initialHardConstraints.getInclude()); + assertEquals(generatedSoftConstraints.getInclude(), initialHardConstraints.getInclude(), + "updated soft constraints should contain the include constraint of hard constraint"); // test addition of hard include with fiber list when existing soft // include with fiber list @@ -224,8 +221,8 @@ public class DowngradeConstraintsTest { initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should contain the include constraint of hard constraint", - generatedSoftConstraints.getInclude(), initialHardConstraints.getInclude()); + assertEquals(generatedSoftConstraints.getInclude(), initialHardConstraints.getInclude(), + "updated soft constraints should contain the include constraint of hard constraint"); // test addition of hard include with link list when existing soft // include with link list @@ -243,24 +240,24 @@ public class DowngradeConstraintsTest { } @Test - public void testUpdateSoftConstraintsForLatency() { + void testUpdateSoftConstraintsForLatency() { HardConstraints initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertNull("updated soft constraints should contain no latency constraint", - generatedSoftConstraints.getLatency()); + assertNull(generatedSoftConstraints.getLatency(), + "updated soft constraints should contain no latency constraint"); initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, Double.valueOf(12.2), false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should not be changed", - initialSoftConstraints.getLatency(), generatedSoftConstraints.getLatency()); - assertEquals("updated soft constraints value should be '12.2'", - (float) 12.2, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f); + assertEquals(initialSoftConstraints.getLatency(), generatedSoftConstraints.getLatency(), + "updated soft constraints should not be changed"); + assertEquals((float) 12.2, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f, + "updated soft constraints value should be '12.2'"); // test addition of hard latency when no soft latency initialHardConstraints = @@ -268,127 +265,127 @@ public class DowngradeConstraintsTest { initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints value should be '16.59'", - (float) 16.59, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f); + assertEquals((float) 16.59, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f, + "updated soft constraints value should be '16.59'"); // test addition of hard latency when existing different soft latency initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, Double.valueOf(12.2), false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints value should be '12.2'", - (float) 12.2, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f); + assertEquals((float) 12.2, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f, + "updated soft constraints value should be '12.2'"); } @Test - public void testUpdateSoftConstraintsForDistance() { + void testUpdateSoftConstraintsForDistance() { HardConstraints initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertNull("updated soft constraints should contain no distance constraint", - generatedSoftConstraints.getDistance()); + assertNull(generatedSoftConstraints.getDistance(), + "updated soft constraints should contain no distance constraint"); initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, "750.2", null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should not be changed", - initialSoftConstraints.getDistance(), generatedSoftConstraints.getDistance()); - assertEquals("updated soft constraints value should be '750.2'", - (float) 750.2, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f); + assertEquals(initialSoftConstraints.getDistance(), generatedSoftConstraints.getDistance(), + "updated soft constraints should not be changed"); + assertEquals((float) 750.2, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f, + "updated soft constraints value should be '750.2'"); // test addition of hard distance when no soft distance initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, "555.5", null); initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints value should be '555.5'", - (float) 555.5, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f); + assertEquals((float) 555.5, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f, + "updated soft constraints value should be '555.5'"); // test addition of hard distance when existing different soft distance initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, "750.2", null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints value should be '555.5'", - (float) 555.5, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f); + assertEquals((float) 555.5, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f, + "updated soft constraints value should be '555.5'"); } @Test - public void testUpdateSoftConstraintsForHopCountAndTEmetric() { + void testUpdateSoftConstraintsForHopCountAndTEmetric() { HardConstraints initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertNull("updated soft constraints should contain no hop-count constraint", - generatedSoftConstraints.getHopCount()); + assertNull(generatedSoftConstraints.getHopCount(), + "updated soft constraints should contain no hop-count constraint"); initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, true, true, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should not be changed", - initialSoftConstraints.getHopCount(), generatedSoftConstraints.getHopCount()); - assertEquals("updated soft constraints max-wdm-hop-count should be '3'", - 3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue()); - assertEquals("updated soft constraints max-otn-hop-count should be '5'", - 5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue()); - assertEquals("updated soft constraints max-wdm-TE-metric should be '8'", - 8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue()); - assertEquals("updated soft constraints max-otn-TE-metric should be '11'", - 11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue()); + assertEquals(initialSoftConstraints.getHopCount(), generatedSoftConstraints.getHopCount(), + "updated soft constraints should not be changed"); + assertEquals(3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue(), + "updated soft constraints max-wdm-hop-count should be '3'"); + assertEquals(5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue(), + "updated soft constraints max-otn-hop-count should be '5'"); + assertEquals(8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue(), + "updated soft constraints max-wdm-TE-metric should be '8'"); + assertEquals(11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue(), + "updated soft constraints max-otn-TE-metric should be '11'"); // test addition of hard hop-count when no soft hop-count initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, true, true, null, null); initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should contain hard constraint", - initialHardConstraints.getHopCount(), generatedSoftConstraints.getHopCount()); - assertEquals("updated soft constraints max-wdm-hop-count should be '3'", - 3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue()); - assertEquals("updated soft constraints max-otn-hop-count should be '5'", - 5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue()); - assertEquals("updated soft constraints max-wdm-TE-metric should be '8'", - 8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue()); - assertEquals("updated soft constraints max-otn-TE-metric should be '11'", - 11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue()); + assertEquals(initialHardConstraints.getHopCount(), generatedSoftConstraints.getHopCount(), + "updated soft constraints should contain hard constraint"); + assertEquals(3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue(), + "updated soft constraints max-wdm-hop-count should be '3'"); + assertEquals(5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue(), + "updated soft constraints max-otn-hop-count should be '5'"); + assertEquals(8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue(), + "updated soft constraints max-wdm-TE-metric should be '8'"); + assertEquals(11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue(), + "updated soft constraints max-otn-TE-metric should be '11'"); // test addition of hard hop-count when existing soft hop-count initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, true, true, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints max-wdm-hop-count should be '3'", - 3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue()); - assertEquals("updated soft constraints max-otn-hop-count should be '5'", - 5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue()); - assertEquals("updated soft constraints max-wdm-TE-metric should be '8'", - 8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue()); - assertEquals("updated soft constraints max-otn-TE-metric should be '11'", - 11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue()); + assertEquals(3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue(), + "updated soft constraints max-wdm-hop-count should be '3'"); + assertEquals(5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue(), + "updated soft constraints max-otn-hop-count should be '5'"); + assertEquals(8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue(), + "updated soft constraints max-wdm-TE-metric should be '8'"); + assertEquals(11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue(), + "updated soft constraints max-otn-TE-metric should be '11'"); } @Test - public void testUpdateSoftConstraintsForCoRouting() { + void testUpdateSoftConstraintsForCoRouting() { HardConstraints initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertNull("updated soft constraints should contain no co-routing constraint", - generatedSoftConstraints.getCoRouting()); + assertNull(generatedSoftConstraints.getCoRouting(), + "updated soft constraints should contain no co-routing constraint"); initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, true, false, null, "coRouting1"); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should not be changed", - initialSoftConstraints.getCoRouting(), generatedSoftConstraints.getCoRouting()); - assertEquals("updated soft constraints should contain 2 co-routed services", - 2, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size()); + assertEquals(initialSoftConstraints.getCoRouting(), generatedSoftConstraints.getCoRouting(), + "updated soft constraints should not be changed"); + assertEquals(2, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size(), + "updated soft constraints should contain 2 co-routed services"); assertTrue(generatedSoftConstraints.getCoRouting().getServiceIdentifierList() .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co .routing.ServiceIdentifierListKey("service 1")) @@ -412,10 +409,10 @@ public class DowngradeConstraintsTest { initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should contain hard constraint", - initialHardConstraints.getCoRouting(), generatedSoftConstraints.getCoRouting()); - assertEquals("updated soft constraints should contain 1 co-routed service", - 1, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size()); + assertEquals(initialHardConstraints.getCoRouting(), generatedSoftConstraints.getCoRouting(), + "updated soft constraints should contain hard constraint"); + assertEquals(1, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size(), + "updated soft constraints should contain 1 co-routed service"); assertTrue(generatedSoftConstraints.getCoRouting().getServiceIdentifierList() .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co .routing.ServiceIdentifierListKey("service 3")) @@ -430,8 +427,8 @@ public class DowngradeConstraintsTest { buildSoftConstraint(null, false, null, null, null, null, true, false, null, "coRouting1"); generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints( initialHardConstraints, initialSoftConstraints); - assertEquals("updated soft constraints should contain 3 co-routed service", - 3, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size()); + assertEquals(3, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size(), + "updated soft constraints should contain 3 co-routed service"); assertThat(generatedSoftConstraints.getCoRouting().getServiceIdentifierList(), IsMapContaining.hasKey( new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co @@ -447,60 +444,58 @@ public class DowngradeConstraintsTest { } @Test - public void testDowngradeHardConstraints() { + void testDowngradeHardConstraints() { HardConstraints initialHardConstraints = null; HardConstraints genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints); - assertNotNull("generated hard-constraints should be empty, not null", genHardConstraints); + assertNotNull(genHardConstraints, "generated hard-constraints should be empty, not null"); initialHardConstraints = new HardConstraintsBuilder().build(); genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints); - assertNotNull("generated hard-constraints should be empty, not null", genHardConstraints); + assertNotNull(genHardConstraints, "generated hard-constraints should be empty, not null"); initialHardConstraints = buildHardConstraint(null, false, null, "link1", null, Double.valueOf(12.8), false, false, null, null); genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints); - assertEquals("Latency value should be 12.8", - (long) 12.8, genHardConstraints.getLatency().getMaxLatency().longValue()); - assertNull("generated hard constraints should only contain max-latency value", - genHardConstraints.getCoRouting()); - assertNull("generated hard constraints should only contain max-latency value", - genHardConstraints.getExclude()); - assertNull("generated hard constraints should only contain max-latency value", - genHardConstraints.getInclude()); + assertEquals((long) 12.8, genHardConstraints.getLatency().getMaxLatency().longValue(), + "Latency value should be 12.8"); + assertNull(genHardConstraints.getCoRouting(), + "generated hard constraints should only contain max-latency value"); + assertNull(genHardConstraints.getExclude(), "generated hard constraints should only contain max-latency value"); + assertNull(genHardConstraints.getInclude(), "generated hard constraints should only contain max-latency value"); } @Test - public void testConvertToSoftConstraints() { + void testConvertToSoftConstraints() { HardConstraints initialHardConstraints = null; SoftConstraints genSoftConstraints = DowngradeConstraints.convertToSoftConstraints(initialHardConstraints); - assertNotNull("generated soft constraints should never be null", genSoftConstraints); - assertNull("generated soft constraints should be empty", genSoftConstraints.getExclude()); - assertNull("generated soft constraints should be empty", genSoftConstraints.getCoRouting()); - assertNull("generated soft constraints should be empty", genSoftConstraints.getLatency()); + assertNotNull(genSoftConstraints, "generated soft constraints should never be null"); + assertNull(genSoftConstraints.getExclude(), "generated soft constraints should be empty"); + assertNull(genSoftConstraints.getCoRouting(), "generated soft constraints should be empty"); + assertNull(genSoftConstraints.getLatency(), "generated soft constraints should be empty"); Set hardCustomerCode = Set.of("customer-code 1", "customer-code 2"); initialHardConstraints = buildHardConstraint(hardCustomerCode, false, null, "link1", "node", null, false, false, null, null); genSoftConstraints = DowngradeConstraints.convertToSoftConstraints(initialHardConstraints); - assertEquals("generated soft constraints should contain customer-code items", 2, - genSoftConstraints.getCustomerCode().size()); + assertEquals(2, genSoftConstraints.getCustomerCode().size(), + "generated soft constraints should contain customer-code items"); assertTrue(genSoftConstraints.getCustomerCode().contains("customer-code 1")); assertTrue(genSoftConstraints.getCustomerCode().contains("customer-code 2")); - assertNotNull("generated soft constraints should contain exclude constraint", genSoftConstraints.getExclude()); - assertEquals("generated soft constraints should contain exclude constraint with one link-id", - 1, genSoftConstraints.getExclude().getLinkIdentifier().values().size()); + assertNotNull(genSoftConstraints.getExclude(), "generated soft constraints should contain exclude constraint"); + assertEquals(1, genSoftConstraints.getExclude().getLinkIdentifier().values().size(), + "generated soft constraints should contain exclude constraint with one link-id"); assertEquals("link-id 1", genSoftConstraints.getExclude().getLinkIdentifier().values().stream().findAny().get().getLinkId()); assertEquals("openroadm-topology", genSoftConstraints.getExclude().getLinkIdentifier().values().stream().findAny().get().getLinkNetworkId()); - assertNotNull("generated soft constraints should contain include constraint", genSoftConstraints.getInclude()); - assertEquals("generated soft constraints should contain include constraint with two node-id", - 2, genSoftConstraints.getInclude().getNodeId().size()); + assertNotNull(genSoftConstraints.getInclude(), "generated soft constraints should contain include constraint"); + assertEquals(2, genSoftConstraints.getInclude().getNodeId().size(), + "generated soft constraints should contain include constraint with two node-id"); assertTrue(genSoftConstraints.getInclude().getNodeId().contains(new NodeIdType("node-id-1"))); assertTrue(genSoftConstraints.getInclude().getNodeId().contains(new NodeIdType("node-id-3"))); - assertNull("generated soft constraints should not contain any latency constraint", - genSoftConstraints.getLatency()); - assertNull("generated soft constraints should not contain any max-distance constraint", - genSoftConstraints.getDistance()); - assertNull("generated soft constraints should not contain any co-routing constraint", - genSoftConstraints.getCoRouting()); + assertNull(genSoftConstraints.getLatency(), + "generated soft constraints should not contain any latency constraint"); + assertNull(genSoftConstraints.getDistance(), + "generated soft constraints should not contain any max-distance constraint"); + assertNull(genSoftConstraints.getCoRouting(), + "generated soft constraints should not contain any co-routing constraint"); } } diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtilsTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtilsTest.java index a36e93461..390650f3c 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtilsTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtilsTest.java @@ -7,6 +7,11 @@ */ package org.opendaylight.transportpce.servicehandler; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; @@ -18,17 +23,15 @@ import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; import org.opendaylight.transportpce.test.AbstractTest; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommon; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.sdnc.request.header.SdncRequestHeaderBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRoutingBuilder; @@ -59,7 +62,6 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesKey; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirectionBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParameters; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths; @@ -75,26 +77,25 @@ public class ModelMappingUtilsTest extends AbstractTest { private CountDownLatch endSignal; private static final int NUM_THREADS = 5; - @Before - public void setUp() { + @BeforeEach + void setUp() { executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS)); endSignal = new CountDownLatch(1); } - @After - public void tearDown() { + @AfterEach + void tearDown() { executorService.shutdownNow(); } private ServiceReconfigureInput buildServiceConfigurationInput() { - DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); - OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); - OffsetDateTime offsetDateTime2 = offsetDateTime.plusDays(10); - return new ServiceReconfigureInputBuilder().setNewServiceName("service 1") - .setServiceName("service 1").setCommonId("common id").setConnectionType(ConnectionType.Service) - .setCustomer("customer").setCustomerContact("customer contact").setDueDate(new DateAndTime( - dtf.format(offsetDateTime))) - .setEndDate(new DateAndTime(dtf.format(offsetDateTime2))) + return new ServiceReconfigureInputBuilder() + .setNewServiceName("service 1").setServiceName("service 1").setCommonId("common id") + .setConnectionType(ConnectionType.Service).setCustomer("customer").setCustomerContact("customer contact") + .setDueDate(new DateAndTime(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx") + .format(OffsetDateTime.now(ZoneOffset.UTC)))) + .setEndDate(new DateAndTime(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx") + .format(OffsetDateTime.now(ZoneOffset.UTC).plusDays(10)))) .setNcCode("nc node").setNciCode("nci node").setSecondaryNciCode("secondry").setOperatorContact("operator") .setServiceAEnd(ServiceDataUtils.getServiceAEndBuildReconfigure().build()) .setServiceZEnd(ServiceDataUtils.getServiceZEndBuildReconfigure().build()) @@ -122,108 +123,114 @@ public class ModelMappingUtilsTest extends AbstractTest { } private PathComputationRequestOutput buildPathComputationOutput() { - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); - ResponseParameters responseParameters = new ResponseParametersBuilder() - .setPathDescription(new PathDescriptionBuilder() - .setAToZDirection(new AToZDirectionBuilder().setAToZWavelengthNumber(Uint32.valueOf(1)) - .setRate(Uint32.valueOf(1)).build()) - .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(Uint32.valueOf(1)) - .setRate(Uint32.valueOf(1)).build()).build()) + return new PathComputationRequestOutputBuilder() + .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder() + .setRequestId("request 1") + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setResponseCode(ResponseCodes.RESPONSE_OK) + .setResponseMessage("PCE calculation in progress") + .build()) + .setResponseParameters(new ResponseParametersBuilder() + .setPathDescription(new PathDescriptionBuilder() + .setAToZDirection(new AToZDirectionBuilder() + .setAToZWavelengthNumber(Uint32.valueOf(1)) + .setRate(Uint32.valueOf(1)) + .build()) + .setZToADirection(new ZToADirectionBuilder() + .setZToAWavelengthNumber(Uint32.valueOf(1)) + .setRate(Uint32.valueOf(1)) + .build()) + .build()) + .build()) .build(); - return new PathComputationRequestOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon) - .setResponseParameters(responseParameters).build(); } @Test //TODO : is this unit test relevant ? - public void mappingServicesNullServiceCreateInput() { + void mappingServicesNullServiceCreateInput() { Services services = ModelMappingUtils.mappingServices(null, null); - Assert.assertEquals(new ServicesBuilder().withKey(new ServicesKey("unknown")).build(), services); + assertEquals(new ServicesBuilder().withKey(new ServicesKey("unknown")).build(), services); } @Test - public void mappingServiceNotNullServiceReconfigureInput() { + void mappingServiceNotNullServiceReconfigureInput() { Services services = ModelMappingUtils.mappingServices(null, buildServiceConfigurationInput()); - Assert.assertEquals("service 1", services.getServiceName()); + assertEquals("service 1", services.getServiceName()); } @Test - public void mappingServiceValid() { - Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(), - null); - Assert.assertEquals("service 1", services.getServiceName()); + void mappingServiceValid() { + Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(), null); + assertEquals("service 1", services.getServiceName()); } @Test //TODO : is this unit test relevant ? - public void mappingServicesPathNullServiceCreateInput() { + void mappingServicesPathNullServiceCreateInput() { ServicePaths services = ModelMappingUtils.mappingServicePaths(null, buildPathComputationOutput()); - Assert.assertEquals(new ServicePathsBuilder().withKey(new ServicePathsKey("unknown")).build(), services); + assertEquals(new ServicePathsBuilder().withKey(new ServicePathsKey("unknown")).build(), services); } @Test - public void mappingServicePathWithServiceInputWithHardConstraints() { + void mappingServicePathWithServiceInputWithHardConstraints() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithHardConstraints(); ServiceInput serviceInput = new ServiceInput(createInput); ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput()); - Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName()); - Assert.assertNotNull(services.getHardConstraints()); + assertEquals(serviceInput.getServiceName(), services.getServicePathName()); + assertNotNull(services.getHardConstraints()); } @Test - public void mappingServicePathWithServiceInputWithSoftConstraints() { + void mappingServicePathWithServiceInputWithSoftConstraints() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithSoftConstraints(); ServiceInput serviceInput = new ServiceInput(createInput); ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput()); - Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName()); - Assert.assertNotNull(services.getSoftConstraints()); + assertEquals(serviceInput.getServiceName(), services.getServicePathName()); + assertNotNull(services.getSoftConstraints()); } @Test - public void createServiceDeleteInputWithServiceRerouteInput() { + void createServiceDeleteInputWithServiceRerouteInput() { ServiceRerouteInput serviceRerouteinput = new ServiceRerouteInputBuilder().setServiceName("reroute").build(); Services services = new ServicesBuilder() - .withKey(new ServicesKey("reroute")) - .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build(); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput - serviceDeleteInput = - ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services); - Assert.assertEquals("reroute", serviceDeleteInput.getServiceName()); - Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId()); + .withKey(new ServicesKey("reroute")) + .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()) + .build(); + var serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services); + assertEquals("reroute", serviceDeleteInput.getServiceName()); + assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId()); } @Test - public void createServiceDeleteInputWithServiceReconfigureInput() { - ServiceReconfigureInput serviceReconfigureInput = new ServiceReconfigureInputBuilder() - .setServiceName("reconf").build(); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput - serviceDeleteInput = - ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput); - Assert.assertEquals("reconf", serviceDeleteInput.getServiceName()); - Assert.assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId()); + void createServiceDeleteInputWithServiceReconfigureInput() { + ServiceReconfigureInput serviceReconfigureInput = new ServiceReconfigureInputBuilder() + .setServiceName("reconf") + .build(); + var serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput); + assertEquals("reconf", serviceDeleteInput.getServiceName()); + assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId()); } @Test - public void createServiceDeleteInputWithServiceRestorationInput() { + void createServiceDeleteInputWithServiceRestorationInput() { Services services = new ServicesBuilder() .withKey(new ServicesKey("rest")) - .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build(); - ServiceRestorationInput serviceRestorationInput = - new ServiceRestorationInputBuilder().setServiceName("rest").build(); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput - serviceDeleteInput = - ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services); - Assert.assertEquals("rest", serviceDeleteInput.getServiceName()); - Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId()); + .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()) + .build(); + ServiceRestorationInput serviceRestorationInput = new ServiceRestorationInputBuilder() + .setServiceName("rest") + .build(); + var serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services); + assertEquals("rest", serviceDeleteInput.getServiceName()); + assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId()); } @Test - public void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader() - throws ExecutionException, InterruptedException { + void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader() + throws ExecutionException, InterruptedException { ServiceDeleteInput input = new ServiceDeleteInputBuilder() - .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build(); + .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()) + .build(); ListenableFuture> serviceDeleteOutputF = ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200"); serviceDeleteOutputF.addListener(new Runnable() { @@ -235,16 +242,14 @@ public class ModelMappingUtilsTest extends AbstractTest { endSignal.await(); RpcResult serviceDeleteOutput = serviceDeleteOutputF.get(); - Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals( - "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals( - "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); - Assert.assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId()); + assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals("ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals("message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); + assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId()); } @Test - public void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader() + void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader() throws ExecutionException, InterruptedException { ServiceDeleteInput input = new ServiceDeleteInputBuilder().build(); ListenableFuture> serviceDeleteOutputF = @@ -258,20 +263,18 @@ public class ModelMappingUtilsTest extends AbstractTest { endSignal.await(); RpcResult serviceDeleteOutput = serviceDeleteOutputF.get(); - Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals( - "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals( - "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); - Assert.assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId()); + assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals("ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals("message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); + assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId()); } @Test - public void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader() + void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader() throws ExecutionException, InterruptedException { - ServiceCreateInput input = - new ServiceCreateInputBuilder() - .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build(); + ServiceCreateInput input = new ServiceCreateInputBuilder() + .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()) + .build(); ListenableFuture> serviceCreatOutputF = ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200"); serviceCreatOutputF.addListener(new Runnable() { @@ -283,16 +286,14 @@ public class ModelMappingUtilsTest extends AbstractTest { endSignal.await(); RpcResult serviceCreatOutput = serviceCreatOutputF.get(); - Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals( - "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals( - "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); - Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); + assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); + assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); } @Test - public void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader() + void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader() throws ExecutionException, InterruptedException { ServiceCreateInput input = new ServiceCreateInputBuilder().build(); ListenableFuture> serviceCreatOutputF = @@ -306,20 +307,18 @@ public class ModelMappingUtilsTest extends AbstractTest { endSignal.await(); RpcResult serviceCreatOutput = serviceCreatOutputF.get(); - Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals( - "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals( - "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); - Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); + assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); + assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); } @Test - public void createCreateServiceReplyWithTempServiceCreatInputWithSdncRequestHeader() + void createCreateServiceReplyWithTempServiceCreatInputWithSdncRequestHeader() throws ExecutionException, InterruptedException { - TempServiceCreateInput input = - new TempServiceCreateInputBuilder() - .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build(); + TempServiceCreateInput input = new TempServiceCreateInputBuilder() + .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()) + .build(); ListenableFuture> serviceCreatOutputF = ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200"); serviceCreatOutputF.addListener(new Runnable() { @@ -331,16 +330,14 @@ public class ModelMappingUtilsTest extends AbstractTest { endSignal.await(); RpcResult serviceCreatOutput = serviceCreatOutputF.get(); - Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals( - "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals( - "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); - Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); + assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); + assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); } @Test - public void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader() + void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader() throws ExecutionException, InterruptedException { TempServiceCreateInput input = new TempServiceCreateInputBuilder().build(); ListenableFuture> serviceCreatOutputF = @@ -354,20 +351,18 @@ public class ModelMappingUtilsTest extends AbstractTest { endSignal.await(); RpcResult serviceCreatOutput = serviceCreatOutputF.get(); - Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals( - "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals( - "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); - Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); + assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); + assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); } @Test - public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader() + void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader() throws ExecutionException, InterruptedException { - ServiceFeasibilityCheckInput input = - new ServiceFeasibilityCheckInputBuilder() - .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build(); + ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder() + .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()) + .build(); ListenableFuture> serviceCreatOutputF = ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200"); serviceCreatOutputF.addListener(new Runnable() { @@ -379,16 +374,14 @@ public class ModelMappingUtilsTest extends AbstractTest { endSignal.await(); RpcResult serviceCreatOutput = serviceCreatOutputF.get(); - Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals( - "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals( - "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); - Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); + assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); + assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); } @Test - public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithoutSdncRequestHeader() + void createCreateServiceReplyWithServiceFeasibilityCheckInputWithoutSdncRequestHeader() throws ExecutionException, InterruptedException { ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder().build(); ListenableFuture> serviceCreatOutputF = @@ -402,16 +395,14 @@ public class ModelMappingUtilsTest extends AbstractTest { endSignal.await(); RpcResult serviceCreatOutput = serviceCreatOutputF.get(); - Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals( - "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals( - "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); - Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); + assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage()); + assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId()); } @Test - public void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException { + void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException { ListenableFuture> serviceRestorationOutputF = ModelMappingUtils.createRestoreServiceReply("message"); serviceRestorationOutputF.addListener(new Runnable() { diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ServiceEndpointTypeTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ServiceEndpointTypeTest.java index c3209527c..c6f53f1ee 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ServiceEndpointTypeTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ServiceEndpointTypeTest.java @@ -7,21 +7,21 @@ */ package org.opendaylight.transportpce.servicehandler; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; public class ServiceEndpointTypeTest { @Test - public void testgetIntValue() { - Assert.assertEquals(1, ServiceEndpointType.SERVICEAEND.getIntValue()); - Assert.assertEquals(2, ServiceEndpointType.SERVICEZEND.getIntValue()); + void testgetIntValue() { + assertEquals(1, ServiceEndpointType.SERVICEAEND.getIntValue()); + assertEquals(2, ServiceEndpointType.SERVICEZEND.getIntValue()); } @Test - public void testForValue() { - Assert.assertEquals(ServiceEndpointType.SERVICEAEND, ServiceEndpointType.forValue(1)); - Assert.assertEquals(ServiceEndpointType.SERVICEZEND, ServiceEndpointType.forValue(2)); + void testForValue() { + assertEquals(ServiceEndpointType.SERVICEAEND, ServiceEndpointType.forValue(1)); + assertEquals(ServiceEndpointType.SERVICEZEND, ServiceEndpointType.forValue(2)); } - -} +} \ No newline at end of file diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java index 63445c36d..1806f20e6 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java @@ -7,8 +7,10 @@ */ package org.opendaylight.transportpce.servicehandler.impl; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl.LogMessages; import com.google.common.util.concurrent.Futures; @@ -20,12 +22,11 @@ import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; -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.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.pce.service.PathComputationService; @@ -79,23 +80,19 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.Uint32; +@ExtendWith(MockitoExtension.class) public class ServicehandlerImplTest extends AbstractTest { @Mock private PathComputationService pathComputationService; - @Mock private RendererServiceOperations rendererServiceOperations; - @Mock private NotificationPublishService notificationPublishService; - @Mock private PceListenerImpl pceListenerImpl; - @Mock private RendererListenerImpl rendererListenerImpl; - @Mock private NetworkModelListenerImpl networkModelListenerImpl; @@ -109,11 +106,10 @@ public class ServicehandlerImplTest extends AbstractTest { private CountDownLatch endSignal; private static final int NUM_THREADS = 5; - @Before - public void setUp() { + @BeforeEach + void setUp() { executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS)); endSignal = new CountDownLatch(1); - MockitoAnnotations.openMocks(this); this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker()); serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput(); @@ -123,26 +119,24 @@ public class ServicehandlerImplTest extends AbstractTest { } @Test - public void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ListenableFuture> result = - servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build()); + void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, + rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, serviceDataStoreOperations); + ListenableFuture> result = servicehandlerImpl + .serviceCreate(new ServiceCreateInputBuilder().build()); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException, + void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException, InterruptedException { final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class); - Mockito.when(serviceDSOperations.getService(serviceCreateInput.getServiceName())) + when(serviceDSOperations.getService(serviceCreateInput.getServiceName())) .thenReturn(Optional.of( new ServicesBuilder() .setServiceName(serviceCreateInput.getServiceName()) @@ -154,14 +148,15 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void createServiceShouldBeSuccessfulWhenPerformPCESuccessful() + void createServiceShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException { - Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); + when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); @@ -169,12 +164,13 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); @@ -187,13 +183,13 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, @@ -202,14 +198,14 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); + void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); @@ -218,13 +214,14 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); @@ -233,14 +230,15 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful() + void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException { - Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); + when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); @@ -249,12 +247,13 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); @@ -267,7 +266,7 @@ public class ServicehandlerImplTest extends AbstractTest { @Test - public void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service reconfigure ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, @@ -281,9 +280,9 @@ public class ServicehandlerImplTest extends AbstractTest { } @Test - public void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { // serviceReconfigure is calling service delete method in renderer - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); + when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); //create service to reconfigure ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, @@ -300,12 +299,12 @@ public class ServicehandlerImplTest extends AbstractTest { } @Test - public void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); - ListenableFuture> result = - servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build()); + ListenableFuture> result = servicehandlerImpl + .serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); @@ -313,7 +312,7 @@ public class ServicehandlerImplTest extends AbstractTest { @Test - public void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service restore ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, @@ -327,9 +326,9 @@ public class ServicehandlerImplTest extends AbstractTest { } @Test - public void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { // serviceRestoration is calling service delete method in renderer - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); + when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); //create service to restore ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, @@ -346,7 +345,7 @@ public class ServicehandlerImplTest extends AbstractTest { } @Test - public void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); @@ -356,35 +355,37 @@ public class ServicehandlerImplTest extends AbstractTest { endSignal.await(); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service reconfigure ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.serviceReroute( - serviceRerouteInput); + ListenableFuture> result = servicehandlerImpl + .serviceReroute(serviceRerouteInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - Mockito.when(pathComputationService.pathComputationRerouteRequest(any())) - .thenReturn(Futures.immediateFuture(new PathComputationRerouteRequestOutputBuilder() - .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder() - .setResponseCode(ResponseCodes.RESPONSE_OK) - .build()) - .build())); + void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + when(pathComputationService.pathComputationRerouteRequest(any())) + .thenReturn(Futures.immediateFuture(new PathComputationRerouteRequestOutputBuilder() + .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder() + .setResponseCode(ResponseCodes.RESPONSE_OK) + .build()) + .build())); Map atoz = Map.of( new AToZKey("0"), new AToZBuilder() @@ -444,12 +445,13 @@ public class ServicehandlerImplTest extends AbstractTest { endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); @@ -460,16 +462,16 @@ public class ServicehandlerImplTest extends AbstractTest { endSignal.await(); RpcResult rpcResult = result.get(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, - rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals( - LogMessages.SERVICE_NON_COMPLIANT, - rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + LogMessages.SERVICE_NON_COMPLIANT, + rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage()); } @Test - public void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); @@ -478,19 +480,19 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); + void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); //create temp service to delete in the temp delete action - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); + ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, + rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, serviceDataStoreOperations); TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput(); serviceDataStoreOperations.createTempService(createInput); @@ -499,12 +501,13 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations); @@ -513,15 +516,15 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } - @Test - public void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful() + void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException { - Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); + when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, @@ -532,8 +535,8 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } - -} +} \ No newline at end of file diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProviderTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProviderTest.java index 85b51d7cb..b6da6dd72 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProviderTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerProviderTest.java @@ -11,11 +11,10 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.transportpce.servicehandler.listeners.NetworkModelListenerImpl; import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl; @@ -24,39 +23,27 @@ import org.opendaylight.transportpce.servicehandler.listeners.ServiceListener; import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; import org.opendaylight.transportpce.test.AbstractTest; +@ExtendWith(MockitoExtension.class) public class ServicehandlerProviderTest extends AbstractTest { @Mock RpcProviderService rpcProviderRegistry; - @Mock ServiceDataStoreOperations serviceDataStoreOperations; - @Mock PceListenerImpl pceListenerImpl; - @Mock ServiceListener serviceListener; - @Mock RendererListenerImpl rendererListenerImpl; - @Mock NetworkModelListenerImpl networkModelListenerImpl; - @Mock ServicehandlerImpl servicehandler; - private AutoCloseable closeable; - - @Before - public void openMocks() { - closeable = MockitoAnnotations.openMocks(this); - } - @Test - public void testInitRegisterServiceHandlerToRpcRegistry() { + void testInitRegisterServiceHandlerToRpcRegistry() { ServicehandlerProvider provider = new ServicehandlerProvider( getDataBroker(), rpcProviderRegistry, getNotificationService() , serviceDataStoreOperations, pceListenerImpl, serviceListener, @@ -64,12 +51,6 @@ public class ServicehandlerProviderTest extends AbstractTest { provider.init(); - verify(rpcProviderRegistry, times(1)) - .registerRpcImplementation(any(), any(ServicehandlerImpl.class)); + verify(rpcProviderRegistry, times(1)).registerRpcImplementation(any(), any(ServicehandlerImpl.class)); } - - @After public void releaseMocks() throws Exception { - closeable.close(); - } - -} +} \ No newline at end of file diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/NetworkModelListenerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/NetworkModelListenerImplTest.java index 396efb90e..53b58a93e 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/NetworkModelListenerImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/NetworkModelListenerImplTest.java @@ -8,9 +8,9 @@ package org.opendaylight.transportpce.servicehandler.listeners; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doCallRealMethod; @@ -23,12 +23,12 @@ import static org.mockito.Mockito.when; import java.util.HashMap; import java.util.Map; import java.util.Optional; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +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.NotificationPublishService; import org.opendaylight.transportpce.common.OperationResult; import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; @@ -59,7 +59,7 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class NetworkModelListenerImplTest { @Mock @@ -69,8 +69,8 @@ public class NetworkModelListenerImplTest { private static PathDescription pathDescription; private NetworkModelListenerImpl networkModelListener; - @Before - public void setUp() { + @BeforeEach + void setUp() { pathDescription = new PathDescriptionBuilder() .setAToZDirection(new AToZDirectionBuilder().setAToZ(new HashMap<>(createMapAtoZ())).build()) .setZToADirection(new ZToADirectionBuilder().setZToA(new HashMap<>(createMapZtoA())).build()) @@ -80,7 +80,7 @@ public class NetworkModelListenerImplTest { } @Test - public void testChangePathElementStateZAShouldNotModifyPathDescriptionsElementStates() { + void testChangePathElementStateZAShouldNotModifyPathDescriptionsElementStates() { Map topologyChanges = Map.of( new TopologyChangesKey("tpNodeIdA", "TpIdA1"), new TopologyChangesBuilder() @@ -96,12 +96,13 @@ public class NetworkModelListenerImplTest { .build() ); - assertEquals(pathDescription.getZToADirection().getZToA(), - networkModelListener.changePathElementStateZA(topologyChanges, pathDescription)); + assertEquals( + pathDescription.getZToADirection().getZToA(), + networkModelListener.changePathElementStateZA(topologyChanges, pathDescription)); } @Test - public void testChangePathElementStateZAShouldModifyPathDescriptionsElementStates() { + void testChangePathElementStateZAShouldModifyPathDescriptionsElementStates() { Map topologyChanges = Map.of( new TopologyChangesKey("tpNodeIdA", "TpIdA1"), new TopologyChangesBuilder() @@ -135,7 +136,7 @@ public class NetworkModelListenerImplTest { } @Test - public void testChangePathElementStateAZShouldNotModifyPathDescriptionsElementStates() { + void testChangePathElementStateAZShouldNotModifyPathDescriptionsElementStates() { Map topologyChanges = Map.of( new TopologyChangesKey("tpNodeIdA", "TpIdA1"), new TopologyChangesBuilder() @@ -150,12 +151,13 @@ public class NetworkModelListenerImplTest { .setState(State.InService) .build()); - assertEquals(pathDescription.getAToZDirection().getAToZ(), - networkModelListener.changePathElementStateAZ(topologyChanges, pathDescription)); + assertEquals( + pathDescription.getAToZDirection().getAToZ(), + networkModelListener.changePathElementStateAZ(topologyChanges, pathDescription)); } @Test - public void testChangePathElementStateAZShouldModifyPathDescriptionsElementStates() { + void testChangePathElementStateAZShouldModifyPathDescriptionsElementStates() { Map topologyChanges = Map.of( new TopologyChangesKey("tpNodeIdA", "TpIdA1"), new TopologyChangesBuilder() @@ -189,7 +191,7 @@ public class NetworkModelListenerImplTest { } @Test - public void testAllElementsinPathinServiceShouldReturnFalse() { + void testAllElementsinPathinServiceShouldReturnFalse() { Map atozmap = pathDescription.getAToZDirection().getAToZ(); atozmap.computeIfPresent( new AToZKey("0"), @@ -210,28 +212,29 @@ public class NetworkModelListenerImplTest { } @Test - public void testAllElementsinPathinServiceShouldReturnTrue() { + void testAllElementsinPathinServiceShouldReturnTrue() { assertTrue(networkModelListener.allElementsinPathinService(pathDescription.getAToZDirection().getAToZ(), pathDescription.getZToADirection().getZToA())); } @Test - public void testUpdateServicePathsShouldNotModifyServiceState() { + void testUpdateServicePathsShouldNotModifyServiceState() { Map servicePathMap = Map.of(new ServicePathsKey("service-path 1"), new ServicePathsBuilder() .setServicePathName("service-path 1") .setPathDescription(pathDescription) .build()); - when(serviceDataStoreOperations.getServicePaths()).thenReturn(Optional.of(new ServicePathListBuilder() - .setServicePaths(servicePathMap).build())); + when(serviceDataStoreOperations.getServicePaths()) + .thenReturn(Optional.of(new ServicePathListBuilder().setServicePaths(servicePathMap).build())); when(serviceDataStoreOperations.modifyServicePath(any(PathDescription.class), anyString())) - .thenReturn(OperationResult.ok("")); - when(serviceDataStoreOperations.getService(anyString())).thenReturn(Optional.of( - new ServicesBuilder().setServiceName("serviceTest") - .setOperationalState(State.InService) - .setAdministrativeState(AdminStates.InService) - .build())); + .thenReturn(OperationResult.ok("")); + when(serviceDataStoreOperations.getService(anyString())) + .thenReturn(Optional.of(new ServicesBuilder() + .setServiceName("serviceTest") + .setOperationalState(State.InService) + .setAdministrativeState(AdminStates.InService) + .build())); Map topologyChanges = Map.of( new TopologyChangesKey("tpNodeIdC", "TpIdC1"), @@ -249,12 +252,12 @@ public class NetworkModelListenerImplTest { networkModelListener.updateServicePaths(new TopologyUpdateResultBuilder() .setTopologyChanges(topologyChanges).build()); - verify(serviceDataStoreOperations, - never()).modifyService(anyString(), any(State.class), any(AdminStates.class)); + verify(serviceDataStoreOperations, never()) + .modifyService(anyString(), any(State.class), any(AdminStates.class)); } @Test - public void testUpdateServicePathsShouldModifyServiceState() { + void testUpdateServicePathsShouldModifyServiceState() { Map servicePathMap = Map.of( new ServicePathsKey("service-path 1"), new ServicePathsBuilder() @@ -262,17 +265,18 @@ public class NetworkModelListenerImplTest { .setPathDescription(pathDescription) .build()); - when(serviceDataStoreOperations.getServicePaths()).thenReturn(Optional.of(new ServicePathListBuilder() - .setServicePaths(servicePathMap).build())); + when(serviceDataStoreOperations.getServicePaths()) + .thenReturn(Optional.of(new ServicePathListBuilder().setServicePaths(servicePathMap).build())); when(serviceDataStoreOperations.modifyServicePath(any(PathDescription.class), anyString())) - .thenReturn(OperationResult.ok("")); - when(serviceDataStoreOperations.getService(anyString())).thenReturn(Optional.of( - new ServicesBuilder().setServiceName("serviceTest") - .setOperationalState(State.InService) - .setAdministrativeState(AdminStates.InService) - .build())); + .thenReturn(OperationResult.ok("")); + when(serviceDataStoreOperations.getService(anyString())) + .thenReturn(Optional.of(new ServicesBuilder() + .setServiceName("serviceTest") + .setOperationalState(State.InService) + .setAdministrativeState(AdminStates.InService) + .build())); when(serviceDataStoreOperations.modifyService(anyString(), any(State.class), any(AdminStates.class))) - .thenReturn(OperationResult.ok("")); + .thenReturn(OperationResult.ok("")); Map topologyChanges = Map.of( new TopologyChangesKey("tpNodeIdA", "TpIdA1"), @@ -284,12 +288,12 @@ public class NetworkModelListenerImplTest { networkModelListener.updateServicePaths(new TopologyUpdateResultBuilder() .setTopologyChanges(topologyChanges).build()); - verify(serviceDataStoreOperations, times(1)).modifyService(anyString(), - eq(State.OutOfService), any(AdminStates.class)); + verify(serviceDataStoreOperations, times(1)) + .modifyService(anyString(), eq(State.OutOfService), any(AdminStates.class)); } @Test - public void testOnTopologyUpdateResultWhenNeverWired() { + void testOnTopologyUpdateResultWhenNeverWired() { NetworkModelListenerImpl networkModelListenerMocked = Mockito.mock(NetworkModelListenerImpl.class); doCallRealMethod().when(networkModelListenerMocked).onTopologyUpdateResult(any(TopologyUpdateResult.class)); @@ -312,12 +316,11 @@ public class NetworkModelListenerImplTest { .setTopologyChanges(topologyChanges1).build()); networkModelListenerMocked.onTopologyUpdateResult(new TopologyUpdateResultBuilder() .setTopologyChanges(topologyChanges2).build()); - verify(networkModelListenerMocked, times(2)).updateServicePaths( - any(TopologyUpdateResult.class)); + verify(networkModelListenerMocked, times(2)).updateServicePaths(any(TopologyUpdateResult.class)); } @Test - public void testOnTopologyUpdateResultWhenAlreadyWired() { + void testOnTopologyUpdateResultWhenAlreadyWired() { NetworkModelListenerImpl networkModelListenerMocked = Mockito.mock(NetworkModelListenerImpl.class); doCallRealMethod().when(networkModelListenerMocked).onTopologyUpdateResult(any(TopologyUpdateResult.class)); @@ -333,8 +336,7 @@ public class NetworkModelListenerImplTest { networkModelListenerMocked.onTopologyUpdateResult(topologyUpdateResult); networkModelListenerMocked.onTopologyUpdateResult(topologyUpdateResult); - verify(networkModelListenerMocked, times(1)).updateServicePaths( - any(TopologyUpdateResult.class)); + verify(networkModelListenerMocked, times(1)).updateServicePaths(any(TopologyUpdateResult.class)); } private Map createMapAtoZ() { diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/ServiceListenerTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/ServiceListenerTest.java index 4471263cf..c3f2070d7 100755 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/ServiceListenerTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/ServiceListenerTest.java @@ -8,7 +8,7 @@ package org.opendaylight.transportpce.servicehandler.listeners; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -21,10 +21,10 @@ import java.util.Collection; import java.util.HashSet; import java.util.Map; import java.util.Optional; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.mdsal.binding.api.DataObjectModification; import org.opendaylight.mdsal.binding.api.DataTreeModification; import org.opendaylight.mdsal.binding.api.NotificationPublishService; @@ -37,9 +37,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev2 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.Restorable; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.sdnc.request.header.SdncRequestHeaderBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.ServiceAEnd; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.ServiceAEndBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.ServiceZEnd; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.ServiceZEndBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.endpoint.RxDirection; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.endpoint.RxDirectionBuilder; @@ -65,7 +63,7 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint8; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ServiceListenerTest { @Mock @@ -78,7 +76,7 @@ public class ServiceListenerTest { private PathComputationService pathComputationService; @Test - public void testOnDataTreeChangedWhenDeleteService() { + void testOnDataTreeChangedWhenDeleteService() { @SuppressWarnings("unchecked") final DataObjectModification service = mock(DataObjectModification.class); final Collection> changes = new HashSet<>(); @@ -103,7 +101,7 @@ public class ServiceListenerTest { } @Test - public void testOnDataTreeChangedWhenServiceBecomesOutOfService() { + void testOnDataTreeChangedWhenServiceBecomesOutOfService() { @SuppressWarnings("unchecked") final DataObjectModification service = mock(DataObjectModification.class); final Collection> changes = new HashSet<>(); @@ -131,7 +129,7 @@ public class ServiceListenerTest { } @Test - public void testOnDataTreeChangedWhenShouldNeverHappen() { + void testOnDataTreeChangedWhenShouldNeverHappen() { @SuppressWarnings("unchecked") final DataObjectModification service = mock(DataObjectModification.class); final Collection> changes = new HashSet<>(); @@ -156,7 +154,7 @@ public class ServiceListenerTest { } @Test - public void testOnDataTreeChangedWhenServiceDegradedShouldBeRerouted() { + void testOnDataTreeChangedWhenServiceDegradedShouldBeRerouted() { @SuppressWarnings("unchecked") final DataObjectModification service = mock(DataObjectModification.class); final Collection> changes = new HashSet<>(); @@ -169,35 +167,29 @@ public class ServiceListenerTest { .setServiceResiliency(serviceResiliency) .build(); when(service.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE); - when(service.getDataBefore()).thenReturn( - new ServicesBuilder(buildService(State.InService, AdminStates.InService)) + when(service.getDataBefore()) + .thenReturn(new ServicesBuilder(buildService(State.InService, AdminStates.InService)) .setServiceResiliency(serviceResiliency) .build()); when(service.getDataAfter()).thenReturn(serviceAfter); when(serviceDataStoreOperations.getService(anyString())).thenReturn(Optional.of(serviceAfter)); - when(servicehandler.serviceDelete(any())).thenReturn( - RpcResultBuilder.success( - new ServiceDeleteOutputBuilder() - .setConfigurationResponseCommon( - new ConfigurationResponseCommonBuilder() + when(servicehandler.serviceDelete(any())) + .thenReturn(RpcResultBuilder.success(new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder() .setResponseCode(ResponseCodes.RESPONSE_OK) .build()) .build()) .buildFuture()); - when(servicehandler.serviceReroute(any())).thenReturn( - RpcResultBuilder.success( - new ServiceRerouteOutputBuilder() - .setConfigurationResponseCommon( - new ConfigurationResponseCommonBuilder() + when(servicehandler.serviceReroute(any())) + .thenReturn(RpcResultBuilder.success(new ServiceRerouteOutputBuilder() + .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder() .setResponseCode(ResponseCodes.RESPONSE_OK) .build()) .build()) .buildFuture()); - when(servicehandler.serviceCreate(any())).thenReturn( - RpcResultBuilder.success( - new ServiceCreateOutputBuilder() - .setConfigurationResponseCommon( - new ConfigurationResponseCommonBuilder() + when(servicehandler.serviceCreate(any())) + .thenReturn(RpcResultBuilder.success(new ServiceCreateOutputBuilder() + .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder() .setResponseCode(ResponseCodes.RESPONSE_OK) .build()) .build()) @@ -217,7 +209,7 @@ public class ServiceListenerTest { } @Test - public void testOnDataTreeChangedWhenServiceDegradedShouldNotBeRerouted() { + void testOnDataTreeChangedWhenServiceDegradedShouldNotBeRerouted() { @SuppressWarnings("unchecked") final DataObjectModification service = mock(DataObjectModification.class); final Collection> changes = new HashSet<>(); @@ -244,27 +236,24 @@ public class ServiceListenerTest { } private Services buildService(State state, AdminStates adminStates) { - ServiceAEnd serviceAEnd = getServiceAEndBuild().build(); - ServiceZEnd serviceZEnd = new ServiceZEndBuilder() - .setClli("clli") - .setServiceFormat(ServiceFormat.Ethernet) - .setServiceRate(Uint32.valueOf(1)) - .setNodeId(new NodeIdType("XPONDER-3-2")) - .setTxDirection(Map.of(new TxDirectionKey(getTxDirection().key()), getTxDirection())) - .setRxDirection(Map.of(new RxDirectionKey(getRxDirection().key()), getRxDirection())) - .build(); - ServicesBuilder builtInput = new ServicesBuilder() + return new ServicesBuilder() .setSdncRequestHeader(new SdncRequestHeaderBuilder().build()) .setCommonId("commonId") .setConnectionType(ConnectionType.Service) .setCustomer("Customer") .setServiceName("service 1") - .setServiceAEnd(serviceAEnd) - .setServiceZEnd(serviceZEnd) + .setServiceAEnd(getServiceAEndBuild().build()) + .setServiceZEnd(new ServiceZEndBuilder() + .setClli("clli") + .setServiceFormat(ServiceFormat.Ethernet) + .setServiceRate(Uint32.valueOf(1)) + .setNodeId(new NodeIdType("XPONDER-3-2")) + .setTxDirection(Map.of(new TxDirectionKey(getTxDirection().key()), getTxDirection())) + .setRxDirection(Map.of(new RxDirectionKey(getRxDirection().key()), getRxDirection())) + .build()) .setOperationalState(state) - .setAdministrativeState(adminStates); - - return builtInput.build(); + .setAdministrativeState(adminStates) + .build(); } private ServiceAEndBuilder getServiceAEndBuild() { @@ -328,4 +317,4 @@ public class ServiceListenerTest { .setPublisherName("ServiceListener") .build(); } -} +} \ No newline at end of file diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapperTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapperTest.java index e13e55f40..beda4b296 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapperTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/PCEServiceWrapperTest.java @@ -7,18 +7,19 @@ */ package org.opendaylight.transportpce.servicehandler.service; + +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; import com.google.common.util.concurrent.ListenableFuture; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.pce.service.PathComputationService; @@ -38,6 +39,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.Service import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInputBuilder; +@ExtendWith(MockitoExtension.class) public class PCEServiceWrapperTest extends AbstractTest { @Mock @@ -47,124 +49,98 @@ public class PCEServiceWrapperTest extends AbstractTest { @InjectMocks private PCEServiceWrapper pceServiceWrapperMock; - private AutoCloseable closeable; - - @Before - public void openMocks() throws NoSuchMethodException { - closeable = MockitoAnnotations.openMocks(this); - } @Test - public void performPCENullSdncRequestHeader() { + void performPCENullSdncRequestHeader() { ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput(); input = new ServiceCreateInputBuilder(input).setSdncRequestHeader(null).build(); PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true); - Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, - pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - pceResponse.getConfigurationResponseCommon().getResponseCode()); - Mockito.verifyNoInteractions(this.pathComputationServiceMock); + assertEquals(ResponseCodes.FINAL_ACK_YES, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_FAILED, pceResponse.getConfigurationResponseCommon().getResponseCode()); + verifyNoInteractions(this.pathComputationServiceMock); } @Test - public void performPCENullServiceName() { + void performPCENullServiceName() { ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput(); input = new ServiceCreateInputBuilder(input).setServiceName(null).build(); PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true); - Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, - pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - pceResponse.getConfigurationResponseCommon().getResponseCode()); - Mockito.verifyNoInteractions(this.pathComputationServiceMock); + assertEquals(ResponseCodes.FINAL_ACK_YES, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_FAILED, pceResponse.getConfigurationResponseCommon().getResponseCode()); + verifyNoInteractions(this.pathComputationServiceMock); } @Test - public void performPCENullCommonId() { + void performPCENullCommonId() { TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput(); input = new TempServiceCreateInputBuilder(input).setCommonId(null).build(); PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true); - Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, - pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - pceResponse.getConfigurationResponseCommon().getResponseCode()); - Mockito.verifyNoInteractions(this.pathComputationServiceMock); + assertEquals(ResponseCodes.FINAL_ACK_YES, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_FAILED, pceResponse.getConfigurationResponseCommon().getResponseCode()); + verifyNoInteractions(this.pathComputationServiceMock); } @Test - public void cancelPCEResourceNullServiceName() { + void cancelPCEResourceNullServiceName() { CancelResourceReserveOutput pceResponse = this.pceServiceWrapperMock.cancelPCEResource(null, ServiceNotificationTypes.ServiceDeleteResult); - Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, - pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - pceResponse.getConfigurationResponseCommon().getResponseCode()); - Mockito.verifyNoInteractions(this.pathComputationServiceMock); + assertEquals(ResponseCodes.FINAL_ACK_YES, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_FAILED, pceResponse.getConfigurationResponseCommon().getResponseCode()); + verifyNoInteractions(this.pathComputationServiceMock); } @Test - public void cancelPCEResourceValid() { + void cancelPCEResourceValid() { ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); CancelResourceReserveOutput output = new CancelResourceReserveOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); ListenableFuture response = ServiceDataUtils.returnFuture(output); - Mockito.when(this.pathComputationServiceMock.cancelResourceReserve(any(CancelResourceReserveInput.class))) - .thenReturn(response); - CancelResourceReserveOutput pceResponse = - this.pceServiceWrapperMock.cancelPCEResource("service 1", ServiceNotificationTypes.ServiceDeleteResult); - Assert.assertEquals(ResponseCodes.FINAL_ACK_NO, - pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_OK, - pceResponse.getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals("PCE calculation in progress", - pceResponse.getConfigurationResponseCommon().getResponseMessage()); + when(this.pathComputationServiceMock.cancelResourceReserve(any(CancelResourceReserveInput.class))) + .thenReturn(response); + CancelResourceReserveOutput pceResponse = this.pceServiceWrapperMock + .cancelPCEResource("service 1", ServiceNotificationTypes.ServiceDeleteResult); + assertEquals(ResponseCodes.FINAL_ACK_NO, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode()); + assertEquals("PCE calculation in progress", pceResponse.getConfigurationResponseCommon().getResponseMessage()); verify(this.pathComputationServiceMock).cancelResourceReserve(any(CancelResourceReserveInput.class)); } @Test - public void performPCEValid() { + void performPCEValid() { ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); PathComputationRequestOutput output = new PathComputationRequestOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); ListenableFuture response = ServiceDataUtils.returnFuture(output); - Mockito.when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class))) - .thenReturn(response); + when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class))) + .thenReturn(response); ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput(); PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true); - Assert.assertEquals(ResponseCodes.FINAL_ACK_NO, - pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_OK, - pceResponse.getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals("PCE calculation in progress", - pceResponse.getConfigurationResponseCommon().getResponseMessage()); + assertEquals(ResponseCodes.FINAL_ACK_NO, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode()); + assertEquals("PCE calculation in progress", pceResponse.getConfigurationResponseCommon().getResponseMessage()); verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class))); } @Test - public void performPCETempValid() { + void performPCETempValid() { ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); PathComputationRequestOutput output = new PathComputationRequestOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); ListenableFuture response = ServiceDataUtils.returnFuture(output); - Mockito.when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class))) - .thenReturn(response); + when(this.pathComputationServiceMock.pathComputationRequest(any(PathComputationRequestInput.class))) + .thenReturn(response); TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput(); PathComputationRequestOutput pceResponse = this.pceServiceWrapperMock.performPCE(input, true); - Assert.assertEquals(ResponseCodes.FINAL_ACK_NO, - pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals("PCE calculation in progress", - pceResponse.getConfigurationResponseCommon().getResponseMessage()); + assertEquals(ResponseCodes.FINAL_ACK_NO, pceResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_OK, pceResponse.getConfigurationResponseCommon().getResponseCode()); + assertEquals("PCE calculation in progress", pceResponse.getConfigurationResponseCommon().getResponseMessage()); verify(this.pathComputationServiceMock).pathComputationRequest((any(PathComputationRequestInput.class))); } - - @After public void releaseMocks() throws Exception { - closeable.close(); - } -} +} \ No newline at end of file diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java index ff4404cd3..47bf4f486 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java @@ -7,18 +7,18 @@ */ package org.opendaylight.transportpce.servicehandler.service; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; import com.google.common.util.concurrent.ListenableFuture; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; @@ -42,6 +42,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempSer * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange * */ +@ExtendWith(MockitoExtension.class) public class RendererServiceWrapperTest extends AbstractTest { @Mock private RendererServiceOperations rendererServiceOperationsMock; @@ -50,115 +51,98 @@ public class RendererServiceWrapperTest extends AbstractTest { @InjectMocks private RendererServiceWrapper rendererServiceWrapperMock; - private AutoCloseable closeable; - - @Before - public void openMocks() throws NoSuchMethodException { - closeable = MockitoAnnotations.openMocks(this); - } @Test - public void performRendererNullServiceHandlerHeader() { - ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput - serviceDeleteInput = - ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input)); + void performRendererNullServiceHandlerHeader() { + var serviceDeleteInput = ModelMappingUtils + .createServiceDeleteInput(new ServiceInput(ServiceDataUtils.buildServiceDeleteInput())); serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceHandlerHeader(null).build(); ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, null); - Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, + assertEquals(ResponseCodes.FINAL_ACK_YES, response.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, + assertEquals(ResponseCodes.RESPONSE_FAILED, response.getConfigurationResponseCommon().getResponseCode()); - Mockito.verifyNoInteractions(this.rendererServiceOperationsMock); + verifyNoInteractions(this.rendererServiceOperationsMock); } @Test - public void performRendererNullServiceName() { - ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput - serviceDeleteInput = - ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input)); + void performRendererNullServiceName() { + var serviceDeleteInput = ModelMappingUtils + .createServiceDeleteInput(new ServiceInput(ServiceDataUtils.buildServiceDeleteInput())); serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceName(null).build(); - ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput, - ServiceNotificationTypes.ServiceDeleteResult, null); - Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, - response.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - response.getConfigurationResponseCommon().getResponseCode()); - Mockito.verifyNoInteractions(this.rendererServiceOperationsMock); + ServiceDeleteOutput response = this.rendererServiceWrapperMock + .performRenderer(serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, null); + assertEquals(ResponseCodes.FINAL_ACK_YES, response.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_FAILED, response.getConfigurationResponseCommon().getResponseCode()); + verifyNoInteractions(this.rendererServiceOperationsMock); } @Test - public void performRendererNullCommonId() { - TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(); - input = new TempServiceDeleteInputBuilder(input).setCommonId(null).build(); - ServiceDeleteOutput response = - this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult); - Assert.assertEquals(ResponseCodes.FINAL_ACK_YES, - response.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - response.getConfigurationResponseCommon().getResponseCode()); - Mockito.verifyNoInteractions(this.rendererServiceOperationsMock); + void performRendererNullCommonId() { + TempServiceDeleteInput input = new TempServiceDeleteInputBuilder(ServiceDataUtils.buildTempServiceDeleteInput()) + .setCommonId(null).build(); + ServiceDeleteOutput response = this.rendererServiceWrapperMock + .performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult); + assertEquals(ResponseCodes.FINAL_ACK_YES, response.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_FAILED, response.getConfigurationResponseCommon().getResponseCode()); + verifyNoInteractions(this.rendererServiceOperationsMock); } - @Test - public void performRendererValid() { + void performRendererValid() { ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress") - .build(); + .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress") + .build(); ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon).build(); + .setConfigurationResponseCommon(configurationResponseCommon).build(); ListenableFuture response = ServiceDataUtils.returnFuture(output); - Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any( - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915 - .ServiceDeleteInput.class), any())).thenReturn(response); + when(this.rendererServiceOperationsMock.serviceDelete(any( + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput + .class), any())) + .thenReturn(response); ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput - serviceDeleteInput = - ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input)); - ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput, - ServiceNotificationTypes.ServiceDeleteResult, null); - Assert.assertEquals(ResponseCodes.FINAL_ACK_NO, - rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_OK, - rendereResponse.getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals("Renderer service delete in progress", - rendereResponse.getConfigurationResponseCommon().getResponseMessage()); + var serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input)); + ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock + .performRenderer(serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, null); + assertEquals( + ResponseCodes.FINAL_ACK_NO, + rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_OK, rendereResponse.getConfigurationResponseCommon().getResponseCode()); + assertEquals( + "Renderer service delete in progress", + rendereResponse.getConfigurationResponseCommon().getResponseMessage()); verify(this.rendererServiceOperationsMock).serviceDelete(any( - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915 - .ServiceDeleteInput.class), any()); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput + .class), any()); } @Test - public void performRendererTempValid() { + void performRendererTempValid() { ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() - .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) - .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress") - .build(); + .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress") + .build(); ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() - .setConfigurationResponseCommon(configurationResponseCommon).build(); + .setConfigurationResponseCommon(configurationResponseCommon).build(); ListenableFuture response = ServiceDataUtils.returnFuture(output); - Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any( - org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915 - .ServiceDeleteInput.class), any())).thenReturn(response); + when(this.rendererServiceOperationsMock.serviceDelete(any( + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput + .class), any())) + .thenReturn(response); TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(); - ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(input, - ServiceNotificationTypes.ServiceDeleteResult); - Assert.assertEquals(ResponseCodes.FINAL_ACK_NO, - rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator()); - Assert.assertEquals(ResponseCodes.RESPONSE_OK, - rendereResponse.getConfigurationResponseCommon().getResponseCode()); - Assert.assertEquals("Renderer service delete in progress", - rendereResponse.getConfigurationResponseCommon().getResponseMessage()); + ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock + .performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult); + assertEquals( + ResponseCodes.FINAL_ACK_NO, + rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator()); + assertEquals(ResponseCodes.RESPONSE_OK, rendereResponse.getConfigurationResponseCommon().getResponseCode()); + assertEquals( + "Renderer service delete in progress", + rendereResponse.getConfigurationResponseCommon().getResponseMessage()); verify(this.rendererServiceOperationsMock).serviceDelete(any( org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput .class), any()); } - - @After public void releaseMocks() throws Exception { - closeable.close(); - } -} +} \ No newline at end of file diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java index 5fa8aba6f..d36752860 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java @@ -7,12 +7,15 @@ */ package org.opendaylight.transportpce.servicehandler.service; +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.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl.LogMessages; import java.util.Optional; -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.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.transportpce.common.OperationResult; import org.opendaylight.transportpce.common.ResponseCodes; @@ -41,52 +44,48 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { private ServiceDataStoreOperationsImpl serviceDataStoreOperations; - @Before - public void init() { + @BeforeEach + void init() { DataBroker dataBroker = this.getNewDataBroker(); this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker); } @Test - public void modifyIfServiceNotPresent() { - OperationResult result = - this.serviceDataStoreOperations.modifyService("service 1", State.InService, AdminStates.InService); - Assert.assertFalse(result.isSuccess()); - Assert.assertEquals(LogMessages.SERVICE_NOT_FOUND, result.getResultMessage()); + void modifyIfServiceNotPresent() { + OperationResult result = this.serviceDataStoreOperations + .modifyService("service 1", State.InService, AdminStates.InService); + assertFalse(result.isSuccess()); + assertEquals(LogMessages.SERVICE_NOT_FOUND, result.getResultMessage()); } @Test - public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() { - + void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); - String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput", - createInput, pathComputationRequestOutput, 3); - - Assert.assertEquals(LogMessages.SERVICE_NOT_FOUND, result); + String result = serviceDataStoreOperations + .writeOrModifyOrDeleteServiceList("serviceCreateInput", createInput, pathComputationRequestOutput, 3); + assertEquals(LogMessages.SERVICE_NOT_FOUND, result); } @Test - public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() { - + void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); - String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1", - createInput, pathComputationRequestOutput, 2); - - Assert.assertNull(result); + String result = serviceDataStoreOperations + .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 2); + assertNull(result); } @Test - public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() { + void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) @@ -94,28 +93,27 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); this.serviceDataStoreOperations.createService(createInput); - String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1", - createInput, pathComputationRequestOutput, 0); - Assert.assertNull(result); + String result = serviceDataStoreOperations + .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 0); + assertNull(result); } @Test - public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() { + void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); - ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build(); PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); this.serviceDataStoreOperations.createService(createInput); - String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1", - createInput, pathComputationRequestOutput, 1); - Assert.assertNull(result); + String result = serviceDataStoreOperations + .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 1); + assertNull(result); } @Test - public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() { + void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) @@ -123,102 +121,101 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).build(); this.serviceDataStoreOperations.createService(createInput); - String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1", - createInput, pathComputationRequestOutput, 2); - Assert.assertNull(result); - + String result = serviceDataStoreOperations + .writeOrModifyOrDeleteServiceList("service 1",createInput, pathComputationRequestOutput, 2); + assertNull(result); } @Test - public void getServiceFromEmptyDataStoreShouldBeEmpty() { + void getServiceFromEmptyDataStoreShouldBeEmpty() { Optional optService = this.serviceDataStoreOperations.getService("service 1"); - Assert.assertFalse(optService.isPresent()); + assertFalse(optService.isPresent()); } @Test - public void createServiceShouldBeSuccessForValidInput() { + void createServiceShouldBeSuccessForValidInput() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); OperationResult result = this.serviceDataStoreOperations.createService(createInput); - Assert.assertTrue(result.isSuccess()); + assertTrue(result.isSuccess()); } @Test - public void getServiceShouldReturnTheCorrectServiceForTheCreatedService() { + void getServiceShouldReturnTheCorrectServiceForTheCreatedService() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); this.serviceDataStoreOperations.createService(createInput); Optional optService = this.serviceDataStoreOperations.getService(createInput.getServiceName()); - Assert.assertTrue(optService.isPresent()); - Assert.assertEquals(createInput.getServiceName(), optService.get().getServiceName()); + assertTrue(optService.isPresent()); + assertEquals(createInput.getServiceName(), optService.get().getServiceName()); } @Test - public void deleteServiceShouldBeSuccessfulForDeletingService() { + void deleteServiceShouldBeSuccessfulForDeletingService() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); this.serviceDataStoreOperations.createService(createInput); OperationResult result = this.serviceDataStoreOperations.deleteService(createInput.getServiceName()); - Assert.assertTrue(result.isSuccess()); + assertTrue(result.isSuccess()); } -// @Test -// public void deleteServiceShouldBeFailedIfServiceDoNotExists() { -// OperationResult result = this.serviceDataStoreOperations.deleteService("Any service"); -// Assert.assertFalse(result.isSuccess()); -// } + @Test + void deleteServiceShouldBeSuccessEvenIfServiceDoNotExists() { + OperationResult result = this.serviceDataStoreOperations.deleteService("Any service"); + assertTrue(result.isSuccess()); + } @Test - public void modifyServiceIsSuccessfulForPresentService() { + void modifyServiceIsSuccessfulForPresentService() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); this.serviceDataStoreOperations.createService(createInput); OperationResult result = this.serviceDataStoreOperations.modifyService(createInput.getServiceName(), State.InService, AdminStates.InService); - Assert.assertTrue(result.isSuccess()); + assertTrue(result.isSuccess()); } @Test - public void getTempServiceFromEmptyDataStoreShouldBeEmpty() { + void getTempServiceFromEmptyDataStoreShouldBeEmpty() { Optional optService = this.serviceDataStoreOperations.getTempService("service 1"); - Assert.assertFalse(optService.isPresent()); + assertFalse(optService.isPresent()); } @Test - public void createTempServiceShouldBeSuccessForValidInput() { + void createTempServiceShouldBeSuccessForValidInput() { TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput(); OperationResult result = this.serviceDataStoreOperations.createTempService(createInput); - Assert.assertTrue(result.isSuccess()); + assertTrue(result.isSuccess()); } @Test - public void getTempServiceShouldReturnTheCorrectTempServiceForTheCreatedService() { + void getTempServiceShouldReturnTheCorrectTempServiceForTheCreatedService() { TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput(); this.serviceDataStoreOperations.createTempService(createInput); Optional optService = this.serviceDataStoreOperations.getTempService(createInput.getCommonId()); - Assert.assertTrue(optService.isPresent()); - Assert.assertEquals(createInput.getCommonId(), optService.get().getCommonId()); + assertTrue(optService.isPresent()); + assertEquals(createInput.getCommonId(), optService.get().getCommonId()); } @Test - public void deleteTempServiceShouldBeSuccessfulForDeletingTempService() { + void deleteTempServiceShouldBeSuccessfulForDeletingTempService() { TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput(); this.serviceDataStoreOperations.createTempService(createInput); OperationResult result = this.serviceDataStoreOperations.deleteTempService(createInput.getCommonId()); - Assert.assertTrue(result.isSuccess()); + assertTrue(result.isSuccess()); } @Test - public void modifyTempServiceIsSuccessfulForPresentTempService() { + void modifyTempServiceIsSuccessfulForPresentTempService() { TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput(); this.serviceDataStoreOperations.createTempService(createInput); OperationResult result = this.serviceDataStoreOperations.modifyTempService( createInput.getCommonId(), State.InService, AdminStates.InService); - Assert.assertTrue(result.isSuccess()); + assertTrue(result.isSuccess()); } @Test - public void createServicePathShouldBeSuccessfulForValidInput() { + void createServicePathShouldBeSuccessfulForValidInput() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); this.serviceDataStoreOperations.createService(createInput); ServiceInput serviceInput = new ServiceInput(createInput); @@ -235,13 +232,13 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters) .build(); - OperationResult result = - this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput); - Assert.assertTrue(result.isSuccess()); + OperationResult result = this.serviceDataStoreOperations + .createServicePath(serviceInput, pathComputationRequestOutput); + assertTrue(result.isSuccess()); } @Test - public void createServicePathShouldFailForInvalidInput() { + void createServicePathShouldFailForInvalidInput() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); this.serviceDataStoreOperations.createService(createInput); ServiceInput serviceInput = new ServiceInput(createInput); @@ -252,13 +249,13 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder() .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters) .build(); - OperationResult result = - this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput); - Assert.assertFalse(result.isSuccess()); + OperationResult result = this.serviceDataStoreOperations + .createServicePath(serviceInput, pathComputationRequestOutput); + assertFalse(result.isSuccess()); } @Test - public void deleteServicePathShouldBeSuccessForDeletingServicePath() { + void deleteServicePathShouldBeSuccessForDeletingServicePath() { ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); this.serviceDataStoreOperations.createService(createInput); ServiceInput serviceInput = new ServiceInput(createInput); @@ -278,6 +275,6 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput); OperationResult result = this.serviceDataStoreOperations.deleteServicePath(serviceInput.getServiceName()); - Assert.assertTrue(result.isSuccess()); + assertTrue(result.isSuccess()); } -} +} \ No newline at end of file diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/MockedNotificationServiceWrapper.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/MockedNotificationServiceWrapper.java index 2a54caaea..ed375bc11 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/MockedNotificationServiceWrapper.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/MockedNotificationServiceWrapper.java @@ -7,7 +7,7 @@ */ package org.opendaylight.transportpce.servicehandler.utils; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/ServiceCreateValidationTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/ServiceCreateValidationTest.java index 6c0f0a961..1f39e73d4 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/ServiceCreateValidationTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/ServiceCreateValidationTest.java @@ -7,10 +7,11 @@ */ package org.opendaylight.transportpce.servicehandler.validation; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.Map; import java.util.Set; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.transportpce.common.OperationResult; import org.opendaylight.transportpce.servicehandler.ServiceInput; import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; @@ -26,16 +27,16 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.Service public class ServiceCreateValidationTest { @Test - public void validateServiceCreateRequestIfCommonIdNull() { + void validateServiceCreateRequestIfCommonIdNull() { ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput()) .setCommonId(null).build(); - OperationResult result = - ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate); - Assert.assertEquals(true, result.isSuccess()); + OperationResult result = ServiceCreateValidation + .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate); + assertEquals(true, result.isSuccess()); } @Test - public void validateServiceCreateRequestIfConstraintsNotNull() { + void validateServiceCreateRequestIfConstraintsNotNull() { ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput()) .setHardConstraints(new HardConstraintsBuilder() .setCoRouting(new CoRoutingBuilder() @@ -57,22 +58,22 @@ public class ServiceCreateValidationTest { .build()) .setCustomerCode(Set.of("Some customer-code")) .build()).build(); - OperationResult result = - ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate); - Assert.assertEquals(false, result.isSuccess()); + OperationResult result = ServiceCreateValidation + .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate); + assertEquals(false, result.isSuccess()); } @Test - public void validateServiceCreateRequestIfConstraintsNull() { + void validateServiceCreateRequestIfConstraintsNull() { ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput()) .setSoftConstraints(null).setHardConstraints(null).build(); - OperationResult result = - ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate); - Assert.assertEquals(true, result.isSuccess()); + OperationResult result = ServiceCreateValidation + .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate); + assertEquals(true, result.isSuccess()); } @Test - public void validateServiceCreateRequestIfHardConstraintsNull() { + void validateServiceCreateRequestIfHardConstraintsNull() { ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput()) .setSoftConstraints(new SoftConstraintsBuilder() .setCoRouting(new CoRoutingBuilder() @@ -84,13 +85,13 @@ public class ServiceCreateValidationTest { .build()) .setCustomerCode(Set.of("Some customer-code")) .build()).setHardConstraints(null).build(); - OperationResult result = - ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate); - Assert.assertEquals(true, result.isSuccess()); + OperationResult result = ServiceCreateValidation + .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate); + assertEquals(true, result.isSuccess()); } @Test - public void validateServiceCreateRequestIfSoftConstraintsNull() { + void validateServiceCreateRequestIfSoftConstraintsNull() { ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput()) .setSoftConstraints(null).setHardConstraints(new HardConstraintsBuilder() .setCoRouting(new CoRoutingBuilder() @@ -102,8 +103,8 @@ public class ServiceCreateValidationTest { .build()) .setCustomerCode(Set.of("Some customer-code")) .build()).build(); - OperationResult result = - ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate); - Assert.assertEquals(true, result.isSuccess()); + OperationResult result = ServiceCreateValidation + .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate); + assertEquals(true, result.isSuccess()); } -} +} \ No newline at end of file diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/CheckCoherencyServiceResiliencyTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/CheckCoherencyServiceResiliencyTest.java index 2bf3840a1..c67ce3004 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/CheckCoherencyServiceResiliencyTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/CheckCoherencyServiceResiliencyTest.java @@ -8,10 +8,13 @@ package org.opendaylight.transportpce.servicehandler.validation.checks; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +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 org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.Protected; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.Restorable; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.Unprotected; @@ -21,106 +24,119 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev2 import org.opendaylight.yangtools.yang.common.Uint64; import org.opendaylight.yangtools.yang.common.Uint8; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class CheckCoherencyServiceResiliencyTest { @Test - public void testCheckWhenResiliencyNull() { - ComplianceCheckResult result = ServicehandlerServiceResiliencyCheck.check( - new ServiceResiliencyBuilder().setRevertive(true).build()); + void testCheckWhenResiliencyNull() { + ComplianceCheckResult result = ServicehandlerServiceResiliencyCheck + .check(new ServiceResiliencyBuilder().setRevertive(true).build()); - Assert.assertFalse(result.hasPassed()); - Assert.assertEquals(ServicehandlerServiceResiliencyCheck.LOG_RESILIENCY_NULL, result.getMessage()); + assertFalse(result.hasPassed()); + assertEquals(ServicehandlerServiceResiliencyCheck.LOG_RESILIENCY_NULL, result.getMessage()); } @Test - public void testCheckWhenUnprotectedResiliencyWithWrongAttributes() { + void testCheckWhenUnprotectedResiliencyWithWrongAttributes() { ServiceResiliencyBuilder input = new ServiceResiliencyBuilder().setResiliency(Unprotected.VALUE); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check(input.setRevertive(true).build()).hasPassed()); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setWaitToRestore(Uint64.valueOf(1)).build()).hasPassed()); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setHoldoffTime(Uint64.valueOf(1)).build()).hasPassed()); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setPreCalculatedBackupPathNumber(Uint8.valueOf(1)).build()).hasPassed()); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setCoupledService(new CoupledServiceBuilder().build()).build()).hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck.check(input.setRevertive(true).build()).hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setWaitToRestore(Uint64.valueOf(1)).build()) + .hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setHoldoffTime(Uint64.valueOf(1)).build()) + .hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setPreCalculatedBackupPathNumber(Uint8.valueOf(1)).build()) + .hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setCoupledService(new CoupledServiceBuilder().build()).build()) + .hasPassed()); } @Test - public void testCheckWhenUnprotectedResiliencyWithCorrectAttributes() { - Assert.assertTrue(ServicehandlerServiceResiliencyCheck.check( - new ServiceResiliencyBuilder() - .setResiliency(Unprotected.VALUE) - .build()) - .hasPassed()); + void testCheckWhenUnprotectedResiliencyWithCorrectAttributes() { + assertTrue(ServicehandlerServiceResiliencyCheck + .check(new ServiceResiliencyBuilder().setResiliency(Unprotected.VALUE).build()) + .hasPassed()); } @Test - public void testCheckWhenUnprotectedDiverselyRoutedResiliencyWithWrongAttributes() { + void testCheckWhenUnprotectedDiverselyRoutedResiliencyWithWrongAttributes() { ServiceResiliencyBuilder input = new ServiceResiliencyBuilder().setResiliency(UnprotectedDiverselyRouted.VALUE); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check(input.setRevertive(true).build()).hasPassed()); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setWaitToRestore(Uint64.valueOf(1)).build()).hasPassed()); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setHoldoffTime(Uint64.valueOf(1)).build()).hasPassed()); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setPreCalculatedBackupPathNumber(Uint8.valueOf(1)).build()).hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck.check(input.setRevertive(true).build()).hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setWaitToRestore(Uint64.valueOf(1)).build()) + .hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setHoldoffTime(Uint64.valueOf(1)).build()) + .hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setPreCalculatedBackupPathNumber(Uint8.valueOf(1)).build()) + .hasPassed()); } @Test - public void testCheckWhenUnprotectedDiverselyRoutedResiliencyWithCorrectAttributes() { - Assert.assertTrue(ServicehandlerServiceResiliencyCheck.check( - new ServiceResiliencyBuilder().setResiliency(UnprotectedDiverselyRouted.VALUE) - .setCoupledService(new CoupledServiceBuilder().build()).build()).hasPassed()); + void testCheckWhenUnprotectedDiverselyRoutedResiliencyWithCorrectAttributes() { + assertTrue(ServicehandlerServiceResiliencyCheck + .check(new ServiceResiliencyBuilder() + .setResiliency(UnprotectedDiverselyRouted.VALUE) + .setCoupledService(new CoupledServiceBuilder().build()) + .build()) + .hasPassed()); } @Test - public void testCheckWhenProtectedResiliencyWithWrongAttributes() { + void testCheckWhenProtectedResiliencyWithWrongAttributes() { ServiceResiliencyBuilder input = new ServiceResiliencyBuilder().setResiliency(Protected.VALUE); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setWaitToRestore(Uint64.valueOf(1)).setRevertive(false).build()).hasPassed()); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setPreCalculatedBackupPathNumber(Uint8.valueOf(1)).build()).hasPassed()); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setCoupledService(new CoupledServiceBuilder().build()).build()).hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setWaitToRestore(Uint64.valueOf(1)).setRevertive(false).build()) + .hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setPreCalculatedBackupPathNumber(Uint8.valueOf(1)).build()) + .hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setCoupledService(new CoupledServiceBuilder().build()).build()) + .hasPassed()); } @Test - public void testCheckWhenProtectedResiliencyWithCorrectAttributes() { - Assert.assertTrue(ServicehandlerServiceResiliencyCheck.check( - new ServiceResiliencyBuilder() - .setResiliency(Protected.VALUE) - .setRevertive(true) - .setWaitToRestore(Uint64.valueOf(1)) - .setHoldoffTime(Uint64.valueOf(1)) - .build()) - .hasPassed()); + void testCheckWhenProtectedResiliencyWithCorrectAttributes() { + assertTrue(ServicehandlerServiceResiliencyCheck + .check(new ServiceResiliencyBuilder() + .setResiliency(Protected.VALUE) + .setRevertive(true) + .setWaitToRestore(Uint64.valueOf(1)) + .setHoldoffTime(Uint64.valueOf(1)) + .build()) + .hasPassed()); } @Test - public void testCheckWhenRestorableOrExternalTriggerRestorableResiliencyWithWrongAttributes() { + void testCheckWhenRestorableOrExternalTriggerRestorableResiliencyWithWrongAttributes() { ServiceResiliencyBuilder input = new ServiceResiliencyBuilder().setResiliency(Restorable.VALUE); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setWaitToRestore(Uint64.valueOf(1)).setRevertive(false).build()).hasPassed()); - Assert.assertFalse(ServicehandlerServiceResiliencyCheck.check( - input.setCoupledService(new CoupledServiceBuilder().build()).build()).hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setWaitToRestore(Uint64.valueOf(1)).setRevertive(false).build()) + .hasPassed()); + assertFalse(ServicehandlerServiceResiliencyCheck + .check(input.setCoupledService(new CoupledServiceBuilder().build()).build()) + .hasPassed()); } @Test - public void testCheckWhenRestorableOrExternalTriggerRestorableResiliencyWithCorrectAttributes() { - Assert.assertTrue(ServicehandlerServiceResiliencyCheck.check( - new ServiceResiliencyBuilder() - .setResiliency(Restorable.VALUE) - .setRevertive(true) - .setWaitToRestore(Uint64.valueOf(1)) - .setHoldoffTime(Uint64.valueOf(1)) - .setPreCalculatedBackupPathNumber(Uint8.valueOf(1)) - .build()) - .hasPassed()); + void testCheckWhenRestorableOrExternalTriggerRestorableResiliencyWithCorrectAttributes() { + assertTrue(ServicehandlerServiceResiliencyCheck + .check(new ServiceResiliencyBuilder() + .setResiliency(Restorable.VALUE) + .setRevertive(true) + .setWaitToRestore(Uint64.valueOf(1)) + .setHoldoffTime(Uint64.valueOf(1)) + .setPreCalculatedBackupPathNumber(Uint8.valueOf(1)) + .build()) + .hasPassed()); } } diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ComplianceCheckResultTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ComplianceCheckResultTest.java index 0c6e44d57..dbabd5af7 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ComplianceCheckResultTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ComplianceCheckResultTest.java @@ -7,17 +7,18 @@ */ package org.opendaylight.transportpce.servicehandler.validation.checks; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; public class ComplianceCheckResultTest { @Test - public void constructComplianceCheckResult() { + void constructComplianceCheckResult() { ComplianceCheckResult checkResult = new ComplianceCheckResult(true); - Assert.assertEquals(true, checkResult.hasPassed()); + assertEquals(true, checkResult.hasPassed()); checkResult = new ComplianceCheckResult(false); - Assert.assertEquals(false, checkResult.hasPassed()); + assertEquals(false, checkResult.hasPassed()); } -} +} \ No newline at end of file diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerComplianceCheckTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerComplianceCheckTest.java index cab20097b..d779f886a 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerComplianceCheckTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerComplianceCheckTest.java @@ -7,87 +7,84 @@ */ package org.opendaylight.transportpce.servicehandler.validation.checks; +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.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerComplianceCheck.LogMessages; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.RpcActions; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.sdnc.request.header.SdncRequestHeaderBuilder; public class ServicehandlerComplianceCheckTest { - public ServicehandlerComplianceCheckTest() { - } - @Test - public void checkFalseSdncRequest() { + void checkFalseSdncRequest() { ComplianceCheckResult result = ServicehandlerComplianceCheck.check("service 1", - new SdncRequestHeaderBuilder().setRequestId("1").setRequestSystemId("1").setNotificationUrl("1") - .setRpcAction(RpcActions.ServiceCreate).build(), - ConnectionType.Service,RpcActions.ServiceCreate, false, false); + new SdncRequestHeaderBuilder().setRequestId("1").setRequestSystemId("1").setNotificationUrl("1") + .setRpcAction(RpcActions.ServiceCreate).build(), + ConnectionType.Service,RpcActions.ServiceCreate, false, false); - Assert.assertEquals("", result.getMessage()); - Assert.assertTrue(result.hasPassed()); + assertEquals("", result.getMessage()); + assertTrue(result.hasPassed()); } @Test - public void checkServiceNameNull() { - ComplianceCheckResult result = ServicehandlerComplianceCheck.check(null, null, - ConnectionType.Service, null, false, false); + void checkServiceNameNull() { + ComplianceCheckResult result = ServicehandlerComplianceCheck + .check(null, null, ConnectionType.Service, null, false, false); - Assert.assertEquals(LogMessages.SERVICENAME_NOT_SET, result.getMessage()); - Assert.assertFalse(result.hasPassed()); + assertEquals(LogMessages.SERVICENAME_NOT_SET, result.getMessage()); + assertFalse(result.hasPassed()); } @Test - public void checkConTypeFalseAndNull() { - ComplianceCheckResult result = ServicehandlerComplianceCheck.check("service 1", null, - null, null, true, false); - Assert.assertEquals(LogMessages.CONNECTIONTYPE_NOT_SET, result.getMessage()); - Assert.assertFalse(result.hasPassed()); + void checkConTypeFalseAndNull() { + ComplianceCheckResult result = ServicehandlerComplianceCheck + .check("service 1", null, null, null, true, false); + assertEquals(LogMessages.CONNECTIONTYPE_NOT_SET, result.getMessage()); + assertFalse(result.hasPassed()); } @Test - public void checkSdncRequestHeaderNull() { - ComplianceCheckResult result = ServicehandlerComplianceCheck.check("service 1", null, - ConnectionType.Service, null, true, true); + void checkSdncRequestHeaderNull() { + ComplianceCheckResult result = ServicehandlerComplianceCheck + .check("service 1", null, ConnectionType.Service, null, true, true); - Assert.assertEquals(LogMessages.HEADER_NOT_SET, result.getMessage()); - Assert.assertFalse(result.hasPassed()); + assertEquals(LogMessages.HEADER_NOT_SET, result.getMessage()); + assertFalse(result.hasPassed()); } @Test - public void checkRequestIdEmptyString() { + void checkRequestIdEmptyString() { ComplianceCheckResult result = ServicehandlerComplianceCheck.check("service 1", - new SdncRequestHeaderBuilder().setRequestId("") - .setRpcAction(RpcActions.ServiceCreate).build(), + new SdncRequestHeaderBuilder().setRequestId("").setRpcAction(RpcActions.ServiceCreate).build(), ConnectionType.Service, RpcActions.ServiceCreate, true, true); - Assert.assertEquals(LogMessages.REQUESTID_NOT_SET, result.getMessage()); - Assert.assertFalse(result.hasPassed()); + assertEquals(LogMessages.REQUESTID_NOT_SET, result.getMessage()); + assertFalse(result.hasPassed()); } @Test - public void checkDifferentAction() { + void checkDifferentAction() { ComplianceCheckResult result = ServicehandlerComplianceCheck.check("service 1", - new SdncRequestHeaderBuilder().setRequestId("1") - .setRpcAction(RpcActions.ServiceCreate).build(), + new SdncRequestHeaderBuilder().setRequestId("1").setRpcAction(RpcActions.ServiceCreate).build(), ConnectionType.Service, RpcActions.NetworkReOptimization, true, true); - Assert.assertEquals( - LogMessages.rpcactionsDiffers(RpcActions.ServiceCreate, RpcActions.NetworkReOptimization), - result.getMessage()); - Assert.assertFalse(result.hasPassed()); + assertEquals( + LogMessages.rpcactionsDiffers(RpcActions.ServiceCreate, RpcActions.NetworkReOptimization), + result.getMessage()); + assertFalse(result.hasPassed()); } @Test - public void checkServiceActionNull() { + void checkServiceActionNull() { ComplianceCheckResult result = ServicehandlerComplianceCheck.check("service 1", new SdncRequestHeaderBuilder().setRequestId("1").build(), ConnectionType.Service, RpcActions.NetworkReOptimization, true, true); - Assert.assertEquals(LogMessages.RPCACTION_NOT_SET, result.getMessage()); - Assert.assertFalse(result.hasPassed()); + assertEquals(LogMessages.RPCACTION_NOT_SET, result.getMessage()); + assertFalse(result.hasPassed()); } } diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerTxRxCheckTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerTxRxCheckTest.java index 832328aa3..032ab931e 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerTxRxCheckTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerTxRxCheckTest.java @@ -8,10 +8,11 @@ package org.opendaylight.transportpce.servicehandler.validation.checks; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerTxRxCheck.LogMessages; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.transportpce.servicehandler.ServiceEndpointType; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.ServiceAEndBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat; @@ -20,47 +21,47 @@ import org.opendaylight.yangtools.yang.common.Uint32; public class ServicehandlerTxRxCheckTest { @Test - public void checkForServiceEndNull() { + void checkForServiceEndNull() { ComplianceCheckResult result = ServicehandlerTxRxCheck.check(null, ServiceEndpointType.SERVICEAEND); - Assert.assertFalse(result.hasPassed()); - Assert.assertEquals(LogMessages.endpointTypeNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage()); + assertFalse(result.hasPassed()); + assertEquals(LogMessages.endpointTypeNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage()); } @Test - public void checkForServiceRateNull() { - ComplianceCheckResult result = - ServicehandlerTxRxCheck.check(new ServiceAEndBuilder().build(), ServiceEndpointType.SERVICEAEND); + void checkForServiceRateNull() { + ComplianceCheckResult result = ServicehandlerTxRxCheck + .check(new ServiceAEndBuilder().build(), ServiceEndpointType.SERVICEAEND); - Assert.assertFalse(result.hasPassed()); - Assert.assertEquals(LogMessages.rateNull(ServiceEndpointType.SERVICEAEND), result.getMessage()); + assertFalse(result.hasPassed()); + assertEquals(LogMessages.rateNull(ServiceEndpointType.SERVICEAEND), result.getMessage()); } @Test - public void checkForServiceRateEquals0() { - ComplianceCheckResult result = ServicehandlerTxRxCheck.check( - new ServiceAEndBuilder().setServiceRate(Uint32.valueOf(0)).build(), ServiceEndpointType.SERVICEAEND); + void checkForServiceRateEquals0() { + ComplianceCheckResult result = ServicehandlerTxRxCheck + .check(new ServiceAEndBuilder().setServiceRate(Uint32.valueOf(0)).build(), ServiceEndpointType.SERVICEAEND); - Assert.assertFalse(result.hasPassed()); - Assert.assertEquals(LogMessages.rateNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage()); + assertFalse(result.hasPassed()); + assertEquals(LogMessages.rateNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage()); } @Test - public void checkForServiceFormatNull() { - ComplianceCheckResult result = ServicehandlerTxRxCheck.check( - new ServiceAEndBuilder().setServiceRate(Uint32.valueOf(3)).build(), ServiceEndpointType.SERVICEAEND); + void checkForServiceFormatNull() { + ComplianceCheckResult result = ServicehandlerTxRxCheck + .check(new ServiceAEndBuilder().setServiceRate(Uint32.valueOf(3)).build(), ServiceEndpointType.SERVICEAEND); - Assert.assertFalse(result.hasPassed()); - Assert.assertEquals(LogMessages.formatNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage()); + assertFalse(result.hasPassed()); + assertEquals(LogMessages.formatNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage()); } @Test - public void checkForClliEmpty() { + void checkForClliEmpty() { ComplianceCheckResult result = ServicehandlerTxRxCheck.check(new ServiceAEndBuilder() - .setServiceRate(Uint32.valueOf(3)).setClli("").setServiceFormat(ServiceFormat.Ethernet).build(), + .setServiceRate(Uint32.valueOf(3)).setClli("").setServiceFormat(ServiceFormat.Ethernet).build(), ServiceEndpointType.SERVICEAEND); - Assert.assertFalse(result.hasPassed()); - Assert.assertEquals(LogMessages.clliNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage()); + assertFalse(result.hasPassed()); + assertEquals(LogMessages.clliNotSet(ServiceEndpointType.SERVICEAEND), result.getMessage()); } -} +} \ No newline at end of file