Reorganization of devicemanager directory structure
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / onf14 / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / onf14 / TestOnf14NetworkElementFactory.java
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.onf14;
19
20 import static org.junit.Assert.assertTrue;
21 import java.io.IOException;
22 import java.util.Optional;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.mockito.Mockito;
26 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
27 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.Onf14NetworkElementFactory;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
33 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
34
35 public class TestOnf14NetworkElementFactory extends Mockito {
36
37     private static NetconfBindingAccessor accessor;
38     private static Capabilities capabilities;
39     private static DeviceManagerServiceProvider serviceProvider;
40     private static ConfigurationFileRepresentation configurationRepresentation;
41
42
43     @BeforeClass
44     public static void init() throws InterruptedException, IOException {
45         capabilities = mock(Capabilities.class);
46         accessor = mock(NetconfBindingAccessor.class);
47         serviceProvider = mock(DeviceManagerServiceProvider.class);
48         configurationRepresentation = mock(ConfigurationFileRepresentation.class);
49
50         when(accessor.getCapabilites()).thenReturn(capabilities);
51         when(serviceProvider.getDataProvider()).thenReturn(mock(DataProvider.class));
52         when(serviceProvider.getConfigurationFileRepresentation()).thenReturn(configurationRepresentation);
53     }
54
55     @Test
56     public void testCreateOnf14Component() throws Exception {
57         when(accessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(true);
58         when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(mock(NetconfBindingAccessor.class)));
59         when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(mock(NetconfDomAccessor.class)));
60         Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
61         assertTrue((factory.create(accessor, serviceProvider)).isPresent());
62     }
63
64     @Test
65     public void testCreateNone() throws Exception {
66         when(accessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(false);
67         Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
68         assertTrue(factory.create(accessor, serviceProvider).isEmpty());
69     }
70 }
71