2466683fdb92de6f466a270d733728e99d1b01b6
[ccsdk/features.git] /
1 /*
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
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
19 package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
20
21 import static org.junit.Assert.assertNotEquals;
22 import com.google.common.io.Files;
23 import java.io.File;
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;
40
41 public class TestMountpointNodeConnectListenerImpl {
42
43     // @formatter:off
44     private static final String TESTCONFIG_CONTENT =
45             "[general]\n"
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"
51             + "timeout=20000\n"
52             + "limit=10000\n"
53             + "maxBatchSize=100\n"
54             + "maxAgeMs=250\n"
55             + "MessageSentThreadOccurance=50\n";
56     // @formatter:on
57     private final String fileName = "test1.properties";
58     private ConfigurationFileRepresentation globalCfg;
59
60
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);
69
70     @Before
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);
77     }
78
79     @Test
80     public void testOnEnterConnected() {
81         nodeConnectListener.onEnterConnected(accessor);
82         assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
83     }
84
85     @Test
86     public void testOnLeaveConnected() {
87         nodeConnectListener.onLeaveConnected(nNodeId, Optional.of(netconfNode));
88         assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
89     }
90
91     @Test
92     public void testClose() throws Exception {
93         //assertEquals(MountpointStatePublisher.stateObjects.size(), 0);
94         nodeConnectListener.close();
95     }
96
97     @After
98     public void after() {
99         File file = new File(fileName);
100         if (file.exists()) {
101             System.out.println("File exists, Deleting it");
102             file.delete();
103         }
104
105     }
106
107 }