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.service.VESCollectorCfgService;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
35 import org.opendaylight.mdsal.dom.api.DOMEvent;
36 import org.opendaylight.mdsal.dom.api.DOMNotification;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
38 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
39 import org.opendaylight.yangtools.yang.common.Uint32;
40 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
41 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
42 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
43 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
44 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 public class TestORanDOMNotification {
51 private static final Logger log = LoggerFactory.getLogger(TestORanDOMNotification.class);
52 static ContainerNode cn = null;
53 static NodeId nodeId = new NodeId("nSky");
54 private static NetconfDomAccessor domAccessor;
55 private static VESCollectorService vesCollectorService;
56 private static DataProvider databaseService;
57 private static VESCollectorCfgService vesCfgService;
58 // Use the below procedure for creating QName if binding generated classes are not available
59 /*String ietf_netconf_notif_ns = "urn:ietf:params:xml:ns:yang:ietf-netconf-notifications";
60 String ietf_netconf_notif_ns_date = "2012-02-06";
61 QName username = QName.create(ietf_netconf_notif_ns, ietf_netconf_notif_ns_date, "username");*/
65 public static void prepare() {
66 domAccessor = mock(NetconfDomAccessor.class);
67 vesCollectorService = mock(VESCollectorService.class);
68 databaseService = mock(DataProvider.class);
69 vesCfgService = mock(VESCollectorCfgService.class);
70 when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
71 when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
72 when(domAccessor.getNodeId()).thenReturn(nodeId);
76 ImmutableContainerNode{
77 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)netconf-config-change,
79 ImmutableContainerNode{
80 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)changed-by,
83 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)server-or-user,
86 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)username,
90 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)session-id,
97 ImmutableUnkeyedListNode{
98 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)edit,
100 ImmutableUnkeyedListEntryNode{
101 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)edit,
104 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)operation,
108 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
115 identifier=(urn:ietf:params:xml:ns:yang:ietf-netconf-notifications?revision=2012-02-06)datastore,
121 private static ContainerNode createDOMNotificationBody() {
122 return Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE))
124 Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_CHANGEDBY))
125 .withChild(Builders.choiceBuilder()
126 .withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_SERVERORUSER))
127 .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_USERNAME, "root"))
128 .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_SESSIONID, Uint32.valueOf(2))).build())
130 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_EDITNODE))
131 .withChild(Builders.unkeyedListEntryBuilder()
132 .withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_EDITNODE))
133 .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_OPERATION, "replace"))
134 .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_TARGET,
135 "/(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"))
138 .withChild(ImmutableNodes.leafNode(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_DATASTORE, "running")).build();
143 ContainerNode cn = createDOMNotificationBody();
144 System.out.println(cn.toString());
145 NetconfDeviceNotification ndn = new NetconfDeviceNotification(cn, Instant.now());
146 ORanDOMChangeNotificationListener changeListener = new ORanDOMChangeNotificationListener(domAccessor, vesCollectorService, databaseService);
147 changeListener.onNotification(ndn);
148 verify(databaseService).writeEventLog(any(EventlogEntity.class));
151 public static class NetconfDeviceNotification implements DOMNotification, DOMEvent {
152 private final ContainerNode content;
153 private final Absolute schemaPath;
154 private final Instant eventTime;
156 NetconfDeviceNotification(final ContainerNode content, final Instant eventTime) {
157 this.content = content;
158 this.eventTime = eventTime;
159 this.schemaPath = Absolute.of(content.getIdentifier().getNodeType());
162 NetconfDeviceNotification(final ContainerNode content, final Absolute schemaPath, final Instant eventTime) {
163 this.content = content;
164 this.eventTime = eventTime;
165 this.schemaPath = schemaPath;
169 public Absolute getType() {
174 public ContainerNode getBody() {
179 public Instant getEventInstant() {