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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test;
21 import static org.junit.Assert.assertNotNull;
22 import com.google.common.io.Files;
24 import java.nio.charset.StandardCharsets;
25 import java.util.HashMap;
26 import java.util.List;
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;
38 public class TestDMaaPVESMsgConsumerMain {
40 private static final String CONFIGURATIONFILE = "test1.properties";
42 private static final String TESTCONFIG_GENERAL = "[general]\n"
43 + "dmaapEnabled=false\n"
44 + "baseUrl=http://localhost:8181\n"
46 + "sdnrPasswd=admin\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"
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"
69 + "fetchPause=10000\n"
73 private static final String TESTCONFIG_GENERAL_INVALID = "[general]\n"
74 + "dmaapEnabled=false\n"
75 + "baseUrl=http://localhost:8181\n"
77 + "sdnrPasswd=admin\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"
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"
100 + "fetchPause=WORLD\n"
104 public GeneralConfig generalConfig;
105 Map<String, Configuration> configMap = new HashMap<String, Configuration>();
106 DMaaPVESMsgConsumerMain dmaapMain;
109 public void preTest1() {
111 Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL);
112 ConfigurationFileRepresentation configFileRepresentation =
113 new ConfigurationFileRepresentation(CONFIGURATIONFILE);
115 generalConfig = new GeneralConfig(configFileRepresentation);
116 PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
117 FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
119 configMap.put("pnfRegistration", pnfRegConfig);
120 configMap.put("fault", faultConfig);
121 } catch (Exception e) {
122 System.out.println("Failed in preTest execution " + e.getMessage());
126 public void preTest2() {
128 Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL_INVALID);
129 ConfigurationFileRepresentation configFileRepresentation =
130 new ConfigurationFileRepresentation(CONFIGURATIONFILE);
132 generalConfig = new GeneralConfig(configFileRepresentation);
133 PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
134 FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
136 configMap.put("pnfRegistration", pnfRegConfig);
137 configMap.put("fault", faultConfig);
138 } catch (Exception e) {
139 System.out.println("Failed in preTest execution " + e.getMessage());
144 public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() {
146 assertNotNull(configMap);
147 dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
151 public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() {
153 assertNotNull(configMap);
154 dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
158 public void postTest() {
159 File file = new File(CONFIGURATIONFILE);
161 System.out.println("File exists, Deleting it");
164 List<DMaaPVESMsgConsumer> consumers = dmaapMain.getConsumers();
165 for (DMaaPVESMsgConsumer consumer : consumers) {
166 // stop all consumers
167 consumer.stopConsumer();