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