From 7f7f0c5790dc63e43a59c53154e796239ab34cbb Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Mon, 21 Jun 2021 16:45:27 +0100 Subject: Convert Intermediary Participant to Spring and refactor Participants Issue-ID: POLICY-3370 Change-Id: I1541fc47b35c91f9ec86ab768bc3cec2cd78647c Signed-off-by: FrancescoFioraEst --- .../simulator/ParticipantSimulatorApplication.java | 3 +++ .../simulator/config/ParticipantConfig.java | 16 --------------- .../parameters/ParticipantSimulatorParameters.java | 11 +++-------- .../src/main/resources/config/application.yaml | 8 -------- .../endtoend/ParticipantSimulatorTest.java | 6 +++++- .../simulator/main/parameters/CommonTestData.java | 23 ---------------------- .../TestParticipantSimulatorParameters.java | 7 ------- .../src/test/resources/application_test.properties | 7 ------- 8 files changed, 11 insertions(+), 70 deletions(-) (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 9f6e4aa4b..8267df477 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 @@ -23,6 +23,7 @@ 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; +import org.springframework.context.annotation.ComponentScan; /** * Starter. @@ -30,6 +31,8 @@ import org.springframework.boot.context.properties.ConfigurationPropertiesScan; */ @SpringBootApplication @ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.participant.simulator.main.parameters") +@ComponentScan({"org.onap.policy.clamp.controlloop.participant.simulator", + "org.onap.policy.clamp.controlloop.participant.intermediary"}) 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/ParticipantConfig.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java index f4e6791ec..c890ec247 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java +++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java @@ -20,9 +20,6 @@ package org.onap.policy.clamp.controlloop.participant.simulator.config; -import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryFactory; -import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameters; import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.RequestResponseLoggingFilter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; @@ -31,19 +28,6 @@ import org.springframework.context.annotation.Configuration; @Configuration public class ParticipantConfig { - /** - * Create ParticipantIntermediaryApi. - * - * @param parameters the Participant Dcae Parameters - * @return ParticipantIntermediaryApi - */ - @Bean - public ParticipantIntermediaryApi participantIntermediaryApi(ParticipantSimulatorParameters parameters) { - ParticipantIntermediaryApi intermediaryApi = new ParticipantIntermediaryFactory().createApiImplementation(); - intermediaryApi.init(parameters.getIntermediaryParameters()); - return intermediaryApi; - } - /** * logging Filter configuration. * 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 5110ac6a6..99579006c 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 @@ -25,8 +25,7 @@ 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.parameters.validation.ParameterGroupConstraint; -import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; @@ -38,13 +37,9 @@ import org.springframework.validation.annotation.Validated; @Getter @Setter @ConfigurationProperties(prefix = "participant") -public class ParticipantSimulatorParameters { +public class ParticipantSimulatorParameters implements ParticipantParameters { - @NotNull @Valid - private ParticipantIntermediaryParameters intermediaryParameters; - @NotNull - @ParameterGroupConstraint - private PolicyModelsProviderParameters databaseProviderParameters; + private ParticipantIntermediaryParameters intermediaryParameters; } 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 a45636b34..82e3b89f1 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 @@ -35,11 +35,3 @@ participant: 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/endtoend/ParticipantSimulatorTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java index 46495f7c3..0b63c395a 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java @@ -40,6 +40,7 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti import org.onap.policy.clamp.controlloop.models.messages.rest.TypedSimpleResponse; import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener; +import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler; import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.CommonTestData; import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.AbstractRestController; import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.TestListenerUtils; @@ -89,6 +90,9 @@ class ParticipantSimulatorTest { @Autowired private ParticipantIntermediaryApi participantIntermediaryApi; + @Autowired + private ParticipantHandler participantHandler; + private static final Object lockit = new Object(); private boolean check = false; @@ -97,7 +101,7 @@ class ParticipantSimulatorTest { if (!check) { check = true; ControlLoopUpdateListener clUpdateListener = - new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler()); + new ControlLoopUpdateListener(participantHandler); ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg(); 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 c53410b28..e85b3ebbe 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 @@ -65,30 +65,7 @@ public class CommonTestData { public Map getParticipantParameterGroupMap(final String name) { final Map map = new TreeMap<>(); - map.put("name", name); map.put("intermediaryParameters", getIntermediaryParametersMap(false)); - map.put("databaseProviderParameters", getDatabaseProviderParametersMap(false)); - return map; - } - - /** - * Returns a property map for a databaseProviderParameters 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 getDatabaseProviderParametersMap(final boolean isEmpty) { - final Map 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"); - } - return map; } 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 e5c7b5e30..3c1d1c2a3 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 @@ -46,13 +46,6 @@ class TestParticipantSimulatorParameters { assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); } - @Test - void testParticipantParameterGroup_EmptyDatabaseProviderParameters() { - final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); - participantParameters.setDatabaseProviderParameters(null); - assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); - } - @Test void testParticipantPolicyParameters_NullTopicSinks() { final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters(); 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 89c57bb12..2b30c4ffd 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 @@ -26,10 +26,3 @@ participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].topicCom 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 -- cgit 1.2.3-korg