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
 
  11  * http://www.apache.org/licenses/LICENSE-2.0
 
  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
 
  17  * ============LICENSE_END==========================================================================
 
  20 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test;
 
  22 import static org.junit.Assert.assertNotNull;
 
  23 import com.google.common.io.Files;
 
  25 import java.nio.charset.StandardCharsets;
 
  26 import java.util.HashMap;
 
  27 import java.util.List;
 
  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.*;
 
  34 public class TestDMaaPVESMsgConsumerMain {
 
  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"
 
  41             + "sdnrPasswd=admin\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"
 
  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"
 
  64             + "fetchPause=10000\n"
 
  68     private static final String TESTCONFIG_GENERAL_INVALID = "[general]\n"
 
  69             + "dmaapEnabled=false\n"
 
  70             + "baseUrl=http://localhost:8181\n"
 
  72             + "sdnrPasswd=admin\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"
 
  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"
 
  95             + "fetchPause=WORLD\n"
 
  98     public GeneralConfig generalConfig;
 
  99     Map<String, MessageConfig> configMap = new HashMap<>();
 
 100     DMaaPVESMsgConsumerMain dmaapMain;
 
 103     public void preTest1() {
 
 105             Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL);
 
 106             ConfigurationFileRepresentation configFileRepresentation =
 
 107                     new ConfigurationFileRepresentation(CONFIGURATIONFILE);
 
 109             generalConfig = new GeneralConfig(configFileRepresentation);
 
 110             PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
 
 111             FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
 
 112             ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation);
 
 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());
 
 122     public void preTest2() {
 
 124             Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL_INVALID);
 
 125             ConfigurationFileRepresentation configFileRepresentation =
 
 126                     new ConfigurationFileRepresentation(CONFIGURATIONFILE);
 
 128             generalConfig = new GeneralConfig(configFileRepresentation);
 
 129             PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
 
 130             FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
 
 131             ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation);
 
 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());
 
 142     public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() {
 
 144         assertNotNull(configMap);
 
 145         dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
 
 149     public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() {
 
 151         assertNotNull(configMap);
 
 152         dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
 
 156     public void postTest() {
 
 157         File file = new File(CONFIGURATIONFILE);
 
 159             System.out.println("File exists, Deleting it");
 
 162         List<DMaaPVESMsgConsumer> consumers = dmaapMain.getConsumers();
 
 163         for (DMaaPVESMsgConsumer consumer : consumers) {
 
 164             // stop all consumers
 
 165             consumer.stopConsumer();