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;
22 import static org.junit.Assert.assertNotEquals;
23 import static org.junit.Assert.assertNotNull;
24 import com.google.common.io.Files;
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;
40 public class TestMountpointNodeStateListenerImpl {
43 private static final String TESTCONFIG_CONTENT =
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"
52 + "maxBatchSize=100\n"
54 + "MessageSentThreadOccurance=50\n";
56 private final String fileName = "test2.properties";
57 private ConfigurationFileRepresentation globalCfg;
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");
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);
77 public void testOnCreated() {
78 assertNotNull(nNodeId);
79 assertNotNull(netconfNode);
80 nodeStateListener.onCreated(nNodeId, netconfNode);
81 assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
85 public void testOnStateChange() {
86 nodeStateListener.onStateChange(nNodeId, netconfNode);
87 assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
91 public void testOnRemoved() {
92 nodeStateListener.onRemoved(nNodeId);
97 File file = new File(fileName);
99 System.out.println("File exists, Deleting it");