summaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins/src/test
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@ericsson.com>2018-09-11 12:38:03 +0100
committerramverma <ram.krishna.verma@ericsson.com>2018-09-11 12:38:24 +0100
commit5e4eb38ae737abd2054108b99bbd7b3649ec77d1 (patch)
treed4ad73ac67c675905f99574ac2a1b6b8c86fb2a2 /plugins/reception-plugins/src/test
parent1662df01bb8e54f17048b8a86f0c5560ae79fe83 (diff)
Fix all sonar issues in distribution
* Fixing all sonar issues in distribution * Adding more test cases to improve code coverage Change-Id: I296f96b66046e25c3c462632091f40565ff75478 Issue-ID: POLICY-1035 Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'plugins/reception-plugins/src/test')
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java88
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java159
-rw-r--r--plugins/reception-plugins/src/test/resources/handling-sdcInvalid.json2
3 files changed, 160 insertions, 89 deletions
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java
deleted file mode 100644
index 65d7ca10..00000000
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Intel. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.distribution.reception.handling.sdc;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Arrays;
-
-import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
-
-/**
- * Class to perform unit test of {@link SdcConfiguration}.
- *
- */
-public class TestSdcConfiguration {
-
- @Test
- public void testSdcConfiguration() throws IOException {
- SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
- try {
- final Gson gson = new GsonBuilder().create();
- configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"),
- SdcReceptionHandlerConfigurationParameterGroup.class);
- } catch (final Exception e) {
- fail("test should not thrown an exception here: " + e.getMessage());
- }
- final GroupValidationResult validationResult = configParameters.validate();
- assertTrue(validationResult.isValid());
- final SdcConfiguration config = new SdcConfiguration(configParameters);
- assertEquals(Arrays.asList("a.com", "b.com", "c.com"), config.getMsgBusAddress());
- assertEquals(Arrays.asList("TOSCA_CSAR", "HEAT"), config.getRelevantArtifactTypes());
- assertEquals("localhost", config.getAsdcAddress());
- assertEquals("policy", config.getUser());
- assertEquals("policy", config.getPassword());
- assertEquals(20, config.getPollingInterval());
- assertEquals(30, config.getPollingTimeout());
- assertEquals("policy-id", config.getConsumerID());
- assertEquals("policy-group", config.getConsumerGroup());
- assertEquals("TEST", config.getEnvironmentName());
- assertEquals("null", config.getKeyStorePath());
- assertEquals("null", config.getKeyStorePassword());
- assertEquals(false, config.activateServerTLSAuth());
- assertEquals(true, config.isFilterInEmptyResources());
- assertEquals(false, config.isUseHttpsWithDmaap());
- }
-
- @Test
- public void testInvalidSdcConfiguration() throws IOException {
- SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
- try {
- final Gson gson = new GsonBuilder().create();
- configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
- SdcReceptionHandlerConfigurationParameterGroup.class);
- } catch (final Exception e) {
- fail("test should not thrown an exception here: " + e.getMessage());
- }
- final GroupValidationResult validationResult = configParameters.validate();
- assertFalse(validationResult.isValid());
-
- }
-}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java
new file mode 100644
index 00000000..df72d45c
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java
@@ -0,0 +1,159 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Intel. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.reception.handling.sdc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+/**
+ * Class to perform unit test of {@link SdcConfiguration}.
+ *
+ */
+public class TestSdcReceptionHandlerConfigurationParameterGroup {
+
+ @Test
+ public void testSdcConfiguration() throws IOException {
+ SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
+ try {
+ final Gson gson = new GsonBuilder().create();
+ configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"),
+ SdcReceptionHandlerConfigurationParameterGroup.class);
+ } catch (final Exception e) {
+ fail("test should not thrown an exception here: " + e.getMessage());
+ }
+ final GroupValidationResult validationResult = configParameters.validate();
+ assertTrue(validationResult.isValid());
+ final SdcConfiguration config = new SdcConfiguration(configParameters);
+ assertEquals(Arrays.asList("a.com", "b.com", "c.com"), config.getMsgBusAddress());
+ assertEquals(Arrays.asList("TOSCA_CSAR", "HEAT"), config.getRelevantArtifactTypes());
+ assertEquals("localhost", config.getAsdcAddress());
+ assertEquals("policy", config.getUser());
+ assertEquals("policy", config.getPassword());
+ assertEquals(20, config.getPollingInterval());
+ assertEquals(30, config.getPollingTimeout());
+ assertEquals("policy-id", config.getConsumerID());
+ assertEquals("policy-group", config.getConsumerGroup());
+ assertEquals("TEST", config.getEnvironmentName());
+ assertEquals("null", config.getKeyStorePath());
+ assertEquals("null", config.getKeyStorePassword());
+ assertEquals(false, config.activateServerTLSAuth());
+ assertEquals(true, config.isFilterInEmptyResources());
+ assertEquals(false, config.isUseHttpsWithDmaap());
+ }
+
+ @Test
+ public void testInvalidSdcConfiguration() throws IOException {
+ SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
+ try {
+ final Gson gson = new GsonBuilder().create();
+ configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
+ SdcReceptionHandlerConfigurationParameterGroup.class);
+ } catch (final Exception e) {
+ fail("test should not thrown an exception here: " + e.getMessage());
+ }
+ final GroupValidationResult validationResult = configParameters.validate();
+ assertFalse(validationResult.isValid());
+ }
+
+ @Test
+ public void testSdcConfigurationBuilder() {
+
+ final SdcReceptionHandlerConfigurationParameterBuilder builder =
+ new SdcReceptionHandlerConfigurationParameterBuilder().setAsdcAddress("localhost")
+ .setConsumerGroup("policy-group").setConsumerId("policy-id").setEnvironmentName("TEST")
+ .setKeystorePassword("password").setKeystorePath("dummyPath").setPassword("policy")
+ .setPollingInterval(10).setPollingTimeout(20).setUser("policy").setUseHttpsWithDmaap(false)
+ .setActiveserverTlsAuth(false).setFilterinEmptyResources(true)
+ .setArtifactTypes(Arrays.asList("TOSCA_CSAR")).setMessageBusAddress(Arrays.asList("localhost"));
+ final SdcReceptionHandlerConfigurationParameterGroup configParameters =
+ new SdcReceptionHandlerConfigurationParameterGroup(builder);
+ configParameters.setName("SDCConfiguration");
+
+ assertEquals(Arrays.asList("localhost"), configParameters.getMessageBusAddress());
+ assertEquals(Arrays.asList("TOSCA_CSAR"), configParameters.getArtifactTypes());
+ assertEquals("localhost", configParameters.getAsdcAddress());
+ assertEquals("policy", configParameters.getUser());
+ assertEquals("policy", configParameters.getPassword());
+ assertEquals(10, configParameters.getPollingInterval());
+ assertEquals(20, configParameters.getPollingTimeout());
+ assertEquals("policy-id", configParameters.getConsumerId());
+ assertEquals("policy-group", configParameters.getConsumerGroup());
+ assertEquals("TEST", configParameters.getEnvironmentName());
+ assertEquals("dummyPath", configParameters.getKeyStorePath());
+ assertEquals("password", configParameters.getKeyStorePassword());
+ assertEquals(false, configParameters.isActiveServerTlsAuth());
+ assertEquals(true, configParameters.isFilterInEmptyResources());
+ assertEquals(false, configParameters.isUseHttpsWithDmaap());
+ }
+
+ @Test
+ public void testSdcConfigurationWithNullList() {
+
+ final SdcReceptionHandlerConfigurationParameterBuilder builder =
+ new SdcReceptionHandlerConfigurationParameterBuilder().setAsdcAddress("localhost")
+ .setConsumerGroup("policy-group").setConsumerId("policy-id").setEnvironmentName("TEST")
+ .setKeystorePassword("password").setKeystorePath("dummyPath").setPassword("policy")
+ .setPollingInterval(10).setPollingTimeout(20).setUser("policy").setUseHttpsWithDmaap(false)
+ .setActiveserverTlsAuth(false).setFilterinEmptyResources(true)
+ .setArtifactTypes(Arrays.asList("TOSCA_CSAR")).setMessageBusAddress(null);
+ final SdcReceptionHandlerConfigurationParameterGroup configParameters =
+ new SdcReceptionHandlerConfigurationParameterGroup(builder);
+ configParameters.setName("SDCConfiguration");
+
+ try {
+ configParameters.validate();
+ fail("Test must throw an exception");
+ } catch (final Exception exp) {
+ assertTrue(exp.getMessage().contains("collection parameter \"messageBusAddress\" is null"));
+ }
+ }
+
+ @Test
+ public void testSdcConfigurationWithEmptyStringList() {
+
+ final SdcReceptionHandlerConfigurationParameterBuilder builder =
+ new SdcReceptionHandlerConfigurationParameterBuilder().setAsdcAddress("localhost")
+ .setConsumerGroup("policy-group").setConsumerId("policy-id").setEnvironmentName("TEST")
+ .setKeystorePassword("password").setKeystorePath("dummyPath").setPassword("policy")
+ .setPollingInterval(10).setPollingTimeout(20).setUser("policy").setUseHttpsWithDmaap(false)
+ .setActiveserverTlsAuth(false).setFilterinEmptyResources(true)
+ .setArtifactTypes(Arrays.asList("")).setMessageBusAddress(Arrays.asList("localhost"));
+ final SdcReceptionHandlerConfigurationParameterGroup configParameters =
+ new SdcReceptionHandlerConfigurationParameterGroup(builder);
+ configParameters.setName("SDCConfiguration");
+
+ final GroupValidationResult validationResult = configParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult().contains("must be a non-blank string"));
+ }
+}
diff --git a/plugins/reception-plugins/src/test/resources/handling-sdcInvalid.json b/plugins/reception-plugins/src/test/resources/handling-sdcInvalid.json
index 112879f4..803fc412 100644
--- a/plugins/reception-plugins/src/test/resources/handling-sdcInvalid.json
+++ b/plugins/reception-plugins/src/test/resources/handling-sdcInvalid.json
@@ -1,6 +1,6 @@
{
"name" : "parameterConfig1",
- "asdcAddress": "localhost",
+ "asdcAddress": "",
"messageBusAddress": [
"a.com",
"b.com",