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.openroadm71.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.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;
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();
66 public void testOnChangeNotification() {
68 when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
69 List<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
72 public int compareTo(PathArgument arg0) {
77 public Class<? extends DataObject> getType() {
78 return Component.class;
81 InstanceIdentifier<?> target = InstanceIdentifier.unsafeOf(pathArguments);
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);
93 public void testOnCreateTechInfoNotification() {
94 when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
95 deviceChangeListener.onCreateTechInfoNotification(createTechInfoNotification());
96 verify(databaseService).writeEventLog(any(EventlogEntity.class));
103 private static ChangeNotification createNotification(EditOperationType type, InstanceIdentifier<?> target) {
104 ChangeNotification change = mock(ChangeNotification.class);
106 @SuppressWarnings("null")
107 final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
108 when(change.nonnullEdit()).thenReturn(edits);
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();