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.yang.mapper;
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;
33 public class TestMapper {
35 private static final YangToolsMapper MAPPER = new YangToolsMapper();
38 public void testYangGenEnumMapperDeser() {
39 NetworkElementConnection con = null;
41 con = MAPPER.readValue("{\"device-type\":\"O-RAN\"}", NetworkElementConnection.class);
42 } catch (JsonProcessingException e) {
46 assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType());
48 con = MAPPER.readValue("{\"device-type\":\"ORAN\"}", NetworkElementConnection.class);
49 } catch (JsonProcessingException e) {
53 assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType());
55 con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class);
56 } catch (JsonProcessingException e) {
60 assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType());
62 con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class);
63 } catch (JsonProcessingException e) {
67 assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType());
71 public void testYangGenEnumMapperSer() {
72 NetworkElementConnection con =
73 new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.ORAN).build();
76 str = MAPPER.writeValueAsString(con);
77 } catch (JsonProcessingException e) {
81 assertEquals("O-RAN", new JSONObject(str).getString("device-type"));
82 con = new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.OROADM).build();
85 str = MAPPER.writeValueAsString(con);
86 } catch (JsonProcessingException e) {
90 assertEquals("O-ROADM", new JSONObject(str).getString("device-type"));