2  * ============LICENSE_START========================================================================
 
   3  * ONAP : ccsdk feature sdnr wt
 
   4  * =================================================================================================
 
   5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
 
   6  * =================================================================================================
 
   7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 
   8  * in compliance with the License. You may obtain a copy of the License at
 
  10  * http://www.apache.org/licenses/LICENSE-2.0
 
  12  * Unless required by applicable law or agreed to in writing, software distributed under the License
 
  13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 
  14  * or implied. See the License for the specific language governing permissions and limitations under
 
  16  * ============LICENSE_END==========================================================================
 
  18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom;
 
  20 import java.time.Instant;
 
  21 import org.junit.Before;
 
  22 import org.junit.Test;
 
  23 import org.mockito.Mockito;
 
  24 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
 
  25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.Onf14DomEthernetContainerNotificationListener;
 
  26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DevicemanagerQNames;
 
  27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.util.NetconfDeviceNotification;
 
  28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
 
  29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
 
  30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
 
  31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
 
  32 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
 
  33 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 
  34 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 
  35 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 
  36 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 
  37 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 
  39 public class TestOnf14DomEthernetContainerNotificationListener extends Mockito {
 
  40     private NetconfDomAccessor accessor;
 
  41     private NodeId nodeId;
 
  42     private DeviceManagerServiceProvider serviceProvider;
 
  43     private FaultService faultService;
 
  44     private DataProvider databaseService;
 
  45     private NotificationService notificationService;
 
  47     private WebsocketManagerService websocketService;
 
  51         accessor = mock(NetconfDomAccessor.class);
 
  52         nodeId = mock(NodeId.class);
 
  53         serviceProvider = mock(DeviceManagerServiceProvider.class);
 
  54         faultService = mock(FaultService.class);
 
  55         databaseService = mock(DataProvider.class);
 
  56         notificationService = mock(NotificationService.class);
 
  57         websocketService = mock(WebsocketManagerService.class);
 
  59         when(serviceProvider.getFaultService()).thenReturn(faultService);
 
  60         when(serviceProvider.getDataProvider()).thenReturn(databaseService);
 
  61         when(serviceProvider.getNotificationService()).thenReturn(notificationService);
 
  62         when(serviceProvider.getWebsocketService()).thenReturn(websocketService);
 
  63         when(accessor.getNodeId()).thenReturn(nodeId);
 
  67     public void testOtherNotif() {
 
  68         Onf14DomEthernetContainerNotificationListener notifListener =
 
  69                 new Onf14DomEthernetContainerNotificationListener(accessor, serviceProvider);
 
  71         NetconfDeviceNotification ndn =
 
  72                 new NetconfDeviceNotification(createEthernetContainerCreationNotification(), Instant.now());
 
  73         notifListener.onNotification(ndn);
 
  74         ndn = new NetconfDeviceNotification(createEthernetContainerAVCNotification(), Instant.now());
 
  75         notifListener.onNotification(ndn);
 
  76         ndn = new NetconfDeviceNotification(createEthernetContainerDeletionNotification(), Instant.now());
 
  77         notifListener.onNotification(ndn);
 
  78         ndn = new NetconfDeviceNotification(createEthernetContainerProblemNotification(), Instant.now());
 
  79         notifListener.onNotification(ndn);
 
  82     private ContainerNode createEthernetContainerProblemNotification() {
 
  83         return Builders.containerBuilder()
 
  85                         NodeIdentifier.create(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION))
 
  86                 .withChild(ImmutableNodes.leafNode(
 
  87                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_COUNTER, "47"))
 
  88                 .withChild(ImmutableNodes.leafNode(
 
  89                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_PROBLEM,
 
  90                         "12345678-0123-2345-abcd-0123456789AB"))
 
  91                 .withChild(ImmutableNodes.leafNode(
 
  92                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_OBJECT_ID_REF,
 
  93                         "12345678-0123-1234-abcd-0123456789AB"))
 
  94                 .withChild(ImmutableNodes.leafNode(
 
  95                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_TIMESTAMP,
 
  96                         "2022-02-05T12:30:45.283Z"))
 
  97                 .withChild(ImmutableNodes.leafNode(
 
  98                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_PROBLEM_NOTIFICATION_SEVERITY,
 
  99                         "SEVERITY_TYPE_CRITICAL"))
 
 103     private ContainerNode createEthernetContainerAVCNotification() {
 
 104         return Builders.containerBuilder()
 
 106                         NodeIdentifier.create(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION))
 
 107                 .withChild(ImmutableNodes
 
 108                         .leafNode(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION_COUNTER, "47"))
 
 109                 .withChild(ImmutableNodes.leafNode(
 
 110                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION_ATTRIBUTE_NAME,
 
 111                         "12345678-0123-2345-abcd-0123456789AB"))
 
 112                 .withChild(ImmutableNodes.leafNode(
 
 113                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION_NEW_VALUE, "new-value"))
 
 114                 .withChild(ImmutableNodes.leafNode(
 
 115                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION_OBJECT_ID_REF,
 
 116                         "12345678-0123-1234-abcd-0123456789AB"))
 
 117                 .withChild(ImmutableNodes.leafNode(
 
 118                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_AVC_NOTIFICATION_TIMESTAMP,
 
 119                         "2022-02-05T12:30:45.283Z"))
 
 123     private ContainerNode createEthernetContainerDeletionNotification() {
 
 124         return Builders.containerBuilder()
 
 126                         NodeIdentifier.create(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION))
 
 127                 .withChild(ImmutableNodes
 
 128                         .leafNode(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION_COUNTER, "47"))
 
 129                 .withChild(ImmutableNodes.leafNode(
 
 130                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION_TIMESTAMP,
 
 131                         "2022-02-05T12:30:45.283Z"))
 
 132                 .withChild(ImmutableNodes.leafNode(
 
 133                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_DELETE_NOTIFICATION_OBJECT_ID_REF,
 
 134                         "12345678-0123-1234-abcd-0123456789AB"))
 
 138     private ContainerNode createEthernetContainerCreationNotification() {
 
 139         return Builders.containerBuilder()
 
 141                         NodeIdentifier.create(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION))
 
 142                 .withChild(ImmutableNodes
 
 143                         .leafNode(Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION_COUNTER, "47"))
 
 144                 .withChild(ImmutableNodes.leafNode(
 
 145                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION_OBJECT_TYPE,
 
 146                         "ethernet-interface-name"))
 
 147                 .withChild(ImmutableNodes.leafNode(
 
 148                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION_TIMESTAMP,
 
 149                         "2022-02-05T12:30:45.283Z"))
 
 150                 .withChild(ImmutableNodes.leafNode(
 
 151                         Onf14DevicemanagerQNames.ETHERNET_CONTAINER_OBJECT_CREATE_NOTIFICATION_OBJECT_ID_REF,
 
 152                         "12345678-0123-1234-abcd-0123456789AB"))