aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager-onap/openroadm71/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmDeviceChangeNotification.java
blob: c3ef7d9ba924a44c8429cca3d279606451b0d570 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * ============LICENSE_START=======================================================
 * ONAP : ccsdk features
 * ================================================================================
 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
 * All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 *
 */
package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl.OpenroadmDeviceChangeNotificationListener;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.RpcStatus;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.ChangeNotification;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.CreateTechInfoNotification;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.CreateTechInfoNotificationBuilder;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.change.notification.Edit;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.change.notification.EditBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;



public class TestOpenRoadmDeviceChangeNotification {
    private static final String NODEID = "Roadm1";
    private NetconfAccessor netconfAccessor = mock(NetconfAccessor.class);
    private DataProvider databaseService = mock(DataProvider.class);
    WebsocketManagerService notificationService = mock(WebsocketManagerService.class);
    private OpenroadmDeviceChangeNotificationListener deviceChangeListener =
            new OpenroadmDeviceChangeNotificationListener(netconfAccessor, databaseService, notificationService);
    private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter();

    @Test
    public void testOnChangeNotification() {

        when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
        Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {

            @Override
            public int compareTo(PathArgument arg0) {
                return 0;
            }

            @Override
            public Class<? extends DataObject> getType() {
                return DataObject.class;
            }
        });
        InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);

        deviceChangeListener.onChangeNotification(createNotification(EditOperationType.Create, target));
        EventlogEntity event =
                new EventlogBuilder().setNodeId(NODEID).setNewValue(String.valueOf(EditOperationType.Create))
                        .setObjectId(target.getPathArguments().toString()).setCounter(1)
                        .setAttributeName(target.getTargetType().getName()).setSourceType(SourceType.Netconf).build();
        verify(databaseService).writeEventLog(event);

    }

    @Test
    public void testOnCreateTechInfoNotification() {
        when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
        deviceChangeListener.onCreateTechInfoNotification(createTechInfoNotification());
        verify(databaseService).writeEventLog(any(EventlogEntity.class));
    }

    /**
     * @param type
     * @return
     */
    private static ChangeNotification createNotification(EditOperationType type, InstanceIdentifier<?> target) {
        ChangeNotification change = mock(ChangeNotification.class);

        @SuppressWarnings("null")
        final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
        when(change.nonnullEdit()).thenReturn(edits);
        return change;
    }

    private static CreateTechInfoNotification createTechInfoNotification() {
        CreateTechInfoNotificationBuilder techInfoNotificationBuilder = new CreateTechInfoNotificationBuilder();
        techInfoNotificationBuilder.setLogFileName("shjkdjld/EHJkk").setShelfId("dsjhdukdgkzw")
                .setStatus(RpcStatus.Successful).setStatusMessage("TestSuccessful");
        return techInfoNotificationBuilder.build();

    }


}