2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2018 Intel. All rights reserved.
 
   4  *  Modifications Copyright (C) 2019 Nordix Foundation.
 
   5  * ================================================================================
 
   6  * Licensed under the Apache License, Version 2.0 (the "License");
 
   7  * you may not use this file except in compliance with the License.
 
   8  * 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
 
  13  * distributed under the License is distributed on an "AS IS" BASIS,
 
  14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  15  * See the License for the specific language governing permissions and
 
  16  * limitations under the License.
 
  18  * SPDX-License-Identifier: Apache-2.0
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.policy.distribution.reception.handling.sdc;
 
  24 import static org.junit.Assert.assertEquals;
 
  25 import static org.junit.Assert.assertFalse;
 
  26 import static org.junit.Assert.assertTrue;
 
  27 import static org.junit.Assert.fail;
 
  29 import com.google.gson.Gson;
 
  30 import com.google.gson.GsonBuilder;
 
  32 import java.io.FileReader;
 
  33 import java.io.IOException;
 
  34 import java.util.Arrays;
 
  36 import org.junit.Test;
 
  37 import org.onap.policy.common.parameters.GroupValidationResult;
 
  38 import org.onap.policy.common.parameters.ValidationStatus;
 
  39 import org.onap.policy.distribution.reception.decoding.hpa.CommonTestData;
 
  42  * Class to perform unit test of {@link SdcConfiguration}.
 
  45 public class TestSdcReceptionHandlerConfigurationParameterGroup {
 
  48     public void testSdcConfiguration() throws IOException {
 
  49         SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
 
  51             final Gson gson = new GsonBuilder().create();
 
  52             configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"),
 
  53                     SdcReceptionHandlerConfigurationParameterGroup.class);
 
  54         } catch (final Exception e) {
 
  55             fail("test should not thrown an exception here: " + e.getMessage());
 
  57         final GroupValidationResult validationResult = configParameters.validate();
 
  58         assertTrue(validationResult.isValid());
 
  59         final SdcConfiguration config = new SdcConfiguration(configParameters);
 
  60         assertEquals(Arrays.asList("a.com", "b.com", "c.com"), config.getMsgBusAddress());
 
  61         assertEquals(Arrays.asList("TOSCA_CSAR", "HEAT"), config.getRelevantArtifactTypes());
 
  62         assertEquals("localhost", config.getAsdcAddress());
 
  63         assertEquals("policy", config.getUser());
 
  64         assertEquals("policy", config.getPassword());
 
  65         assertEquals(20, config.getPollingInterval());
 
  66         assertEquals(30, config.getPollingTimeout());
 
  67         assertEquals("policy-id", config.getConsumerID());
 
  68         assertEquals("policy-group", config.getConsumerGroup());
 
  69         assertEquals("TEST", config.getEnvironmentName());
 
  70         assertEquals("null", config.getKeyStorePath());
 
  71         assertEquals("null", config.getKeyStorePassword());
 
  72         assertEquals(false, config.activateServerTLSAuth());
 
  73         assertEquals(true, config.isFilterInEmptyResources());
 
  74         assertEquals(false, config.isUseHttpsWithDmaap());
 
  78     public void testInvalidSdcConfiguration() throws IOException {
 
  79         SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
 
  81             final Gson gson = new GsonBuilder().create();
 
  82             configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
 
  83                     SdcReceptionHandlerConfigurationParameterGroup.class);
 
  84         } catch (final Exception e) {
 
  85             fail("test should not thrown an exception here: " + e.getMessage());
 
  87         final GroupValidationResult validationResult = configParameters.validate();
 
  88         assertFalse(validationResult.isValid());
 
  92     public void testEmptyParameters() {
 
  93         final SdcReceptionHandlerConfigurationParameterGroup configurationParameters =
 
  94                 CommonTestData.getPolicyDecoderParameters("src/test/resources/parameters/EmptyParameters.json",
 
  95                         SdcReceptionHandlerConfigurationParameterGroup.class);
 
  97         assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());