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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14;
20 import static org.junit.Assert.assertTrue;
21 import com.google.common.io.Files;
23 import java.io.IOException;
24 import java.nio.charset.StandardCharsets;
25 import java.util.Optional;
26 import org.junit.AfterClass;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.mockito.Mockito;
30 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.Onf14NetworkElementFactory;
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.NetconfBindingAccessor;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
38 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
39 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
41 public class TestOnf14NetworkElementFactory extends Mockito {
43 private static NetconfAccessor accessor;
44 private static Optional<NetconfDomAccessor> domAccessor;
45 private static Capabilities capabilities;
46 private static DeviceManagerServiceProvider serviceProvider;
47 private static ConfigurationFileRepresentation configurationRepresentation;
48 private static String filename = "test.properties";
51 private static final String TESTCONFIG_CONTENT = "[dmonf14]\n"
58 public static void init() throws InterruptedException, IOException {
59 Files.asCharSink(new File(filename), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
60 configurationRepresentation = new ConfigurationFileRepresentation(filename);
61 capabilities = mock(Capabilities.class);
62 accessor = mock(NetconfAccessor.class);
63 domAccessor = Optional.of(mock(NetconfDomAccessor.class));
64 serviceProvider = mock(DeviceManagerServiceProvider.class);
66 when(accessor.getCapabilites()).thenReturn(capabilities);
67 when(serviceProvider.getDataProvider()).thenReturn(mock(DataProvider.class));
68 when(serviceProvider.getConfigurationFileRepresentation()).thenReturn(configurationRepresentation);
72 public void testCreateOnf14Dom() throws Exception {
73 when(accessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(true);
74 when(accessor.getNetconfDomAccessor()).thenReturn(domAccessor);
75 when(domAccessor.get().getBindingNormalizedNodeSerializer()).thenReturn(mock(BindingNormalizedNodeSerializer.class));
76 Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
77 factory.init(serviceProvider);
78 assertTrue((factory.create(accessor, serviceProvider)).isPresent());
82 public void testCreateOnf14Binding() throws Exception {
83 when(accessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(true);
84 when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(mock(NetconfBindingAccessor.class)));
85 Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
86 assertTrue(factory.create(accessor, serviceProvider).isPresent());
90 public void testCreateNone() throws Exception {
91 when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(mock(NetconfBindingAccessor.class)));
92 when(accessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(false);
93 Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
94 assertTrue(factory.create(accessor, serviceProvider).isEmpty());
98 public static void cleanUp() {
99 File file = new File(filename);
101 System.out.println("File exists, Deleting it");