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.verify;
26 import static org.mockito.Mockito.when;
27 import com.google.common.io.Files;
29 import java.io.IOException;
30 import java.nio.charset.StandardCharsets;
31 import java.time.Instant;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Mock;
37 import org.mockito.junit.MockitoJUnitRunner;
38 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
39 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding.TestORanFaultNotificationListener;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
43 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
44 import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl;
45 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
46 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
47 import org.opendaylight.mdsal.dom.api.DOMEvent;
48 import org.opendaylight.mdsal.dom.api.DOMNotification;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
50 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
51 import org.opendaylight.yangtools.yang.common.QName;
52 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
53 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
54 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
55 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
56 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
60 @RunWith(MockitoJUnitRunner.class)
61 public class TestORanDOMFaultNotificationListener {
62 private static final Logger LOG = LoggerFactory.getLogger(TestORanFaultNotificationListener.class);
63 private static final String TESTFILENAME = "configFile.txt";
66 private static final String TESTCONFIG_CONTENT = "[VESCollector]\n"
67 + "VES_COLLECTOR_ENABLED=true\n"
68 + "VES_COLLECTOR_TLS_ENABLED=true\n"
69 + "VES_COLLECTOR_TRUST_ALL_CERTS=true\n"
70 + "VES_COLLECTOR_USERNAME=sample1\n"
71 + "VES_COLLECTOR_PASSWORD=sample1\n"
72 + "VES_COLLECTOR_IP=[2001:db8:1:1::1]\n"
73 + "VES_COLLECTOR_PORT=8443\n"
74 + "VES_COLLECTOR_VERSION=v7\n"
75 + "REPORTING_ENTITY_NAME=ONAP SDN-R\n"
76 + "EVENTLOG_MSG_DETAIL=SHORT\n"
81 NetconfDomAccessor domAccessor;
83 DataProvider dataProvider;
85 FaultService faultService;
87 DeviceManagerServiceProvider serviceProvider;
89 WebsocketManagerService websocketManagerService;
91 DataProvider databaseService;
92 VESCollectorService vesCollectorService;
96 public void afterAndBefore() {
97 File f = new File(TESTFILENAME);
99 LOG.info("Remove {}", f.getAbsolutePath());
105 public void test() throws IOException {
106 Files.asCharSink(new File(TESTFILENAME), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
107 vesCollectorService = new VESCollectorServiceImpl(new ConfigurationFileRepresentation(TESTFILENAME));
108 when(domAccessor.getNodeId()).thenReturn(new NodeId("nSky"));
109 ORanDOMFaultNotificationListener faultListener = new ORanDOMFaultNotificationListener(domAccessor,
110 vesCollectorService, faultService, websocketManagerService, databaseService);
111 NetconfDeviceNotification ndn = new NetconfDeviceNotification(createORANDOMFault(), Instant.now());
112 faultListener.onNotification(ndn);
114 verify(faultService).faultNotification(any(FaultlogEntity.class));
117 public static ContainerNode createORANDOMFault() {
118 final QName fault_id = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-id");
119 final QName fault_source = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-source");
120 final QName fault_severity = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-severity");
121 final QName is_cleared = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "is-cleared");
122 final QName fault_text = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-text");
123 return Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF))
124 .withChild(ImmutableNodes.leafNode(fault_id, "47"))
125 .withChild(ImmutableNodes.leafNode(fault_source, "Slot-2-Port-B"))
126 .withChild(ImmutableNodes.leafNode(fault_severity, "MAJOR"))
127 .withChild(ImmutableNodes.leafNode(is_cleared, "true"))
128 .withChild(ImmutableNodes.leafNode(fault_text, "CPRI Port Down")).build();
132 public static class NetconfDeviceNotification implements DOMNotification, DOMEvent {
133 private final ContainerNode content;
134 private final Absolute schemaPath;
135 private final Instant eventTime;
137 NetconfDeviceNotification(final ContainerNode content, final Instant eventTime) {
138 this.content = content;
139 this.eventTime = eventTime;
140 this.schemaPath = Absolute.of(content.getIdentifier().getNodeType());
143 NetconfDeviceNotification(final ContainerNode content, final Absolute schemaPath, final Instant eventTime) {
144 this.content = content;
145 this.eventTime = eventTime;
146 this.schemaPath = schemaPath;
150 public Absolute getType() {
155 public ContainerNode getBody() {
160 public Instant getEventInstant() {