2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
28 import java.time.Instant;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.notification.ORanDOMChangeNotificationListener;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
37 import org.opendaylight.mdsal.dom.api.DOMEvent;
38 import org.opendaylight.mdsal.dom.api.DOMNotification;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
40 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
41 import org.opendaylight.yangtools.yang.common.Uint32;
42 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
43 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
44 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
45 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
46 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 public class TestORanDOMNotification {
53 private static final Logger log = LoggerFactory.getLogger(TestORanDOMNotification.class);
54 static ContainerNode cn = null;
55 static NodeId nodeId = new NodeId("nSky");
56 private static NetconfDomAccessor domAccessor;
57 private static VESCollectorService vesCollectorService;
58 private static DataProvider databaseService;
59 private static VESCollectorCfgService vesCfgService;
60 // Use the below procedure for creating QName if binding generated classes are not available
61 /*String ietf_netconf_notif_ns = "urn:ietf:params:xml:ns:yang:ietf-netconf-notifications";
62 String ietf_netconf_notif_ns_date = "2012-02-06";
63 QName username = QName.create(ietf_netconf_notif_ns, ietf_netconf_notif_ns_date, "username");*/
67 public static void prepare() {
68 domAccessor = mock(NetconfDomAccessor.class);
69 vesCollectorService = mock(VESCollectorService.class);
70 databaseService = mock(DataProvider.class);
71 vesCfgService = mock(VESCollectorCfgService.class);
72 when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
73 when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
74 when(domAccessor.getNodeId()).thenReturn(nodeId);
78 ImmutableContainerNode{
79 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)netconf-config-change,
81 ImmutableContainerNode{
82 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)changed-by,
85 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)server-or-user,
88 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)username,
92 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)session-id,
99 ImmutableUnkeyedListNode{
100 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)edit,
102 ImmutableUnkeyedListEntryNode{
103 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)edit,
106 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)operation,
110 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
117 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)datastore,
123 private static ContainerNode createDOMNotificationBody() {
124 return Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE))
126 Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_CHANGEDBY))
127 .withChild(Builders.choiceBuilder()
128 .withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_SERVERORUSER))
129 .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_USERNAME, "root"))
130 .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_SESSIONID, Uint32.valueOf(2))).build())
132 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_EDITNODE))
133 .withChild(Builders.unkeyedListEntryBuilder()
134 .withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_EDITNODE))
135 .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_OPERATION, "replace"))
136 .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_TARGET,
137 "/(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"))
140 .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_DATASTORE, "running")).build();
145 ContainerNode cn = createDOMNotificationBody();
146 NetconfDeviceNotification ndn = new NetconfDeviceNotification(cn, Instant.now());
147 ORanDOMChangeNotificationListener changeListener = new ORanDOMChangeNotificationListener(domAccessor, vesCollectorService, databaseService);
148 changeListener.onNotification(ndn);
149 verify(databaseService).writeEventLog(any(EventlogEntity.class));
152 public static class NetconfDeviceNotification implements DOMNotification, DOMEvent {
153 private final ContainerNode content;
154 private final Absolute schemaPath;
155 private final Instant eventTime;
157 NetconfDeviceNotification(final ContainerNode content, final Instant eventTime) {
158 this.content = content;
159 this.eventTime = eventTime;
160 this.schemaPath = Absolute.of(content.getIdentifier().getNodeType());
163 NetconfDeviceNotification(final ContainerNode content, final Absolute schemaPath, final Instant eventTime) {
164 this.content = content;
165 this.eventTime = eventTime;
166 this.schemaPath = schemaPath;
170 public Absolute getType() {
175 public ContainerNode getBody() {
180 public Instant getEventInstant() {