2  * ============LICENSE_START=======================================================
 
   3  * ONAP : ccsdk features
 
   4  * ================================================================================
 
   5  * Copyright (C) 2020 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.openroadm.test;
 
  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.util.Arrays;
 
  29 import java.util.List;
 
  30 import org.eclipse.jdt.annotation.NonNull;
 
  31 import org.junit.Test;
 
  32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
 
  33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
 
  34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
 
  35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmDeviceChangeNotificationListener;
 
  36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
 
  37 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
 
  38 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev191129.RpcStatus;
 
  39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.ChangeNotification;
 
  40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.CreateTechInfoNotification;
 
  41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.CreateTechInfoNotificationBuilder;
 
  42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.Edit;
 
  43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.EditBuilder;
 
  44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
 
  45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
 
  46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
 
  47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
 
  48 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 
  49 import org.opendaylight.yangtools.yang.binding.DataObject;
 
  50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
  51 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 
  55 public class TestOpenRoadmDeviceChangeNotification {
 
  56     private static final String NODEID = "Roadm1";
 
  57     private NetconfAccessor netconfAccessor = mock(NetconfAccessor.class);
 
  58     private DataProvider databaseService = mock(DataProvider.class);
 
  59     WebsocketManagerService notificationService = mock(WebsocketManagerService.class);
 
  60     private OpenroadmDeviceChangeNotificationListener deviceChangeListener =
 
  61             new OpenroadmDeviceChangeNotificationListener(netconfAccessor, databaseService, notificationService);
 
  62     private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter();
 
  65     public void testOnChangeNotification() {
 
  67         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
 
  68         Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
 
  71             public int compareTo(PathArgument arg0) {
 
  76             public Class<? extends DataObject> getType() {
 
  77                 return DataObject.class;
 
  80         InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
 
  82         deviceChangeListener.onChangeNotification(createNotification(EditOperationType.Create, target));
 
  83         EventlogEntity event =
 
  84                 new EventlogBuilder().setNodeId(NODEID).setNewValue(String.valueOf(EditOperationType.Create))
 
  85                         .setObjectId(target.getPathArguments().toString()).setCounter(1)
 
  86                         .setAttributeName(target.getTargetType().getName()).setSourceType(SourceType.Netconf).build();
 
  87         verify(databaseService).writeEventLog(event);
 
  92     public void testOnCreateTechInfoNotification() {
 
  93         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
 
  94         deviceChangeListener.onCreateTechInfoNotification(createTechInfoNotification());
 
  95         verify(databaseService).writeEventLog(any(EventlogEntity.class));
 
 102     private static ChangeNotification createNotification(EditOperationType type, InstanceIdentifier<?> target) {
 
 103         ChangeNotification change = mock(ChangeNotification.class);
 
 105         @SuppressWarnings("null")
 
 106         final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
 
 107         when(change.nonnullEdit()).thenReturn(edits);
 
 111     private static CreateTechInfoNotification createTechInfoNotification() {
 
 112         CreateTechInfoNotificationBuilder techInfoNotificationBuilder = new CreateTechInfoNotificationBuilder();
 
 113         techInfoNotificationBuilder.setLogFileName("shjkdjld/EHJkk").setShelfId("dsjhdukdgkzw")
 
 114                 .setStatus(RpcStatus.Successful).setStatusMessage("TestSuccessful");
 
 115         return techInfoNotificationBuilder.build();