2 * Copyright (c) 2024 Smartoptics and others. All rights reserved.
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
9 package org.opendaylight.transportpce.pce.networkanalyzer.port;
11 import java.util.HashMap;
14 import org.junit.jupiter.api.Assertions;
15 import org.junit.jupiter.api.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.PathComputationRequestInput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.path.computation.request.input.ServiceAEnd;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.path.computation.request.input.ServiceZEnd;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.port.PortBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.endpoint.sp.RxDirection;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.endpoint.sp.TxDirection;
24 class PreferenceFactoryTest {
27 void emptyPathComputationRequest_returnEmptyHashmap() {
29 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
30 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
32 Map<String, Set<String>> expected = new HashMap<>();
33 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
38 void pathComputationRequestServiceAEndRxDirectionWithoutDeviceAndPort_returnEmptyHashmap() {
40 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
41 ServiceAEnd serviceAEnd = Mockito.mock(ServiceAEnd.class);
42 RxDirection rxDirection = Mockito.mock(RxDirection.class);
44 Mockito.when(rxDirection.getPort()).thenReturn(new PortBuilder().build());
45 Mockito.when(serviceAEnd.getRxDirection()).thenReturn(rxDirection);
46 Mockito.when(pathComputationRequestInput.getServiceAEnd()).thenReturn(serviceAEnd);
48 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
50 Map<String, Set<String>> expected = new HashMap<>();
51 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
56 void pathComputationRequestServiceAEndRxDirectionWithoutPort_returnEmptyHashmap() {
58 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
59 ServiceAEnd serviceAEnd = Mockito.mock(ServiceAEnd.class);
60 RxDirection rxDirection = Mockito.mock(RxDirection.class);
62 Mockito.when(rxDirection.getPort()).thenReturn(
64 .setPortDeviceName("ROADM-B-SRG1")
67 Mockito.when(serviceAEnd.getRxDirection()).thenReturn(rxDirection);
68 Mockito.when(pathComputationRequestInput.getServiceAEnd()).thenReturn(serviceAEnd);
70 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
72 Map<String, Set<String>> expected = new HashMap<>();
73 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
78 void pathComputationRequestServiceAEndRxDirectionTxRx_returnHashmap() {
80 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
81 ServiceAEnd serviceAEnd = Mockito.mock(ServiceAEnd.class);
82 RxDirection rxDirection = Mockito.mock(RxDirection.class);
84 Mockito.when(rxDirection.getPort()).thenReturn(
86 .setPortDeviceName("ROADM-B-SRG1")
87 .setPortName("SRG1-PP1-TXRX")
90 Mockito.when(serviceAEnd.getRxDirection()).thenReturn(rxDirection);
91 Mockito.when(pathComputationRequestInput.getServiceAEnd()).thenReturn(serviceAEnd);
93 Map<String, Set<String>> expected = new HashMap<>();
94 expected.put("ROADM-B-SRG1", Set.of("SRG1-PP1-TXRX"));
95 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
97 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
102 void pathComputationRequestServiceAEndRxDirectionTx_returnHashmap() {
104 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
105 ServiceAEnd serviceAEnd = Mockito.mock(ServiceAEnd.class);
106 RxDirection rxDirection = Mockito.mock(RxDirection.class);
108 Mockito.when(rxDirection.getPort()).thenReturn(
110 .setPortDeviceName("ROADM-B-SRG1")
111 .setPortName("SRG1-PP1-TX")
114 Mockito.when(serviceAEnd.getRxDirection()).thenReturn(rxDirection);
115 Mockito.when(pathComputationRequestInput.getServiceAEnd()).thenReturn(serviceAEnd);
117 Map<String, Set<String>> expected = new HashMap<>();
118 expected.put("ROADM-B-SRG1", Set.of("SRG1-PP1-TX"));
119 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
121 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
126 void pathComputationRequestServiceAEndRxDirectionRx_returnHashmap() {
128 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
129 ServiceAEnd serviceAEnd = Mockito.mock(ServiceAEnd.class);
130 TxDirection txDirection = Mockito.mock(TxDirection.class);
132 Mockito.when(txDirection.getPort()).thenReturn(
134 .setPortDeviceName("ROADM-B-SRG1")
135 .setPortName("SRG1-PP1-RX")
138 Mockito.when(serviceAEnd.getTxDirection()).thenReturn(txDirection);
139 Mockito.when(pathComputationRequestInput.getServiceAEnd()).thenReturn(serviceAEnd);
141 Map<String, Set<String>> expected = new HashMap<>();
142 expected.put("ROADM-B-SRG1", Set.of("SRG1-PP1-RX"));
143 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
145 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
150 void pathComputationRequestServiceZEndRx_returnHashmap() {
152 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
153 ServiceZEnd serviceZEnd = Mockito.mock(ServiceZEnd.class);
154 RxDirection rxDirection = Mockito.mock(RxDirection.class);
156 Mockito.when(rxDirection.getPort()).thenReturn(
158 .setPortDeviceName("ROADM-B-SRG1")
159 .setPortName("SRG1-PP1-TXRX")
162 Mockito.when(serviceZEnd.getRxDirection()).thenReturn(rxDirection);
163 Mockito.when(pathComputationRequestInput.getServiceZEnd()).thenReturn(serviceZEnd);
165 Map<String, Set<String>> expected = new HashMap<>();
166 expected.put("ROADM-B-SRG1", Set.of("SRG1-PP1-TXRX"));
167 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
169 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
174 void pathComputationRequestServiceZEndTxDirectionTxRx_returnHashmap() {
176 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
177 ServiceZEnd serviceZEnd = Mockito.mock(ServiceZEnd.class);
178 TxDirection txDirection = Mockito.mock(TxDirection.class);
180 Mockito.when(txDirection.getPort()).thenReturn(
182 .setPortDeviceName("ROADM-B-SRG1")
183 .setPortName("SRG1-PP1-TXRX")
186 Mockito.when(serviceZEnd.getTxDirection()).thenReturn(txDirection);
187 Mockito.when(pathComputationRequestInput.getServiceZEnd()).thenReturn(serviceZEnd);
189 Map<String, Set<String>> expected = new HashMap<>();
190 expected.put("ROADM-B-SRG1", Set.of("SRG1-PP1-TXRX"));
191 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
193 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
198 void pathComputationRequestServiceZEndTxDirectionTx_returnHashmap() {
200 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
201 ServiceZEnd serviceZEnd = Mockito.mock(ServiceZEnd.class);
202 TxDirection txDirection = Mockito.mock(TxDirection.class);
204 Mockito.when(txDirection.getPort()).thenReturn(
206 .setPortDeviceName("ROADM-B-SRG1")
207 .setPortName("SRG1-PP1-TX")
210 Mockito.when(serviceZEnd.getTxDirection()).thenReturn(txDirection);
211 Mockito.when(pathComputationRequestInput.getServiceZEnd()).thenReturn(serviceZEnd);
213 Map<String, Set<String>> expected = new HashMap<>();
214 expected.put("ROADM-B-SRG1", Set.of("SRG1-PP1-TX"));
215 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
217 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
222 void pathComputationRequestServiceZEndTxDirectionRx_returnHashmap() {
224 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
225 ServiceZEnd serviceZEnd = Mockito.mock(ServiceZEnd.class);
226 TxDirection txDirection = Mockito.mock(TxDirection.class);
228 Mockito.when(txDirection.getPort()).thenReturn(
230 .setPortDeviceName("ROADM-B-SRG1")
231 .setPortName("SRG1-PP1-RX")
234 Mockito.when(serviceZEnd.getTxDirection()).thenReturn(txDirection);
235 Mockito.when(pathComputationRequestInput.getServiceZEnd()).thenReturn(serviceZEnd);
237 Map<String, Set<String>> expected = new HashMap<>();
238 expected.put("ROADM-B-SRG1", Set.of("SRG1-PP1-RX"));
239 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
241 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
246 void pathEmptyComputationRequestServiceZEndTx_returnHashmap() {
248 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
249 ServiceZEnd serviceZEnd = Mockito.mock(ServiceZEnd.class);
250 TxDirection txDirection = Mockito.mock(TxDirection.class);
252 Mockito.when(txDirection.getPort()).thenReturn(
254 .setPortDeviceName("ROADM-B-SRG1")
258 Mockito.when(serviceZEnd.getTxDirection()).thenReturn(txDirection);
259 Mockito.when(pathComputationRequestInput.getServiceZEnd()).thenReturn(serviceZEnd);
261 Map<String, Set<String>> expected = new HashMap<>();
263 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
264 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
269 void pathUnexpectedPortName_returnHashmap() {
271 PathComputationRequestInput pathComputationRequestInput = Mockito.mock(PathComputationRequestInput.class);
272 ServiceZEnd serviceZEnd = Mockito.mock(ServiceZEnd.class);
273 TxDirection txDirection = Mockito.mock(TxDirection.class);
275 Mockito.when(txDirection.getPort()).thenReturn(
277 .setPortDeviceName("ROADM-B-SRG1")
278 .setPortName("FUBAR")
281 Mockito.when(serviceZEnd.getTxDirection()).thenReturn(txDirection);
282 Mockito.when(pathComputationRequestInput.getServiceZEnd()).thenReturn(serviceZEnd);
284 Map<String, Set<String>> expected = new HashMap<>();
285 expected.put("ROADM-B-SRG1", Set.of("FUBAR"));
287 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
288 Assertions.assertEquals(expected, portPreferenceFactory.nodePortMap(pathComputationRequestInput));
293 void addingMultiplePort() {
295 PreferenceFactory portPreferenceFactory = new PreferenceFactory();
296 Map<String, Set<String>> mapper = new HashMap<>();
299 Assertions.assertTrue(portPreferenceFactory.add("ROADM-B-SRG1", "SRG1-PP1-TXRX", mapper));
300 Assertions.assertTrue(portPreferenceFactory.add("ROADM-B-SRG1", "SRG1-PP2-TXRX", mapper));
301 Assertions.assertTrue(portPreferenceFactory.add("ROADM-B-SRG1", "SRG1-PP3-RX", mapper));
302 Assertions.assertTrue(portPreferenceFactory.add("ROADM-B-SRG1", "SRG1-PP3-TX", mapper));
304 //This port already exists, should return false.
305 Assertions.assertFalse(portPreferenceFactory.add("ROADM-B-SRG1", "SRG1-PP2-TXRX", mapper));
307 Assertions.assertEquals(
308 Set.of("SRG1-PP1-TXRX", "SRG1-PP2-TXRX", "SRG1-PP3-RX", "SRG1-PP3-TX"),
309 mapper.get("ROADM-B-SRG1")