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 com.fasterxml.jackson.core.JsonProcessingException;
26 import java.util.HashMap;
28 import org.json.JSONObject;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.IdentifierDeserializer;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
34 import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.AddressLocation;
35 import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.AddressLocationBuilder;
36 import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.AddressType;
37 import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.ItemCode;
38 import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.address.location.entity.ItemList;
39 import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.address.location.entity.ItemListBuilder;
40 import org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.address.location.entity.ItemListKey;
42 public class TestYangToolsMapper {
44 private static final YangToolsMapper MAPPER = new YangToolsMapper();
48 MAPPER.addKeyDeserializer(ItemListKey.class, new IdentifierDeserializer());
52 public void testYangMapperDeser() {
53 AddressLocation al = null;
56 al = MAPPER.readValue(
58 + " \"address-type\": \"OFFICE\",\n"
59 + " \"delivery-date-time\": \"2022-03-15T11:12:13.890Z\",\n"
60 + " \"delivery-url\": \"delivery.uri\",\n"
61 + " \"item-list\": [\n"
63 + " \"item-key\": \"org.opendaylight.yang.gen.v1.urn.test.yang.utils.norev.ItemCode\"\n"
67 AddressLocation.class);
68 } catch (JsonProcessingException e) {
71 assertEquals(AddressType.OFFICE, al.getAddressType());
72 assertEquals("2022-03-15T11:12:13.890Z", al.getDeliveryDateTime().getValue());
73 System.out.println("Delivery Date = " + al.getDeliveryDateTime().getValue());
74 System.out.println(al.getItemList());
75 System.out.println(al.getDeliveryUrl().getValue());
79 public void testYangMapperSer() {
80 Map<ItemListKey, ItemList> items = new HashMap<ItemListKey, ItemList>();
81 ItemList il = new ItemListBuilder().setItemKey(ItemCode.class).build();
82 items.put(new ItemListKey(ItemCode.class), il);
84 Uri uri = new Uri("delivery.uri");
86 AddressLocation al = new AddressLocationBuilder().setId("99").setAddressType(AddressType.HOME)
87 .setDeliveryDateTime(new DateAndTime("2022-03-15T11:12:13.890Z")).setItemList(items)
88 .setDeliveryUrl(uri).build();
92 str = MAPPER.writeValueAsString(al);
93 } catch (JsonProcessingException e) {
96 assertEquals("HOME", new JSONObject(str).getString("address-type"));
97 assertEquals("2022-03-15T11:12:13.890Z", new JSONObject(str).getString("delivery-date-time"));
98 System.out.println(new JSONObject(str).getJSONArray("item-list"));
99 System.out.println(str);