From 8f7bb6db21d8c280c30c1f19284bb3cfaa404df9 Mon Sep 17 00:00:00 2001 From: lapentafd Date: Wed, 14 Jul 2021 11:16:48 +0100 Subject: Code Coverage on clamp-participant-intermediary-parameters Issue-ID: POLICY-3452 Change-Id: I2cfeaabb6bf232e193430c724434a9669b889bad Signed-off-by: lapentafd --- .../main/parameters/CommonTestData.java | 113 +++++++++++++++++++++ .../TestParticipantIntermediaryParameters.java | 67 ++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java create mode 100644 participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java (limited to 'participant/participant-intermediary/src') 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 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 getIntermediaryParametersMap(final String name) { + final Map 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 getTopicParametersMap(final boolean isEmpty) { + final Map 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(); + } +} -- cgit 1.2.3-korg