5fc1c5e15e6c6fc5dcbb14d3d9202ed6ab275d51
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Update Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *     http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=======================================================
22  *
23  */
24 package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
25
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.util.Collection;
30 import java.util.List;
31 import java.util.Properties;
32 import java.util.concurrent.TimeUnit;
33 import org.json.JSONObject;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
38 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
39 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.GeneralConfig;
40 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisherMain;
41 import org.onap.dmaap.mr.client.MRBatchingPublisher;
42 import org.onap.dmaap.mr.client.response.MRPublisherResponse;
43 import org.slf4j.Logger;
44
45 public class TestMountpointStatePublisher {
46
47     private static final String CONFIGURATIONTESTFILE = "test3.properties";
48     public Thread publisher;
49     MountpointStatePublisherMain mountpointStatePublisher;
50     ConfigurationFileRepresentation configFileRepresentation;
51     GeneralConfig cfg;
52
53     @Before
54     public void testMountpointStatePublisherData() {
55         String testJsonData =
56                 "{\"NodeId\":\"69322972e178_50001\",\"NetConfNodeState\":\"Connecting\",\"TimeStamp\":\"2019-11-12T12:45:08.604Z\"}";
57         configFileRepresentation =
58                 new ConfigurationFileRepresentation(CONFIGURATIONTESTFILE);
59         cfg = new GeneralConfig(configFileRepresentation);
60         JSONObject jsonObj = new JSONObject(testJsonData);
61         mountpointStatePublisher = new MountpointStatePublisherMain(cfg);
62         mountpointStatePublisher.getStateObjects().add(jsonObj);
63     }
64
65     @Test
66     public void testMountpointStatePublisherConfiguration() throws InterruptedException {
67         ConfigurationFileRepresentation configFileRepresentation =
68                 new ConfigurationFileRepresentation(CONFIGURATIONTESTFILE);
69         GeneralConfig cfg = new GeneralConfig(configFileRepresentation);
70
71         MountpointStatePublisherMain pub = new MountpointStatePublisherMock(cfg);
72         pub.createPublisher(null);
73         pub.publishMessage(pub.createPublisher(null), "Test DMaaP Message");
74
75     }
76
77     public class MountpointStatePublisherMock extends MountpointStatePublisherMain {
78
79         public MountpointStatePublisherMock(Configuration config) {
80             super(config);
81         }
82
83         @Override
84         public MRBatchingPublisher createPublisher(Properties publisherProperties) {
85
86             return new MRBatchingPublisher() {
87
88                 @Override
89                 public int send(String msg) throws IOException {
90                     System.out.println("Message to send - " + msg);
91                     return 0;
92                 }
93
94                 @Override
95                 public int send(String partition, String msg) throws IOException {
96                     return 0;
97                 }
98
99                 @Override
100                 public int send(message msg) throws IOException {
101                     return 0;
102                 }
103
104                 @Override
105                 public int send(Collection<message> msgs) throws IOException {
106                     return 0;
107                 }
108
109                 @Override
110                 public void close() {
111
112                 }
113
114                 @Override
115                 public void logTo(Logger log) {
116
117                 }
118
119                 @Override
120                 public void setApiCredentials(String apiKey, String apiSecret) {
121
122                 }
123
124                 @Override
125                 public void clearApiCredentials() {
126
127                 }
128
129                 @Override
130                 public int getPendingMessageCount() {
131                     return 0;
132                 }
133
134                 @Override
135                 public List<message> close(long timeout, TimeUnit timeoutUnits)
136                         throws IOException, InterruptedException {
137                     return null;
138                 }
139
140                 @Override
141                 public MRPublisherResponse sendBatchWithResponse() {
142                     return null;
143                 }
144
145             };
146         }
147     }
148
149     @After
150     public void after() {
151         File file = new File(CONFIGURATIONTESTFILE);
152         if (file.exists()) {
153             System.out.println("File exists, Deleting it");
154             file.delete();
155         }
156
157     }
158
159 }