11fb2f3b9cc069b3763f85cba97aed07b1fc118f
[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  * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
7  * =================================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software distributed under the License
14  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15  * or implied. See the License for the specific language governing permissions and limitations under
16  * the License.
17  * ============LICENSE_END==========================================================================
18  */
19
20 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test;
21
22 import static org.junit.Assert.assertNotNull;
23 import com.google.common.io.Files;
24 import java.io.File;
25 import java.nio.charset.StandardCharsets;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29 import org.junit.After;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
32 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.*;
33
34 public class TestDMaaPVESMsgConsumerMain {
35
36     private static final String CONFIGURATIONFILE = "test1.properties";
37     private static final String TESTCONFIG_GENERAL = "[general]\n"
38             + "dmaapEnabled=false\n"
39             + "baseUrl=http://localhost:8181\n"
40             + "sdnrUser=admin\n"
41             + "sdnrPasswd=admin\n"
42             + "\n"
43             + "[pnfRegistration]\n"
44             + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.impl.DMaaPPNFRegVESMsgConsumer\n"
45             + "TransportType=HTTPNOAUTH\n"
46             + "host=onap-dmap:3904\n"
47             + "topic=unauthenticated.VES_PNFREG_OUTPUT\n"
48             + "contenttype=application/json\n"
49             + "group=myG\n"
50             + "id=C1\n"
51             + "timeout=20000\n"
52             + "limit=10000\n"
53             + "\n"
54             + "[fault]\n"
55             + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer.java\n"
56             + "TransportType=HTTPNOAUTH\n"
57             + "host=onap-dmap:3904\n"
58             + "topic=unauthenticated.SEC_FAULT_OUTPUT\n"
59             + "contenttype=application/json\n"
60             + "group=myG\n"
61             + "id=C1\n"
62             + "timeout=20000\n"
63             + "limit=10000\n"
64             + "fetchPause=10000\n"
65             + "\n"
66             + "";
67
68     private static final String TESTCONFIG_GENERAL_INVALID = "[general]\n"
69             + "dmaapEnabled=false\n"
70             + "baseUrl=http://localhost:8181\n"
71             + "sdnrUser=admin\n"
72             + "sdnrPasswd=admin\n"
73             + "\n"
74             + "[pnfRegistration]\n"
75             + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer.java\n"
76             + "TransportType=HTTPNOAUTH\n"
77             + "host=onap-dmap:3904\n"
78             + "topic=unauthenticated.VES_PNFREG_OUTPUT\n"
79             + "contenttype=application/json\n"
80             + "group=myG\n"
81             + "id=C1\n"
82             + "timeout=20000\n"
83             + "limit=10000\n"
84             + "\n"
85             + "[fault]\n"
86             + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer.java\n"
87             + "TransportType=HTTPNOAUTH\n"
88             + "host=onap-dmap:3904\n"
89             + "topic=unauthenticated.SEC_FAULT_OUTPUT\n"
90             + "contenttype=application/json\n"
91             + "group=myG\n"
92             + "id=C1\n"
93             + "timeout=HELLO\n"
94             + "limit=10000\n"
95             + "fetchPause=WORLD\n"
96             + "\n"
97             + "";
98     public GeneralConfig generalConfig;
99     Map<String, MessageConfig> configMap = new HashMap<>();
100     DMaaPVESMsgConsumerMain dmaapMain;
101
102
103     public void preTest1() {
104         try {
105             Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL);
106             ConfigurationFileRepresentation configFileRepresentation =
107                     new ConfigurationFileRepresentation(CONFIGURATIONFILE);
108
109             generalConfig = new GeneralConfig(configFileRepresentation);
110             PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
111             FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
112
113             configMap.put("pnfRegistration", pnfRegConfig);
114             configMap.put("fault", faultConfig);
115         } catch (Exception e) {
116             System.out.println("Failed in preTest execution " + e.getMessage());
117         }
118     }
119
120     public void preTest2() {
121         try {
122             Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL_INVALID);
123             ConfigurationFileRepresentation configFileRepresentation =
124                     new ConfigurationFileRepresentation(CONFIGURATIONFILE);
125
126             generalConfig = new GeneralConfig(configFileRepresentation);
127             PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
128             FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
129
130             configMap.put("pnfRegistration", pnfRegConfig);
131             configMap.put("fault", faultConfig);
132         } catch (Exception e) {
133             System.out.println("Failed in preTest execution " + e.getMessage());
134         }
135     }
136
137     @Test
138     public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() {
139         preTest1();
140         assertNotNull(configMap);
141         dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
142     }
143
144     @Test
145     public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() {
146         preTest2();
147         assertNotNull(configMap);
148         dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
149     }
150
151     @After
152     public void postTest() {
153         File file = new File(CONFIGURATIONFILE);
154         if (file.exists()) {
155             System.out.println("File exists, Deleting it");
156             file.delete();
157         }
158         List<DMaaPVESMsgConsumer> consumers = dmaapMain.getConsumers();
159         for (DMaaPVESMsgConsumer consumer : consumers) {
160             // stop all consumers
161             consumer.stopConsumer();
162         }
163     }
164 }
165
166