a6d276d489527458748c60760ce2e5b66406c5d8
[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.Mockito.mock;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
27 import java.util.Arrays;
28 import java.util.List;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmDeviceChangeNotificationListener;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
36 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev191129.RpcStatus;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.ChangeNotification;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.CreateTechInfoNotification;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.CreateTechInfoNotificationBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.Edit;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.EditBuilder;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
48 import org.opendaylight.yangtools.yang.binding.DataObject;
49 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
51
52
53
54 public class TestOpenRoadmDeviceChangeNotification {
55     private static final String NODEID = "Roadm1";
56     private NetconfAccessor netconfAccessor = mock(NetconfAccessor.class);
57     private DataProvider databaseService = mock(DataProvider.class);
58     WebsocketManagerService notificationService = mock(WebsocketManagerService.class);
59     private OpenroadmDeviceChangeNotificationListener deviceChangeListener =
60             new OpenroadmDeviceChangeNotificationListener(netconfAccessor, databaseService, notificationService);
61     private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter();
62
63     @Test
64     public void testOnChangeNotification() {
65
66         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
67         Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
68
69             @Override
70             public int compareTo(PathArgument arg0) {
71                 return 0;
72             }
73
74             @Override
75             public Class<? extends DataObject> getType() {
76                 return DataObject.class;
77             }
78         });
79         InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
80
81         deviceChangeListener.onChangeNotification(createNotification(EditOperationType.Create, target));
82         EventlogEntity event =
83                 new EventlogBuilder().setNodeId(NODEID).setNewValue(String.valueOf(EditOperationType.Create))
84                         .setObjectId(target.getPathArguments().toString()).setCounter(1)
85                         .setAttributeName(target.getTargetType().getName()).setSourceType(SourceType.Netconf).build();
86         verify(databaseService).writeEventLog(event);
87
88     }
89
90     @Test
91     public void testOnCreateTechInfoNotification() {
92         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
93         deviceChangeListener.onCreateTechInfoNotification(createTechInfoNotification());
94         EventlogEntity event = new EventlogBuilder().setNodeId(NODEID).setCounter(1)
95                 .setId(createTechInfoNotification().getShelfId())
96                 .setAttributeName(createTechInfoNotification().getShelfId())
97                 .setObjectId(createTechInfoNotification().getShelfId())
98                 .setNewValue(createTechInfoNotification().getStatus().getName()).setSourceType(SourceType.Netconf)
99                 .setTimestamp(ncTimeConverter.getTimeStamp()).build();
100         verify(databaseService).writeEventLog(event);
101     }
102
103     /**
104      * @param type
105      * @return
106      */
107     private static ChangeNotification createNotification(EditOperationType type, InstanceIdentifier<?> target) {
108         ChangeNotification change = mock(ChangeNotification.class);
109
110         @SuppressWarnings("null")
111         final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
112         when(change.nonnullEdit()).thenReturn(edits);
113         return change;
114     }
115
116     private static CreateTechInfoNotification createTechInfoNotification() {
117         CreateTechInfoNotificationBuilder techInfoNotificationBuilder = new CreateTechInfoNotificationBuilder();
118         techInfoNotificationBuilder.setLogFileName("shjkdjld/EHJkk").setShelfId("dsjhdukdgkzw")
119                 .setStatus(RpcStatus.Successful).setStatusMessage("TestSuccessful");
120         return techInfoNotificationBuilder.build();
121
122     }
123
124
125 }