2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 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==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
21 import static org.junit.Assert.assertNotEquals;
22 import com.google.common.io.Files;
24 import java.io.IOException;
25 import java.nio.charset.StandardCharsets;
26 import java.util.Optional;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
31 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.GeneralConfig;
32 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointNodeConnectListenerImpl;
33 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisherMain;
34 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.NetconfAccessorMock;
35 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.NetconfNodeMock;
36 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.NetconfNodeStateServiceMock;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
39 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
41 public class TestMountpointNodeConnectListenerImpl {
44 private static final String TESTCONFIG_CONTENT =
46 + "dmaapEnabled=false\n"
47 + "TransportType=HTTPNOAUTH\n"
48 + "host=onap-dmap:3904\n"
49 + "topic=unauthenticated.SDNR_MOUNTPOINT_STATE_INFO\n"
50 + "contenttype=application/json\n"
53 + "maxBatchSize=100\n"
55 + "MessageSentThreadOccurance=50\n";
57 private final String fileName = "test1.properties";
58 private ConfigurationFileRepresentation globalCfg;
61 NetconfNodeStateServiceMock netconfNodeStateServiceMock = new NetconfNodeStateServiceMock();
62 MountpointNodeConnectListenerImpl nodeConnectListener =
63 new MountpointNodeConnectListenerImpl(netconfNodeStateServiceMock);
64 MountpointStatePublisherMain mountpointStatePublisher;
65 NetconfNodeMock netconfNodeMock = new NetconfNodeMock();
66 NetconfNode netconfNode = netconfNodeMock.getNetconfNode();
67 NodeId nNodeId = new NodeId("nSky");
68 NetconfAccessor accessor = new NetconfAccessorMock(nNodeId, netconfNode);
71 public void initialize() throws IOException {
72 Files.asCharSink(new File(fileName), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
73 globalCfg = new ConfigurationFileRepresentation(fileName);
74 GeneralConfig cfg = new GeneralConfig(globalCfg);
75 mountpointStatePublisher = new MountpointStatePublisherMain(cfg);
76 nodeConnectListener.start(mountpointStatePublisher);
80 public void testOnEnterConnected() {
81 nodeConnectListener.onEnterConnected(accessor);
82 assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
86 public void testOnLeaveConnected() {
87 nodeConnectListener.onLeaveConnected(nNodeId, Optional.of(netconfNode));
88 assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
92 public void testClose() throws Exception {
93 //assertEquals(MountpointStatePublisher.stateObjects.size(), 0);
94 nodeConnectListener.close();
99 File file = new File(fileName);
101 System.out.println("File exists, Deleting it");