f567f9335be29df2613d472ef99b0fa323dc231b
[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.onf14.dom;
19
20 import static org.junit.Assert.assertTrue;
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.Optional;
24 import org.junit.AfterClass;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.mockito.Mockito;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.Onf14DomNetworkElementFactory;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
35 import org.opendaylight.yangtools.yang.common.QNameModule;
36 import org.opendaylight.yangtools.yang.common.Revision;
37 import org.opendaylight.yangtools.yang.common.XMLNamespace;
38
39 public class TestOnf14NetworkElementFactory extends Mockito {
40
41     private static final QNameModule qnm = QNameModule.create(XMLNamespace.of("urn:onf:yang:core-model-1-4"), Revision.of("2019-11-27"));
42     private static NetconfAccessor accessor;
43     private static NetconfDomAccessor domAccessor;
44     private static Capabilities capabilities;
45     private static DeviceManagerServiceProvider serviceProvider;
46     private static String filename = "test.properties";
47
48
49     @BeforeClass
50     public static void init() throws InterruptedException, IOException {
51         capabilities = mock(Capabilities.class);
52         accessor = mock(NetconfAccessor.class);
53         domAccessor = mock(NetconfDomAccessor.class);
54         serviceProvider = mock(DeviceManagerServiceProvider.class);
55
56         when(domAccessor.getCapabilites()).thenReturn(capabilities);
57         when(serviceProvider.getDataProvider()).thenReturn(mock(DataProvider.class));
58         when(serviceProvider.getFaultService()).thenReturn(mock(FaultService.class));
59
60     }
61
62     @Test
63     public void testCreateOnf14Dom() throws Exception {
64         when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
65         when(capabilities.isSupportingNamespaceAndRevision(
66                 QNameModule.create(XMLNamespace.of("urn:onf:yang:core-model-1-4"), Revision.of("2019-11-27"))))
67                         .thenReturn(true);
68         when(capabilities.isSupportingNamespaceAndRevision(
69                 QNameModule.create(XMLNamespace.of("urn:onf:yang:alarms-1-0"), Revision.of("2022-03-02"))))
70                         .thenReturn(true);
71         Onf14DomNetworkElementFactory factory = new Onf14DomNetworkElementFactory();
72         factory.init(serviceProvider);
73         assertTrue((factory.create(accessor, serviceProvider)).isPresent());
74     }
75
76     @Test
77     public void testCreateNone() throws Exception {
78         when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
79         when(capabilities.isSupportingNamespaceAndRevision(
80                 QNameModule.create(XMLNamespace.of("urn:onf:yang:core-model-1-4"), Revision.of("2019-11-27"))))
81                         .thenReturn(false);
82         Onf14DomNetworkElementFactory factory = new Onf14DomNetworkElementFactory();
83         assertTrue(factory.create(accessor, serviceProvider).isEmpty());
84     }
85
86     @AfterClass
87     public static void cleanUp() {
88         File file = new File(filename);
89         if (file.exists()) {
90             System.out.println("File exists, Deleting it");
91             file.delete();
92         }
93     }
94 }
95