8d95a4c5350ebd9f1dc7dc3165266931824b4c4d
[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
22 import static org.junit.Assert.assertNotEquals;
23 import static org.junit.Assert.assertNotNull;
24 import com.google.common.io.Files;
25 import java.io.File;
26 import java.io.IOException;
27 import java.nio.charset.StandardCharsets;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
32 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.GeneralConfig;
33 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointNodeStateListenerImpl;
34 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisherMain;
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.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
38 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
39
40 public class TestMountpointNodeStateListenerImpl {
41
42     // @formatter:off
43     private static final String TESTCONFIG_CONTENT =
44             "[general]\n"
45             + "dmaapEnabled=false\n"
46             + "TransportType=HTTPNOAUTH\n"
47             + "host=onap-dmap:3904\n"
48             + "topic=unauthenticated.SDNR_MOUNTPOINT_STATE_INFO\n"
49             + "contenttype=application/json\n"
50             + "timeout=20000\n"
51             + "limit=10000\n"
52             + "maxBatchSize=100\n"
53             + "maxAgeMs=250\n"
54             + "MessageSentThreadOccurance=50\n";
55     // @formatter:on
56     private final String fileName = "test2.properties";
57     private ConfigurationFileRepresentation globalCfg;
58
59     NetconfNodeStateServiceMock netconfNodeStateServiceMock = new NetconfNodeStateServiceMock();
60     MountpointNodeStateListenerImpl nodeStateListener =
61             new MountpointNodeStateListenerImpl(netconfNodeStateServiceMock);
62     MountpointStatePublisherMain mountpointStatePublisher;
63     NetconfNodeMock netconfNodeMock = new NetconfNodeMock();
64     NetconfNode netconfNode = netconfNodeMock.getNetconfNode();
65     NodeId nNodeId = new NodeId("nSky");
66
67     @Before
68     public void initialize() throws IOException {
69         Files.asCharSink(new File(fileName), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
70         globalCfg = new ConfigurationFileRepresentation(fileName);
71         GeneralConfig cfg = new GeneralConfig(globalCfg);
72         mountpointStatePublisher = new MountpointStatePublisherMain(cfg);
73         nodeStateListener.start(mountpointStatePublisher);
74     }
75
76     @Test
77     public void testOnCreated() {
78         assertNotNull(nNodeId);
79         assertNotNull(netconfNode);
80         nodeStateListener.onCreated(nNodeId, netconfNode);
81         assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
82     }
83
84     @Test
85     public void testOnStateChange() {
86         nodeStateListener.onStateChange(nNodeId, netconfNode);
87         assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
88     }
89
90     @Test
91     public void testOnRemoved() {
92         nodeStateListener.onRemoved(nNodeId);
93     }
94
95     @After
96     public void after() {
97         File file = new File(fileName);
98         if (file.exists()) {
99             System.out.println("File exists, Deleting it");
100             file.delete();
101         }
102
103     }
104
105 }