diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2021-06-15 16:01:31 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2021-06-23 17:07:17 +0100 |
commit | dbc13c78875a3d5493054a7252a7804daae8cf1f (patch) | |
tree | 635e3600320c38a44a9f0f54db471fcf5e3995ed /participant/participant-impl/participant-impl-policy/src | |
parent | df2d3298e9881410dff5547e0ba9850135d63d5c (diff) |
Move parameters from config Json file to application.yaml
Issue-ID: POLICY-3343
Change-Id: Id78c00a5a241337f684a70feeee543f3a88fc01c
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-policy/src')
17 files changed, 160 insertions, 652 deletions
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParametersConfig.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParametersConfig.java deleted file mode 100644 index 9c65d029c..000000000 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParametersConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============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.policy.config; - -import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; -import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.ParticipantPolicyParameterHandler; -import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.ParticipantPolicyParameters; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class ParametersConfig { - - @Value("${participant.file}") - private String file; - - @Bean - public ParticipantPolicyParameters participantPolicyParameters() throws ControlLoopException { - return new ParticipantPolicyParameterHandler().toParticipantDcaeParameters(file); - } -} diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameterHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameterHandler.java deleted file mode 100644 index 0d8e70013..000000000 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameterHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============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.policy.main.parameters; - -import java.io.File; -import javax.ws.rs.core.Response; -import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; -import org.onap.policy.common.parameters.BeanValidationResult; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; - -/** - * This class handles reading, parsing and validating of policy participant parameters from JSON files. - */ -public class ParticipantPolicyParameterHandler { - - private static final Coder CODER = new StandardCoder(); - - /** - * Read the parameters from the parameter file. - * - * @param path the path passed to policy - * @return the parameters read from the configuration file - * @throws ControlLoopException on parameter exceptions - */ - public ParticipantPolicyParameters toParticipantDcaeParameters(final String path) throws ControlLoopException { - ParticipantPolicyParameters parameters = null; - - // Read the parameters - try { - // Read the parameters from JSON - File file = new File(path); - parameters = CODER.decode(file, ParticipantPolicyParameters.class); - } catch (final CoderException e) { - final String errorMessage = - "error reading parameters from \"" + path + "\"\n" + "(" + e.getClass().getSimpleName() + ")"; - throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, errorMessage, e); - } - - // The JSON processing returns null if there is an empty file - if (parameters == null) { - throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, "no parameters found in \"" + path + "\""); - } - - // validate the parameters - final BeanValidationResult validationResult = parameters.validate(); - if (!validationResult.isValid()) { - final String returnMessage = - "validation error(s) on parameters from \"" + path + "\"\n" + validationResult.getResult(); - - throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, returnMessage); - } - - return parameters; - } -} diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java index 490722a45..91f7ae47f 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java @@ -20,30 +20,32 @@ package org.onap.policy.clamp.controlloop.participant.policy.main.parameters; -import javax.validation.constraints.NotBlank; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; import lombok.Getter; +import lombok.Setter; import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters; -import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; -import org.onap.policy.common.parameters.ParameterGroupImpl; -import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.endpoints.parameters.RestClientParameters; +import org.onap.policy.common.parameters.validation.ParameterGroupConstraint; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + /** * Class to hold all parameters needed for the policy participant. * */ -@NotNull -@NotBlank +@Validated @Getter -public class ParticipantPolicyParameters extends ParameterGroupImpl { +@Setter +@ConfigurationProperties(prefix = "participant") +public class ParticipantPolicyParameters { + + @NotNull + @Valid private ParticipantIntermediaryParameters intermediaryParameters; - private BusTopicParams policyApiParameters; - /** - * Create the policy participant parameter group. - * - * @param name the parameter group name - */ - public ParticipantPolicyParameters(final String name) { - super(name); - } + @NotNull + @ParameterGroupConstraint + private RestClientParameters policyApiParameters; } diff --git a/participant/participant-impl/participant-impl-policy/src/main/resources/config/PolicyParticipantConfig.json b/participant/participant-impl/participant-impl-policy/src/main/resources/config/PolicyParticipantConfig.json deleted file mode 100644 index bf458fae9..000000000 --- a/participant/participant-impl/participant-impl-policy/src/main/resources/config/PolicyParticipantConfig.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "ControlLoopParticipantGroup", - "intermediaryParameters": { - "name": "Participant parameters", - "reportingTimeInterval": 120000, - "description": "Participant Description", - "participantType":{ - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version":"2.3.1" - }, - "participantId": { - "name": "org.onap.PM_Policy", - "version": "1.0.0" - }, - "clampControlLoopTopics": { - "topicSources": [ - { - "topic": "POLICY-CLRUNTIME-PARTICIPANT", - "servers": [ - "message-router" - ], - "topicCommInfrastructure": "dmaap", - "fetchTimeout": 15000 - } - ], - "topicSinks": [ - { - "topic": "POLICY-CLRUNTIME-PARTICIPANT", - "servers": [ - "message-router" - ], - "topicCommInfrastructure": "dmaap" - }, - { - "topic": "POLICY-NOTIFICATION", - "servers": [ - "message-router" - ], - "topicCommInfrastructure": "dmaap" - } - ] - } - }, - "policyApiParameters": { - "clientName": "api", - "hostname": "policy-api", - "port": "6969", - "userName": "healthcheck", - "password": "zb!XztG34", - "https": true, - "allowSelfSignedCerts": true - } -} diff --git a/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml index 79eca8f92..7bf4f623a 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml +++ b/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml @@ -1,3 +1,33 @@ participant: - file: src/main/resources/config/PolicyParticipantConfig.json + policyApiParameters: + clientName: api + hostname: policy-api + port: 6969 + userName: healthcheck + password: zb!XztG34 + https: true + allowSelfSignedCerts: true + intermediaryParameters: + reportingTimeInterval: 120000 + description: Participant Description + participantId: + name: org.onap.PM_Policy + version: 1.0.0 + participantType: + name: org.onap.policy.controlloop.PolicyControlLoopParticipant + version: 2.3.1 + clampControlLoopTopics: + topicSources[0]: + topic: POLICY-CLRUNTIME-PARTICIPANT + servers[0]: ${topicServer:message-router} + topicCommInfrastructure: dmaap + fetchTimeout: 15000 + topicSinks[0]: + topic: POLICY-CLRUNTIME-PARTICIPANT + servers[0]: ${topicServer:message-router} + topicCommInfrastructure: dmaap + topicSinks[1]: + topic: POLICY-NOTIFICATION + servers[0]: ${topicServer:message-router} + topicCommInfrastructure: dmaap diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java index 2a6f4b005..d34a38103 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java @@ -41,7 +41,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@TestPropertySource(properties = "participant.file=src/test/resources/parameters/TestParameters.json") +@TestPropertySource(locations = {"classpath:application_test.properties"}) class ParticipantPolicyTest { private static final Object lockit = new Object(); diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java index 1acc2c838..38861472c 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java @@ -20,19 +20,11 @@ package org.onap.policy.clamp.controlloop.participant.policy.main.parameters; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException; import org.onap.policy.common.endpoints.parameters.TopicParameters; -import org.onap.policy.common.parameters.ParameterGroup; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -47,23 +39,19 @@ public class CommonTestData { public static final long TIME_INTERVAL = 2000; public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams()); - public static final Coder coder = new StandardCoder(); + public static final Coder CODER = new StandardCoder(); /** - * Converts the contents of a map to a parameter class. + * Get ParticipantPolicyParameters. * - * @param <T> the type of ParameterGroup to process - * @param source property map - * @param clazz class of object to be created from the map - * @return a new object represented by the map - * @throws ControlLoopRuntimeException on decoding errors + * @return ParticipantPolicyParameters */ - public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) { + public ParticipantPolicyParameters getParticipantPolicyParameters() { try { - return coder.convert(source, clazz); + return CODER.convert(getParticipantPolicyParametersMap(PARTICIPANT_GROUP_NAME), + ParticipantPolicyParameters.class); } catch (final CoderException e) { - throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, - "cannot create " + clazz.getName() + " from map", e); + throw new RuntimeException("cannot create ParticipantPolicyParameters from map", e); } } @@ -79,27 +67,24 @@ public class CommonTestData { map.put("name", name); map.put("intermediaryParameters", getIntermediaryParametersMap(false)); - map.put("databaseProviderParameters", getDatabaseProviderParametersMap(false)); + map.put("policyApiParameters", getPolicyApiParametersMap()); return map; } /** - * Returns a property map for a databaseProviderParameters map for test cases. + * Returns a property map for a policyApiParameters 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> getDatabaseProviderParametersMap(final boolean isEmpty) { + public Map<String, Object> getPolicyApiParametersMap() { final Map<String, Object> map = new TreeMap<>(); - if (!isEmpty) { - map.put("name", "PolicyProviderParameterGroup"); - map.put("implementation", "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl"); - map.put("databaseDriver", "org.h2.Driver"); - map.put("databaseUrl", "jdbc:h2:mem:testdb"); - map.put("databaseUser", "policy"); - map.put("databasePassword", "P01icY"); - map.put("persistenceUnit", "ToscaConceptTest"); - } + map.put("clientName", "api"); + map.put("hostname", "localhost"); + map.put("port", 6969); + map.put("userName", "healthcheck"); + map.put("password", "zb!XztG34"); + map.put("https", false); + map.put("allowSelfSignedCerts", true); return map; } @@ -163,59 +148,6 @@ public class CommonTestData { } /** - * Gets the standard participant parameters. - * - * @param port port to be inserted into the parameters - * @return the standard participant parameters - * @throws ControlLoopRuntimeException on parameter read errors - */ - public ParticipantPolicyParameters getParticipantPolicyParameters(int port) { - try { - return coder.decode(getParticipantPolicyParametersAsString(port), ParticipantPolicyParameters.class); - - } catch (CoderException e) { - throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "cannot read participant parameters", - e); - } - } - - /** - * Gets the standard participant parameters, as a String. - * - * @param port port to be inserted into the parameters - * @return the standard participant parameters - * @throws ControlLoopRuntimeException on parameter read errors - */ - public static String getParticipantPolicyParametersAsString(int port) { - - try { - File file = new File(getParamFile()); - String json = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); - - json = json.replace("${port}", String.valueOf(port)); - json = json.replace("${dbName}", "jdbc:h2:mem:testdb"); - - return json; - - } catch (IOException e) { - throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "cannot read participant parameters", - e); - - } - } - - /** - * Gets the full path to the parameter file, which may vary depending on whether or - * not this is an end-to-end test. - * - * @return the parameter file name - */ - private static String getParamFile() { - String paramFile = "src/test/resources/parameters/TestParametersStd.json"; - return paramFile; - } - - /** * Nulls out a field within a JSON string. * * @param json JSON string diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParametersTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParametersTest.java new file mode 100644 index 000000000..74e7cb1bc --- /dev/null +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParametersTest.java @@ -0,0 +1,66 @@ +/*- + * ============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.policy.main.parameters; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.validation.Validation; +import javax.validation.ValidatorFactory; +import org.junit.jupiter.api.Test; + +class ParticipantPolicyParametersTest { + private CommonTestData commonTestData = new CommonTestData(); + private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); + + @Test + void testParticipantPolicyParameters() { + final ParticipantPolicyParameters participantParameters = commonTestData.getParticipantPolicyParameters(); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isEmpty(); + } + + @Test + void testParticipantPolicyParameters_NullTopicSinks() { + final ParticipantPolicyParameters participantParameters = commonTestData.getParticipantPolicyParameters(); + participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSinks(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testParticipantPolicyParameters_NullTopicSources() { + final ParticipantPolicyParameters participantParameters = commonTestData.getParticipantPolicyParameters(); + participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSources(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testParticipantPolicyParameters_NullPolicyApiParameters() { + final ParticipantPolicyParameters participantParameters = commonTestData.getParticipantPolicyParameters(); + participantParameters.setPolicyApiParameters(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testParticipantPolicyParameters_NullHostname() { + final ParticipantPolicyParameters participantParameters = commonTestData.getParticipantPolicyParameters(); + participantParameters.getPolicyApiParameters().setHostname(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } +} diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameterHandler.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameterHandler.java deleted file mode 100644 index 8c12a4038..000000000 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameterHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============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.policy.main.parameters; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; - -import java.io.FileNotFoundException; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; -import org.onap.policy.common.utils.coder.CoderException; - -class TestParticipantPolicyParameterHandler { - - @Test - void testParameterHandlerNoParameterFile() throws ControlLoopException { - final String path = "src/test/resources/parameters/NoParametersFile.json"; - - assertThatThrownBy(() -> new ParticipantPolicyParameterHandler().toParticipantDcaeParameters(path)) - .hasCauseInstanceOf(CoderException.class) - .hasRootCauseInstanceOf(FileNotFoundException.class); - } - - @Test - void testParameterHandlerInvalidParameters() throws ControlLoopException { - final String path = "src/test/resources/parameters/InvalidParameters.json"; - - assertThatThrownBy(() -> new ParticipantPolicyParameterHandler().toParticipantDcaeParameters(path)) - .hasMessageStartingWith("error reading parameters from") - .hasCauseInstanceOf(CoderException.class); - } - - @Test - void testParticipantParameterGroup() throws ControlLoopException { - final String path = "src/test/resources/parameters/TestParameters.json"; - final ParticipantPolicyParameters parGroup = new ParticipantPolicyParameterHandler() - .toParticipantDcaeParameters(path); - assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, parGroup.getName()); - } -} diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameters.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameters.java deleted file mode 100644 index 5ffe5101d..000000000 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameters.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============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.policy.main.parameters; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; - -import java.util.Map; -import org.junit.Test; -import org.onap.policy.common.parameters.ValidationResult; - -public class TestParticipantPolicyParameters { - CommonTestData commonTestData = new CommonTestData(); - - @Test - public void testParticipantPolicyParameters_Named() { - final ParticipantPolicyParameters participantParameters = new ParticipantPolicyParameters("my-name"); - assertEquals("my-name", participantParameters.getName()); - } - - @Test - public void testParticipantPolicyParameters() { - final ParticipantPolicyParameters participantParameters = commonTestData.toObject( - commonTestData.getParticipantPolicyParametersMap(CommonTestData.PARTICIPANT_GROUP_NAME), - ParticipantPolicyParameters.class); - assertThat(participantParameters.validate().isValid()).isTrue(); - } - - @Test - public void testParticipantPolicyParameters_NullName() { - final ParticipantPolicyParameters participantParameters = commonTestData - .toObject(commonTestData.getParticipantPolicyParametersMap(null), - ParticipantPolicyParameters.class); - final ValidationResult validationResult = participantParameters.validate(); - assertFalse(validationResult.isValid()); - assertEquals(null, participantParameters.getName()); - assertThat(validationResult.getResult()).contains("is null"); - } - - @Test - public void testParticipantPolicyParameters_EmptyName() { - final ParticipantPolicyParameters participantParameters = commonTestData - .toObject(commonTestData.getParticipantPolicyParametersMap(""), - ParticipantPolicyParameters.class); - final ValidationResult validationResult = participantParameters.validate(); - assertFalse(validationResult.isValid()); - assertEquals("", participantParameters.getName()); - assertThat(validationResult.getResult()).contains( - "item \"name\" value \"\" INVALID, " + "is blank"); - } - - @Test - public void testParticipantPolicyParameters_SetName() { - final ParticipantPolicyParameters participantParameters = commonTestData.toObject( - commonTestData.getParticipantPolicyParametersMap(CommonTestData.PARTICIPANT_GROUP_NAME), - ParticipantPolicyParameters.class); - participantParameters.setName("ParticipantNewGroup"); - assertThat(participantParameters.validate().isValid()).isTrue(); - assertEquals("ParticipantNewGroup", participantParameters.getName()); - } - - @Test - public void testParticipantPolicyParameters_EmptyParticipantIntermediaryParameters() { - final Map<String, Object> map = - commonTestData.getParticipantPolicyParametersMap(CommonTestData.PARTICIPANT_GROUP_NAME); - map.replace("intermediaryParameters", commonTestData.getIntermediaryParametersMap(true)); - final ParticipantPolicyParameters participantParameters = - commonTestData.toObject(map, ParticipantPolicyParameters.class); - final ValidationResult validationResult = participantParameters.validate(); - assertNull(validationResult.getResult()); - } - - @Test - public void testParticipantPolicyParametersp_EmptyTopicParameters() { - final Map<String, Object> map = - commonTestData.getParticipantPolicyParametersMap(CommonTestData.PARTICIPANT_GROUP_NAME); - final Map<String, Object> intermediaryParametersMap = commonTestData.getIntermediaryParametersMap(false); - intermediaryParametersMap.put("clampControlLoopTopics", commonTestData.getTopicParametersMap(true)); - map.replace("intermediaryParameters", intermediaryParametersMap); - - final ParticipantPolicyParameters participantParameters = - commonTestData.toObject(map, ParticipantPolicyParameters.class); - final ValidationResult validationResult = participantParameters.validate(); - assertNull(validationResult.getResult()); - } -} diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/application_test.properties b/participant/participant-impl/participant-impl-policy/src/test/resources/application_test.properties new file mode 100644 index 000000000..2f260825b --- /dev/null +++ b/participant/participant-impl/participant-impl-policy/src/test/resources/application_test.properties @@ -0,0 +1,27 @@ +server.servlet.context-path=/onap/participantsim +server.error.path=/error + +participant.policyApiParameters.clientName=api +participant.policyApiParameters.hostname=localhost +participant.policyApiParameters.port=6969 +participant.policyApiParameters.userName=healthcheck +participant.policyApiParameters.password=zb!XztG34 +participant.policyApiParameters.https=false +participant.policyApiParameters.allowSelfSignedCerts=true +participant.intermediaryParameters.reportingTimeInterval: 120000 +participant.intermediaryParameters.description: Participant Description +participant.intermediaryParameters.participantId.name: org.onap.PM_Policy +participant.intermediaryParameters.participantId.version: 1.0.0 +participant.intermediaryParameters.participantType.name: org.onap.policy.controlloop.PolicyControlLoopParticipant +participant.intermediaryParameters.participantType.version: 2.3.1 +participant.intermediaryParameters.clampControlLoopTopics.name=ControlLoop Topics +participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].topic=POLICY-CLRUNTIME-PARTICIPANT +participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].servers[0]=localhost +participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].topicCommInfrastructure=dmaap +participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].fetchTimeout=15000 +participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].topic=POLICY-CLRUNTIME-PARTICIPANT +participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].servers[0]=localhost +participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].topicCommInfrastructure=dmaap +participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].topic=POLICY-NOTIFICATION +participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].servers[0]=localhost +participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].topicCommInfrastructure=dmaap diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/InvalidParameters.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/InvalidParameters.json deleted file mode 100644 index 1035ccb67..000000000 --- a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/InvalidParameters.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": " -} diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/MinimumParametersH2.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/MinimumParametersH2.json deleted file mode 100644 index 30250be68..000000000 --- a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/MinimumParametersH2.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "ControlLoopParticipantGroup", - "intermediaryParameters": { - "name": "Participant parameters", - "reportingTimeInterval": 120000, - "description": "Participant Description", - "participantType":{ - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version":"2.3.1" - }, - "participantId": { - "name": "org.onap.PM_Policy", - "version": "1.0.0" - }, - "clampControlLoopTopics": { - "topicSources": [ - { - "topic": "POLICY-CLRUNTIME-PARTICIPANT", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap", - "fetchTimeout": 15000 - } - ], - "topicSinks": [ - { - "topic": "POLICY-CLRUNTIME-PARTICIPANT", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap" - }, - { - "topic": "POLICY-NOTIFICATION", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap" - } - ] - } - }, - "databaseProviderParameters": { - "name": "PolicyProviderParameterGroup", - "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl", - "databaseDriver": "org.h2.Driver", - "databaseUrl": "jdbc:h2:mem:testdb", - "databaseUser": "policy", - "databasePassword": "P01icY", - "persistenceUnit": "ToscaConceptTest" - } -} diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/NoParameters.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/NoParameters.json deleted file mode 100644 index 7a73a41bf..000000000 --- a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/NoParameters.json +++ /dev/null @@ -1,2 +0,0 @@ -{ -}
\ No newline at end of file diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParameters.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParameters.json deleted file mode 100644 index 024f72d6d..000000000 --- a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParameters.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "ControlLoopParticipantGroup", - "intermediaryParameters": { - "name": "Participant parameters", - "reportingTimeInterval": 120000, - "description": "Participant Description", - "participantType":{ - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version":"2.3.1" - }, - "participantId": { - "name": "org.onap.PM_Policy", - "version": "1.0.0" - }, - "clampControlLoopTopics": { - "topicSources": [ - { - "topic": "POLICY-CLRUNTIME-PARTICIPANT", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap", - "fetchTimeout": 15000 - } - ], - "topicSinks": [ - { - "topic": "POLICY-CLRUNTIME-PARTICIPANT", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap" - }, - { - "topic": "POLICY-NOTIFICATION", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap" - } - ] - } - }, - "policyApiParameters": { - "clientName": "api", - "hostname": "localhost", - "port": "6969", - "userName": "healthcheck", - "password": "zb!XztG34", - "https": false, - "allowSelfSignedCerts": true - } -} diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParametersStd.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParametersStd.json deleted file mode 100644 index 79540631a..000000000 --- a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParametersStd.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "ControlLoopParticipantGroup", - "intermediaryParameters": { - "name": "Participant parameters", - "reportingTimeInterval": 120000, - "description": "Participant Description", - "participantType": { - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version": "2.3.1" - }, - "participantId": { - "name": "org.onap.PM_Policy", - "version": "1.0.0" - }, - "clampControlLoopTopics": { - "topicSources": [ - { - "topic": "POLICY-CLRUNTIME-PARTICIPANT", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap", - "fetchTimeout": 15000 - } - ], - "topicSinks": [ - { - "topic": "POLICY-CLRUNTIME-PARTICIPANT", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap" - }, - { - "topic": "POLICY-NOTIFICATION", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap" - } - ] - } - }, - "databaseProviderParameters": { - "name": "PolicyProviderParameterGroup", - "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl", - "databaseDriver": "org.h2.Driver", - "databaseUrl": "jdbc:h2:mem:testdb", - "databaseUser": "policy", - "databasePassword": "P01icY", - "persistenceUnit": "ToscaConceptTest" - } -} diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/Unreadable.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/Unreadable.json deleted file mode 100644 index e33409f82..000000000 --- a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/Unreadable.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "ControlLoopRuntimeGroup", - "participantParameters": { - "heartBeatMs": 120000, - "updateParameters": { - "maxRetryCount": 1, - "maxWaitMs": 30000 - }, - "stateChangeParameters": { - "maxRetryCount": 1, - "maxWaitMs": 30000 - } - }, - "databaseProviderParameters": { - "name": "PolicyProviderParameterGroup", - "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl", - "databaseDriver": "org.h2.Driver", - "databaseUrl": "jdbc:h2:mem:testdb", - "databaseUser": "policy", - "databasePassword": "P01icY", - "persistenceUnit": "ToscaConceptTest" - }, - "topicParameterGroup": { - "topicSources": [ - { - "topic": "POLICY-CLRUNTIME-PARTICIPANT", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap", - "fetchTimeout": 15000 - } - ], - "topicSinks": [ - { - "topic": "POLICY-CLRUNTIME-PARTICIPANT", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap" - }, - { - "topic": "POLICY-NOTIFICATION", - "servers": [ - "localhost" - ], - "topicCommInfrastructure": "dmaap" - } - ] - } -} - - |