50c23101545b9529ba752a1a41da9af10baf55bd
[ccsdk/features.git] /
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.dataprovider.test;
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.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnection;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
33
34 public class TestMapper {
35
36     private static final YangToolsMapper MAPPER = new YangToolsMapper();
37
38     @Test
39     public void testYangGenEnumMapperDeser() {
40         NetworkElementConnection con = null;
41         try {
42             con = MAPPER.readValue("{\"device-type\":\"O-RAN\"}", NetworkElementConnection.class);
43         } catch (JsonProcessingException e) {
44             e.printStackTrace();
45             fail(e.getMessage());
46         }
47         assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType());
48         try {
49             con = MAPPER.readValue("{\"device-type\":\"ORAN\"}", NetworkElementConnection.class);
50         } catch (JsonProcessingException e) {
51             e.printStackTrace();
52             fail(e.getMessage());
53         }
54         assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType());
55         try {
56             con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class);
57         } catch (JsonProcessingException e) {
58             e.printStackTrace();
59             fail(e.getMessage());
60         }
61         assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType());
62         try {
63             con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class);
64         } catch (JsonProcessingException e) {
65             e.printStackTrace();
66             fail(e.getMessage());
67         }
68         assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType());
69     }
70
71     @Test
72     public void testYangGenEnumMapperSer() {
73         NetworkElementConnection con =
74                 new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.ORAN).build();
75         String str = null;
76         try {
77             str = MAPPER.writeValueAsString(con);
78         } catch (JsonProcessingException e) {
79             e.printStackTrace();
80             fail(e.getMessage());
81         }
82         assertEquals("O-RAN", new JSONObject(str).getString("device-type"));
83         con = new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.OROADM).build();
84         str = null;
85         try {
86             str = MAPPER.writeValueAsString(con);
87         } catch (JsonProcessingException e) {
88             e.printStackTrace();
89             fail(e.getMessage());
90         }
91         assertEquals("O-ROADM", new JSONObject(str).getString("device-type"));
92     }
93 }