40a48c3589ddc5d6924d02a583ab1e4ed1ab8e6c
[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
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
52     @BeforeClass
53     public static void init() throws InterruptedException, IOException {
54         accessor = mock(NetconfBindingAccessor.class);
55         capabilities = mock(Capabilities.class);
56         dataBroker = mock(DataBroker.class);
57         transactionUtils = mock(TransactionUtils.class);
58         serviceProvider = mock(DeviceManagerServiceProvider.class);
59         when(accessor.getNodeId()).thenReturn(new NodeId("RoadmA2"));
60         when(accessor.getCapabilites()).thenReturn(capabilities);
61         when(accessor.getDataBroker()).thenReturn(dataBroker);
62         when(accessor.getTransactionUtils()).thenReturn(transactionUtils);
63         when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(accessor));
64         when(serviceProvider.getDataProvider()).thenReturn(null);
65
66         final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class;
67         InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build();
68         when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
69                 deviceId)).thenReturn(mock(OrgOpenroadmDevice.class));
70
71         when(accessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
72     }
73
74     @Test
75     public void testCapabiltiesAvailable1() {
76         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true);
77         OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory();
78         assertTrue((factory.create(accessor, serviceProvider)).isPresent());
79     }
80
81     @Test
82     public void testCapabiltiesAvailable2() {
83         when(accessor.getCapabilites().isSupportingNamespaceAndRevision("http://org/openroadm/device", "2018-10-19"))
84                 .thenReturn(true);
85         OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory();
86         assertTrue((factory.create(accessor, serviceProvider)).isPresent());
87     }
88
89     @Test
90     public void testCapabiltiesNotAvailable() throws Exception {
91         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(false);
92         OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory();
93         assertFalse(factory.create(accessor, serviceProvider).isPresent());
94     }
95
96     @After
97     public void cleanUp() throws Exception {
98
99     }
100
101 }