Merge "Optimize cm-handle registration with CPS-DMI Plugin to upload yang model"
[ccsdk/features.git] / sdnr / wt / common-yang / utils / src / test / java / org / onap / ccsdk / features / sdnr / wt / yang / mapper / TestMapper.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.yang.mapper;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.fail;
26 import com.fasterxml.jackson.core.JsonProcessingException;
27 import org.json.JSONObject;
28 import org.junit.Test;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnection;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
32
33 public class TestMapper {
34
35     private static final YangToolsMapper MAPPER = new YangToolsMapper();
36
37     @Test
38     public void testYangGenEnumMapperDeser() {
39         NetworkElementConnection con = null;
40         try {
41             con = MAPPER.readValue("{\"device-type\":\"O-RAN\"}", NetworkElementConnection.class);
42         } catch (JsonProcessingException e) {
43             e.printStackTrace();
44             fail(e.getMessage());
45         }
46         assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType());
47         try {
48             con = MAPPER.readValue("{\"device-type\":\"ORAN\"}", NetworkElementConnection.class);
49         } catch (JsonProcessingException e) {
50             e.printStackTrace();
51             fail(e.getMessage());
52         }
53         assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType());
54         try {
55             con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class);
56         } catch (JsonProcessingException e) {
57             e.printStackTrace();
58             fail(e.getMessage());
59         }
60         assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType());
61         try {
62             con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class);
63         } catch (JsonProcessingException e) {
64             e.printStackTrace();
65             fail(e.getMessage());
66         }
67         assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType());
68     }
69
70     @Test
71     public void testYangGenEnumMapperSer() {
72         NetworkElementConnection con =
73                 new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.ORAN).build();
74         String str = null;
75         try {
76             str = MAPPER.writeValueAsString(con);
77         } catch (JsonProcessingException e) {
78             e.printStackTrace();
79             fail(e.getMessage());
80         }
81         assertEquals("O-RAN", new JSONObject(str).getString("device-type"));
82         con = new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.OROADM).build();
83         str = null;
84         try {
85             str = MAPPER.writeValueAsString(con);
86         } catch (JsonProcessingException e) {
87             e.printStackTrace();
88             fail(e.getMessage());
89         }
90         assertEquals("O-ROADM", new JSONObject(str).getString("device-type"));
91     }
92 }