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