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