aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-07-19 13:22:31 +0000
committerGerrit Code Review <gerrit@onap.org>2021-07-19 13:22:31 +0000
commit87d96a043499a636053d12b3b9dbb73b830c760e (patch)
treeb727f1468d21d01c60b2c95642b283ccd9dc2cab
parent68d287984f99e466b3daf44ec2300c0dfefada47 (diff)
parent8f7bb6db21d8c280c30c1f19284bb3cfaa404df9 (diff)
Merge "Code Coverage on clamp-participant-intermediary-parameters"
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java113
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java67
2 files changed, 180 insertions, 0 deletions
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
new file mode 100644
index 000000000..93ba15846
--- /dev/null
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
@@ -0,0 +1,113 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * 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.clamp.controlloop.participant.intermediary.main.parameters;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
+import org.onap.policy.common.endpoints.parameters.TopicParameters;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+/**
+ * Class to hold/create all parameters for test cases.
+ */
+public class CommonTestData {
+ public static final String PARTICIPANT_GROUP_NAME = "ControlLoopParticipantGroup";
+ public static final String DESCRIPTION = "Participant description";
+ public static final long TIME_INTERVAL = 2000;
+ public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
+
+ public static final Coder CODER = new StandardCoder();
+
+ /**
+ * Get ParticipantIntermediaryParameters.
+ *
+ * @return ParticipantIntermediaryParameters
+ */
+ public ParticipantIntermediaryParameters getParticipantIntermediaryParameters() {
+ try {
+ return CODER.convert(getIntermediaryParametersMap(PARTICIPANT_GROUP_NAME),
+ ParticipantIntermediaryParameters.class);
+ } catch (final CoderException e) {
+ throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
+ }
+ }
+
+ /**
+ * Returns a property map for a intermediaryParameters map for test cases.
+ *
+ * @param name name of the parameters
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getIntermediaryParametersMap(final String name) {
+ final Map<String, Object> map = new TreeMap<>();
+ map.put("name", name);
+ map.put("participantId", getParticipantId());
+ map.put("description", DESCRIPTION);
+ map.put("participantType", getParticipantId());
+ map.put("reportingTimeInterval", TIME_INTERVAL);
+ map.put("clampControlLoopTopics", getTopicParametersMap(false));
+
+ return map;
+ }
+
+ /**
+ * Returns a property map for a TopicParameters map for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ if (!isEmpty) {
+ map.put("topicSources", TOPIC_PARAMS);
+ map.put("topicSinks", TOPIC_PARAMS);
+ }
+ return map;
+ }
+
+ /**
+ * Returns topic parameters for test cases.
+ *
+ * @return topic parameters
+ */
+ public static TopicParameters getTopicParams() {
+ final TopicParameters topicParams = new TopicParameters();
+ topicParams.setTopic("POLICY-CLRUNTIME-PARTICIPANT");
+ topicParams.setTopicCommInfrastructure("dmaap");
+ topicParams.setServers(Arrays.asList("localhost"));
+ return topicParams;
+ }
+
+ /**
+ * Returns participantId for test cases.
+ *
+ * @return participant Id
+ */
+ public static ToscaConceptIdentifier getParticipantId() {
+ return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.1");
+ }
+}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java
new file mode 100644
index 000000000..d554a55b6
--- /dev/null
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * 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.clamp.controlloop.participant.intermediary.main.parameters;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
+
+/**
+ * Class to perform unit test of {@link ParticipantParameterGroup}.
+ */
+class TestParticipantIntermediaryParameters {
+ private CommonTestData commonTestData = new CommonTestData();
+ private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
+
+ @Test
+ void testParticipantIntermediaryParameterGroup() {
+ final ParticipantIntermediaryParameters participantParameters =
+ commonTestData.getParticipantIntermediaryParameters();
+ assertThat(validatorFactory.getValidator().validate(participantParameters)).isEmpty();
+ }
+
+ @Test
+ void testParticipantIntermediaryParameterGroup_EmptyParameter() {
+ final ParticipantIntermediaryParameters participantParameters =
+ commonTestData.getParticipantIntermediaryParameters();
+ participantParameters.setClampControlLoopTopics(null);
+ assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+ }
+
+ @Test
+ void testParticipantIntermediaryParameters_NullTopicSinks() {
+ final ParticipantIntermediaryParameters participantParameters =
+ commonTestData.getParticipantIntermediaryParameters();
+ participantParameters.getClampControlLoopTopics().setTopicSinks(null);
+ assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+ }
+
+ @Test
+ void testParticipantIntermediaryParameters_NullTopicSources() {
+ final ParticipantIntermediaryParameters participantParameters =
+ commonTestData.getParticipantIntermediaryParameters();
+ participantParameters.getClampControlLoopTopics().setTopicSources(null);
+ assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+ }
+}