From dbc13c78875a3d5493054a7252a7804daae8cf1f Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 15 Jun 2021 16:01:31 +0100 Subject: Move parameters from config Json file to application.yaml Issue-ID: POLICY-3343 Change-Id: Id78c00a5a241337f684a70feeee543f3a88fc01c Signed-off-by: FrancescoFioraEst --- .../simulator/ParticipantSimulatorApplication.java | 2 + .../simulator/config/ParametersConfig.java | 40 -------- .../ParticipantSimulatorParameterHandler.java | 76 --------------- .../parameters/ParticipantSimulatorParameters.java | 33 ++++--- .../main/rest/ParticipantErrorController.java | 4 - .../resources/config/CDSParticipantConfig.json | 61 ------------ .../resources/config/DCAEParticipantConfig.json | 31 ------ .../resources/config/PolicyParticipantConfig.json | 31 ------ .../src/main/resources/config/application.yaml | 32 ++++++- .../simulator/main/parameters/CommonTestData.java | 106 ++------------------- .../TestParticipantSimulatorParameterHandler.java | 71 -------------- .../TestParticipantSimulatorParameters.java | 85 +++++------------ .../src/test/resources/application_test.properties | 30 +++++- .../test/resources/parameters/EmptyParameters.json | 0 .../resources/parameters/InvalidParameters.json | 3 - .../test/resources/parameters/NoParameters.json | 2 - .../test/resources/parameters/TestParameters.json | 61 ------------ .../resources/parameters/TestParametersStd.json | 61 ------------ .../src/test/resources/parameters/Unreadable.json | 61 ------------ 19 files changed, 107 insertions(+), 683 deletions(-) delete mode 100644 participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParametersConfig.java delete mode 100644 participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameterHandler.java delete mode 100644 participant/participant-impl/participant-impl-simulator/src/main/resources/config/CDSParticipantConfig.json delete mode 100644 participant/participant-impl/participant-impl-simulator/src/main/resources/config/DCAEParticipantConfig.json delete mode 100644 participant/participant-impl/participant-impl-simulator/src/main/resources/config/PolicyParticipantConfig.json delete mode 100644 participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java delete mode 100644 participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/EmptyParameters.json delete mode 100644 participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/InvalidParameters.json delete mode 100644 participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/NoParameters.json delete mode 100644 participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParameters.json delete mode 100644 participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParametersStd.json delete mode 100644 participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/Unreadable.json (limited to 'participant/participant-impl/participant-impl-simulator') diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java index 3aa1c36db..9f6e4aa4b 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java +++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java @@ -22,12 +22,14 @@ package org.onap.policy.clamp.controlloop.participant.simulator; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; /** * Starter. * */ @SpringBootApplication +@ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.participant.simulator.main.parameters") public class ParticipantSimulatorApplication { public static void main(String[] args) { diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParametersConfig.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParametersConfig.java deleted file mode 100644 index 936df2c57..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/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.simulator.config; - -import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; -import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameterHandler; -import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameters; -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 ParticipantSimulatorParameters participantSimulatorParameters() throws ControlLoopException { - return new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(file); - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameterHandler.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameterHandler.java deleted file mode 100644 index 178d08794..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameterHandler.java +++ /dev/null @@ -1,76 +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.simulator.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 participant simulator parameters from JSON files. - */ -public class ParticipantSimulatorParameterHandler { - - private static final Coder CODER = new StandardCoder(); - - /** - * Read the parameters from the path of the file. - * - * @param path path of the config file. - * @return the parameters read from the configuration file - * @throws ControlLoopException on parameter exceptions - */ - public ParticipantSimulatorParameters toParticipantSimulatorParameters(String path) throws ControlLoopException { - ParticipantSimulatorParameters parameters = null; - // Read the parameters - try { - // Read the parameters from JSON - File file = new File(path); - parameters = CODER.decode(file, ParticipantSimulatorParameters.class); - } catch (final CoderException e) { - final String errorMessage = "error reading parameters from \"" + path + "\"" + System.lineSeparator() + "(" - + 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) { - final String errorMessage = "no parameters found in \"" + path + "\""; - throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, errorMessage); - } - - // validate the parameters - final BeanValidationResult validationResult = parameters.validate(); - if (!validationResult.isValid()) { - final String returnMessage = "validation error(s) on parameters from \"" + path + "\"" - + System.lineSeparator() + validationResult.getResult(); - - throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, returnMessage); - } - - return parameters; - } - -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java index a4e62b446..5110ac6a6 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java +++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java @@ -20,32 +20,31 @@ package org.onap.policy.clamp.controlloop.participant.simulator.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.parameters.RestServerParameters; -import org.onap.policy.common.parameters.ParameterGroupImpl; -import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.validation.ParameterGroupConstraint; import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; /** * Class to hold all parameters needed for the participant simulator. * */ -@NotNull -@NotBlank +@Validated @Getter -public class ParticipantSimulatorParameters extends ParameterGroupImpl { - private RestServerParameters restServerParameters; +@Setter +@ConfigurationProperties(prefix = "participant") +public class ParticipantSimulatorParameters { + + @NotNull + @Valid private ParticipantIntermediaryParameters intermediaryParameters; - private PolicyModelsProviderParameters databaseProviderParameters; - /** - * Create the participant simulator parameter group. - * - * @param name the parameter group name - */ - public ParticipantSimulatorParameters(final String name) { - super(name); - } + @NotNull + @ParameterGroupConstraint + private PolicyModelsProviderParameters databaseProviderParameters; } diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/ParticipantErrorController.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/ParticipantErrorController.java index 82c1ac602..d4429b879 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/ParticipantErrorController.java +++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/ParticipantErrorController.java @@ -94,8 +94,4 @@ public class ParticipantErrorController implements ErrorController { return ResponseEntity.status(getStatus(request)).body(resp); } - - public String getErrorPath() { - return path; - } } diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/CDSParticipantConfig.json b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/CDSParticipantConfig.json deleted file mode 100644 index 544edb1ff..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/CDSParticipantConfig.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "ControlLoopParticipantGroup", - "restServerParameters": { - "host": "0.0.0.0", - "port": 6969, - "userName": "healthcheck", - "password": "zb!XztG34", - "https": false, - "aaf": false - }, - "intermediaryParameters": { - "name": "Participant parameters", - "reportingTimeInterval": 120000, - "description": "Participant Description", - "participantId": { - "name": "org.onap.PM_CDS_Blueprint", - "version": "1.0.0" - }, - "participantType": { - "name": "org.onap.PM_CDS_Blueprint", - "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" - } - ] - } - }, - "databaseProviderParameters": { - "name": "PolicyProviderParameterGroup", - "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl", - "databaseDriver": "org.mariadb.jdbc.Driver", - "databaseUrl": "jdbc:mariadb://mariadb:3306/cdsparticipantsim", - "databaseUser": "policy", - "databasePassword": "P01icY", - "persistenceUnit": "ToscaConceptTest" - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/DCAEParticipantConfig.json b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/DCAEParticipantConfig.json deleted file mode 100644 index e80570f93..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/DCAEParticipantConfig.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name":"ParticipantParameterGroup", - "participantStatusParameters":{ - "timeIntervalMs": 10000, - "description":"Participant Status", - "participantType":{ - "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", - "version":"2.3.4" - }, - "participantId":{ - "name": "DCAEParticipant0", - "version":"1.0.0" - }, - "participantDefinition":{ - "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", - "version":"2.3.4" - } - }, - "topicParameterGroup": { - "topicSources" : [{ - "topic" : "POLICY-CLRUNTIME-PARTICIPANT", - "servers" : [ "127.0.0.1:3904" ], - "topicCommInfrastructure" : "dmaap" - }], - "topicSinks" : [{ - "topic" : "POLICY-CLRUNTIME-PARTICIPANT", - "servers" : [ "127.0.0.1:3904" ], - "topicCommInfrastructure" : "dmaap" - }] - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/PolicyParticipantConfig.json b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/PolicyParticipantConfig.json deleted file mode 100644 index 8c8fa33cb..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/PolicyParticipantConfig.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name":"ParticipantParameterGroup", - "participantStatusParameters":{ - "timeIntervalMs":10000, - "description":"Participant Status", - "participantType":{ - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version":"2.3.1" - }, - "participantId":{ - "name": "PolicyParticipant0", - "version":"1.0.0" - }, - "participantDefinition":{ - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version":"2.3.1" - } - }, - "topicParameterGroup": { - "topicSources" : [{ - "topic" : "POLICY-CLRUNTIME-PARTICIPANT", - "servers" : [ "127.0.0.1:3904" ], - "topicCommInfrastructure" : "dmaap" - }], - "topicSinks" : [{ - "topic" : "POLICY-CLRUNTIME-PARTICIPANT", - "servers" : [ "127.0.0.1:3904" ], - "topicCommInfrastructure" : "dmaap" - }] - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml index b1fc135a5..a45636b34 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml +++ b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml @@ -12,4 +12,34 @@ server: path: /error participant: - file: src/main/resources/config/CDSParticipantConfig.json + intermediaryParameters: + reportingTimeInterval: 120000 + description: Participant Description + participantId: + name: org.onap.PM_CDS_Blueprint + version: 1.0.0 + participantType: + name: org.onap.PM_CDS_Blueprint + version: 1.0.0 + 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 + databaseProviderParameters: + name: PolicyProviderParameterGroup + implementation: org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl + databaseDriver: org.mariadb.jdbc.Driver + databaseUrl: jdbc:mariadb://mariadb:3306/cdsparticipantsim + databaseUser: policy + databasePassword: P01icY + persistenceUnit: ToscaConceptTest diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java index 2c9b1ccd2..c53410b28 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java @@ -20,19 +20,11 @@ package org.onap.policy.clamp.controlloop.participant.simulator.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; @@ -46,30 +38,20 @@ public class CommonTestData { public static final String DESCRIPTION = "Participant description"; public static final long TIME_INTERVAL = 2000; public static final List TOPIC_PARAMS = Arrays.asList(getTopicParams()); - private static final String REST_SERVER_PASSWORD = "zb!XztG34"; - private static final String REST_SERVER_USER = "healthcheck"; - private static final int REST_SERVER_PORT = 6969; - public static final String REST_SERVER_HOST = "0.0.0.0"; - private static final boolean REST_SERVER_HTTPS = true; - private static final boolean REST_SERVER_AAF = false; - 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 ParticipantSimulatorParameters. * - * @param the specific parameter group type to convert - * @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 parameter parsing errors + * @return ParticipantSimulatorParameters */ - public T toObject(final Map source, final Class clazz) { + public ParticipantSimulatorParameters getParticipantSimulatorParameters() { try { - return coder.convert(source, clazz); + return CODER.convert(getParticipantParameterGroupMap(PARTICIPANT_GROUP_NAME), + ParticipantSimulatorParameters.class); } catch (final CoderException e) { - throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, - "cannot create " + clazz.getName() + " from map", e); + throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e); } } @@ -84,33 +66,11 @@ public class CommonTestData { final Map map = new TreeMap<>(); map.put("name", name); - map.put("restServerParameters", getRestServerParametersMap(false)); map.put("intermediaryParameters", getIntermediaryParametersMap(false)); map.put("databaseProviderParameters", getDatabaseProviderParametersMap(false)); return map; } - /** - * Returns a property map for a RestServerParameters 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 getRestServerParametersMap(final boolean isEmpty) { - final Map map = new TreeMap<>(); - map.put("https", REST_SERVER_HTTPS); - map.put("aaf", REST_SERVER_AAF); - - if (!isEmpty) { - map.put("host", REST_SERVER_HOST); - map.put("port", REST_SERVER_PORT); - map.put("userName", REST_SERVER_USER); - map.put("password", REST_SERVER_PASSWORD); - } - - return map; - } - /** * Returns a property map for a databaseProviderParameters map for test cases. * @@ -190,58 +150,6 @@ public class CommonTestData { return participantId; } - /** - * 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 ParticipantSimulatorParameters getParticipantParameterGroup(int port) { - try { - return coder.decode(getParticipantParameterGroupAsString(port), ParticipantSimulatorParameters.class); - - } catch (CoderException e) { - throw new ControlLoopRuntimeException(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 getParticipantParameterGroupAsString(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. * diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java deleted file mode 100644 index 44b49f355..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java +++ /dev/null @@ -1,71 +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.simulator.main.parameters; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; - -import java.io.FileNotFoundException; -import org.apache.commons.io.DirectoryWalker.CancelException; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; -import org.onap.policy.common.utils.coder.CoderException; - -/** - * Class to perform unit test of {@link ParticipantParameterHandler}. - */ -class TestParticipantSimulatorParameterHandler { - - @Test - void testParameterHandlerNoParameterFile() throws ControlLoopException { - final String path = "src/test/resources/parameters/NoParametersFile.json"; - - assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(path)) - .hasCauseInstanceOf(CoderException.class) - .hasRootCauseInstanceOf(FileNotFoundException.class); - } - - @Test - void testParameterHandlerInvalidParameters() throws ControlLoopException { - final String path = "src/test/resources/parameters/InvalidParameters.json"; - - assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(path)) - .hasMessageStartingWith("error reading parameters from") - .hasCauseInstanceOf(CoderException.class); - } - - @Test - void testParameterHandlerNoParameters() throws CancelException, ControlLoopException { - final String path = "src/test/resources/parameters/EmptyParameters.json"; - - assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(path)) - .hasMessageContaining("no parameters found"); - } - - @Test - void testParticipantParameterGroup() throws ControlLoopException { - final String path = "src/test/resources/parameters/TestParameters.json"; - - final ParticipantSimulatorParameters parGroup = new ParticipantSimulatorParameterHandler() - .toParticipantSimulatorParameters(path); - assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, parGroup.getName()); - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java index 41c5b09b0..e5c7b5e30 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java @@ -21,90 +21,49 @@ package org.onap.policy.clamp.controlloop.participant.simulator.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 javax.validation.Validation; +import javax.validation.ValidatorFactory; import org.junit.jupiter.api.Test; -import org.onap.policy.common.parameters.ValidationResult; /** * Class to perform unit test of {@link ParticipantParameterGroup}. */ class TestParticipantSimulatorParameters { - CommonTestData commonTestData = new CommonTestData(); - - @Test - void testParticipantParameterGroup_Named() { - final ParticipantSimulatorParameters participantParameters = new ParticipantSimulatorParameters("my-name"); - assertEquals("my-name", participantParameters.getName()); - } + private CommonTestData commonTestData = new CommonTestData(); + private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); @Test void testParticipantParameterGroup() { - final ParticipantSimulatorParameters participantParameters = commonTestData.toObject( - commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME), - ParticipantSimulatorParameters.class); - assertThat(participantParameters.validate().isValid()).isTrue(); - assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, participantParameters.getName()); + final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isEmpty(); } @Test - void testParticipantParameterGroup_NullName() { - final ParticipantSimulatorParameters participantParameters = commonTestData - .toObject(commonTestData.getParticipantParameterGroupMap(null), - ParticipantSimulatorParameters.class); - final ValidationResult validationResult = participantParameters.validate(); - assertFalse(validationResult.isValid()); - assertEquals(null, participantParameters.getName()); - assertThat(validationResult.getResult()).contains("is null"); - } - - @Test - void testParticipantParameterGroup_EmptyName() { - final ParticipantSimulatorParameters participantParameters = commonTestData - .toObject(commonTestData.getParticipantParameterGroupMap(""), - ParticipantSimulatorParameters.class); - final ValidationResult validationResult = participantParameters.validate(); - assertFalse(validationResult.isValid()); - assertEquals("", participantParameters.getName()); - assertThat(validationResult.getResult()).contains( - "item \"name\" value \"\" INVALID, " + "is blank"); + void testParticipantParameterGroup_EmptyParticipantIntermediaryParameters() { + final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); + participantParameters.setIntermediaryParameters(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); } @Test - void testParticipantParameterGroup_SetName() { - final ParticipantSimulatorParameters participantParameters = commonTestData.toObject( - commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME), - ParticipantSimulatorParameters.class); - participantParameters.setName("ParticipantNewGroup"); - assertThat(participantParameters.validate().isValid()).isTrue(); - assertEquals("ParticipantNewGroup", participantParameters.getName()); + void testParticipantParameterGroup_EmptyDatabaseProviderParameters() { + final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); + participantParameters.setDatabaseProviderParameters(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); } @Test - void testParticipantParameterGroup_EmptyParticipantIntermediaryParameters() { - final Map map = - commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME); - map.replace("intermediaryParameters", commonTestData.getIntermediaryParametersMap(true)); - final ParticipantSimulatorParameters participantParameters = - commonTestData.toObject(map, ParticipantSimulatorParameters.class); - final ValidationResult validationResult = participantParameters.validate(); - assertNull(validationResult.getResult()); + void testParticipantPolicyParameters_NullTopicSinks() { + final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); + participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSinks(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); } @Test - void testParticipantParameterGroupp_EmptyTopicParameters() { - final Map map = - commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME); - final Map intermediaryParametersMap = commonTestData.getIntermediaryParametersMap(false); - intermediaryParametersMap.put("clampControlLoopTopics", commonTestData.getTopicParametersMap(true)); - map.replace("intermediaryParameters", intermediaryParametersMap); - - final ParticipantSimulatorParameters participantParameters = - commonTestData.toObject(map, ParticipantSimulatorParameters.class); - final ValidationResult validationResult = participantParameters.validate(); - assertNull(validationResult.getResult()); + void testParticipantPolicyParameters_NullTopicSources() { + final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); + participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSources(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); } } diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties b/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties index c31bb9d6b..89c57bb12 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties +++ b/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties @@ -4,4 +4,32 @@ spring.security.user.password=zb!XztG34 server.servlet.context-path=/onap/participantsim server.error.path=/error -participant.file=src/test/resources/parameters/TestParameters.json +participant.restServerParameters.host=0.0.0.0 +participant.restServerParameters.port=6969 +participant.restServerParameters.userName=healthcheck +participant.restServerParameters.password=zb!XztG34 +participant.restServerParameters.https=false +participant.restServerParameters.aaf=false +participant.intermediaryParameters.reportingTimeInterval=120000 +participant.intermediaryParameters.description=Participant Description +participant.intermediaryParameters.participantId.name=org.onap.PM_CDS_Blueprint +participant.intermediaryParameters.participantId.version=1.0.0 +participant.intermediaryParameters.participantType.name=org.onap.PM_CDS_Blueprint +participant.intermediaryParameters.participantType.version=1.0.0 +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 +participant.databaseProviderParameters.name=PolicyProviderParameterGroup +participant.databaseProviderParameters.implementation=org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl +participant.databaseProviderParameters.databaseDriver=org.h2.Driver +participant.databaseProviderParameters.databaseUrl=jdbc:h2:mem:testdb +participant.databaseProviderParameters.databaseUser=policy +participant.databaseProviderParameters.databasePassword=P01icY +participant.databaseProviderParameters.persistenceUnit=ToscaConceptTest diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/EmptyParameters.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/EmptyParameters.json deleted file mode 100644 index e69de29bb..000000000 diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/InvalidParameters.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/InvalidParameters.json deleted file mode 100644 index 1035ccb67..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/InvalidParameters.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": " -} diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/NoParameters.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/NoParameters.json deleted file mode 100644 index 7a73a41bf..000000000 --- a/participant/participant-impl/participant-impl-simulator/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-simulator/src/test/resources/parameters/TestParameters.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParameters.json deleted file mode 100644 index 8c594044b..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParameters.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "ControlLoopParticipantGroup", - "restServerParameters": { - "host": "0.0.0.0", - "port": 6969, - "userName": "healthcheck", - "password": "zb!XztG34", - "https": false, - "aaf": false - }, - "intermediaryParameters": { - "name": "Participant parameters", - "reportingTimeInterval": 120000, - "description": "Participant Description", - "participantId": { - "name": "org.onap.PM_CDS_Blueprint", - "version": "1.0.0" - }, - "participantType": { - "name": "org.onap.PM_CDS_Blueprint", - "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-simulator/src/test/resources/parameters/TestParametersStd.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParametersStd.json deleted file mode 100644 index 0295a8f91..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParametersStd.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "ControlLoopParticipantGroup", - "restServerParameters": { - "host": "0.0.0.0", - "port": ${port}, - "userName": "healthcheck", - "password": "zb!XztG34", - "https": false, - "aaf": false - }, - "intermediaryParameters": { - "name": "Participant parameters", - "reportingTimeInterval": 120000, - "description": "Participant Description", - "participantId": { - "name": "org.onap.PM_CDS_Blueprint", - "version": "1.0.0" - }, - "participantType": { - "name": "org.onap.PM_CDS_Blueprint", - "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-simulator/src/test/resources/parameters/Unreadable.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/Unreadable.json deleted file mode 100644 index fc36b49e4..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/Unreadable.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "ControlLoopRuntimeGroup", - "restServerParameters": { - "host": "0.0.0.0", - "port": 6969, - "userName": "healthcheck", - "password": "zb!XztG34", - "https": false, - "aaf": false - }, - "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" - } - ] - } -} - - -- cgit 1.2.3-korg