f9b5b514d1e4536ec4b180f80716f15a4e78975a
[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.openroadm71.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.http.org.openroadm.device.rev200529.circuit.pack.features.circuit.pack.components.Component;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
49 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
50 import org.opendaylight.yangtools.yang.binding.DataObject;
51 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
52 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
53
54
55
56 public class TestOpenRoadmDeviceChangeNotification {
57     private static final String NODEID = "Roadm1";
58     private NetconfAccessor netconfAccessor = mock(NetconfAccessor.class);
59     private DataProvider databaseService = mock(DataProvider.class);
60     WebsocketManagerService notificationService = mock(WebsocketManagerService.class);
61     private OpenroadmDeviceChangeNotificationListener deviceChangeListener =
62             new OpenroadmDeviceChangeNotificationListener(netconfAccessor, databaseService, notificationService);
63     private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter();
64
65     @Test
66     public void testOnChangeNotification() {
67
68         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
69         List<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
70
71             @Override
72             public int compareTo(PathArgument arg0) {
73                 return 0;
74             }
75
76             @Override
77             public Class<? extends DataObject> getType() {
78                 return Component.class;
79             }
80         });
81         InstanceIdentifier<?> target = InstanceIdentifier.unsafeOf(pathArguments);
82
83         deviceChangeListener.onChangeNotification(createNotification(EditOperationType.Create, target));
84         EventlogEntity event =
85                 new EventlogBuilder().setNodeId(NODEID).setNewValue(String.valueOf(EditOperationType.Create))
86                         .setObjectId(target.getPathArguments().toString()).setCounter(1)
87                         .setAttributeName(target.getTargetType().getName()).setSourceType(SourceType.Netconf).build();
88         verify(databaseService).writeEventLog(event);
89
90     }
91
92     @Test
93     public void testOnCreateTechInfoNotification() {
94         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
95         deviceChangeListener.onCreateTechInfoNotification(createTechInfoNotification());
96         verify(databaseService).writeEventLog(any(EventlogEntity.class));
97     }
98
99     /**
100      * @param type
101      * @return
102      */
103     private static ChangeNotification createNotification(EditOperationType type, InstanceIdentifier<?> target) {
104         ChangeNotification change = mock(ChangeNotification.class);
105
106         @SuppressWarnings("null")
107         final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
108         when(change.nonnullEdit()).thenReturn(edits);
109         return change;
110     }
111
112     private static CreateTechInfoNotification createTechInfoNotification() {
113         CreateTechInfoNotificationBuilder techInfoNotificationBuilder = new CreateTechInfoNotificationBuilder();
114         techInfoNotificationBuilder.setLogFileName("shjkdjld/EHJkk").setShelfId("dsjhdukdgkzw")
115                 .setStatus(RpcStatus.Successful).setStatusMessage("TestSuccessful");
116         return techInfoNotificationBuilder.build();
117
118     }
119
120
121 }