Migrate common module to JUnit5
[transportpce.git] / common / src / test / java / org / opendaylight / transportpce / common / service / ServiceTypeTest.java
1 /*
2  * Copyright © 2021 Orange.  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
9 package org.opendaylight.transportpce.common.service;
10
11
12 import static org.junit.jupiter.api.Assertions.assertEquals;
13 import static org.junit.jupiter.api.Assertions.assertNull;
14
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.MappingBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.PortQual;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes;
20 import org.opendaylight.yangtools.yang.common.Uint32;
21
22 public class ServiceTypeTest {
23
24     @Test
25     void getServiceTypeForServiceFormatUnknownTest() {
26         String serviceType = ServiceTypes.getServiceType("toto", null, null);
27         assertNull(serviceType, "service-type should be null");
28     }
29
30     @Test
31     void getServiceTypeForServiceFormatOCTest() {
32         String serviceType = ServiceTypes.getServiceType("OC", Uint32.valueOf(100), null);
33         assertEquals("100GEt", serviceType, "service-type should be 100GEt");
34         serviceType = ServiceTypes.getServiceType("OC", null, null);
35         assertNull(serviceType, "service-type should be null");
36     }
37
38     @Test
39     void getServiceTypeForServiceFormatEthernetTest() {
40         String serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(400), null);
41         assertEquals("400GE", serviceType, "service-type should be 400GE");
42         serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(100), null);
43         assertEquals("100GEt", serviceType, "service-type should be 100GEt");
44         Mapping mapping = new MappingBuilder()
45             .setLogicalConnectionPoint("logicalConnectionPoint")
46             .setPortQual(PortQual.XpdrClient.getName())
47             .build();
48         serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(100), mapping);
49         assertEquals("100GEt", serviceType, "service-type should be 100GEt");
50
51         mapping = new MappingBuilder()
52             .setLogicalConnectionPoint("logicalConnectionPoint")
53             .setPortQual(PortQual.SwitchClient.getName())
54             .build();
55         serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(100), mapping);
56         assertEquals("100GEm", serviceType, "service-type should be 100GEm");
57         serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(10), mapping);
58         assertEquals("10GE", serviceType, "service-type should be 10GE");
59         serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(1), mapping);
60         assertEquals("1GE", serviceType, "service-type should be 1GE");
61
62         mapping = new MappingBuilder()
63             .setLogicalConnectionPoint("logicalConnectionPoint")
64             .setPortQual(PortQual.SwitchClient.getName())
65             .setXponderType(XpdrNodeTypes.Switch)
66             .build();
67         serviceType = ServiceTypes.getServiceType("Ethernet", Uint32.valueOf(100), mapping);
68         assertEquals("100GEs", serviceType, "service-type should be 100GEs");
69     }
70
71     @Test
72     void getOtnServiceTypeForServiceFormatEthernetTest() {
73         String serviceType = ServiceTypes.getOtnServiceType("toto", Uint32.valueOf(123));
74         assertNull(serviceType, "service-type should be null");
75         serviceType = ServiceTypes.getOtnServiceType("Ethernet", Uint32.valueOf(123));
76         assertNull(serviceType, "service-type should be null");
77         serviceType = ServiceTypes.getOtnServiceType("Ethernet", Uint32.valueOf(1));
78         assertEquals("1GE", serviceType, "service-type should be 1GE");
79         serviceType = ServiceTypes.getOtnServiceType("Ethernet", Uint32.valueOf(10));
80         assertEquals("10GE", serviceType, "service-type should be 10GE");
81         serviceType = ServiceTypes.getOtnServiceType("Ethernet", Uint32.valueOf(100));
82         assertEquals("100GEm", serviceType, "service-type should be 100GEm");
83
84         serviceType = ServiceTypes.getOtnServiceType("OTU", Uint32.valueOf(100));
85         assertEquals("OTU4", serviceType, "service-type should be OTU4");
86         serviceType = ServiceTypes.getOtnServiceType("OTU", Uint32.valueOf(400));
87         assertEquals("OTUC4", serviceType, "service-type should be OTUC4");
88
89         serviceType = ServiceTypes.getOtnServiceType("ODU", Uint32.valueOf(100));
90         assertEquals("ODU4", serviceType, "service-type should be ODU4");
91         serviceType = ServiceTypes.getOtnServiceType("ODU", Uint32.valueOf(400));
92         assertEquals("ODUC4", serviceType, "service-type should be ODUC4");
93     }
94 }