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
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==========================================================================
17 ******************************************************************************/
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test;
21 import static org.junit.Assert.assertNotNull;
24 import java.nio.charset.StandardCharsets;
25 import java.util.HashMap;
26 import java.util.List;
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;
39 import com.google.common.io.Files;
41 public class TestDMaaPVESMsgConsumerMain {
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" +
48 "sdnrPasswd=admin\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" +
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" +
71 "fetchPause=10000\n" +
75 private static final String TESTCONFIG_GENERAL_INVALID="[general]\n" +
76 "dmaapEnabled=false\n" +
77 "baseUrl=http://localhost:8181\n" +
79 "sdnrPasswd=admin\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" +
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" +
102 "fetchPause=WORLD\n" +
105 public GeneralConfig generalConfig;
106 Map<String, Configuration> configMap = new HashMap<String, Configuration>();
107 DMaaPVESMsgConsumerMain dmaapMain;
110 public void preTest1() {
112 Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL);
113 ConfigurationFileRepresentation configFileRepresentation = 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 = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
131 generalConfig = new GeneralConfig(configFileRepresentation);
132 PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
133 FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
135 configMap.put("pnfRegistration", pnfRegConfig);
136 configMap.put("fault", faultConfig);
137 } catch (Exception e) {
138 System.out.println("Failed in preTest execution "+e.getMessage());
143 public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() {
145 assertNotNull(configMap);
146 dmaapMain = new DMaaPVESMsgConsumerMain(configMap);
150 public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() {
152 assertNotNull(configMap);
153 dmaapMain = new DMaaPVESMsgConsumerMain(configMap);
157 public void postTest() {
158 File file = new File("test.properties");
160 System.out.println("File exists, Deleting it");
163 List<DMaaPVESMsgConsumer> consumers = DMaaPVESMsgConsumerMain.getConsumers();
164 for (DMaaPVESMsgConsumer consumer : consumers) {
165 // stop all consumers
166 consumer.stopConsumer();