856948940a0073aa605676aa72a3c72ca795aff0
[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.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28 import java.io.IOException;
29 import java.util.Optional;
30 import org.junit.After;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmNetworkElementFactory;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
38 import org.opendaylight.mdsal.binding.api.DataBroker;
39 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43
44 public class TestOpenRoadmNetworkElementFactory {
45 //    variables
46     private static NetconfBindingAccessor accessor;
47     private static DeviceManagerServiceProvider serviceProvider;
48     private static Capabilities capabilities;
49     private static TransactionUtils transactionUtils;
50     private static DataBroker dataBroker;
51     // end of variables
52
53     // public methods
54     @BeforeClass
55     public static void init() throws InterruptedException, IOException {
56         accessor = mock(NetconfBindingAccessor.class);
57         capabilities = mock(Capabilities.class);
58         dataBroker = mock(DataBroker.class);
59         transactionUtils = mock(TransactionUtils.class);
60         serviceProvider = mock(DeviceManagerServiceProvider.class);
61         when(accessor.getNodeId()).thenReturn(new NodeId("RoadmA2"));
62         when(accessor.getCapabilites()).thenReturn(capabilities);
63         when(accessor.getDataBroker()).thenReturn(dataBroker);
64         when(accessor.getTransactionUtils()).thenReturn(transactionUtils);
65         when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(accessor));
66         when(serviceProvider.getDataProvider()).thenReturn(null);
67
68         final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class;
69         InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build();
70         when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
71                 deviceId)).thenReturn(mock(OrgOpenroadmDevice.class));
72
73         when(accessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
74     }
75
76     @Test
77     public void testCapabiltiesAvailable1() {
78         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true);
79         OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory();
80         assertTrue((factory.create(accessor, serviceProvider)).isPresent());
81     }
82
83     @Test
84     public void testCapabiltiesAvailable2() {
85         when(accessor.getCapabilites().isSupportingNamespaceAndRevision("http://org/openroadm/device", "2018-10-19"))
86                 .thenReturn(true);
87         OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory();
88         assertTrue((factory.create(accessor, serviceProvider)).isPresent());
89     }
90
91     @Test
92     public void testCapabiltiesNotAvailable() throws Exception {
93         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(false);
94         OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory();
95         assertFalse(factory.create(accessor, serviceProvider).isPresent());
96     }
97
98     @After
99     public void cleanUp() throws Exception {
100
101     }
102     // end of public methods
103 }