0a195e03b00ab0a88d509343e897874c527eb8fa
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 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 java.io.IOException;
25 import org.jline.utils.Log;
26 import org.junit.Test;
27 import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper2;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataTypeBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity;
31
32 public class TestYangGenSalMappingOpenRoadm {
33
34     @Test
35     public void testOpenroadmPM() throws IOException, ClassNotFoundException {
36         out(method());
37         // @formatter:off
38         String jsonString = "{\n"
39                 + "    \"time-stamp\":\"2020-09-24T22:59:48.6Z\", \n"
40                 + "    \"node-name\":\"Rdm-1\",\n"
41                 + "    \"uuid-interface\":\"physical-link\",\n"
42                 + "    \"scanner-id\":\"ryyyyyyyryryr\",\n"
43                 + "    \"granularity-period\":\"Period24Hours\",\n"
44                 + "    \"performance-data\":{\n"
45                 + "         \"measurement\":[{\n"
46                 + "            \"pm-value\":{\"uint64\":1464170942461338033},\n"
47                 + "            \"pm-key\":\"org.opendaylight"
48                 + ".yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.OpticalPowerInputOSCMin\"\n"
49                 + "         }]\n"
50                 + "        }\n"
51                 + "}\n";
52         // @formatter:on
53         // Map to JSON String to Object
54         PmDataTypeBuilder builder = new PmDataTypeBuilder();
55         builder.setInt64("10");
56         PmDataType pmDataType = builder.build();
57         out("Result is: "+pmDataType);
58
59         YangToolsMapper2<PmdataEntity> mapper2 = new YangToolsMapper2<>(PmdataEntity.class, null);
60         out("Created mapper");
61         PmdataEntity generatepmdNode = mapper2.readValue(jsonString.getBytes(), PmdataEntity.class);
62         out(generatepmdNode.toString()); // Print it with specified indentation
63     }
64
65     /*
66      * --------------------------------- Private
67      */
68
69     private static String method() {
70         String nameofCurrMethod = new Throwable().getStackTrace()[1].getMethodName();
71         return nameofCurrMethod;
72     }
73
74     private static void out(String text) {
75         System.out.println("----------------------");
76         System.out.println(text);
77         Log.info("Log: "+text);
78     }
79
80 }