Update portmapping YANG model
[transportpce.git] / renderer / src / test / java / org / opendaylight / transportpce / renderer / openroadminterface / OpenRoadMInterface221Test.java
1 /*
2  * Copyright © 2019 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.renderer.openroadminterface;
9
10 import java.util.Arrays;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Ignore;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.transportpce.common.fixedflex.SpectrumInformation;
17 import org.opendaylight.transportpce.common.mapping.PortMapping;
18 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
19 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
20 import org.opendaylight.transportpce.test.AbstractTest;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.MappingBuilder;
22 import org.opendaylight.yangtools.yang.common.Uint32;
23
24 @Ignore
25 public class OpenRoadMInterface221Test extends AbstractTest {
26
27     private final PortMapping portMapping = Mockito.mock(PortMapping.class);
28     private OpenRoadmInterface221 openRoadMInterface221;
29     private final String nodeId = "node1";
30
31     @Before
32     public void setup() {
33
34         OpenRoadmInterfaces openRoadmInterfaces = Mockito.spy(OpenRoadmInterfaces.class);
35         this.openRoadMInterface221 = new OpenRoadmInterface221(portMapping, openRoadmInterfaces);
36     }
37
38     @Test
39     public void testCreateOpenRoadmEthInterface() throws OpenRoadmInterfaceException {
40
41         String logicalConnPoint = "logicalConnPoint";
42         Mockito.when(portMapping.getMapping(nodeId, logicalConnPoint)).thenReturn(new MappingBuilder().build());
43         Assert.assertEquals(openRoadMInterface221.createOpenRoadmEthInterface(nodeId, logicalConnPoint),
44                 logicalConnPoint + "-ETHERNET");
45     }
46
47     @Test(expected = Exception.class)
48     public void testCreateOpenRoadmEthInterfaceThrowsExcpetion() throws OpenRoadmInterfaceException {
49
50         String logicalConnPoint = "logicalConnPoint";
51         Mockito.when(portMapping.getMapping(nodeId, logicalConnPoint)).thenReturn(null);
52         openRoadMInterface221.createOpenRoadmEthInterface(nodeId, logicalConnPoint);
53     }
54
55     @Test
56     public void testCreateFlexOCH() throws OpenRoadmInterfaceException {
57
58         String logicalConnPoint = "logicalConnPoint";
59         Mockito.when(portMapping.getMapping(nodeId, logicalConnPoint)).thenReturn(new MappingBuilder().build());
60         SpectrumInformation spectrumInformation = new SpectrumInformation();
61         spectrumInformation.setWaveLength(Uint32.valueOf(1));
62         spectrumInformation.setLowerSpectralSlotNumber(761);
63         spectrumInformation.setHigherSpectralSlotNumber(768);
64         Assert.assertNotNull(openRoadMInterface221.createFlexOCH(nodeId, logicalConnPoint, spectrumInformation));
65         Assert.assertEquals(openRoadMInterface221.createFlexOCH(nodeId, logicalConnPoint, spectrumInformation),
66                 Arrays.asList(logicalConnPoint + "-nmc-761:768"));
67     }
68
69     @Test
70     public void testCreateFlexOCHReturnsMoreThanOneElement() throws OpenRoadmInterfaceException {
71
72         String logicalConnPoint = "logicalConnPointDEG";
73         Mockito.when(portMapping.getMapping(nodeId, logicalConnPoint)).thenReturn(new MappingBuilder().build());
74         SpectrumInformation spectrumInformation = new SpectrumInformation();
75         spectrumInformation.setWaveLength(Uint32.valueOf(1));
76         spectrumInformation.setLowerSpectralSlotNumber(761);
77         spectrumInformation.setHigherSpectralSlotNumber(768);
78         Assert.assertNotNull(openRoadMInterface221.createFlexOCH(nodeId, logicalConnPoint,spectrumInformation));
79         Assert.assertEquals(openRoadMInterface221.createFlexOCH(nodeId, logicalConnPoint, spectrumInformation),
80                 Arrays.asList(logicalConnPoint + "-mc-761:768", logicalConnPoint + "-nmc-761:768"));
81     }
82
83     @Test
84     public void testCreateOpenRoadmOchInterface() throws OpenRoadmInterfaceException {
85
86         String logicalConnPoint = "logicalConnPoint";
87         Mockito.when(portMapping.getMapping(nodeId, logicalConnPoint))
88                 .thenReturn(new MappingBuilder().setLogicalConnectionPoint(logicalConnPoint).build());
89         SpectrumInformation spectrumInformation = new SpectrumInformation();
90         spectrumInformation.setWaveLength(Uint32.valueOf(1));
91         spectrumInformation.setLowerSpectralSlotNumber(761);
92         spectrumInformation.setHigherSpectralSlotNumber(768);
93         Assert.assertEquals(openRoadMInterface221.createOpenRoadmOchInterface(nodeId, logicalConnPoint,
94                 spectrumInformation), logicalConnPoint + "-761:768");
95     }
96
97     @Test
98     public void testCreateOpenRoadmOtu4Interface() throws OpenRoadmInterfaceException {
99
100         String logicalConnPoint = "logicalConnPoint";
101         String supportOchInterface = "supportOchInterface";
102         Mockito.when(portMapping.getMapping(nodeId, logicalConnPoint))
103                 .thenReturn(new MappingBuilder().setLogicalConnectionPoint(logicalConnPoint).build());
104         Assert.assertEquals(
105                 openRoadMInterface221.createOpenRoadmOtu4Interface(nodeId, logicalConnPoint, supportOchInterface),
106                 logicalConnPoint + "-OTU");
107
108     }
109
110     @Test
111     public void testCreateOpenRoadmOchInterfaceName() {
112
113         String logicalConnPoint = "logicalConnPoint";
114         Assert.assertEquals(openRoadMInterface221.createOpenRoadmOchInterfaceName(logicalConnPoint, "761:768"),
115                 logicalConnPoint + "-761:768");
116
117     }
118
119     @Test
120     public void testCreateOpenRoadmOmsInterfaceSupportingOmsNotNull() throws OpenRoadmInterfaceException {
121
122         String supportingOms = "supportingOms";
123         Assert.assertEquals(openRoadMInterface221.createOpenRoadmOmsInterface(nodeId,
124                 new MappingBuilder().setSupportingOms(supportingOms).build()), supportingOms);
125     }
126
127     @Test
128     public void testCreateOpenRoadmOmsInterfaceSupportingOmsNotNullException() throws OpenRoadmInterfaceException {
129
130         Assert.assertNull(openRoadMInterface221.createOpenRoadmOmsInterface(nodeId, new MappingBuilder().build()));
131     }
132
133     @Test
134     public void testCreateOpenRoadmOmsInterfaceSupportingOmsNull() throws OpenRoadmInterfaceException {
135
136         String supportingOts = "supportingOts";
137         String logicalConnPoint = "logicalConnPoint";
138         Assert.assertEquals(
139                 openRoadMInterface221.createOpenRoadmOmsInterface(nodeId, new MappingBuilder()
140                         .setLogicalConnectionPoint(logicalConnPoint).setSupportingOts(supportingOts).build()),
141                 "OMS-" + logicalConnPoint);
142     }
143
144 }