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;
31 import java.io.FileReader;
32 import java.io.IOException;
33 import java.util.Arrays;
34 import org.junit.Test;
35 import org.onap.policy.common.parameters.GroupValidationResult;
36 import org.onap.policy.common.parameters.ValidationStatus;
37 import org.onap.policy.distribution.reception.decoding.hpa.CommonTestData;
40 * Class to perform unit test of {@link SdcConfiguration}.
43 public class TestSdcReceptionHandlerConfigurationParameterGroup {
46 public void testSdcConfiguration() throws IOException {
47 SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
49 final Gson gson = new GsonBuilder().create();
50 configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"),
51 SdcReceptionHandlerConfigurationParameterGroup.class);
52 } catch (final Exception e) {
53 fail("test should not thrown an exception here: " + e.getMessage());
55 final GroupValidationResult validationResult = configParameters.validate();
56 assertTrue(validationResult.isValid());
57 final SdcConfiguration config = new SdcConfiguration(configParameters);
58 assertEquals(Arrays.asList("a.com", "b.com", "c.com"), config.getMsgBusAddress());
59 assertEquals(Arrays.asList("TOSCA_CSAR", "HEAT"), config.getRelevantArtifactTypes());
60 assertEquals("localhost", config.getAsdcAddress());
61 assertEquals("policy", config.getUser());
62 assertEquals("policy", config.getPassword());
63 assertEquals(20, config.getPollingInterval());
64 assertEquals(30, config.getPollingTimeout());
65 assertEquals("policy-id", config.getConsumerID());
66 assertEquals("policy-group", config.getConsumerGroup());
67 assertEquals("TEST", config.getEnvironmentName());
68 assertEquals("null", config.getKeyStorePath());
69 assertEquals("null", config.getKeyStorePassword());
70 assertEquals(false, config.activateServerTLSAuth());
71 assertEquals(true, config.isFilterInEmptyResources());
72 assertEquals(false, config.isUseHttpsWithDmaap());
76 public void testInvalidSdcConfiguration() throws IOException {
77 SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
79 final Gson gson = new GsonBuilder().create();
80 configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
81 SdcReceptionHandlerConfigurationParameterGroup.class);
82 } catch (final Exception e) {
83 fail("test should not thrown an exception here: " + e.getMessage());
85 final GroupValidationResult validationResult = configParameters.validate();
86 assertFalse(validationResult.isValid());
90 public void testEmptyParameters() {
91 final SdcReceptionHandlerConfigurationParameterGroup configurationParameters =
92 CommonTestData.getPolicyDecoderParameters("src/test/resources/parameters/EmptyParameters.json",
93 SdcReceptionHandlerConfigurationParameterGroup.class);
95 assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());