c3ef7d9ba924a44c8429cca3d279606451b0d570
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test;
23
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.openroadm71.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.rev200529.RpcStatus;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.ChangeNotification;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.CreateTechInfoNotification;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.CreateTechInfoNotificationBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.change.notification.Edit;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.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;
52
53
54
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();
63
64     @Test
65     public void testOnChangeNotification() {
66
67         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
68         Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
69
70             @Override
71             public int compareTo(PathArgument arg0) {
72                 return 0;
73             }
74
75             @Override
76             public Class<? extends DataObject> getType() {
77                 return DataObject.class;
78             }
79         });
80         InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
81
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);
88
89     }
90
91     @Test
92     public void testOnCreateTechInfoNotification() {
93         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
94         deviceChangeListener.onCreateTechInfoNotification(createTechInfoNotification());
95         verify(databaseService).writeEventLog(any(EventlogEntity.class));
96     }
97
98     /**
99      * @param type
100      * @return
101      */
102     private static ChangeNotification createNotification(EditOperationType type, InstanceIdentifier<?> target) {
103         ChangeNotification change = mock(ChangeNotification.class);
104
105         @SuppressWarnings("null")
106         final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
107         when(change.nonnullEdit()).thenReturn(edits);
108         return change;
109     }
110
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();
116
117     }
118
119
120 }