summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common-yang/utils/src/test
diff options
context:
space:
mode:
authorhighstreetherbert <herbert.eiselt@highstreet-technologies.com>2021-11-19 14:46:00 +0100
committerhighstreetherbert <herbert.eiselt@highstreet-technologies.com>2021-11-19 14:46:20 +0100
commit3e739d832853e821472facb181aa972ecfb45b1c (patch)
tree35a79049048a506c03884e09d65c7a477c4cffd4 /sdnr/wt/common-yang/utils/src/test
parent71031b0b238ee51affd8135fdd648d9a70a6970b (diff)
Synchronize sdnr/wt artifacts
Synchronize sdnr/wt common, help, apigateway Issue-ID: CCSDK-3528 Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com> Change-Id: I4b5e5ce1b16adad80e670bdf08943e4a3eb658f1 Signed-off-by: highstreetherbert <herbert.eiselt@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/TestDataMappings.java99
-rw-r--r--sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangGenSalMapping.java273
2 files changed, 372 insertions, 0 deletions
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestDataMappings.java b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestDataMappings.java
new file mode 100644
index 000000000..584b4b044
--- /dev/null
+++ b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestDataMappings.java
@@ -0,0 +1,99 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2019 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.fail;
+import java.io.IOException;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data;
+
+public class TestDataMappings {
+
+ // @formatter:off
+ private static final String PMDATA15M_SERVERDB_JSON = "{\n"
+ + "\"node-name\": \"sim2\",\n"
+ + "\"uuid-interface\": \"LP-MWPS-TTP-01\",\n"
+ + "\"layer-protocol-name\": \"MWPS\",\n"
+ + "\"radio-signal-id\": \"Test11\",\n"
+ + "\"time-stamp\": \"2017-07-04T14:00:00.0Z\",\n"
+ + "\"granularity-period\": \"Period15Min\",\n"
+ + "\"scanner-id\": \"PM_RADIO_15M_9\",\n"
+ + "\"performance-data\": {\n"
+ + "\"es\": 0,\n"
+ + "\"rx-level-avg\": -41,\n"
+ + "\"time2-states\": -1,\n"
+ + "\"time4-states-s\": 0,\n"
+ + "\"time4-states\": 0,\n"
+ + "\"time8-states\": 0,\n"
+ + "\"time16-states-s\": -1,\n"
+ + "\"time16-states\": 0,\n"
+ + "\"time32-states\": 0,\n"
+ + "\"time64-states\": 0,\n"
+ + "\"time128-states\": 0,\n"
+ + "\"time256-states\": 900,\n"
+ + "\"time512-states\": -1,\n"
+ + "\"time512-states-l\": -1,\n"
+ + "\"time1024-states\": -1,\n"
+ + "\"time1024-states-l\": -1,\n"
+ + "\"time2048-states\": -1,\n"
+ + "\"time2048-states-l\": -1,\n"
+ + "\"time4096-states\": -1,\n"
+ + "\"time4096-states-l\": -1,\n"
+ + "\"time8192-states\": -1,\n"
+ + "\"time8192-states-l\": -1,\n"
+ + "\"snir-min\": -99,\n"
+ + "\"snir-max\": -99,\n"
+ + "\"snir-avg\": -99,\n"
+ + "\"xpd-min\": -99,\n"
+ + "\"xpd-max\": -99,\n"
+ + "\"xpd-avg\": -99,\n"
+ + "\"rf-temp-min\": -99,\n"
+ + "\"rf-temp-max\": -99,\n"
+ + "\"rf-temp-avg\": -99,\n"
+ + "\"defect-blocks-sum\": -1,\n"
+ + "\"time-period\": 900,\n"
+ + "\"tx-level-min\": 25,\n"
+ + "\"tx-level-max\": 25,\n"
+ + "\"tx-level-avg\": 25,\n"
+ + "\"rx-level-min\": -41,\n"
+ + "\"rx-level-max\": -41,\n"
+ + "\"unavailability\": 0,\n"
+ + "\"ses\": 0,\n"
+ + "\"cses\": 0\n"
+ + "},\n"
+ + "\"suspect-interval-flag\": false\n"
+ + "}";
+ // @formatter:on
+ @Test
+ public void testPmData15m() throws ClassNotFoundException {
+
+ YangToolsMapper2<Data> mapper = new YangToolsMapper2<Data>(Data.class, null);
+ try {
+ Data data = mapper.readValue(PMDATA15M_SERVERDB_JSON.getBytes(), Data.class);
+ System.out.println(data);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("Can not parse data");
+ }
+ }
+
+}
diff --git a/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangGenSalMapping.java b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangGenSalMapping.java
new file mode 100644
index 000000000..40164d756
--- /dev/null
+++ b/sdnr/wt/common-yang/utils/src/test/java/org/onap/ccsdk/features/sdnr/wt/yang/mapper/TestYangGenSalMapping.java
@@ -0,0 +1,273 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2019 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.json.JSONObject;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.IdentifierDeserializer;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.OdlHelloMessageCapabilitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata15m.entity.PerformanceDataBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.DataBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestYangGenSalMapping {
+
+ // Create mapper for serialization and deserialization
+ DataProviderYangToolsMapper mapper = new DataProviderYangToolsMapper();
+
+ @Test
+ public void test1() throws IOException {
+
+ // Create test object
+ NetconfNodeBuilder netconfNodeBuilder = new NetconfNodeBuilder();
+ netconfNodeBuilder.setConnectedMessage("ConnMessage");
+
+ LoginPasswordBuilder loginPasswordBuilder = new LoginPasswordBuilder();
+ loginPasswordBuilder.setUsername("myTestUsername");
+ loginPasswordBuilder.setPassword("myTestPassword");
+ netconfNodeBuilder.setCredentials(loginPasswordBuilder.build());
+
+ OdlHelloMessageCapabilitiesBuilder odlHelloMessageCapabilitiesBuilder =
+ new OdlHelloMessageCapabilitiesBuilder();
+ List<Uri> uriList = new ArrayList<>();
+ uriList.add(new Uri("test.uri"));
+ odlHelloMessageCapabilitiesBuilder.setCapability(uriList);
+ netconfNodeBuilder.setOdlHelloMessageCapabilities(odlHelloMessageCapabilitiesBuilder.build());
+
+ NetconfNode netconfNode = netconfNodeBuilder.build();
+ out(netconfNode.toString());
+
+ // Map Object to JSON String
+ String res = mapper.writeValueAsString(netconfNode);
+ JSONObject json = new JSONObject(res); // Convert text to object
+ out(json.toString(4)); // Print it with specified indentation
+
+ // Map to JSON String to Object
+ NetconfNode generatedNode = mapper.readValue(res.getBytes(), NetconfNode.class);
+ out(generatedNode.toString()); // Print it with specified indentation
+ // Compare result
+ //TODO - Guilin
+ //out("Equal? "+netconfNode.equals(generatedNode));
+ }
+
+ @Test
+ public void test3() throws IOException {
+
+ PerformanceDataBuilder performanceBuilder = new PerformanceDataBuilder();
+ performanceBuilder.setEs(99);
+ DataBuilder pmData15MinutesBuilder = new DataBuilder();
+ pmData15MinutesBuilder.setLayerProtocolName("fdsaf");
+ pmData15MinutesBuilder.setTimeStamp(new DateAndTime("2017-03-01T09:15:00.0Z"));
+ pmData15MinutesBuilder.setPerformanceData(performanceBuilder.build());
+
+ // Map Object to JSON String
+ String res = mapper.writeValueAsString(pmData15MinutesBuilder.build());
+ JSONObject json = new JSONObject(res); // Convert text to object
+ out(json.toString(4)); // Print it with specified indentation
+
+ // Map to JSON String to Object
+ Data generatedNode = mapper.readValue(res.getBytes(), Data.class);
+ out(generatedNode.toString()); // Print it with specified indentation
+ }
+
+ @Test
+ public void test4() throws IOException {
+ // @formatter:off
+ String jsonString = "{\n"
+ + "\"node-name\": \"Sim2230\",\n"
+ + "\"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n"
+ + "\"layer-protocol-name\": \"MWPS\",\n"
+ + "\"radio-signal-id\": \"Test8\",\n"
+ + "\"time-stamp\": \"2017-03-01T09:15:00.0Z\",\n"
+ + "\"granularity-period\": \"Period15Min\",\n"
+ + "\"scanner-id\": \"PM_RADIO_15M_4\",\n"
+ + "\"performance-data\": {\n"
+ + "\"unavailability\": 0,\n"
+ + "\"tx-level-max\": 3,\n"
+ + "\"tx-level-avg\": 3,\n"
+ + "\"rx-level-min\": -44,\n"
+ + "\"rx-level-max\": -45,\n"
+ + "\"rx-level-avg\": -44,\n"
+ + "\"time2-states\": 0,\n"
+ + "\"time4-states-s\": 0,\n"
+ + "\"time4-states\": 0,\n"
+ + "\"time8-states\": -1,\n"
+ + "\"time16-states-s\": -1,\n"
+ + "\"time16-states\": 0,\n"
+ + "\"time32-states\": -1,\n"
+ + "\"time64-states\": 900,\n"
+ + "\"time128-states\": -1,\n"
+ + "\"time256-states\": -1,\n"
+ + "\"time512-states\": -1,\n"
+ + "\"time512-states-l\": -1,\n"
+ + "\"time1024-states\": -1,\n"
+ + "\"time1024-states-l\": -1,\n"
+ + "\"time8192-states-l\": -1,\n"
+ + "\"time8192-states\": -1,\n"
+ + "\"time2048-states\": -1,\n"
+ + "\"snir-min\": -99,\n"
+ + "\"snir-max\": -99,\n"
+ + "\"snir-avg\": -99,\n"
+ + "\"xpd-min\": -99,\n"
+ + "\"xpd-max\": -99,\n"
+ + "\"xpd-avg\": -99,\n"
+ + "\"rf-temp-min\": -99,\n"
+ + "\"rf-temp-max\": -99,\n"
+ + "\"rf-temp-avg\": -99,\n"
+ + "\"defect-blocks-sum\": -1,\n"
+ + "\"time-period\": 900,\n"
+ + "\"cses\": 0,\n"
+ + "\"time4096-states-l\": -1,\n"
+ + "\"tx-level-min\": 3,\n"
+ + "\"es\": 0,\n"
+ + "\"time2048-states-l\": -1,\n"
+ + "\"time4096-states\": -1,\n"
+ + "\"ses\": 0\n"
+ + "},\n"
+ + "\"suspect-interval-flag\": false\n"
+ + "}\n"
+ + "}";
+ // @formatter:on
+ // Map to JSON String to Object
+ Data generatedNode = mapper.readValue(jsonString.getBytes(), Data.class);
+ out(generatedNode.toString()); // Print it with specified indentation
+ }
+
+ @Test
+ public void test5() throws IOException {
+ // @formatter:off
+ String jsonString = "{\n"
+ + " \"time-stamp\": \"2017-03-01T06:45:00.0Z\",\n"
+ + " \"node-name\": \"Sim2230\",\n"
+ + " \"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n"
+ + " \"scanner-id\": \"PM_RADIO_15M_14\",\n"
+ + " \"layer-protocol-name\": \"MWPS\",\n"
+ + " \"granularity-period\": \"Period15Min\",\n"
+ + " \"radio-signal-id\": \"Test8\",\n"
+ + " \"suspect-interval-flag\": false,\n"
+ + " \"performance-data\": {\n"
+ + " \"time4096-states-l\": -1,\n"
+ + " \"time16-states-s\": -1,\n"
+ + " \"tx-level-max\": 3,\n"
+ + " \"snir-max\": -99,\n"
+ + " \"time16-states\": 0,\n"
+ + " \"time64-states\": 900,\n"
+ + " \"unavailability\": 0,\n"
+ + " \"time8192-states-l\": -1,\n"
+ + " \"time512-states\": -1,\n"
+ + " \"xpd-min\": -99,\n"
+ + " \"xpd-avg\": -99,\n"
+ + " \"tx-level-avg\": 3,\n"
+ + " \"tx-level-min\": 3,\n"
+ + " \"rf-temp-min\": -99,\n"
+ + " \"rf-temp-avg\": -99,\n"
+ + " \"snir-avg\": -99,\n"
+ + " \"snir-min\": -99,\n"
+ + " \"time-period\": 900,\n"
+ + " \"time2-states\": 0,\n"
+ + " \"time4-states\": 0,\n"
+ + " \"time8-states\": -1,\n"
+ + " \"ses\": 0,\n"
+ + " \"time2048-states-l\": -1,\n"
+ + " \"time2048-states\": -1,\n"
+ + " \"xpd-max\": -99,\n"
+ + " \"rf-temp-max\": -99,\n"
+ + " \"time8192-states\": -1,\n"
+ + " \"time128-states\": -1,\n"
+ + " \"time256-states\": -1,\n"
+ + " \"rx-level-min\": -44,\n"
+ + " \"rx-level-avg\": -44,\n"
+ + " \"time1024-states-l\": -1,\n"
+ + " \"es\": 0,\n"
+ + " \"cses\": 0,\n"
+ + " \"time4-states-s\": 0,\n"
+ + " \"time1024-states\": -1,\n"
+ + " \"time512-states-l\": -1,\n"
+ + " \"time4096-states\": -1,\n"
+ + " \"rx-level-max\": -45,\n"
+ + " \"defect-blocks-sum\": -1,\n"
+ + " \"time32-states\": -1\n"
+ + " }\n"
+ + "}";
+ // @formatter:on
+ // Map to JSON String to Object
+ Data generatedNode = mapper.readValue(jsonString.getBytes(), Data.class);
+ out(generatedNode.toString()); // Print it with specified indentation
+ }
+
+ @Test
+ public void test8() throws IOException {
+ out(method());
+ String input;
+ input = "id-dd-dd";
+ System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
+ input = "idDdGg";
+ System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
+ input = "_idDdGg";
+ System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
+ input = "--ff--gfg";
+ System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
+ input = "";
+ System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
+ }
+
+ /* ---------------------------------
+ * Private
+ */
+ private static String method() {
+ String nameofCurrMethod = new Throwable().getStackTrace()[1].getMethodName();
+ return nameofCurrMethod;
+ }
+
+ private static void out(String text) {
+ System.out.println("----------------------");
+ System.out.println(text);
+ }
+
+ private static class DataProviderYangToolsMapper extends YangToolsMapper {
+
+ @SuppressWarnings("unused")
+ private final Logger LOG = LoggerFactory.getLogger(DataProviderYangToolsMapper.class);
+ private static final long serialVersionUID = 1L;
+
+ public DataProviderYangToolsMapper() {
+ super();
+ this.addDeserializer(Credentials.class, LoginPasswordBuilder.class.getName());
+ this.addKeyDeserializer(MeasurementKey.class, new IdentifierDeserializer());
+ }
+
+
+ }
+
+}