summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java
diff options
context:
space:
mode:
authorMichael DÜrre <michael.duerre@highstreet-technologies.com>2022-03-10 10:39:16 +0100
committerDan Timoney <dtimoney@att.com>2022-03-23 15:08:48 -0400
commiteb2a7c97c0007b013bd1784ac17d57be02b63d03 (patch)
treeb0861438532727219216cfd426e21ae053abb31a /sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java
parent3c74361514bb920ed441d105f66ca978bd074ced (diff)
migrate sdnr features to phosphorus
fix mapper and switch to dom api Updated to use phosphorus version of parent poms Issue-ID: CCSDK-3566 Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com> Change-Id: I98c5bef9286622e0d66b53db687557d798cd53f5 Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java')
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanRegistrationToVESpnfRegistration.java72
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ComponentHelper.java (renamed from sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ComponentHelper.java)2
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestAlarmNotif.java (renamed from sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestAlarmNotif.java)3
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestHardwareClass.java (renamed from sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestHardwareClass.java)2
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanChangeNotificationListener.java (renamed from sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanChangeNotificationListener.java)3
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanFaultNotificationListener.java (renamed from sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanFaultNotificationListener.java)3
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanNetworkElement.java (renamed from sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElement.java)10
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanToInternalDataModel.java (renamed from sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanToInternalDataModel.java)3
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestDeviceManagerORanImpl.java (renamed from sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestDeviceManagerORanImpl.java)10
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORANInventory.java250
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORANReadHardware.java383
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMFaultNotificationListener.java164
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNetworkElement.java111
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNotification.java184
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMToInternalDataModel.java202
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanNetworkElementFactory.java (renamed from sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElementFactory.java)23
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanRegistrationToVESpnfRegistration.java119
-rw-r--r--sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/YangParserTestUtils.java380
18 files changed, 1829 insertions, 95 deletions
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanRegistrationToVESpnfRegistration.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanRegistrationToVESpnfRegistration.java
deleted file mode 100644
index 115765d46..000000000
--- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanRegistrationToVESpnfRegistration.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * ============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.devicemanager.oran.impl;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanRegistrationToVESpnfRegistrationMapper;
-import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
-import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
-import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TestORanRegistrationToVESpnfRegistration {
-
- @Mock
- NetconfAccessor netconfAccessor;
- @Mock
- VESCollectorService vesCollectorService;
- @Mock
- VESCollectorCfgService vesCfgService;
-
- private final int SEQUENCE_NO = 10;
-
- @Test
- public void test() {
- String dateTimeString = "2020-02-05T12:30:45.283Z";
- String name = "Slot-0";
-
- NetconfNode testNetconfNode = mock(NetconfNode.class);
- when(testNetconfNode.getHost()).thenReturn(new Host(new IpAddress(new Ipv4Address("10.10.10.10"))));
-
- when(netconfAccessor.getNodeId()).thenReturn(new NodeId("nSky"));
- when(netconfAccessor.getNetconfNode()).thenReturn(testNetconfNode);
- when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
- when(vesCfgService.getReportingEntityName()).thenReturn("SDN-R");
- Component testComponent = ComponentHelper.get(name, dateTimeString);
-
- ORanRegistrationToVESpnfRegistrationMapper mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfAccessor, vesCollectorService);
- mapper.mapCommonEventHeader(testComponent);
- mapper.mapPNFRegistrationFields(testComponent);
- }
-
-}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ComponentHelper.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ComponentHelper.java
index 05c825fdc..64cdd5f80 100644
--- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ComponentHelper.java
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ComponentHelper.java
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*
*/
-package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
import java.util.Arrays;
import java.util.List;
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestAlarmNotif.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestAlarmNotif.java
index 4d10dd154..883271d4c 100644
--- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestAlarmNotif.java
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestAlarmNotif.java
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*
*/
-package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
@@ -60,7 +60,6 @@ public class TestAlarmNotif implements AlarmNotif {
return FaultSeverity.CRITICAL;
}
- @Override
public @Nullable Boolean isIsCleared() {
return true;
}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestHardwareClass.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestHardwareClass.java
index 64b6ac1ab..753e6c97f 100644
--- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestHardwareClass.java
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestHardwareClass.java
@@ -15,7 +15,7 @@
* the License.
* ============LICENSE_END==========================================================================
*/
-package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.rev180313.HardwareClass;
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanChangeNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanChangeNotificationListener.java
index da4d830d7..d8ea2664f 100644
--- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanChangeNotificationListener.java
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanChangeNotificationListener.java
@@ -16,7 +16,7 @@
* ============LICENSE_END==========================================================================
*/
-package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
@@ -30,6 +30,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding.ORanChangeNotificationListener;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanFaultNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanFaultNotificationListener.java
index af2515c9a..e26af989e 100644
--- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanFaultNotificationListener.java
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanFaultNotificationListener.java
@@ -15,7 +15,7 @@
* the License.
* ============LICENSE_END==========================================================================
*/
-package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -31,6 +31,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding.ORanFaultNotificationListener;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElement.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanNetworkElement.java
index af7664ab8..3de211013 100644
--- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElement.java
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanNetworkElement.java
@@ -15,7 +15,7 @@
* the License.
* ============LICENSE_END==========================================================================
*/
-package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -25,9 +25,9 @@ import java.io.IOException;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.junit.BeforeClass;
-import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.startup.ORanNetworkElementFactory;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
@@ -36,6 +36,7 @@ import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT;
@@ -55,6 +56,7 @@ public class TestORanNetworkElement {
private static Capabilities capabilities;
private static TransactionUtils transactionUtils;
private static NetconfBindingAccessor bindingAccessor;
+ private static NetconfDomAccessor domAccessor;
private static VESCollectorService vesCollectorService;
private static NotificationProxyParser notificationProxyParser;
private static VESCollectorCfgService vesCfgService;
@@ -67,6 +69,7 @@ public class TestORanNetworkElement {
serviceProvider = mock(DeviceManagerServiceProvider.class);
transactionUtils = mock(TransactionUtils.class);
bindingAccessor = mock(NetconfBindingAccessor.class);
+ domAccessor = mock(NetconfDomAccessor.class);
vesCollectorService = mock(VESCollectorService.class);
notificationProxyParser = mock(NotificationProxyParser.class);
vesCfgService = mock(VESCollectorCfgService.class);
@@ -75,6 +78,7 @@ public class TestORanNetworkElement {
when(accessor.getCapabilites()).thenReturn(capabilities);
when(accessor.getNodeId()).thenReturn(nodeId);
when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor));
+ when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
when(bindingAccessor.getCapabilites()).thenReturn(capabilities);
when(bindingAccessor.getTransactionUtils()).thenReturn(transactionUtils);
when(bindingAccessor.getNodeId()).thenReturn(nodeId);
@@ -91,7 +95,7 @@ public class TestORanNetworkElement {
}
- @Test
+ //@Test
public void test() {
Optional<NetworkElement> oRanNe;
when(capabilities.isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true);
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanToInternalDataModel.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanToInternalDataModel.java
index e2e0eb812..a4470d335 100644
--- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanToInternalDataModel.java
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/TestORanToInternalDataModel.java
@@ -15,7 +15,7 @@
* the License.
* ============LICENSE_END==========================================================================
*/
-package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -26,7 +26,6 @@ import java.util.function.IntConsumer;
import java.util.stream.IntStream;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanToInternalDataModel;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestDeviceManagerORanImpl.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestDeviceManagerORanImpl.java
index 98db4bbb6..f3932bc41 100644
--- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestDeviceManagerORanImpl.java
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestDeviceManagerORanImpl.java
@@ -15,12 +15,14 @@
* the License.
* ============LICENSE_END==========================================================================
*/
-package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom;
import static org.mockito.Mockito.mock;
import java.io.IOException;
+import org.junit.After;
import org.junit.Before;
-import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.DeviceManagerORanImpl;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding.DeviceManagerORanImpl;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
public class TestDeviceManagerORanImpl {
@@ -30,7 +32,7 @@ public class TestDeviceManagerORanImpl {
public void init() throws InterruptedException, IOException {
}
- // @Test
+ @Test
public void test() throws Exception {
devMgrOran = new DeviceManagerORanImpl();
NetconfNetworkElementService netconfNetworkElementService = mock(NetconfNetworkElementService.class);
@@ -43,7 +45,7 @@ public class TestDeviceManagerORanImpl {
}
}
- //@After
+ @After
public void cleanUp() throws Exception {
devMgrOran.close();
}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORANInventory.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORANInventory.java
new file mode 100644
index 000000000..337996a3d
--- /dev/null
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORANInventory.java
@@ -0,0 +1,250 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2021 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.devicemanager.oran.impl.dom;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.binding.CodeHelpers;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
+
+public class TestORANInventory {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestORANInventory.class);
+ private static final QNameModule IETF_HARDWARE_MODULE = QNameModule
+ .create(XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-hardware"), Revision.of("2018-03-13"));
+ private static final QName HW_CONTAINER = QName.create(IETF_HARDWARE_MODULE, "hardware");
+ private static final QName HW_COMPONENT_LIST = QName.create(IETF_HARDWARE_MODULE, "component");
+ private static final QName HW_COMPONENT_LIST_KEY = QName.create(IETF_HARDWARE_MODULE, "name");
+ private static final QName HW_COMPONENT_LIST_CLASS = QName.create(IETF_HARDWARE_MODULE, "class");
+ private static final QName HW_COMPONENT_LIST_DESC = QName.create(IETF_HARDWARE_MODULE, "description"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_PARENT = QName.create(IETF_HARDWARE_MODULE, "parent"); // leaf:leafref
+ private static final QName HW_COMPONENT_LIST_CONTAINS_CHILD = QName.create(IETF_HARDWARE_MODULE, "contains-child"); // leaf-list:leafref
+ private static final QName HW_COMPONENT_LIST_HW_REV = QName.create(IETF_HARDWARE_MODULE, "hardware-rev"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_SER_NUM = QName.create(IETF_HARDWARE_MODULE, "serial-num"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_MFG_NAME = QName.create(IETF_HARDWARE_MODULE, "mfg-name"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_MODEL_NAME = QName.create(IETF_HARDWARE_MODULE, "model-name"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_MFG_DATE = QName.create(IETF_HARDWARE_MODULE, "mfg-date"); // leaf:yang:date-and-time
+
+ private static EffectiveModelContext schemaContext;
+ private static @NonNull Inference hwContainerSchema;
+
+ @BeforeClass
+ public static void setup() throws IOException {
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/");
+ hwContainerSchema = Inference.ofDataTreePath(schemaContext, HW_CONTAINER);
+ System.out.println("URL is - " + TestORANReadHardware.class.getResource("/"));
+ }
+
+ @AfterClass
+ public static void cleanup() {
+ schemaContext = null;
+ hwContainerSchema = null;
+ }
+
+ @Test
+ public void testIetfHardwareFromXML() throws XMLStreamException, URISyntaxException, IOException, SAXException {
+
+ final InputStream resourceAsStream = TestORANReadHardware.class.getResourceAsStream("/ietf-hardware.xml");
+
+ /*
+ * final XMLInputFactory factory = XMLInputFactory.newInstance();
+ * XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
+ */
+ final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
+
+ final NormalizedNodeResult result = new NormalizedNodeResult();
+ final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+
+ final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, hwContainerSchema);
+ xmlParser.parse(reader);
+
+ xmlParser.flush();
+ xmlParser.close();
+
+ NormalizedNode transformedInput = result.getResult();
+ NodeId nodeId = new NodeId("nSky");
+ getInventoryList(nodeId, transformedInput);
+ }
+
+ public static List<Inventory> getInventoryList(NodeId nodeId, NormalizedNode hwData) {
+
+ List<Inventory> inventoryResultList = new ArrayList<Inventory>();
+ ContainerNode hwContainer = (ContainerNode) hwData;
+ MapNode componentMap = (MapNode) hwContainer.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST));
+ Collection<MapEntryNode> componentMapEntries = componentMap.body();
+
+ for (MapEntryNode componentMapEntryNode : getRootComponents(componentMapEntries)) {
+ inventoryResultList = recurseGetInventory(nodeId, componentMapEntryNode, componentMapEntries, 0,
+ inventoryResultList);
+ }
+ // Verify if result is complete
+ if (componentMapEntries.size() != inventoryResultList.size()) {
+ LOG.warn(
+ "Not all data were written to the Inventory. Potential entries with missing "
+ + "contained-child. Node Id = {}, Components Found = {}, Entries written to Database = {}",
+ nodeId.getValue(), componentMapEntries.size(), inventoryResultList.size());
+ }
+ return inventoryResultList;
+ }
+
+ private static List<Inventory> recurseGetInventory(NodeId nodeId, MapEntryNode component,
+ Collection<MapEntryNode> componentList, int treeLevel, List<Inventory> inventoryResultList) {
+ LOG.info("Tree level = {}", treeLevel);
+ // Add element to list, if conversion successfull
+ Optional<Inventory> oInventory = getInternalEquipment(nodeId, component, treeLevel);
+ if (oInventory.isPresent()) {
+ inventoryResultList.add(oInventory.get());
+ }
+ // Walk through list of child keys and add to list
+ for (String childUuid : CodeHelpers
+ .nonnull(ORanDMDOMUtility.getLeafListValue(component, HW_COMPONENT_LIST_CONTAINS_CHILD))) {
+ LOG.info("Calling recursively- component is {}", childUuid);
+ for (MapEntryNode c : getComponentsByName(childUuid, componentList)) {
+ inventoryResultList = recurseGetInventory(nodeId, c, componentList, treeLevel + 1, inventoryResultList);
+ }
+ }
+ return inventoryResultList;
+ }
+
+ public static List<MapEntryNode> getRootComponents(Collection<MapEntryNode> componentMapEntries) {
+ List<MapEntryNode> resultList = new ArrayList<>();
+ for (MapEntryNode componentMapEntryNode : componentMapEntries) {
+ if (ORanDMDOMUtility.getLeafValue(componentMapEntryNode, HW_COMPONENT_LIST_PARENT) == null) { // Root
+ // elements
+ // do not
+ // have a
+ // parent
+ resultList.add(componentMapEntryNode);
+ }
+ }
+ return resultList;
+ }
+
+ private static List<MapEntryNode> getComponentsByName(String name, Collection<MapEntryNode> componentList) {
+ List<MapEntryNode> resultList = new ArrayList<>();
+ for (MapEntryNode c : componentList) {
+ if (name.equals(ORanDMDOMUtility.getKeyValue(c))) { // <-- Component list is flat search for child's of name
+ resultList.add(c);
+ }
+ }
+ return resultList;
+ }
+
+ public static Optional<Inventory> getInternalEquipment(NodeId nodeId, MapEntryNode component, int treeLevel) {
+
+ // Make sure that expected data are not null
+ Objects.requireNonNull(nodeId);
+ Objects.requireNonNull(component);
+
+ // Read manadatory data
+
+ @Nullable
+ String nodeIdString = nodeId.getValue();
+ @Nullable
+ String uuid = ORanDMDOMUtility.getKeyValue(component);
+ @Nullable
+ String idParent = ORanDMDOMUtility.getLeafValue(component, HW_COMPONENT_LIST_PARENT);
+ @Nullable
+ String uuidParent = idParent != null ? idParent : uuid; // <- Passt nicht
+ LOG.info("Dump = {}, {}, {}, {}", uuidParent, uuid, treeLevel, nodeIdString);
+ // do consistency check if all mandatory parameters are there
+ if (treeLevel >= 0 && nodeIdString != null && uuid != null && uuidParent != null) {
+ LOG.info("Creating new instance of Inventory");
+ // Build output data
+
+ InventoryBuilder inventoryBuilder = new InventoryBuilder();
+
+ // General assumed as mandatory
+ inventoryBuilder.setNodeId(nodeIdString);
+ inventoryBuilder.setUuid(uuid);
+ inventoryBuilder.setParentUuid(uuidParent);
+ inventoryBuilder.setTreeLevel(Uint32.valueOf(treeLevel));
+
+ // -- String list with ids of holders (optional)
+ inventoryBuilder
+ .setContainedHolder(ORanDMDOMUtility.getLeafListValue(component, HW_COMPONENT_LIST_CONTAINS_CHILD));
+
+ // -- Manufacturer related things (optional)
+ @Nullable
+ String mfgName = ORanDMDOMUtility.getLeafValue(component, HW_COMPONENT_LIST_MFG_NAME);
+ inventoryBuilder.setManufacturerName(mfgName);
+ inventoryBuilder.setManufacturerIdentifier(mfgName);
+
+ // Equipment type (optional)
+ inventoryBuilder.setDescription(ORanDMDOMUtility.getLeafValue(component, HW_COMPONENT_LIST_DESC));
+ inventoryBuilder.setModelIdentifier(ORanDMDOMUtility.getLeafValue(component, HW_COMPONENT_LIST_MODEL_NAME));
+
+ inventoryBuilder.setPartTypeId(ORanDMDOMUtility.getLeafValue(component, HW_COMPONENT_LIST_CLASS));
+
+ inventoryBuilder.setTypeName(ORanDMDOMUtility.getKeyValue(component));
+ inventoryBuilder.setVersion(ORanDMDOMUtility.getLeafValue(component, HW_COMPONENT_LIST_HW_REV));
+
+ // Equipment instance (optional)
+ @Nullable
+ String mfgDate = ORanDMDOMUtility.getLeafValue(component, HW_COMPONENT_LIST_MFG_DATE);
+ if (mfgDate != null) {
+ inventoryBuilder.setDate(mfgDate);
+ }
+ inventoryBuilder.setSerial(ORanDMDOMUtility.getLeafValue(component, HW_COMPONENT_LIST_SER_NUM));
+
+ return Optional.of(inventoryBuilder.build());
+ }
+ return Optional.empty();
+ }
+
+}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORANReadHardware.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORANReadHardware.java
new file mode 100644
index 000000000..b2da8e61f
--- /dev/null
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORANReadHardware.java
@@ -0,0 +1,383 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2021 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.devicemanager.oran.impl.dom;
+
+import com.google.common.base.VerifyException;
+import com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.binding.CodeHelpers;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
+//import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference; //Yangtool 8.0
+import org.xml.sax.SAXException;
+
+public class TestORANReadHardware {
+
+ /*
+ * private static final QNameModule IETF_HARDWARE_MODULE =
+ * QNameModule.create(XMLNamespace.of(
+ * "urn:ietf:params:xml:ns:yang:ietf-hardware"), Revision.of("2018-03-13"));
+ */ // Applicable for Yangtools 8.0
+ // private static final URI IETF_HARDWARE_URI =
+ // URI.create("urn:ietf:params:xml:ns:yang:ietf-hardware");
+ private static final QNameModule IETF_HARDWARE_MODULE = QNameModule
+ .create(XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-hardware"), Revision.of("2018-03-13"));
+ private static final QName HW_CONTAINER = QName.create(IETF_HARDWARE_MODULE, "hardware");
+ private static final QName HW_COMPONENT_LIST = QName.create(IETF_HARDWARE_MODULE, "component");
+ private static final QName HW_COMPONENT_LIST_KEY = QName.create(IETF_HARDWARE_MODULE, "name");
+ private static final QName HW_COMPONENT_LIST_CLASS = QName.create(IETF_HARDWARE_MODULE, "class");
+ private static final QName HW_COMPONENT_LIST_PHYSICAL_INDEX = QName.create(IETF_HARDWARE_MODULE, "physical-index"); // leaf:int32
+ private static final QName HW_COMPONENT_LIST_DESC = QName.create(IETF_HARDWARE_MODULE, "description"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_PARENT = QName.create(IETF_HARDWARE_MODULE, "parent"); // leaf:leafref
+ private static final QName HW_COMPONENT_LIST_PARENT_REL_POS = QName.create(IETF_HARDWARE_MODULE, "parent-rel-pos"); // leaf:int32
+ private static final QName HW_COMPONENT_LIST_CONTAINS_CHILD = QName.create(IETF_HARDWARE_MODULE, "contains-child"); // leaf-list:leafref
+ private static final QName HW_COMPONENT_LIST_HW_REV = QName.create(IETF_HARDWARE_MODULE, "hardware-rev"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_FW_REV = QName.create(IETF_HARDWARE_MODULE, "firmware-rev"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_SW_REV = QName.create(IETF_HARDWARE_MODULE, "software-rev"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_SER_NUM = QName.create(IETF_HARDWARE_MODULE, "serial-num"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_MFG_NAME = QName.create(IETF_HARDWARE_MODULE, "mfg-name"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_MODEL_NAME = QName.create(IETF_HARDWARE_MODULE, "model-name"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_ALIAS = QName.create(IETF_HARDWARE_MODULE, "alias"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_ASSET_ID = QName.create(IETF_HARDWARE_MODULE, "asset-id"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_IS_FRU = QName.create(IETF_HARDWARE_MODULE, "is-fru"); // leaf:boolean
+ private static final QName HW_COMPONENT_LIST_MFG_DATE = QName.create(IETF_HARDWARE_MODULE, "mfg-date"); // leaf:yang:date-and-time
+ private static final QName HW_COMPONENT_LIST_URI = QName.create(IETF_HARDWARE_MODULE, "uri"); // leaf-list:inet:uri
+ private static final QName HW_COMPONENT_LIST_UUID = QName.create(IETF_HARDWARE_MODULE, "uuid"); // leaf:yang:uuid
+ private static final QName HW_COMPONENT_LIST_STATE = QName.create(IETF_HARDWARE_MODULE, "state"); // leaf:yang:uuid
+ private static final QName HW_COMPONENT_LIST_ADMIN_STATE = QName.create(IETF_HARDWARE_MODULE, "admin-state"); // leaf:yang:uuid
+ private static final QName HW_COMPONENT_LIST_OPER_STATE = QName.create(IETF_HARDWARE_MODULE, "oper-state"); // leaf:yang:uuid
+
+ private static EffectiveModelContext schemaContext;
+ private static Inference hwContainerSchema;
+
+ @BeforeClass
+ public static void setup() throws IOException {
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/");
+ hwContainerSchema = Inference.ofDataTreePath(schemaContext, HW_CONTAINER);
+ System.out.println("URL is - " + TestORANReadHardware.class.getResource("/"));
+ }
+
+ @AfterClass
+ public static void cleanup() {
+ schemaContext = null;
+ hwContainerSchema = null;
+ }
+
+ @Test
+ public void testIetfHardwareFromXML() throws XMLStreamException, URISyntaxException, IOException, SAXException {
+
+ final InputStream resourceAsStream = TestORANReadHardware.class.getResourceAsStream("/ietf-hardware.xml");
+
+ /*
+ * final XMLInputFactory factory = XMLInputFactory.newInstance();
+ * XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
+ */
+ final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
+
+ final NormalizedNodeResult result = new NormalizedNodeResult();
+ final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+
+ final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, hwContainerSchema);
+ xmlParser.parse(reader);
+
+ xmlParser.flush();
+ xmlParser.close();
+
+ NormalizedNode transformedInput = result.getResult();
+ System.out.println("Hardware Data = " + transformedInput);
+
+ ContainerNode hwContainer = (ContainerNode) transformedInput;
+ MapNode containerMap = (MapNode) hwContainer.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST));
+ Collection<MapEntryNode> containerMapEntries = containerMap.body();
+ for (MapEntryNode mapEntryNode : containerMapEntries) {
+ NodeIdentifierWithPredicates componentKey = mapEntryNode.getIdentifier(); // list key
+ System.out.println("Key Name is - " + componentKey.keySet());
+ System.out.println("Key Value is - " + componentKey.getValue(HW_COMPONENT_LIST_KEY));
+
+ LeafNode<?> classField = (LeafNode<?>) mapEntryNode
+ .getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_CLASS));
+ System.out.println("Class = " + classField.getIdentifier().getNodeType().getLocalName() + " Value = "
+ + classField.body().toString());
+ Object obj = classField.body();
+ System.out.println(obj.getClass());
+ if (obj instanceof QName) {
+ System.out.println("This is of type QName");
+ }
+ LeafNode<?> aliasLeaf = (LeafNode<?>) mapEntryNode
+ .getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_ALIAS));
+ // System.out.println("Alias = " + aliasLeaf.getValue().toString());
+ System.out.println("Alias = " + getLeafValue(mapEntryNode, HW_COMPONENT_LIST_ALIAS));
+
+ try {
+ DataContainerChild childSet = mapEntryNode
+ .getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_CONTAINS_CHILD));
+
+ Collection<?> childEntry = (Collection<?>) childSet.body();
+ Iterator<?> childEntryItr = childEntry.iterator();
+ while (childEntryItr.hasNext()) {
+ LeafSetEntryNode<?> childEntryNode = (LeafSetEntryNode<?>) childEntryItr.next();
+ System.out.println("Child Node - " + childEntryNode.body());
+ }
+ } catch (VerifyException ve) {
+ // System.out.println("Child not not exist");
+ }
+
+ try {
+ LeafSetNode<?> containsChildSet = (LeafSetNode<?>) mapEntryNode
+ .getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_CONTAINS_CHILD));
+ Collection<?> containsChildSetEntry = containsChildSet.body();
+ Iterator<?> childItr = containsChildSetEntry.iterator();
+ while (childItr.hasNext()) {
+ LeafSetEntryNode<?> childEntryNode = (LeafSetEntryNode<?>) childItr.next();
+ System.out.println("Child Node - " + childEntryNode.body());
+ }
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+
+ try {
+ System.out
+ .println(CodeHelpers.nonnull(getLeafListValue(mapEntryNode, HW_COMPONENT_LIST_CONTAINS_CHILD)));
+ for (String childUuid : CodeHelpers
+ .nonnull(getLeafListValue(mapEntryNode, HW_COMPONENT_LIST_CONTAINS_CHILD))) {
+ System.out.println("Calling recursively - " + childUuid);
+ }
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String description = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_DESC))
+ .body();
+ System.out.println("Description = " + description);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String serialNum = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_SER_NUM))
+ .body();
+ System.out.println("Serial Number = " + serialNum);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String firmwareRev = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_FW_REV))
+ .body();
+ System.out.println("Firmware Rev = " + firmwareRev);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String swRev = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_SW_REV)).body();
+ System.out.println("Software Rev = " + swRev);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String modelName = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_MODEL_NAME))
+ .body();
+ System.out.println("Model Name = " + modelName);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ Integer parentRelPos = (Integer) mapEntryNode
+ .getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_PARENT_REL_POS)).body();
+ System.out.println("Parent Rel Pos = " + (parentRelPos != null ? parentRelPos.intValue() : null));
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String parent = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_PARENT))
+ .body();
+ System.out.println("Parent = " + parent);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String hwRev = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_HW_REV)).body();
+ System.out.println("Hardware Revision = " + hwRev);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String mfgName = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_MFG_NAME))
+ .body();
+ System.out.println("Manufacturer Name = " + mfgName);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ DataContainerChild mfgNameOpt = mapEntryNode
+ .getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_MFG_NAME));
+ if (mfgNameOpt != null) {
+ System.out.println("Mfg Name - " + (String) mfgNameOpt.body());
+ }
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String assetID = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_ASSET_ID))
+ .body();
+ System.out.println("Asset ID = " + assetID);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String mfgDate = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_MFG_DATE))
+ .body();
+ System.out.println("Mfg Date = " + mfgDate);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String uri = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_URI)).body();
+ System.out.println("URI = " + uri);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ Boolean isFRU = (Boolean) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_IS_FRU))
+ .body();
+ System.out.println("IS FRU = " + isFRU);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+ try {
+ String uuid = (String) mapEntryNode.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_UUID)).body()
+ .toString();
+ System.out.println("UUID = " + uuid);
+ } catch (VerifyException | NoSuchElementException e) {
+ // System.out.println("Child not not exist");
+ }
+
+ try {
+ ContainerNode state = (ContainerNode) mapEntryNode
+ .getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_STATE));
+ String adminState = (String) state.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_ADMIN_STATE))
+ .body().toString();
+ System.out.println("Admin State = " + adminState);
+ String operState = (String) state.getChildByArg(new NodeIdentifier(HW_COMPONENT_LIST_OPER_STATE)).body()
+ .toString();
+
+ System.out.println("Oper State = " + operState);
+ } catch (VerifyException | NoSuchElementException e) {
+ System.out.println("Child not not exist");
+ }
+
+ System.out.println("********************************************");
+
+ }
+ // assertNotNull(transformedInput);
+
+ }
+
+ public static String getLeafValue(DataContainerNode componentEntry, QName leafQName) {
+ NodeIdentifier leafNodeIdentifier = new NodeIdentifier(leafQName);
+ try {
+ LeafNode<?> optLeafNode = (LeafNode<?>) componentEntry.getChildByArg(leafNodeIdentifier);
+ if (optLeafNode.body() instanceof QName) {
+ System.out.println("Leaf is of type QName");
+ }
+ return optLeafNode.body().toString();
+ } catch (NoSuchElementException nsee) {
+ System.out.println("Leaf with QName {} not found" + leafQName.toString());
+ return null;
+ }
+ }
+
+ public static List<String> getLeafListValue(DataContainerNode componentEntry, QName leafListQName) {
+ if (componentEntry instanceof MapEntryNode) {
+ List<String> containsChildList = new ArrayList<String>();
+ DataContainerChild childSet = componentEntry.getChildByArg(new NodeIdentifier(leafListQName));
+ if (childSet != null) {
+ Collection<?> childEntry = (Collection<?>) childSet.body();
+ Iterator<?> childEntryItr = childEntry.iterator();
+ while (childEntryItr.hasNext()) {
+ LeafSetEntryNode<?> childEntryNode = (LeafSetEntryNode<?>) childEntryItr.next();
+ containsChildList.add(childEntryNode.body().toString());
+ }
+ }
+ return containsChildList;
+ }
+ return null;
+ }
+
+ @Test
+ public void testIetfHardwareFromNormalizedNode() {
+ buildIetfHardwareContainerNode();
+ }
+
+ private static NormalizedNode buildIetfHardwareContainerNode() {
+ MapNode componentMap = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST))
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(
+ NodeIdentifierWithPredicates.of(HW_COMPONENT_LIST, HW_COMPONENT_LIST_KEY, "chassis"))
+ .withChild(
+ Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST_CLASS))
+ .withValue("ianahw:chassis").build())
+ .withChild(Builders.leafBuilder()
+ .withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST_PHYSICAL_INDEX)).withValue(1)
+ .build())
+ .build())
+ .build();
+ return componentMap;
+ }
+
+}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMFaultNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMFaultNotificationListener.java
new file mode 100644
index 000000000..8abfb2d3e
--- /dev/null
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMFaultNotificationListener.java
@@ -0,0 +1,164 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2021 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.devicemanager.oran.impl.dom;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import com.google.common.io.Files;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding.TestORanFaultNotificationListener;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
+import org.opendaylight.mdsal.dom.api.DOMEvent;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestORanDOMFaultNotificationListener {
+ private static final Logger LOG = LoggerFactory.getLogger(TestORanFaultNotificationListener.class);
+ private static final String TESTFILENAME = "configFile.txt";
+
+ // @formatter:off
+ private static final String TESTCONFIG_CONTENT = "[VESCollector]\n"
+ + "VES_COLLECTOR_ENABLED=true\n"
+ + "VES_COLLECTOR_TLS_ENABLED=true\n"
+ + "VES_COLLECTOR_TRUST_ALL_CERTS=true\n"
+ + "VES_COLLECTOR_USERNAME=sample1\n"
+ + "VES_COLLECTOR_PASSWORD=sample1\n"
+ + "VES_COLLECTOR_IP=[2001:db8:1:1::1]\n"
+ + "VES_COLLECTOR_PORT=8443\n"
+ + "VES_COLLECTOR_VERSION=v7\n"
+ + "REPORTING_ENTITY_NAME=ONAP SDN-R\n"
+ + "EVENTLOG_MSG_DETAIL=SHORT\n"
+ + "";
+ // @formatter:on
+
+ @Mock
+ NetconfDomAccessor domAccessor;
+ @Mock
+ DataProvider dataProvider;
+ @Mock
+ FaultService faultService;
+ @Mock
+ DeviceManagerServiceProvider serviceProvider;
+ @Mock
+ WebsocketManagerService websocketManagerService;
+ @Mock
+ DataProvider databaseService;
+ VESCollectorService vesCollectorService;
+
+ @After
+ @Before
+ public void afterAndBefore() {
+ File f = new File(TESTFILENAME);
+ if (f.exists()) {
+ LOG.info("Remove {}", f.getAbsolutePath());
+ f.delete();
+ }
+ }
+
+ @Test
+ public void test() throws IOException {
+ Files.asCharSink(new File(TESTFILENAME), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
+ vesCollectorService = new VESCollectorServiceImpl(new ConfigurationFileRepresentation(TESTFILENAME));
+ when(domAccessor.getNodeId()).thenReturn(new NodeId("nSky"));
+ ORanDOMFaultNotificationListener faultListener = new ORanDOMFaultNotificationListener(domAccessor,
+ vesCollectorService, faultService, websocketManagerService, databaseService);
+ NetconfDeviceNotification ndn = new NetconfDeviceNotification(createORANDOMFault(), Instant.now());
+ faultListener.onNotification(ndn);
+
+ verify(faultService).faultNotification(any(FaultlogEntity.class));
+ }
+
+ public static ContainerNode createORANDOMFault() {
+ final QName fault_id = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-id");
+ final QName fault_source = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-source");
+ final QName fault_severity = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-severity");
+ final QName is_cleared = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "is-cleared");
+ final QName fault_text = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-text");
+ return Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF))
+ .withChild(ImmutableNodes.leafNode(fault_id, "47"))
+ .withChild(ImmutableNodes.leafNode(fault_source, "Slot-2-Port-B"))
+ .withChild(ImmutableNodes.leafNode(fault_severity, "MAJOR"))
+ .withChild(ImmutableNodes.leafNode(is_cleared, "true"))
+ .withChild(ImmutableNodes.leafNode(fault_text, "CPRI Port Down")).build();
+ }
+
+
+ public static class NetconfDeviceNotification implements DOMNotification, DOMEvent {
+ private final ContainerNode content;
+ private final Absolute schemaPath;
+ private final Instant eventTime;
+
+ NetconfDeviceNotification(final ContainerNode content, final Instant eventTime) {
+ this.content = content;
+ this.eventTime = eventTime;
+ this.schemaPath = Absolute.of(content.getIdentifier().getNodeType());
+ }
+
+ NetconfDeviceNotification(final ContainerNode content, final Absolute schemaPath, final Instant eventTime) {
+ this.content = content;
+ this.eventTime = eventTime;
+ this.schemaPath = schemaPath;
+ }
+
+ @Override
+ public Absolute getType() {
+ return schemaPath;
+ }
+
+ @Override
+ public ContainerNode getBody() {
+ return content;
+ }
+
+ @Override
+ public Instant getEventInstant() {
+ return eventTime;
+ }
+ }
+}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNetworkElement.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNetworkElement.java
new file mode 100644
index 000000000..c75f4f5a1
--- /dev/null
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNetworkElement.java
@@ -0,0 +1,111 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2021 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.devicemanager.oran.impl.dom;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import java.io.IOException;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.startup.ORanNetworkElementFactory;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public class TestORanDOMNetworkElement {
+
+ private static final QName OneCell =
+ QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern();
+ private static final @NonNull QName OnapSystem =
+ QName.create("urn:onap:system", "2020-10-26", "onap-system").intern();
+ private static String NODEIDSTRING = "nSky";
+ private static NodeId nodeId = new NodeId(NODEIDSTRING);
+
+ private static NetconfAccessor accessor;
+ private static DeviceManagerServiceProvider serviceProvider;
+ private static Capabilities capabilities;
+ private static NetconfDomAccessor domAccessor;
+ private static VESCollectorService vesCollectorService;
+ private static NotificationProxyParser notificationProxyParser;
+ private static VESCollectorCfgService vesCfgService;
+ private static WebsocketManagerService websocketManagerService;
+
+ @BeforeClass
+ public static void init() throws InterruptedException, IOException {
+ capabilities = mock(Capabilities.class);
+ accessor = mock(NetconfAccessor.class);
+ serviceProvider = mock(DeviceManagerServiceProvider.class);
+ domAccessor = mock(NetconfDomAccessor.class);
+ vesCollectorService = mock(VESCollectorService.class);
+ notificationProxyParser = mock(NotificationProxyParser.class);
+ vesCfgService = mock(VESCollectorCfgService.class);
+ websocketManagerService = mock(WebsocketManagerService.class);
+
+ when(accessor.getCapabilites()).thenReturn(capabilities);
+ when(accessor.getNodeId()).thenReturn(nodeId);
+ when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
+ when(domAccessor.getNodeId()).thenReturn(nodeId);
+ when(domAccessor.getCapabilites()).thenReturn(capabilities);
+ when(vesCollectorService.getNotificationProxyParser()).thenReturn(notificationProxyParser);
+
+ DataProvider dataProvider = mock(DataProvider.class);
+ FaultService faultService = mock(FaultService.class);
+ when(serviceProvider.getWebsocketService()).thenReturn(websocketManagerService);
+ when(serviceProvider.getFaultService()).thenReturn(faultService);
+ when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
+ when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
+ when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
+ when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
+
+ }
+
+ @Test
+ public void test() {
+ Optional<NetworkElement> oRanNe;
+ when(capabilities.isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(true);
+ when(capabilities.isSupportingNamespace(OneCell)).thenReturn(false);
+ when(capabilities.isSupportingNamespace(OnapSystem)).thenReturn(false);
+
+ ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
+ oRanNe = factory.create(accessor, serviceProvider);
+ assertTrue(factory.create(accessor, serviceProvider).isPresent());
+ oRanNe.get().register();
+ oRanNe.get().deregister();
+ oRanNe.get().getAcessor();
+ oRanNe.get().getDeviceType();
+ assertEquals(oRanNe.get().getNodeId().getValue(), "nSky");
+ }
+}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNotification.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNotification.java
new file mode 100644
index 000000000..1665ac1ad
--- /dev/null
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNotification.java
@@ -0,0 +1,184 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2021 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.devicemanager.oran.impl.dom;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.time.Instant;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
+import org.opendaylight.mdsal.dom.api.DOMEvent;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class TestORanDOMNotification {
+
+ private static final Logger log = LoggerFactory.getLogger(TestORanDOMNotification.class);
+ static ContainerNode cn = null;
+ static NodeId nodeId = new NodeId("nSky");
+ private static NetconfDomAccessor domAccessor;
+ private static VESCollectorService vesCollectorService;
+ private static DataProvider databaseService;
+ private static VESCollectorCfgService vesCfgService;
+ // Use the below procedure for creating QName if binding generated classes are not available
+ /*String ietf_netconf_notif_ns = "urn:ietf:params:xml:ns:yang:ietf-netconf-notifications";
+ String ietf_netconf_notif_ns_date = "2012-02-06";
+ QName username = QName.create(ietf_netconf_notif_ns, ietf_netconf_notif_ns_date, "username");*/
+
+
+ @BeforeClass
+ public static void prepare() {
+ domAccessor = mock(NetconfDomAccessor.class);
+ vesCollectorService = mock(VESCollectorService.class);
+ databaseService = mock(DataProvider.class);
+ vesCfgService = mock(VESCollectorCfgService.class);
+ when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
+ when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
+ when(domAccessor.getNodeId()).thenReturn(nodeId);
+ }
+
+ /*
+ ImmutableContainerNode{
+ identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)netconf-config-change,
+ value=[
+ ImmutableContainerNode{
+ identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)changed-by,
+ value=[
+ ImmutableChoiceNode{
+ identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)server-or-user,
+ value=[
+ ImmutableLeafNode{
+ identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)username,
+ value=root
+ },
+ ImmutableLeafNode{
+ identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)session-id,
+ value=2
+ }
+ ]
+ }
+ ]
+ },
+ ImmutableUnkeyedListNode{
+ identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)edit,
+ value=[
+ ImmutableUnkeyedListEntryNode{
+ identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)edit,
+ value=[
+ ImmutableLeafNode{
+ identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)operation,
+ value=replace
+ },
+ ImmutableLeafNode{
+ identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)target, value=/(urn:ietf:params:xml:ns:yang:ietf-hardware?revision=2018-03-13)hardware/component/component[{(urn:ietf:params:xml:ns:yang:ietf-hardware?revision=2018-03-13)name=chassis-fan3}]/alias
+ }
+ ]
+ }
+ ]
+ },
+ ImmutableLeafNode{
+ identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)datastore,
+ value=running
+ }
+ ]
+ }
+ */
+ private static ContainerNode createDOMNotificationBody() {
+ return Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE))
+ .withChild(
+ Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_CHANGEDBY))
+ .withChild(Builders.choiceBuilder()
+ .withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_SERVERORUSER))
+ .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_USERNAME, "root"))
+ .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_SESSIONID, Uint32.valueOf(2))).build())
+ .build())
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_EDITNODE))
+ .withChild(Builders.unkeyedListEntryBuilder()
+ .withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_EDITNODE))
+ .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_OPERATION, "replace"))
+ .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_TARGET,
+ "/(urn:ietf:params:xml:ns:yang:ietf-hardware?revision=2018-03-13)hardware/component[{(urn:ietf:params:xml:ns:yang:ietf-hardware?revision=2018-03-13)name=chassis-fan3}]/alias"))
+ .build())
+ .build())
+ .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_DATASTORE, "running")).build();
+ }
+
+ @Test
+ public void test() {
+ ContainerNode cn = createDOMNotificationBody();
+ System.out.println(cn.toString());
+ NetconfDeviceNotification ndn = new NetconfDeviceNotification(cn, Instant.now());
+ ORanDOMChangeNotificationListener changeListener = new ORanDOMChangeNotificationListener(domAccessor, vesCollectorService, databaseService);
+ changeListener.onNotification(ndn);
+ verify(databaseService).writeEventLog(any(EventlogEntity.class));
+ }
+
+ public static class NetconfDeviceNotification implements DOMNotification, DOMEvent {
+ private final ContainerNode content;
+ private final Absolute schemaPath;
+ private final Instant eventTime;
+
+ NetconfDeviceNotification(final ContainerNode content, final Instant eventTime) {
+ this.content = content;
+ this.eventTime = eventTime;
+ this.schemaPath = Absolute.of(content.getIdentifier().getNodeType());
+ }
+
+ NetconfDeviceNotification(final ContainerNode content, final Absolute schemaPath, final Instant eventTime) {
+ this.content = content;
+ this.eventTime = eventTime;
+ this.schemaPath = schemaPath;
+ }
+
+ @Override
+ public Absolute getType() {
+ return schemaPath;
+ }
+
+ @Override
+ public ContainerNode getBody() {
+ return content;
+ }
+
+ @Override
+ public Instant getEventInstant() {
+ return eventTime;
+ }
+ }
+
+}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMToInternalDataModel.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMToInternalDataModel.java
new file mode 100644
index 000000000..4eac71cde
--- /dev/null
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMToInternalDataModel.java
@@ -0,0 +1,202 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2021 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.devicemanager.oran.impl.dom;
+
+import static org.junit.Assert.assertEquals;
+import com.google.common.collect.Sets;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.time.Instant;
+import java.util.List;
+import java.util.Optional;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.mdsal.dom.api.DOMEvent;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+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.Guicutthrough;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
+import org.xml.sax.SAXException;
+
+public class TestORanDOMToInternalDataModel {
+
+ private static final QNameModule IETF_HARDWARE_MODULE = QNameModule
+ .create(XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-hardware"), Revision.of("2018-03-13"));
+ private static final QName HW_CONTAINER = QName.create(IETF_HARDWARE_MODULE, "hardware");
+
+ private static final QNameModule IETF_SYSTEM_MODULE = QNameModule
+ .create(XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-system"), Revision.of("2014-08-06"));
+ private static final QName IETF_CONTAINER = QName.create(IETF_SYSTEM_MODULE, "system");
+
+ private static EffectiveModelContext schemaContext;
+ private static Inference hwContainerSchema;
+ private static Inference systemSchema;
+
+ private static final NodeId nodeId = new NodeId("nSky");
+
+ @BeforeClass
+ public static void setup() throws IOException {
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/");
+ hwContainerSchema = Inference.ofDataTreePath(schemaContext, HW_CONTAINER);
+ systemSchema = Inference.ofDataTreePath(schemaContext, IETF_CONTAINER);
+ }
+
+ @AfterClass
+ public static void cleanup() {
+ schemaContext = null;
+ hwContainerSchema = null;
+ systemSchema = null;
+ }
+
+ @Test
+ public void testIetfHardwareFromXML() throws XMLStreamException, URISyntaxException, IOException, SAXException {
+
+ final InputStream resourceAsStream = TestORANReadHardware.class.getResourceAsStream("/ietf-hardware.xml");
+
+ /*
+ * final XMLInputFactory factory = XMLInputFactory.newInstance();
+ * XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
+ */
+ final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
+
+ final NormalizedNodeResult result = new NormalizedNodeResult();
+ final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+
+ final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, hwContainerSchema);
+ xmlParser.parse(reader);
+
+ xmlParser.flush();
+ xmlParser.close();
+
+ NormalizedNode transformedInput = result.getResult();
+
+ List<Inventory> inventoryList = ORanDOMToInternalDataModel.getInventoryList(nodeId, transformedInput);
+ assertEquals("All elements", 27, inventoryList.size());
+ assertEquals("Treelevel always there", 0,
+ inventoryList.stream().filter(inventory -> inventory.getTreeLevel() == null).count());
+ }
+
+ @Test
+ public void testIetfSystemFromXML() throws XMLStreamException, URISyntaxException, IOException, SAXException {
+
+ final InputStream resourceAsStream = TestORANReadHardware.class.getResourceAsStream("/onap-system.xml");
+
+ final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
+
+ final NormalizedNodeResult result = new NormalizedNodeResult();
+ final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+
+ final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, systemSchema);
+ xmlParser.parse(reader);
+
+ xmlParser.flush();
+ xmlParser.close();
+
+ NormalizedNode transformedInput = result.getResult();
+ ContainerNode cn = (ContainerNode) transformedInput;
+ AugmentationIdentifier onapSystemIID = YangInstanceIdentifier.AugmentationIdentifier.create(
+ Sets.newHashSet(ORanDeviceManagerQNames.ONAP_SYSTEM_NAME, ORanDeviceManagerQNames.ONAP_SYSTEM_WEB_UI));
+ Optional<Guicutthrough> gc = ORanDOMToInternalDataModel.getGuicutthrough(cn.getChildByArg(onapSystemIID));
+ assertEquals(gc.isPresent(), true);
+
+ }
+
+ @Test
+ public void testORANFault() {
+ ContainerNode cn = createORANDOMFault();
+ NetconfDeviceNotification faultNotif = new NetconfDeviceNotification(cn, Instant.now());
+ FaultlogEntity fle = ORanDOMToInternalDataModel.getFaultLog(faultNotif, nodeId, 1);
+ assertEquals(fle.getId(), "47");
+ }
+
+ public static ContainerNode createORANDOMFault() {
+ final QName fault_id = QName.create(ORanDeviceManagerQNames.ORAN_FM_FAULT_ID, "fault-id");
+ final QName fault_source = QName.create(ORanDeviceManagerQNames.ORAN_FM_FAULT_SOURCE, "fault-source");
+ final QName fault_severity = QName.create(ORanDeviceManagerQNames.ORAN_FM_FAULT_SEVERITY, "fault-severity");
+ final QName is_cleared = QName.create(ORanDeviceManagerQNames.ORAN_FM_FAULT_IS_CLEARED, "is-cleared");
+ final QName fault_text = QName.create(ORanDeviceManagerQNames.ORAN_FM_FAULT_TEXT, "fault-text");
+ return Builders.containerBuilder()
+ .withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF))
+ .withChild(ImmutableNodes.leafNode(fault_id, "47"))
+ .withChild(ImmutableNodes.leafNode(fault_source, "Slot-2-Port-B"))
+ .withChild(ImmutableNodes.leafNode(fault_severity, "MAJOR"))
+ .withChild(ImmutableNodes.leafNode(is_cleared, "true"))
+ .withChild(ImmutableNodes.leafNode(fault_text, "CPRI Port Down")).build();
+ }
+
+ public static class NetconfDeviceNotification implements DOMNotification, DOMEvent {
+ private final ContainerNode content;
+ private final Absolute schemaPath;
+ private final Instant eventTime;
+
+ NetconfDeviceNotification(final ContainerNode content, final Instant eventTime) {
+ this.content = content;
+ this.eventTime = eventTime;
+ this.schemaPath = Absolute.of(content.getIdentifier().getNodeType());
+ }
+
+ NetconfDeviceNotification(final ContainerNode content, final Absolute schemaPath, final Instant eventTime) {
+ this.content = content;
+ this.eventTime = eventTime;
+ this.schemaPath = schemaPath;
+ }
+
+ @Override
+ public Absolute getType() {
+ return schemaPath;
+ }
+
+ @Override
+ public ContainerNode getBody() {
+ return content;
+ }
+
+ @Override
+ public Instant getEventInstant() {
+ return eventTime;
+ }
+ }
+}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElementFactory.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanNetworkElementFactory.java
index fc382bfe2..27793e4bb 100644
--- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElementFactory.java
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanNetworkElementFactory.java
@@ -2,7 +2,7 @@
* ============LICENSE_START========================================================================
* ONAP : ccsdk feature sdnr wt
* =================================================================================================
- * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
+ * Copyright (C) 2021 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
@@ -15,7 +15,7 @@
* the License.
* ============LICENSE_END==========================================================================
*/
-package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@@ -26,37 +26,43 @@ import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.startup.ORanNetworkElementFactory;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
-import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
public class TestORanNetworkElementFactory {
private static String NODEIDSTRING = "nSky";
- private static NetconfBindingAccessor accessor;
+ private static NetconfAccessor accessor;
private static DeviceManagerServiceProvider serviceProvider;
private static Capabilities capabilities;
private static VESCollectorService vesCollectorService;
private static FaultService faultService;
private static WebsocketManagerService notificationService;
private static DataProvider databaseService;
+ private static NodeId nodeId = new NodeId(NODEIDSTRING);
@BeforeClass
public static void init() throws InterruptedException, IOException {
NetconfBindingAccessor bindingAccessor = mock(NetconfBindingAccessor.class);
- NodeId nodeId = new NodeId(NODEIDSTRING);
when(bindingAccessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
when(bindingAccessor.getNodeId()).thenReturn(nodeId);
+ NetconfDomAccessor domAccessor = mock(NetconfDomAccessor.class);
+ when(domAccessor.getNodeId()).thenReturn(nodeId);
+
capabilities = mock(Capabilities.class);
- accessor = mock(NetconfBindingAccessor.class);
+ //accessor = mock(NetconfBindingAccessor.class);
+ accessor = mock(NetconfAccessor.class);
serviceProvider = mock(DeviceManagerServiceProvider.class);
vesCollectorService = mock(VESCollectorService.class);
faultService = mock(FaultService.class);
@@ -65,6 +71,7 @@ public class TestORanNetworkElementFactory {
when(accessor.getCapabilites()).thenReturn(capabilities);
when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor));
+ when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
when(serviceProvider.getFaultService()).thenReturn(faultService);
when(serviceProvider.getWebsocketService()).thenReturn(notificationService);
when(serviceProvider.getDataProvider()).thenReturn(databaseService);
@@ -74,14 +81,14 @@ public class TestORanNetworkElementFactory {
@Test
public void testCreateORANHWComponent() throws Exception {
- when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true);
+ when(accessor.getCapabilites().isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(true);
ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
assertTrue((factory.create(accessor, serviceProvider)).isPresent());
}
@Test
public void testCreateNone() throws Exception {
- when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(false);
+ when(accessor.getCapabilites().isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(false);
ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
assertTrue(!(factory.create(accessor, serviceProvider).isPresent()));
}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanRegistrationToVESpnfRegistration.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanRegistrationToVESpnfRegistration.java
new file mode 100644
index 000000000..d520af5ba
--- /dev/null
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanRegistrationToVESpnfRegistration.java
@@ -0,0 +1,119 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2021 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.devicemanager.oran.impl.dom;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding.ORanRegistrationToVESpnfRegistrationMapper;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestORanRegistrationToVESpnfRegistration {
+
+ @Mock
+ NetconfAccessor netconfAccessor;
+ @Mock
+ VESCollectorService vesCollectorService;
+ @Mock
+ VESCollectorCfgService vesCfgService;
+
+ private static final QNameModule IETF_HARDWARE_MODULE = QNameModule
+ .create(XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-hardware"), Revision.of("2018-03-13"));
+ private static final QName HW_COMPONENT_LIST = QName.create(IETF_HARDWARE_MODULE, "component");
+ private static final QName HW_COMPONENT_LIST_KEY = QName.create(IETF_HARDWARE_MODULE, "name");
+ private static final QName HW_COMPONENT_LIST_CLASS = QName.create(IETF_HARDWARE_MODULE, "class");
+ private static final QName HW_COMPONENT_LIST_PHYSICAL_INDEX = QName.create(IETF_HARDWARE_MODULE, "physical-index"); // leaf:int32
+ private static final QName HW_COMPONENT_LIST_DESC = QName.create(IETF_HARDWARE_MODULE, "description"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_SW_REV = QName.create(IETF_HARDWARE_MODULE, "software-rev"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_SER_NUM = QName.create(IETF_HARDWARE_MODULE, "serial-num"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_MFG_NAME = QName.create(IETF_HARDWARE_MODULE, "mfg-name"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_MODEL_NAME = QName.create(IETF_HARDWARE_MODULE, "model-name"); // leaf:String
+ private static final QName HW_COMPONENT_LIST_ALIAS = QName.create(IETF_HARDWARE_MODULE, "alias"); // leaf:String
+
+ @Test
+ public void test() {
+ NetconfNode testNetconfNode = mock(NetconfNode.class);
+ when(testNetconfNode.getHost()).thenReturn(new Host(new IpAddress(new Ipv4Address("10.10.10.10"))));
+
+ when(netconfAccessor.getNodeId()).thenReturn(new NodeId("nSky"));
+ when(netconfAccessor.getNetconfNode()).thenReturn(testNetconfNode);
+ when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
+ when(vesCfgService.getReportingEntityName()).thenReturn("SDN-R");
+
+ ORanRegistrationToVESpnfRegistrationMapper mapper = new ORanRegistrationToVESpnfRegistrationMapper(
+ netconfAccessor, vesCollectorService);
+ VESCommonEventHeaderPOJO commonHeader = mapper.mapCommonEventHeader(buildComponentEntry());
+ VESPNFRegistrationFieldsPOJO pnfFields = mapper.mapPNFRegistrationFields(buildComponentEntry());
+
+ assertEquals(commonHeader.getNfVendorName(), "ISCO");
+ assertEquals(pnfFields.getUnitType(), "chassis");
+ assertEquals(pnfFields.getSerialNumber(), "10283");
+ assertEquals(pnfFields.getSoftwareVersion(), "3.8.1 (2020-10-30 11:47:59)");
+ }
+
+ public MapEntryNode buildComponentEntry() {
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(
+ NodeIdentifierWithPredicates.of(HW_COMPONENT_LIST, HW_COMPONENT_LIST_KEY, "chassis"))
+ .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST_CLASS))
+ .withValue("ianahw:chassis").build())
+ .withChild(Builders.leafBuilder()
+ .withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST_PHYSICAL_INDEX)).withValue(1).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST_MFG_NAME))
+ .withValue("ISCO").build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST_MODEL_NAME))
+ .withValue("ProteusCPRI Compact").build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST_ALIAS))
+ .withValue("chassis").build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST_SER_NUM))
+ .withValue("10283").build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST_DESC))
+ .withValue("HighStreet-ONAP40").build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(HW_COMPONENT_LIST_SW_REV))
+ .withValue("3.8.1 (2020-10-30 11:47:59)").build())
+ .build();
+
+ }
+
+}
diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/YangParserTestUtils.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/YangParserTestUtils.java
new file mode 100644
index 000000000..1d1726003
--- /dev/null
+++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/YangParserTestUtils.java
@@ -0,0 +1,380 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom;
+
+import com.google.common.annotations.Beta;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.YangConstants;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.api.YangParser;
+import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
+import org.opendaylight.yangtools.yang.parser.api.YangParserException;
+import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
+import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+/**
+ * Utility class which provides convenience methods for producing effective schema context based on the supplied
+ * yang/yin sources or paths to these sources.
+ */
+@Beta
+public final class YangParserTestUtils {
+
+ private static final FileFilter YANG_FILE_FILTER = file -> {
+ // Locale keeps SpotBugs happy. It should not matter that much anyway.
+ final String name = file.getName().toLowerCase(Locale.ENGLISH);
+ return name.endsWith(YangConstants.RFC6020_YANG_FILE_EXTENSION) && file.isFile();
+ };
+
+ private static final @NonNull YangParserFactory PARSER_FACTORY;
+
+ static {
+ final Iterator<@NonNull YangParserFactory> it = ServiceLoader.load(YangParserFactory.class).iterator();
+ if (!it.hasNext()) {
+ throw new IllegalStateException("No YangParserFactory found");
+ }
+ PARSER_FACTORY = it.next();
+ }
+
+ private YangParserTestUtils() {
+ // Hidden on purpose
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
+ * default mode and all YANG features are supported.
+ *
+ * @param resource relative path to the YANG file to be parsed
+ *
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResource(final String resource) {
+ return parseYangResource(resource, YangParserConfiguration.DEFAULT);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
+ *
+ * @param resource relative path to the YANG file to be parsed
+ * @param parserMode mode of statement parser
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResource(final String resource, final YangParserConfiguration config) {
+ return parseYangResource(resource, config, null);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
+ * default mode.
+ *
+ * @param resource relative path to the YANG file to be parsed
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * model are resolved
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResource(final String resource, final Set<QName> supportedFeatures) {
+ return parseYangResource(resource, YangParserConfiguration.DEFAULT, supportedFeatures);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG source.
+ *
+ * @param resource relative path to the YANG file to be parsed
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * model are resolved
+ * @param parserMode mode of statement parser
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResource(final String resource, final YangParserConfiguration config,
+ final Set<QName> supportedFeatures) {
+ final YangTextSchemaSource source = YangTextSchemaSource.forResource(YangParserTestUtils.class, resource);
+ return parseYangSources(config, supportedFeatures, source);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
+ * default mode and all YANG features are supported.
+ *
+ * @param files YANG files to be parsed
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangFiles(final File... files) {
+ return parseYangFiles(Arrays.asList(files));
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
+ * default mode and all YANG features are supported.
+ *
+ * @param files collection of YANG files to be parsed
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangFiles(final Collection<File> files) {
+ return parseYangFiles(YangParserConfiguration.DEFAULT, files);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
+ * default mode.
+ *
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * models are resolved
+ * @param files YANG files to be parsed
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangFiles(final Set<QName> supportedFeatures, final File... files) {
+ return parseYangFiles(supportedFeatures, Arrays.asList(files));
+ }
+
+ public static EffectiveModelContext parseYangFiles(final Set<QName> supportedFeatures,
+ final Collection<File> files) {
+ return parseYangFiles(supportedFeatures, YangParserConfiguration.DEFAULT, files);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
+ *
+ * @param parserMode mode of statement parser
+ * @param files YANG files to be parsed
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangFiles(final YangParserConfiguration config, final File... files) {
+ return parseYangFiles(config, Arrays.asList(files));
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
+ *
+ * @param parserMode mode of statement parser
+ * @param files collection of YANG files to be parsed
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangFiles(final YangParserConfiguration config,
+ final Collection<File> files) {
+ return parseYangFiles(null, config, files);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources.
+ *
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * models are resolved
+ * @param parserMode mode of statement parser
+ * @param files YANG files to be parsed
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangFiles(final Set<QName> supportedFeatures,
+ final YangParserConfiguration config, final File... files) {
+ return parseYangFiles(supportedFeatures, config, Arrays.asList(files));
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources.
+ *
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * models are resolved
+ * @param parserMode mode of statement parser
+ * @param files YANG files to be parsed
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangFiles(final Set<QName> supportedFeatures,
+ final YangParserConfiguration config, final Collection<File> files) {
+ return parseSources(config, supportedFeatures,
+ files.stream().map(YangTextSchemaSource::forFile).collect(Collectors.toList()));
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
+ * default mode and all YANG features are supported.
+ *
+ * @param resourcePath relative path to the directory with YANG files to be parsed
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResourceDirectory(final String resourcePath) {
+ return parseYangResourceDirectory(resourcePath, YangParserConfiguration.DEFAULT);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
+ *
+ * @param resourcePath relative path to the directory with YANG files to be parsed
+ * @param parserMode mode of statement parser
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResourceDirectory(final String resourcePath,
+ final YangParserConfiguration config) {
+ return parseYangResourceDirectory(resourcePath, null, config);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
+ * default mode.
+ *
+ * @param resourcePath relative path to the directory with YANG files to be parsed
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * models are resolved
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResourceDirectory(final String resourcePath,
+ final Set<QName> supportedFeatures) {
+ return parseYangResourceDirectory(resourcePath, supportedFeatures, YangParserConfiguration.DEFAULT);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources.
+ *
+ * @param resourcePath relative path to the directory with YANG files to be parsed
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * models are resolved
+ * @param parserMode mode of statement parser
+ * @return effective schema context
+ */
+ @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Wrong inferent on listFiles")
+ public static EffectiveModelContext parseYangResourceDirectory(final String resourcePath,
+ final Set<QName> supportedFeatures, final YangParserConfiguration config) {
+ final URI directoryPath;
+ try {
+ directoryPath = YangParserTestUtils.class.getResource(resourcePath).toURI();
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Failed to open resource " + resourcePath, e);
+ }
+ return parseYangFiles(supportedFeatures, config, new File(directoryPath).listFiles(YANG_FILE_FILTER));
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
+ * default mode and all YANG features are supported.
+ *
+ * @param clazz Resource lookup base
+ * @param resources Resource names to be looked up
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResources(final Class<?> clazz, final String... resources) {
+ return parseYangResources(clazz, Arrays.asList(resources));
+ }
+
+ public static EffectiveModelContext parseYangResources(final Class<?> clazz, final Collection<String> resources) {
+ final List<YangTextSchemaSource> sources = new ArrayList<>(resources.size());
+ for (final String r : resources) {
+ sources.add(YangTextSchemaSource.forResource(clazz, r));
+ }
+ return parseSources(YangParserConfiguration.DEFAULT, null, sources);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
+ * default mode.
+ *
+ * @param yangDirs relative paths to the directories containing YANG files to be parsed
+ * @param yangFiles relative paths to the YANG files to be parsed
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * models are resolved
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResources(final List<String> yangDirs, final List<String> yangFiles,
+ final Set<QName> supportedFeatures) {
+ return parseYangResources(yangDirs, yangFiles, supportedFeatures, YangParserConfiguration.DEFAULT);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
+ *
+ * @param yangResourceDirs relative paths to the directories containing YANG files to be parsed
+ * @param yangResources relative paths to the YANG files to be parsed
+ * @param statementParserMode mode of statement parser
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResources(final List<String> yangResourceDirs,
+ final List<String> yangResources, final YangParserConfiguration config) {
+ return parseYangResources(yangResourceDirs, yangResources, null, config);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources.
+ *
+ * @param yangResourceDirs relative paths to the directories containing YANG files to be parsed
+ * @param yangResources relative paths to the YANG files to be parsed
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * models are resolved
+ * @param statementParserMode mode of statement parser
+ * @return effective schema context
+ */
+ public static EffectiveModelContext parseYangResources(final List<String> yangResourceDirs,
+ final List<String> yangResources, final Set<QName> supportedFeatures,
+ final YangParserConfiguration config) {
+ final List<File> allYangFiles = new ArrayList<>();
+ for (final String yangDir : yangResourceDirs) {
+ allYangFiles.addAll(getYangFiles(yangDir));
+ }
+
+ for (final String yangFile : yangResources) {
+ try {
+ allYangFiles.add(new File(YangParserTestUtils.class.getResource(yangFile).toURI()));
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Invalid resource " + yangFile, e);
+ }
+ }
+
+ return parseYangFiles(supportedFeatures, config, allYangFiles);
+ }
+
+ public static EffectiveModelContext parseYangSources(final YangParserConfiguration config,
+ final Set<QName> supportedFeatures, final YangTextSchemaSource... sources) {
+ return parseSources(config, supportedFeatures, Arrays.asList(sources));
+ }
+
+ public static EffectiveModelContext parseSources(final YangParserConfiguration config,
+ final Set<QName> supportedFeatures, final Collection<? extends SchemaSourceRepresentation> sources) {
+ final YangParser parser = PARSER_FACTORY.createParser(config);
+ if (supportedFeatures != null) {
+ parser.setSupportedFeatures(supportedFeatures);
+ }
+
+ try {
+ parser.addSources(sources);
+ } catch (YangSyntaxErrorException e) {
+ throw new IllegalArgumentException("Malformed source", e);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Failed to read a source", e);
+ }
+
+ try {
+ return parser.buildEffectiveModel();
+ } catch (YangParserException e) {
+ throw new IllegalStateException("Failed to assemble SchemaContext", e);
+ }
+ }
+
+ @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Wrong inferent on listFiles")
+ private static Collection<File> getYangFiles(final String resourcePath) {
+ final URI directoryPath;
+ try {
+ directoryPath = YangParserTestUtils.class.getResource(resourcePath).toURI();
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Failed to open resource directory " + resourcePath, e);
+ }
+ return Arrays.asList(new File(directoryPath).listFiles(YANG_FILE_FILTER));
+ }
+}