be0191f87394da43f6bd57cba29330c795675c4d
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.impl.test;
19
20 import static org.junit.Assert.assertTrue;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.when;
23 import java.io.File;
24 import java.io.IOException;
25 import java.util.Optional;
26 import org.junit.After;
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.WrapperMicrowaveModelRev170324;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.WrapperMicrowaveModelRev180907;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.microwave.WrapperMicrowaveModelRev181010;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.impl.DeviceManagerOnfConfiguration;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.impl.ONFCoreNetworkElementFactory;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
38 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
39 import org.opendaylight.mdsal.binding.api.DataBroker;
40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
42 import org.opendaylight.yangtools.yang.common.QName;
43
44 public class TestONFCoreNetworkElementFactory {
45
46     static NetconfBindingAccessor accessor;
47     static DeviceManagerServiceProvider serviceProvider;
48     static Capabilities capabilities;
49     static DataBroker dataBroker;
50     static NodeId nNodeId;
51     static DeviceManagerOnfConfiguration configuration;
52     QName qCapability;
53     static File configFile;
54
55
56     @BeforeClass
57     public static void init() throws InterruptedException, IOException {
58
59         capabilities = mock(Capabilities.class);
60         accessor = mock(NetconfBindingAccessor.class);
61         serviceProvider = mock(DeviceManagerServiceProvider.class);
62         dataBroker = mock(DataBroker.class);
63
64         configFile = new File("devicemanager.properties");
65         ConfigurationFileRepresentation configFileRep = new ConfigurationFileRepresentation(configFile);
66         configuration = new DeviceManagerOnfConfiguration(configFileRep);
67
68         when(accessor.getCapabilites()).thenReturn(capabilities);
69         //when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
70         nNodeId = new NodeId("nSky");
71         NetconfBindingAccessor bindingAccessor = mock(NetconfBindingAccessor.class);
72         when(bindingAccessor.getNodeId()).thenReturn(nNodeId);
73         when(bindingAccessor.getCapabilites()).thenReturn(capabilities);
74
75         when(accessor.getNodeId()).thenReturn(nNodeId);
76         when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor));
77         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(NetworkElement.QNAME)).thenReturn(true);
78
79     }
80
81     @AfterClass
82     public static void after() {
83         configFile.delete();
84     }
85
86     @Test
87     public void testCreateMWModelRev170324() throws Exception {
88         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev170324.QNAME))
89                 .thenReturn(true);
90         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev180907.QNAME))
91                 .thenReturn(false);
92         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev181010.QNAME))
93                 .thenReturn(false);
94         ONFCoreNetworkElementFactory factory = new ONFCoreNetworkElementFactory(configuration);
95         assertTrue(factory.create(accessor, serviceProvider).isPresent());
96     }
97
98     @Test
99     public void testCreateMWModelRev180907() throws Exception {
100         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev170324.QNAME))
101                 .thenReturn(false);
102         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev180907.QNAME))
103                 .thenReturn(true);
104         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev181010.QNAME))
105                 .thenReturn(false);
106         ONFCoreNetworkElementFactory factory = new ONFCoreNetworkElementFactory(configuration);
107         assertTrue(factory.create(accessor, serviceProvider).isPresent());
108     }
109
110     @Test
111     public void testCreateMWModelRev181010() throws Exception {
112         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev170324.QNAME))
113                 .thenReturn(false);
114         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev180907.QNAME))
115                 .thenReturn(false);
116         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev181010.QNAME))
117                 .thenReturn(true);
118         ONFCoreNetworkElementFactory factory = new ONFCoreNetworkElementFactory(configuration);
119         assertTrue(factory.create(accessor, serviceProvider).isPresent());
120     }
121
122     @After
123     public void cleanUp() throws Exception {
124
125     }
126 }
127