032850afb07de50e57e152a0fabd39138a84a0b7
[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.mountpointregistrar.test;
20
21 import static org.junit.Assert.assertNotNull;
22 import com.google.common.io.Files;
23 import java.io.File;
24 import java.nio.charset.StandardCharsets;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import org.junit.After;
29 import org.junit.Test;
30 import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
31 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
32 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPVESMsgConsumer;
33 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPVESMsgConsumerMain;
34 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.FaultConfig;
35 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.GeneralConfig;
36 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFRegistrationConfig;
37
38 public class TestDMaaPVESMsgConsumerMain {
39
40     private static final String CONFIGURATIONFILE = "test1.properties";
41     // @formatter:off
42     private static final String TESTCONFIG_GENERAL = "[general]\n"
43             + "dmaapEnabled=false\n"
44             + "baseUrl=http://localhost:8181\n"
45             + "sdnrUser=admin\n"
46             + "sdnrPasswd=admin\n"
47             + "\n"
48             + "[pnfRegistration]\n"
49             + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.impl.DummyPNFRegVESMsgConsumer\n"
50             + "TransportType=HTTPNOAUTH\n"
51             + "host=onap-dmap:3904\n"
52             + "topic=unauthenticated.VES_PNFREG_OUTPUT\n"
53             + "contenttype=application/json\n"
54             + "group=myG\n"
55             + "id=C1\n"
56             + "timeout=20000\n"
57             + "limit=10000\n"
58             + "\n"
59             + "[fault]\n"
60             + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.impl.DummyFaultVESMsgConsumer\n"
61             + "TransportType=HTTPNOAUTH\n"
62             + "host=onap-dmap:3904\n"
63             + "topic=unauthenticated.SEC_FAULT_OUTPUT\n"
64             + "contenttype=application/json\n"
65             + "group=myG\n"
66             + "id=C1\n"
67             + "timeout=20000\n"
68             + "limit=10000\n"
69             + "fetchPause=10000\n"
70             + "\n"
71             + "";
72
73     private static final String TESTCONFIG_GENERAL_INVALID = "[general]\n"
74             + "dmaapEnabled=false\n"
75             + "baseUrl=http://localhost:8181\n"
76             + "sdnrUser=admin\n"
77             + "sdnrPasswd=admin\n"
78             + "\n"
79             + "[pnfRegistration]\n"
80             + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.impl.DummyPNFRegVESMsgConsumer\n"
81             + "TransportType=HTTPNOAUTH\n"
82             + "host=onap-dmap:3904\n"
83             + "topic=unauthenticated.VES_PNFREG_OUTPUT\n"
84             + "contenttype=application/json\n"
85             + "group=myG\n"
86             + "id=C1\n"
87             + "timeout=20000\n"
88             + "limit=10000\n"
89             + "\n"
90             + "[fault]\n"
91             + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.impl.DummyFaultVESMsgConsumer\n"
92             + "TransportType=HTTPNOAUTH\n"
93             + "host=onap-dmap:3904\n"
94             + "topic=unauthenticated.SEC_FAULT_OUTPUT\n"
95             + "contenttype=application/json\n"
96             + "group=myG\n"
97             + "id=C1\n"
98             + "timeout=HELLO\n"
99             + "limit=10000\n"
100             + "fetchPause=WORLD\n"
101             + "\n"
102             + "";
103     // @formatter:on
104     public GeneralConfig generalConfig;
105     Map<String, Configuration> configMap = new HashMap<String, Configuration>();
106     DMaaPVESMsgConsumerMain dmaapMain;
107
108     //  @Before
109     public void preTest1() {
110         try {
111             Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL);
112             ConfigurationFileRepresentation configFileRepresentation =
113                     new ConfigurationFileRepresentation(CONFIGURATIONFILE);
114
115             generalConfig = new GeneralConfig(configFileRepresentation);
116             PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
117             FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
118
119             configMap.put("pnfRegistration", pnfRegConfig);
120             configMap.put("fault", faultConfig);
121         } catch (Exception e) {
122             System.out.println("Failed in preTest execution " + e.getMessage());
123         }
124     }
125
126     public void preTest2() {
127         try {
128             Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL_INVALID);
129             ConfigurationFileRepresentation configFileRepresentation =
130                     new ConfigurationFileRepresentation(CONFIGURATIONFILE);
131
132             generalConfig = new GeneralConfig(configFileRepresentation);
133             PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
134             FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
135
136             configMap.put("pnfRegistration", pnfRegConfig);
137             configMap.put("fault", faultConfig);
138         } catch (Exception e) {
139             System.out.println("Failed in preTest execution " + e.getMessage());
140         }
141     }
142
143     @Test
144     public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() {
145         preTest1();
146         assertNotNull(configMap);
147         dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
148     }
149
150     @Test
151     public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() {
152         preTest2();
153         assertNotNull(configMap);
154         dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
155     }
156
157     @After
158     public void postTest() {
159         File file = new File(CONFIGURATIONFILE);
160         if (file.exists()) {
161             System.out.println("File exists, Deleting it");
162             file.delete();
163         }
164         List<DMaaPVESMsgConsumer> consumers = dmaapMain.getConsumers();
165         for (DMaaPVESMsgConsumer consumer : consumers) {
166             // stop all consumers
167             consumer.stopConsumer();
168         }
169     }
170 }
171
172