summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/data-provider/provider/src/test/java
diff options
context:
space:
mode:
authorMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-01-07 10:03:05 +0100
committerRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2021-01-29 11:46:14 +0100
commita3e70a1a48d13193d9f28a2d91089d5b253d3e91 (patch)
tree26f381c2aebc5e1ca5de05e14a0a6df424aec917 /sdnr/wt/data-provider/provider/src/test/java
parent9e845affab000be46b38223e45f92b590947e892 (diff)
update common and data-provider
fixes for aluminum Issue-ID: CCSDK-3076 Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com> Change-Id: I5416e3328b067609a8820c8c0d4414d362c65ba2 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/provider/src/test/java')
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java22
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java22
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java10
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java3
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java61
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java27
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java148
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/issues/TestIssue227.java126
8 files changed, 324 insertions, 95 deletions
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java
index 92ac04702..624451ca7 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java
@@ -21,6 +21,7 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -31,6 +32,8 @@ import java.nio.file.Files;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
+import org.jline.utils.Log;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -103,7 +106,12 @@ public class TestAbout {
assertTrue(printOut.getByteArrayOutputStream().size() > 0);
}
-
+ @Test
+ public void testGetGroupId() {
+ AboutHelperServlet sv = new AboutHelperServlet();
+ assertNotNull(sv.getGroupIdOrDefault(null));
+ }
+
private class AboutHelperServlet extends AboutHttpServlet {
@@ -116,6 +124,16 @@ public class TestAbout {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp);
}
-
+ @Override
+ public String getGroupIdOrDefault(String def) {
+ return super.getGroupIdOrDefault(def);
+ }
+ @Override
+ protected String getManifestValue(String key) {
+ if(key == "Bundle-SymbolicName") {
+ return "org.onap.ccsdk.features.sdnr.wt.sdnr-wt-data-provider-provider";
+ }
+ return super.getManifestValue(key);
+ }
}
}
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java
index 5f78999d0..b7a4db51b 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java
@@ -42,7 +42,7 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.requests.BaseRequest;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper2;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper;
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.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInputBuilder;
@@ -61,7 +61,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteNetworkElementConnectionInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultlog;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GranularityPeriodType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListInputBuilder;
@@ -306,7 +306,7 @@ public class TestCRUDforDatabase {
CreateNetworkElementConnectionOutputBuilder create = null;
CreateNetworkElementConnectionInput input = new CreateNetworkElementConnectionInputBuilder().setNodeId(name)
- .setIsRequired(true).setHost(url).setPort(port).build();
+ .setIsRequired(true).setHost(url).setPort(YangHelper2.getLongOrUint32(port)).build();
String dbId = null;
try {
@@ -342,7 +342,7 @@ public class TestCRUDforDatabase {
final long port2 = 5960;
UpdateNetworkElementConnectionInput updateInput = new UpdateNetworkElementConnectionInputBuilder().setId(dbId)
- .setHost(url2).setPort(port2).setIsRequired(false).build();
+ .setHost(url2).setPort(YangHelper2.getLongOrUint32(port2)).setIsRequired(false).build();
UpdateNetworkElementConnectionOutputBuilder updateOutput = null;
try {
updateOutput = dbProvider.updateNetworkElementConnection(updateInput);
@@ -1363,18 +1363,20 @@ public class TestCRUDforDatabase {
+ "\"implemented-interface\": \"org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultlog\",\n"
+ "\"source-type\": \"Netconf\",\n" + "\"node-id\": \"sim4\",\n" + "\"problem\": \"signalIsLost\"\n"
+ "}";
- YangToolsMapper2<Faultlog> yangtoolsMapper = new YangToolsMapper2<>(Faultlog.class,null);
- FaultlogEntity log = yangtoolsMapper.readValue(jsonString, Faultlog.class);
- System.out.println(log);
- System.out.println(yangtoolsMapper.writeValueAsString(log));
+ YangToolsMapper yangtoolsMapper = new YangToolsMapper();
+ Faultlog log = yangtoolsMapper.readValue(jsonString, Faultlog.class);
+ System.out.println(yangtoolsMapper.writeValueAsString((new FaultlogBuilder(log).build())));
+ System.out.println("Check3");
} catch (IOException e) {
- fail(e.getMessage());
+ e.printStackTrace();
+ fail("Fail");
}
}
private Pagination getPagination(long pageSize, int page) {
- return new PaginationBuilder().setPage(BigInteger.valueOf(page)).setSize(pageSize).build();
+ return new PaginationBuilder().setPage(YangHelper2.getBigIntegerOrUint64(BigInteger.valueOf(page)))
+ .setSize(YangHelper2.getLongOrUint32(pageSize)).build();
}
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java
index 6584d0503..eaaa31107 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java
@@ -21,9 +21,10 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
+import static org.junit.Assert.fail;
import java.io.IOException;
import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data;
public class TestDataMappings {
@@ -35,7 +36,7 @@ public class TestDataMappings {
+ "\"layer-protocol-name\": \"MWPS\",\n"
+ "\"radio-signal-id\": \"Test11\",\n"
+ "\"time-stamp\": \"2017-07-04T14:00:00.0Z\",\n"
- + "\"granularity-period\": \"PERIOD_15MIN\",\n"
+ + "\"granularity-period\": \"Period15Min\",\n"
+ "\"scanner-id\": \"PM_RADIO_15M_9\",\n"
+ "\"performance-data\": {\n"
+ "\"es\": 0,\n"
@@ -84,14 +85,15 @@ public class TestDataMappings {
+ "}";
// @formatter:on
@Test
- public void testPmData15m() {
+ public void testPmData15m() throws ClassNotFoundException {
- YangToolsMapper mapper = new YangToolsMapper();
+ 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/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java
index 95abfdd58..7e63c183c 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java
@@ -40,6 +40,7 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryReq
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.entity.HtDatabaseEventsService;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
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.params.xml.ns.yang.data.provider.rev201110.ConnectionLogStatus;
@@ -281,7 +282,7 @@ public class TestEventService {
* @return
*/
private static NetworkElementConnectionEntity createNeConnection(String nodeId, NetworkElementDeviceType devType) {
- return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host").setPort(1234L)
+ return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host").setPort(YangHelper2.getLongOrUint32(1234L))
.setCoreModelCapability("123").setStatus(ConnectionLogStatus.Connected).setDeviceType(devType)
.setIsRequired(true).build();
}
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java
index 294dd436f..53c72115d 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java
@@ -22,7 +22,6 @@
package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
import java.io.IOException;
-import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.apache.sshd.common.util.io.IoUtils;
@@ -43,12 +42,9 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataTreeProviderImpl;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
-/**
- * @author Michael Dürre
- *
- */
public class TestTree {
+ private static String resourceDirectoryPath="/"+TestTree.class.getSimpleName()+"/";
private static ElasticSearchDataProvider dbProvider;
private static HtDatabaseClient dbRawProvider;
@@ -65,38 +61,29 @@ public class TestTree {
}
private static void fillTestData() throws IOException {
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.5.5", getFileContent("/testequipment/1.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.7.0", getFileContent("/testequipment/2.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.55.1.2", getFileContent("/testequipment/3.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.65.1.2", getFileContent("/testequipment/4.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/SHELF-1.1.0.0", getFileContent("/testequipment/5.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.1.5", getFileContent("/testequipment/6.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.1.8", getFileContent("/testequipment/7.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.6.5", getFileContent("/testequipment/8.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/ODU-1.56.0.0", getFileContent("/testequipment/9.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.56.1.2", getFileContent("/testequipment/10.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/IDU-1.65.0.0", getFileContent("/testequipment/11.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.65.1.4", getFileContent("/testequipment/12.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.6.0", getFileContent("/testequipment/13.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.8.0", getFileContent("/testequipment/14.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.9.0", getFileContent("/testequipment/15.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.55.1.4", getFileContent("/testequipment/16.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.1.7", getFileContent("/testequipment/17.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/IDU-1.55.0.0", getFileContent("/testequipment/18.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.1.0", getFileContent("/testequipment/19.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.5.0", getFileContent("/testequipment/20.json"));
- dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.5.6", getFileContent("/testequipment/21.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.5.5", getFileContent("1.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.7.0", getFileContent("2.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.55.1.2", getFileContent("3.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.65.1.2", getFileContent("4.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/SHELF-1.1.0.0", getFileContent("5.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.1.5", getFileContent("6.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.1.8", getFileContent("7.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.6.5", getFileContent("8.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/ODU-1.56.0.0", getFileContent("9.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.56.1.2", getFileContent("10.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/IDU-1.65.0.0", getFileContent("11.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.65.1.4", getFileContent("12.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.6.0", getFileContent("13.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.8.0", getFileContent("14.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.9.0", getFileContent("15.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.55.1.4", getFileContent("16.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.1.7", getFileContent("17.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/IDU-1.55.0.0", getFileContent("18.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.1.0", getFileContent("19.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/CARD-1.1.5.0", getFileContent("20.json"));
+ dbRawProvider.doWriteRaw(Entity.Inventoryequipment.getName(), "sim1/a2.module-1.1.5.6", getFileContent("21.json"));
}
- /**
- * @param string
- * @return
- * @throws URISyntaxException
- * @throws IOException
- */
- private static String getFileContent(String filename) throws IOException {
- return String.join("\n",IoUtils.readAllLines(TestTree.class.getResourceAsStream(filename)));
- }
@Test
public void testInventoryTree() throws IOException {
@@ -148,4 +135,8 @@ public class TestTree {
e = DataTreeHttpServlet.getEntity("/tree/read-inventoryequipment-tree/");
System.out.println(e);
}
+
+ private static String getFileContent(String filename) throws IOException {
+ return String.join("\n",IoUtils.readAllLines(TestTree.class.getResourceAsStream(resourceDirectoryPath+filename)));
+ }
}
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java
index f7ab7c383..3c9d4946b 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java
@@ -28,6 +28,7 @@ import java.util.List;
import org.eclipse.jdt.annotation.Nullable;
import org.json.JSONObject;
import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
@@ -37,7 +38,9 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.CreateIndexRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteIndexRequest;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapperHelper;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper;
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;
@@ -284,8 +287,8 @@ public class TestYangGenSalMapping {
ReadPmdata15mListInputBuilder inputBuilder = new ReadPmdata15mListInputBuilder();
PaginationBuilder paginationBuilder = new PaginationBuilder();
- paginationBuilder.setPage(new BigInteger("1"));
- paginationBuilder.setSize(20L);
+ paginationBuilder.setPage(YangHelper2.getBigIntegerOrUint64(new BigInteger("1")));
+ paginationBuilder.setSize(YangHelper2.getLongOrUint32(20L));
inputBuilder.setPagination(paginationBuilder.build());
ReadPmdata15mListInput input = inputBuilder.build();
@@ -295,8 +298,8 @@ public class TestYangGenSalMapping {
long page = getPage(input);
long pageSize = getPageSize(input);
- QueryBuilder query = fromFilter(input.getFilter()).from((page - 1) * pageSize).size(pageSize);
- setSortOrder(query, input.getSortorder());
+ QueryBuilder query = fromFilter(YangHelper.getList(input.getFilter())).from((page - 1) * pageSize).size(pageSize);
+ setSortOrder(query, YangHelper.getList(input.getSortorder()));
SearchResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data> result =
pm15mRW.doReadAll(query);
@@ -337,15 +340,15 @@ public class TestYangGenSalMapping {
out(method());
String input;
input = "id-dd-dd";
- System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input));
+ System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
input = "idDdGg";
- System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input));
+ System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
input = "_idDdGg";
- System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input));
+ System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
input = "--ff--gfg";
- System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input));
+ System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
input = "";
- System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input));
+ System.out.println("Map " + input + " to " + YangToolsMapperHelper.toCamelCaseAttributeName(input));
}
/* ---------------------------------
@@ -361,7 +364,7 @@ public class TestYangGenSalMapping {
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.DataBuilder dataBuilder =
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.DataBuilder();
dataBuilder.setDescription(description);
- dataBuilder.setTreeLevel(treeLevel);
+ dataBuilder.setTreeLevel(YangHelper2.getLongOrUint32(treeLevel));
return dataBuilder;
}
@@ -429,8 +432,8 @@ public class TestYangGenSalMapping {
long totalSize) {
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Pagination value =
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.PaginationBuilder()
- .setPage(BigInteger.valueOf(page)).setSize(pageSize).setTotal(BigInteger.valueOf(totalSize))
- .build();
+ .setPage(YangHelper2.getBigIntegerOrUint64(BigInteger.valueOf(page))).setSize(YangHelper2.getLongOrUint32(pageSize))
+ .setTotal(YangHelper2.getBigIntegerOrUint64(BigInteger.valueOf(totalSize))).build();
outputBuilder.setPagination(value);
}
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java
index 0a195e03b..56df62819 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java
@@ -21,47 +21,130 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.Map;
+import org.apache.sshd.common.util.io.IoUtils;
+import org.eclipse.jdt.annotation.Nullable;
import org.jline.utils.Log;
import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper2;
import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.BIPErrorCounter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.OpticalPowerInputOSCMin;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GranularityPeriodType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.entity.PerformanceData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.entity.PerformanceDataBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.Measurement;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementKey;
+import org.opendaylight.yangtools.yang.common.Uint64;
-public class TestYangGenSalMappingOpenRoadm {
+public class TestYangGenSalMappingOpenRoadm extends Mockito {
+
+ private static String resourceDirectoryPath = "/" + TestYangGenSalMappingOpenRoadm.class.getSimpleName() + "/";
@Test
- public void testOpenroadmPM() throws IOException, ClassNotFoundException {
- out(method());
- // @formatter:off
- String jsonString = "{\n"
- + " \"time-stamp\":\"2020-09-24T22:59:48.6Z\", \n"
- + " \"node-name\":\"Rdm-1\",\n"
- + " \"uuid-interface\":\"physical-link\",\n"
- + " \"scanner-id\":\"ryyyyyyyryryr\",\n"
- + " \"granularity-period\":\"Period24Hours\",\n"
- + " \"performance-data\":{\n"
- + " \"measurement\":[{\n"
- + " \"pm-value\":{\"uint64\":1464170942461338033},\n"
- + " \"pm-key\":\"org.opendaylight"
- + ".yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.OpticalPowerInputOSCMin\"\n"
- + " }]\n"
- + " }\n"
- + "}\n";
- // @formatter:on
- // Map to JSON String to Object
- PmDataTypeBuilder builder = new PmDataTypeBuilder();
- builder.setInt64("10");
- PmDataType pmDataType = builder.build();
- out("Result is: "+pmDataType);
-
- YangToolsMapper2<PmdataEntity> mapper2 = new YangToolsMapper2<>(PmdataEntity.class, null);
- out("Created mapper");
+ public void testOpenroadmPMBuilder() throws IOException, ClassNotFoundException {
+ out("Test: " + method());
+
+ MeasurementBuilder measurementBuilder1 = new MeasurementBuilder();
+ measurementBuilder1.setPmKey(OpticalPowerInputOSCMin.class);
+ measurementBuilder1.setPmValue(new PmDataType(Uint64.valueOf(64L)));
+ Measurement measurement1 = measurementBuilder1.build();
+
+ MeasurementBuilder measurementBuilder2 = new MeasurementBuilder();
+ measurementBuilder2.setPmKey(BIPErrorCounter.class);
+ measurementBuilder2.setPmValue(new PmDataType(Uint64.valueOf(65L)));
+ Measurement measurement2 = measurementBuilder2.build();
+
+ PerformanceDataBuilder performanceDataBuilder = new PerformanceDataBuilder();
+ performanceDataBuilder.setMeasurement(
+ YangHelper2.getListOrMap(MeasurementKey.class, Arrays.asList(measurement1, measurement2)));
+
+ PmdataEntityBuilder pmDataEntitybuilder = new PmdataEntityBuilder();
+ pmDataEntitybuilder.setPerformanceData(performanceDataBuilder.build());
+
+ PmdataEntity pmDataType = pmDataEntitybuilder.build();
+
+ YangToolsMapper mapper2 = new YangToolsMapper();
+ String jsonString = mapper2.writeValueAsString(pmDataType);
+ out("Result json after mapping: " + jsonString);
+
PmdataEntity generatepmdNode = mapper2.readValue(jsonString.getBytes(), PmdataEntity.class);
+ out("Original: " + pmDataType.toString());
+ out("Mapped : " + generatepmdNode.toString());
+ assertTrue("Can mapping not working", generatepmdNode.equals(pmDataType));
+ }
+
+ @Test
+ public void testOpenroadmPMString1() throws IOException, ClassNotFoundException {
+ out("Test: " + method());
+ String jsonString2 = getFileContent("pmdata1.json");
+ YangToolsMapper mapper2 = new YangToolsMapper();
+ PmdataEntity generatepmdNode = mapper2.readValue(jsonString2.getBytes(), PmdataEntity.class);
+ out("String1:"+generatepmdNode.toString()); // Print it with specified indentation
+ assertTrue("GranularityPeriod", generatepmdNode.getGranularityPeriod().equals(GranularityPeriodType.Period15Min));
+ assertTrue("NodeName", generatepmdNode.getNodeName().equals("NTS_RDM2"));
+ @Nullable PerformanceData performanceData = generatepmdNode.getPerformanceData();
+ assertNotNull("PerformanceData", performanceData);
+ @Nullable Map<MeasurementKey, Measurement> measurement = performanceData.getMeasurement();
+ assertNotNull("Measurement", measurement);
+ Measurement measurement1 = measurement.get(new MeasurementKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.OpticalPowerInputOSCMin.class));
+ assertTrue("Measurement=64", measurement1.getPmValue().stringValue().equals("64"));
+ }
+
+ @Test
+ public void testOpenroadmPMString2() throws IOException, ClassNotFoundException {
+ out("Test: " + method());
+ String jsonString2 = getFileContent("pmdata2.json");
+ YangToolsMapper mapper2 = new YangToolsMapper();
+ PmdataEntity generatepmdNode = mapper2.readValue(jsonString2.getBytes(), PmdataEntity.class);
+ out(generatepmdNode.toString()); // Print it with specified indentation
+ }
+
+ @Test
+ public void testOpenroadmPMString3() throws IOException, ClassNotFoundException {
+ out("Test: " + method());
+ String jsonString2 = getFileContent("pmdata3.json");
+ YangToolsMapper2<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data> mapper2 =
+ new YangToolsMapper2<>(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data.class,
+ null);
+ PmdataEntity generatepmdNode = mapper2.readValue(jsonString2.getBytes(), PmdataEntity.class);
out(generatepmdNode.toString()); // Print it with specified indentation
}
+
+ @Test
+ public void testOpenroadmPMString4() throws IOException, ClassNotFoundException {
+ out("Test: " + method());
+ String jsonString = getFileContent("pmdata3.json");
+ YangToolsMapper2<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data> mapper =
+ new YangToolsMapper2<>(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data.class,
+ null);
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data data =
+ mapper.readValue(jsonString.getBytes(),
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data.class);
+
+ assertTrue("GranularityPeriod", data.getGranularityPeriod().equals(GranularityPeriodType.Period15Min));
+ assertTrue("NodeName", data.getNodeName().equals("openroadm1"));
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata15m.entity.@Nullable PerformanceData performanceData =
+ data.getPerformanceData();
+ assertNotNull("PerformanceData", performanceData);
+ @Nullable Map<MeasurementKey, Measurement> measurement = performanceData.getMeasurement();
+ assertNotNull("Measurement", measurement);
+ Measurement measurement1 = measurement.get(new MeasurementKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.DelayTCM2Up.class));
+ assertTrue("Measurement=11298624220985537708", measurement1.getPmValue().stringValue().equals("11298624220985537708"));
+ }
/*
* --------------------------------- Private
*/
@@ -72,9 +155,12 @@ public class TestYangGenSalMappingOpenRoadm {
}
private static void out(String text) {
- System.out.println("----------------------");
- System.out.println(text);
- Log.info("Log: "+text);
+ Log.info("Log: " + text);
+ }
+
+ private static String getFileContent(String filename) throws IOException {
+ return String.join("\n",
+ IoUtils.readAllLines(TestTree.class.getResourceAsStream(resourceDirectoryPath + filename)));
}
}
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/issues/TestIssue227.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/issues/TestIssue227.java
new file mode 100644
index 000000000..9cfc3ead0
--- /dev/null
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/issues/TestIssue227.java
@@ -0,0 +1,126 @@
+/*
+ * ============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.dataprovider.test.issues;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import java.io.IOException;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.yangtools.yang.common.Uint32;
+
+public class TestIssue227 extends Mockito {
+
+ static String inputJsonString = "{\"value1\":\"forty-two\", \"value2\":\"forty-three\"}";
+ static String inputJsonNumber = "{\"value1\":42, \"value2\":43}";
+
+ @Test
+ public void testWithException() {
+ String inputJson = inputJsonNumber;
+ System.out.println("Input " + inputJson);
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
+
+ doMapping(mapper, inputJson);
+ }
+
+ @Test
+ public void testWithMixin() {
+ String inputJson = inputJsonNumber;
+ System.out.println("Input " + inputJson);
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
+ mapper.addMixIn(TestBuilder.class, IgnoreFooSetValueIntMixIn.class);
+
+ doMapping(mapper, inputJson);
+ }
+
+
+ private void doMapping(ObjectMapper mapper, String json) {
+ TestBuilder foo;
+ try {
+ foo = mapper.readValue(json.getBytes(), TestBuilder.class);
+ System.out.println("Foo " + foo);
+ System.out.println(mapper.writeValueAsString(foo));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ static class TestBuilder {
+
+ private String value1;
+ private String value2;
+
+ String getValue1() {
+ return value1;
+ }
+
+ public void setValue1(String value) {
+ this.value1 = value;
+ }
+
+ public void setValue1(int value) {
+ this.value1 = String.valueOf(value);
+ }
+
+ public void setValue1(long value) {
+ this.value1 = String.valueOf(value);
+ }
+
+ public void setValue1(Uint32 value) {
+ this.value1 = String.valueOf(value);
+ }
+
+ public String getValue2() {
+ return value2;
+ }
+
+ public void setValue2(String value) {
+ this.value2 = value;
+ }
+
+ public void setValue2(int value) {
+ this.value2 = String.valueOf(value);
+ }
+
+ @Override
+ public String toString() {
+ return "Foo [value1=" + value1 + ", value2=" + value2 + "]";
+ }
+
+ }
+
+
+ private abstract class IgnoreFooSetValueIntMixIn {
+ @JsonProperty
+ public abstract void setValue1(String value);
+
+ @JsonProperty
+ public abstract void setValue2(String value);
+ }
+}
+
+