2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
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;
34 public class TestMapper {
36 private static final YangToolsMapper MAPPER = new YangToolsMapper();
39 public void testYangGenEnumMapperDeser() {
40 NetworkElementConnection con = null;
42 con = MAPPER.readValue("{\"device-type\":\"O-RAN\"}", NetworkElementConnection.class);
43 } catch (JsonProcessingException e) {
47 assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType());
49 con = MAPPER.readValue("{\"device-type\":\"ORAN\"}", NetworkElementConnection.class);
50 } catch (JsonProcessingException e) {
54 assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType());
56 con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class);
57 } catch (JsonProcessingException e) {
61 assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType());
63 con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class);
64 } catch (JsonProcessingException e) {
68 assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType());
72 public void testYangGenEnumMapperSer() {
73 NetworkElementConnection con =
74 new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.ORAN).build();
77 str = MAPPER.writeValueAsString(con);
78 } catch (JsonProcessingException e) {
82 assertEquals("O-RAN", new JSONObject(str).getString("device-type"));
83 con = new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.OROADM).build();
86 str = MAPPER.writeValueAsString(con);
87 } catch (JsonProcessingException e) {
91 assertEquals("O-ROADM", new JSONObject(str).getString("device-type"));