ecfb8d081838d57f7ce920516d03c0504798a6fc
[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             ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation);
113
114             configMap.put("pnfRegistration", pnfRegConfig);
115             configMap.put("fault", faultConfig);
116             configMap.put("provisioning", provisioningConfig);
117         } catch (Exception e) {
118             System.out.println("Failed in preTest execution " + e.getMessage());
119         }
120     }
121
122     public void preTest2() {
123         try {
124             Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL_INVALID);
125             ConfigurationFileRepresentation configFileRepresentation =
126                     new ConfigurationFileRepresentation(CONFIGURATIONFILE);
127
128             generalConfig = new GeneralConfig(configFileRepresentation);
129             PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
130             FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
131             ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation);
132
133             configMap.put("pnfRegistration", pnfRegConfig);
134             configMap.put("fault", faultConfig);
135             configMap.put("provisioning", provisioningConfig);
136         } catch (Exception e) {
137             System.out.println("Failed in preTest execution " + e.getMessage());
138         }
139     }
140
141     @Test
142     public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() {
143         preTest1();
144         assertNotNull(configMap);
145         dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
146     }
147
148     @Test
149     public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() {
150         preTest2();
151         assertNotNull(configMap);
152         dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
153     }
154
155     @After
156     public void postTest() {
157         File file = new File(CONFIGURATIONFILE);
158         if (file.exists()) {
159             System.out.println("File exists, Deleting it");
160             file.delete();
161         }
162         List<DMaaPVESMsgConsumer> consumers = dmaapMain.getConsumers();
163         for (DMaaPVESMsgConsumer consumer : consumers) {
164             // stop all consumers
165             consumer.stopConsumer();
166         }
167     }
168 }
169
170