diff options
author | Michael DÜrre <michael.duerre@highstreet-technologies.com> | 2021-09-23 10:15:21 +0200 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2021-09-23 15:37:31 +0000 |
commit | f03758806c601e63cc835e423498c17c0b5dc429 (patch) | |
tree | 21dcb3fd490ec8ec8298dac62d724d0a9921f2da /sdnr/wt/common-yang/utils/src/test | |
parent | 0eaf2d56a8ac8de275cd80d3db38c02f110faa30 (diff) |
fixed yang enum serialization
fixed serializer for yang types with -
Issue-ID: CCSDK-3452
Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Change-Id: I0e212c585b2874c2f5d154b25615aac17a3da634
Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/common-yang/utils/src/test')
-rw-r--r-- | sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestMapper.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestMapper.java b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestMapper.java new file mode 100644 index 000000000..2d2e0114c --- /dev/null +++ b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestMapper.java @@ -0,0 +1,92 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.yang.mapper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.json.JSONObject; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnection; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType; + +public class TestMapper { + + private static final YangToolsMapper MAPPER = new YangToolsMapper(); + + @Test + public void testYangGenEnumMapperDeser() { + NetworkElementConnection con = null; + try { + con = MAPPER.readValue("{\"device-type\":\"O-RAN\"}", NetworkElementConnection.class); + } catch (JsonProcessingException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType()); + try { + con = MAPPER.readValue("{\"device-type\":\"ORAN\"}", NetworkElementConnection.class); + } catch (JsonProcessingException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + assertEquals(NetworkElementDeviceType.ORAN, con.getDeviceType()); + try { + con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class); + } catch (JsonProcessingException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType()); + try { + con = MAPPER.readValue("{\"device-type\":\"O-ROADM\"}", NetworkElementConnection.class); + } catch (JsonProcessingException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + assertEquals(NetworkElementDeviceType.OROADM, con.getDeviceType()); + } + + @Test + public void testYangGenEnumMapperSer() { + NetworkElementConnection con = + new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.ORAN).build(); + String str = null; + try { + str = MAPPER.writeValueAsString(con); + } catch (JsonProcessingException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + assertEquals("O-RAN", new JSONObject(str).getString("device-type")); + con = new NetworkElementConnectionBuilder().setDeviceType(NetworkElementDeviceType.OROADM).build(); + str = null; + try { + str = MAPPER.writeValueAsString(con); + } catch (JsonProcessingException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + assertEquals("O-ROADM", new JSONObject(str).getString("device-type")); + } +} |