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.*;
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.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;
40 import com.google.common.io.Files;
42 public class TestDMaaPVESMsgConsumerMain {
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" +
49 "sdnrPasswd=admin\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" +
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" +
72 "fetchPause=10000\n" +
76 private static final String TESTCONFIG_GENERAL_INVALID="[general]\n" +
77 "dmaapEnabled=false\n" +
78 "baseUrl=http://localhost:8181\n" +
80 "sdnrPasswd=admin\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" +
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" +
103 "fetchPause=WORLD\n" +
106 public GeneralConfig generalConfig;
107 Map<String, Configuration> configMap = new HashMap<String, Configuration>();
108 DMaaPVESMsgConsumerMain dmaapMain;
111 public void preTest1() {
113 Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL);
114 ConfigurationFileRepresentation configFileRepresentation = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
116 generalConfig = new GeneralConfig(configFileRepresentation);
117 PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
118 FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
120 configMap.put("pnfRegistration", pnfRegConfig);
121 configMap.put("fault", faultConfig);
122 } catch (Exception e) {
123 System.out.println("Failed in preTest execution "+e.getMessage());
127 public void preTest2() {
129 Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL_INVALID);
130 ConfigurationFileRepresentation configFileRepresentation = 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);
151 public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() {
153 assertNotNull(configMap);
154 dmaapMain = new DMaaPVESMsgConsumerMain(configMap);
158 public void postTest() {
159 List<DMaaPVESMsgConsumer> consumers = DMaaPVESMsgConsumerMain.getConsumers();
160 for (DMaaPVESMsgConsumer consumer : consumers) {
161 // stop all consumers
162 consumer.stopConsumer();