add unit tests for DowngradeConstraints 45/83245/3
authorAhmed Abbas <ahmad.helmy@orange.com>
Thu, 25 Jul 2019 07:51:22 +0000 (09:51 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Thu, 25 Jul 2019 16:06:06 +0000 (18:06 +0200)
- add UT for updateSoftConstraints method
- add UT for downgradeHardConstraints method
- add UT for convertToSoftConstraints method

Change-Id: I419385d617adb39c87807acc35ef5d0fb2147562
Signed-off-by: Ahmed Abbas <ahmad.helmy@orange.com>
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraintsTest.java [new file with mode: 0644]
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ConstraintsUtils.java [new file with mode: 0644]

diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraintsTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraintsTest.java
new file mode 100644 (file)
index 0000000..fbf3086
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.servicehandler;
+
+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.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildHardConstraintWithCoRouting;
+import static org.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildHardConstraintWithGeneral;
+import static org.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildHardConstraintWithNullGeneral;
+import static org.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildSoftConstraintWithCoRouting;
+import static org.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildSoftConstraintWithGeneral;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRouting;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.General;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints;
+
+/**
+ * Class to test downgrading and updating Constraints .
+ *
+ * @author Ahmed Helmy ( ahmad.helmy@orange.com )
+ *
+ */
+public class DowngradeConstraintsTest {
+
+
+
+    @Test
+    public void testUpdateSoftConstraintsBothCoRouting() {
+        HardConstraints initialHardConstraints = buildHardConstraintWithCoRouting();
+        SoftConstraints initialSoftConstraints = buildSoftConstraintWithCoRouting();
+        SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
+                  initialHardConstraints, initialSoftConstraints);
+
+        assertEquals(
+                generatedSoftConstraints.getCustomerCode().get(0),
+                initialHardConstraints.getCustomerCode().get(0));
+        assertEquals(
+                ((CoRouting)generatedSoftConstraints.getCoRoutingOrGeneral())
+                        .getCoRouting().getExistingService().get(0),
+                ((CoRouting)initialHardConstraints.getCoRoutingOrGeneral())
+                        .getCoRouting().getExistingService().get(0));
+    }
+
+    @Test
+    public void testUpdateSoftConstraintsBothGeneral() {
+        HardConstraints initialHardConstraints = buildHardConstraintWithGeneral();
+        SoftConstraints initialSoftConstraints = buildSoftConstraintWithGeneral();
+        SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
+                initialHardConstraints, initialSoftConstraints);
+
+        assertEquals(
+                generatedSoftConstraints.getCustomerCode().get(0),
+                initialHardConstraints.getCustomerCode().get(0));
+        assertEquals(
+                ((General)generatedSoftConstraints.getCoRoutingOrGeneral())
+                        .getDiversity().getExistingService().get(0),
+                ((General)initialHardConstraints.getCoRoutingOrGeneral())
+                        .getDiversity().getExistingService().get(0));
+
+        assertEquals(
+                ((General)generatedSoftConstraints.getCoRoutingOrGeneral())
+                        .getExclude().getSupportingServiceName().get(0),
+                ((General)initialHardConstraints.getCoRoutingOrGeneral())
+                        .getExclude().getSupportingServiceName().get(0));
+        assertEquals(
+                ((General)generatedSoftConstraints.getCoRoutingOrGeneral())
+                        .getExclude().getNodeId(),
+                ((General)initialHardConstraints.getCoRoutingOrGeneral())
+                        .getExclude().getNodeId());
+        assertEquals(
+                ((General)generatedSoftConstraints.getCoRoutingOrGeneral())
+                        .getInclude().getSupportingServiceName().get(0),
+                ((General)initialHardConstraints.getCoRoutingOrGeneral())
+                        .getInclude().getSupportingServiceName().get(0));
+
+        assertEquals(
+                ((General)generatedSoftConstraints.getCoRoutingOrGeneral())
+                        .getInclude().getNodeId(),
+                ((General)initialHardConstraints.getCoRoutingOrGeneral())
+                        .getInclude().getNodeId());
+    }
+
+    @Test
+    public void testUpdateSoftConstraintsHardGeneralAndSoftCoRouting() {
+        HardConstraints initialHardConstraints = buildHardConstraintWithGeneral();
+        SoftConstraints initialSoftConstraints = buildSoftConstraintWithCoRouting();
+
+
+        SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
+                initialHardConstraints, initialSoftConstraints);
+
+        assertEquals(
+                generatedSoftConstraints.getCustomerCode().get(0),
+                initialHardConstraints.getCustomerCode().get(0));
+        assertTrue(
+                generatedSoftConstraints.getCoRoutingOrGeneral() instanceof  General);
+
+
+    }
+
+
+    @Test
+    public void testUpdateSoftConstraintsHardCoRoutingAndSoftCoGeneral() {
+        HardConstraints initialHardConstraints = buildHardConstraintWithCoRouting();
+        SoftConstraints initialSoftConstraints = buildSoftConstraintWithGeneral();
+
+
+        SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
+                initialHardConstraints, initialSoftConstraints);
+
+        assertEquals(
+                generatedSoftConstraints.getCustomerCode().get(0),
+                initialHardConstraints.getCustomerCode().get(0));
+        assertTrue(
+                generatedSoftConstraints.getCoRoutingOrGeneral() instanceof  CoRouting);
+
+    }
+
+    @Test
+    public void testDowngradeHardConstraintsWithHardGeneralConstraintsSuccess() {
+        HardConstraints initialHardConstraints =
+                buildHardConstraintWithGeneral();
+
+
+        HardConstraints generatedHardConstraints =
+                DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
+
+        assertTrue(generatedHardConstraints.getCoRoutingOrGeneral() instanceof  General);
+
+        assertNotNull((General)generatedHardConstraints.getCoRoutingOrGeneral());
+
+        assertEquals(
+                ((General) generatedHardConstraints.getCoRoutingOrGeneral()).getLatency().getMaxLatency(),
+                ((General) initialHardConstraints.getCoRoutingOrGeneral()).getLatency().getMaxLatency());
+
+    }
+
+    @Test
+    public void testDowngradeHardConstraintsWithNullGeneralHardConstraints() {
+        HardConstraints initialHardConstraints =
+                buildHardConstraintWithNullGeneral();
+
+        HardConstraints generatedHardConstraints =
+                DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
+
+        assertNull(generatedHardConstraints.getCoRoutingOrGeneral());
+
+    }
+
+    @Test
+    public void testDowngradeHardConstraintsWithHardCoRoutingConstraints() {
+        HardConstraints initialHardConstraints =
+                buildHardConstraintWithCoRouting();
+
+        HardConstraints generatedHardConstraints =
+                DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
+
+        assertNull(generatedHardConstraints.getCoRoutingOrGeneral());
+
+    }
+
+
+    @Test
+    public void testConvertToSoftConstraintsFromGeneralHardSuccess() {
+        HardConstraints initialHardConstraints = buildHardConstraintWithGeneral();
+
+
+        SoftConstraints generatedSoftConstraints =
+                DowngradeConstraints.convertToSoftConstraints(initialHardConstraints);
+
+        assertEquals(
+                generatedSoftConstraints.getCustomerCode().get(0),
+                initialHardConstraints.getCustomerCode().get(0));
+        assertTrue(
+                generatedSoftConstraints.getCoRoutingOrGeneral() instanceof  General);
+
+        assertEquals(
+                ((General)generatedSoftConstraints.getCoRoutingOrGeneral())
+                        .getDiversity().getExistingService().get(0),
+                ((General)initialHardConstraints.getCoRoutingOrGeneral())
+                        .getDiversity().getExistingService().get(0));
+
+    }
+
+    @Test
+    public void testConvertToSoftConstraintsFromCoRoutingHardSuccess() {
+        HardConstraints initialHardConstraints = buildHardConstraintWithCoRouting();
+
+
+        SoftConstraints generatedSoftConstraints =
+                DowngradeConstraints.convertToSoftConstraints(initialHardConstraints);
+
+        assertEquals(
+                generatedSoftConstraints.getCustomerCode().get(0),
+                initialHardConstraints.getCustomerCode().get(0));
+        assertTrue(
+                generatedSoftConstraints.getCoRoutingOrGeneral() instanceof  CoRouting);
+
+        assertEquals(
+                ((CoRouting)generatedSoftConstraints.getCoRoutingOrGeneral())
+                        .getCoRouting().getExistingService().get(0),
+                ((CoRouting)initialHardConstraints.getCoRoutingOrGeneral())
+                        .getCoRouting().getExistingService().get(0));
+
+    }
+
+    @Test
+    public void testConvertToSoftConstraintsFromHardNull() {
+        HardConstraints initialHardConstraints = buildHardConstraintWithNullGeneral();
+
+        SoftConstraints generatedSoftConstraints =
+                DowngradeConstraints.convertToSoftConstraints(initialHardConstraints);
+
+        assertNull(generatedSoftConstraints.getCoRoutingOrGeneral());
+
+    }
+
+}
diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ConstraintsUtils.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ConstraintsUtils.java
new file mode 100644 (file)
index 0000000..d45f12c
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.servicehandler.utils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRoutingBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.GeneralBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.DiversityBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.ExcludeBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.IncludeBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.LatencyBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.diversity.existing.service.contraints.ExistingServiceApplicabilityBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraintsBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraintsBuilder;
+
+/**
+ * Utility Class to Build Hard Constraints and Soft Constraints.
+ *
+ * @author Ahmed Helmy ( ahmad.helmy@orange.com )
+ *
+ */
+public final class ConstraintsUtils {
+
+    private ConstraintsUtils() {
+
+    }
+
+    public static SoftConstraints buildSoftConstraintWithCoRouting() {
+        return new SoftConstraintsBuilder()
+                .setCoRoutingOrGeneral(new CoRoutingBuilder()
+                    .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
+                        .constrains.rev161014.constraints.co.routing.or.general.co.routing
+                        .CoRoutingBuilder().setExistingService(
+                            new ArrayList<>(Collections.singletonList("existing-service 1"))).build())
+                    .build())
+                .setCustomerCode(new ArrayList<>(Collections.singletonList("customer-code 1")))
+                .build();
+    }
+
+    public static HardConstraints buildHardConstraintWithCoRouting() {
+        return new HardConstraintsBuilder()
+                .setCoRoutingOrGeneral(new CoRoutingBuilder()
+                    .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
+                        .constrains.rev161014.constraints.co.routing.or.general.co.routing
+                        .CoRoutingBuilder().setExistingService(
+                            new ArrayList<>(Collections.singletonList("existing-service 1"))).build())
+                    .build())
+                .setCustomerCode(new ArrayList<>(Collections.singletonList("customer-code 1")))
+                .build();
+    }
+
+    public static HardConstraints buildHardConstraintWithGeneral() {
+        return new HardConstraintsBuilder()
+                .setCoRoutingOrGeneral(new GeneralBuilder()
+                    .setExclude(new ExcludeBuilder()
+                        .setNodeId(
+                            new ArrayList<>(Collections.singletonList("Ex-Node-Id 1")))
+                        .setFiberBundle(
+                            new ArrayList<>(Collections.singletonList("Ex-Fiber-Bundle 1")))
+                        .setSite(
+                            new ArrayList<>(Collections.singletonList("Ex-site 1")))
+                        .setSupportingServiceName(
+                            new ArrayList<>(Collections.singletonList("Ex-supporting-Service 1")))
+                                .build())
+                    .setInclude(new IncludeBuilder()
+                        .setNodeId(
+                            new ArrayList<>(Collections.singletonList("Inc-Node-Id 1")))
+                        .setFiberBundle(
+                            new ArrayList<>(Collections.singletonList("Inc-Fiber-Bundle 1")))
+                        .setSite(new ArrayList<>(Collections.singletonList("Inc-site 1")))
+                        .setSupportingServiceName(
+                            new ArrayList<>(Collections.singletonList("Inc-supporting-Service-name 1")))
+                        .build())
+                    .setDiversity(new DiversityBuilder()
+                        .setExistingService(
+                            new ArrayList<>(Collections.singletonList("div-existing-service 1")))
+                        .setExistingServiceApplicability(new ExistingServiceApplicabilityBuilder()
+                            .setNode(Boolean.TRUE)
+                            .setSite(Boolean.TRUE)
+                            .setSrlg(Boolean.TRUE)
+                            .build())
+                        .build())
+                    .setLatency(new LatencyBuilder().setMaxLatency(1L).build())
+                    .build())
+                .setCustomerCode(new ArrayList<>(Collections.singletonList("customer-code 1")))
+                .build();
+    }
+
+    public static HardConstraints buildHardConstraintWithNullGeneral() {
+        return new HardConstraintsBuilder()
+                .setCoRoutingOrGeneral(null)
+                .setCustomerCode(new ArrayList<>(Collections.singletonList("customer-code 1")))
+                .build();
+    }
+
+    public static SoftConstraints buildSoftConstraintWithGeneral() {
+        return new SoftConstraintsBuilder()
+                .setCoRoutingOrGeneral(new GeneralBuilder()
+                    .setExclude(new ExcludeBuilder()
+                        .setNodeId(new ArrayList<>())
+                        .setFiberBundle(new ArrayList<>())
+                        .setSite(new ArrayList<>())
+                        .setSupportingServiceName(new ArrayList<>())
+                        .build())
+                    .setInclude(new IncludeBuilder()
+                        .setNodeId(new ArrayList<>())
+                        .setFiberBundle(new ArrayList<>())
+                        .setSite(new ArrayList<>())
+                        .setSupportingServiceName(new ArrayList<>())
+                        .build())
+                    .setDiversity(new DiversityBuilder()
+                        .setExistingService(new ArrayList<>())
+                        .setExistingServiceApplicability(new ExistingServiceApplicabilityBuilder()
+                            .build())
+                        .build())
+                    .build())
+                .setCustomerCode(new ArrayList<>(Collections.singletonList("customer-code 1")))
+                .build();
+
+    }
+}