diff options
author | Liam Fallon <liam.fallon@est.tech> | 2021-06-25 12:34:04 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-06-25 12:34:04 +0000 |
commit | 78d0be555197b29cd9de4b882c9525d6b6b2e524 (patch) | |
tree | 5473d222ccf01be249fb716d78d8f4853f681667 /participant/participant-impl/participant-impl-dcae/src/test | |
parent | c2f0aac6784db56706931a5fa409e18a3dc872cd (diff) | |
parent | dbc13c78875a3d5493054a7252a7804daae8cf1f (diff) |
Merge "Move parameters from config Json file to application.yaml"
Diffstat (limited to 'participant/participant-impl/participant-impl-dcae/src/test')
16 files changed, 380 insertions, 516 deletions
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java index 6d7592db0..46317729a 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java @@ -48,7 +48,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 PartecipantDcaeTest { private static final CommInfrastructure INFRA = CommInfrastructure.NOOP; diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClientTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClientTest.java index 6e375222e..f730f36f4 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClientTest.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClientTest.java @@ -60,9 +60,7 @@ class ClampHttpClientTest { public static void setUp() { CommonTestData commonTestData = new CommonTestData(); - parameters = commonTestData.toObject( - commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME), - ParticipantDcaeParameters.class); + parameters = commonTestData.getParticipantDcaeParameters(); mockServer = ClientAndServer.startClientAndServer(parameters.getClampClientParameters().getPort()); diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ConsulDcaeHttpClientTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ConsulDcaeHttpClientTest.java index 734919e4c..5155fed1d 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ConsulDcaeHttpClientTest.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ConsulDcaeHttpClientTest.java @@ -48,9 +48,7 @@ class ConsulDcaeHttpClientTest { public static void startServer() { CommonTestData commonTestData = new CommonTestData(); - parameters = commonTestData.toObject( - commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME), - ParticipantDcaeParameters.class); + parameters = commonTestData.getParticipantDcaeParameters(); mockServer = ClientAndServer.startClientAndServer(parameters.getConsulClientParameters().getPort()); diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java new file mode 100644 index 000000000..ab181d476 --- /dev/null +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java @@ -0,0 +1,144 @@ +/*- + * ============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.dcae.main.handler; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.UUID; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; +import org.onap.policy.clamp.controlloop.participant.dcae.httpclient.ClampHttpClient; +import org.onap.policy.clamp.controlloop.participant.dcae.httpclient.ConsulDcaeHttpClient; +import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.CommonTestData; +import org.onap.policy.clamp.controlloop.participant.dcae.model.Loop; +import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +/** + * Class to perform unit test of {@link ControlLoopElementHandler}. + * + */ +@ExtendWith(SpringExtension.class) +class ControlLoopElementHandlerTest { + + private static final String LOOP = "pmsh_loop"; + private static final String TEMPLATE = "LOOP_TEMPLATE_k8s_pmsh"; + private static final String BLUEPRINT_DEPLOYED = "BLUEPRINT_DEPLOYED"; + private static final String MICROSERVICE_INSTALLED_SUCCESSFULLY = "MICROSERVICE_INSTALLED_SUCCESSFULLY"; + + public static final Coder CODER = new StandardCoder(); + private CommonTestData commonTestData = new CommonTestData(); + + @Test + void test_ControlLoopElementStateChange() { + ClampHttpClient clampClient = spy(mock(ClampHttpClient.class)); + ConsulDcaeHttpClient consulClient = mock(ConsulDcaeHttpClient.class); + ControlLoopElementHandler controlLoopElementHandler = + new ControlLoopElementHandler(clampClient, consulClient, commonTestData.getParticipantDcaeParameters()); + + when(clampClient.getstatus(eq(LOOP))).thenReturn(new Loop()); + + ParticipantIntermediaryApi intermediaryApi = mock(ParticipantIntermediaryApi.class); + controlLoopElementHandler.setIntermediaryApi(intermediaryApi); + + controlLoopElementHandler.controlLoopElementStateChange(UUID.randomUUID(), ControlLoopState.PASSIVE, + ControlLoopOrderedState.UNINITIALISED); + + verify(clampClient).undeploy(eq(LOOP)); + } + + @Test + void testCreate_ControlLoopElementUpdate() throws PfModelException, JSONException, CoderException { + ClampHttpClient clampClient = spy(mock(ClampHttpClient.class)); + Loop loopDeployed = CODER.convert(CommonTestData.createJsonStatus(BLUEPRINT_DEPLOYED), Loop.class); + when(clampClient.create(eq(LOOP), eq(TEMPLATE))).thenReturn(loopDeployed); + when(clampClient.deploy(eq(LOOP))).thenReturn(true); + + Loop loopInstalled = + CODER.convert(CommonTestData.createJsonStatus(MICROSERVICE_INSTALLED_SUCCESSFULLY), Loop.class); + when(clampClient.getstatus(eq(LOOP))).thenReturn(null, loopInstalled); + + ConsulDcaeHttpClient consulClient = spy(mock(ConsulDcaeHttpClient.class)); + when(consulClient.deploy(any(String.class), any(String.class))).thenReturn(true); + + ControlLoopElementHandler controlLoopElementHandler = + new ControlLoopElementHandler(clampClient, consulClient, commonTestData.getParticipantDcaeParameters()); + + ParticipantIntermediaryApi intermediaryApi = mock(ParticipantIntermediaryApi.class); + controlLoopElementHandler.setIntermediaryApi(intermediaryApi); + + ControlLoopElement element = new ControlLoopElement(); + element.setId(UUID.randomUUID()); + element.setOrderedState(ControlLoopOrderedState.PASSIVE); + + final ToscaServiceTemplate controlLoopDefinition = new ToscaServiceTemplate(); + controlLoopElementHandler.controlLoopElementUpdate(element, controlLoopDefinition); + + verify(clampClient).create(eq(LOOP), eq(TEMPLATE)); + verify(consulClient).deploy(any(String.class), any(String.class)); + verify(clampClient).deploy(eq(LOOP)); + } + + @Test + void test_ControlLoopElementUpdate() throws PfModelException, JSONException, CoderException { + ClampHttpClient clampClient = spy(mock(ClampHttpClient.class)); + Loop loopDeployed = CODER.convert(CommonTestData.createJsonStatus(BLUEPRINT_DEPLOYED), Loop.class); + Loop loopInstalled = + CODER.convert(CommonTestData.createJsonStatus(MICROSERVICE_INSTALLED_SUCCESSFULLY), Loop.class); + when(clampClient.getstatus(eq(LOOP))).thenReturn(loopDeployed, loopInstalled); + when(clampClient.deploy(eq(LOOP))).thenReturn(true); + + ConsulDcaeHttpClient consulClient = spy(mock(ConsulDcaeHttpClient.class)); + when(consulClient.deploy(any(String.class), any(String.class))).thenReturn(true); + + ControlLoopElementHandler controlLoopElementHandler = + new ControlLoopElementHandler(clampClient, consulClient, commonTestData.getParticipantDcaeParameters()); + + ParticipantIntermediaryApi intermediaryApi = mock(ParticipantIntermediaryApi.class); + controlLoopElementHandler.setIntermediaryApi(intermediaryApi); + + ControlLoopElement element = new ControlLoopElement(); + element.setId(UUID.randomUUID()); + element.setOrderedState(ControlLoopOrderedState.PASSIVE); + + ToscaServiceTemplate controlLoopDefinition = new ToscaServiceTemplate(); + controlLoopElementHandler.controlLoopElementUpdate(element, controlLoopDefinition); + + verify(clampClient, times(0)).create(eq(LOOP), eq(TEMPLATE)); + verify(consulClient).deploy(any(String.class), any(String.class)); + verify(clampClient).deploy(eq(LOOP)); + } +} diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java index 5d8881eb3..4b6dcd619 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java @@ -31,7 +31,6 @@ import java.util.TreeMap; import javax.ws.rs.core.Response; 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; @@ -54,24 +53,19 @@ public class CommonTestData { private static final boolean REST_CONSUL_HTTPS = false; private static final boolean REST_CLIENT_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 ParticipantDcaeParameters. * - * @param <T> specific type of ParameterGroup class - * @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 errors + * @return ParticipantDcaeParameters */ - public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) { + public ParticipantDcaeParameters getParticipantDcaeParameters() { try { - return coder.convert(source, clazz); - + return CODER.convert(getParticipantParameterGroupMap(PARTICIPANT_GROUP_NAME), + ParticipantDcaeParameters.class); } catch (final CoderException e) { - throw new ControlLoopRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, - "cannot create " + clazz.getName() + " from map", e); + throw new RuntimeException("cannot create ParticipantDcaeParameters from map", e); } } @@ -86,10 +80,31 @@ public class CommonTestData { final Map<String, Object> map = new TreeMap<>(); map.put("name", name); + map.put("checkCount", 10); + map.put("secCount", 10); + map.put("jsonBodyConsulPath", "src/main/resources/parameters/consul.json"); map.put("clampClientParameters", getClampClientParametersMap(false)); map.put("consulClientParameters", getConsulClientParametersMap(false)); map.put("intermediaryParameters", getIntermediaryParametersMap(false)); - map.put("databaseProviderParameters", getDatabaseProviderParametersMap(false)); + map.put("clampClientEndPoints", getClampClientEndPoints()); + map.put("consulClientEndPoints", getConsulClientEndPoints()); + return map; + } + + private Map<String, Object> getConsulClientEndPoints() { + final Map<String, Object> map = new TreeMap<>(); + map.put("deploy", "/v1/kv/dcae-pmsh:"); + return map; + } + + private Map<String, Object> getClampClientEndPoints() { + final Map<String, Object> map = new TreeMap<>(); + map.put("status", "/restservices/clds/v2/loop/getstatus/"); + map.put("create", "/restservices/clds/v2/loop/create/%s?templateName=%s"); + map.put("deploy", "/restservices/clds/v2/loop/deploy/"); + map.put("stop", "/restservices/clds/v2/loop/stop/"); + map.put("delete", "/restservices/clds/v2/loop/delete/"); + map.put("undeploy", "/restservices/clds/v2/loop/undeploy/"); return map; } @@ -148,27 +163,6 @@ public class CommonTestData { } /** - * 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<String, Object> getDatabaseProviderParametersMap(final boolean isEmpty) { - 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"); - } - - return map; - } - - /** * Returns a property map for a intermediaryParameters map for test cases. * * @param isEmpty boolean value to represent that object created should be empty or not @@ -229,58 +223,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 errors - */ - public ParticipantDcaeParameters getParticipantParameterGroup(int port) { - try { - return coder.decode(getParticipantParameterGroupAsString(port), ParticipantDcaeParameters.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 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() { - return "src/test/resources/parameters/TestParametersStd.json"; - } - - /** * Nulls out a field within a JSON string. * * @param json JSON string diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParametersTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParametersTest.java new file mode 100644 index 000000000..b59cee756 --- /dev/null +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParametersTest.java @@ -0,0 +1,163 @@ +/*- + * ============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.dcae.main.parameters; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.validation.Validation; +import javax.validation.ValidatorFactory; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; +import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters; + +/** + * Class to perform unit test of {@link ParticipantDcaeParameters}. + * It will be tested the "javax.validation.constraints" + * + */ +class ParticipantDcaeParametersTest { + private CommonTestData commonTestData = new CommonTestData(); + private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); + + @Test + void testParticipantDcaeParameters() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isEmpty(); + } + + @Test + void testZeroCheckCount() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.setCheckCount(0); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoClampClientEndPoints() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.setClampClientEndPoints(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoClampClientEndPointCreate() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.getClampClientEndPoints().setCreate(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoClampClientEndPointDelete() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.getClampClientEndPoints().setDelete(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoClampClientEndPointDeploy() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.getClampClientEndPoints().setDeploy(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoClampClientEndPointStatus() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.getClampClientEndPoints().setStatus(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoClampClientEndPointStop() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.getClampClientEndPoints().setStop(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoClampClientEndPointUndeploy() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.getClampClientEndPoints().setUndeploy(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoClampClientParameters() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.setClampClientParameters(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoHostname() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.getClampClientParameters().setHostname(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoTopicSinks() throws ControlLoopException { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + + ParticipantIntermediaryParameters intermediaryParameters = participantParameters.getIntermediaryParameters(); + intermediaryParameters.getClampControlLoopTopics().setTopicSinks(null); + + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoTopicSources() throws ControlLoopException { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + + ParticipantIntermediaryParameters intermediaryParameters = participantParameters.getIntermediaryParameters(); + intermediaryParameters.getClampControlLoopTopics().setTopicSources(null); + + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoConsulClientParameters() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.setConsulClientParameters(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoConsulHostname() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.getConsulClientParameters().setHostname(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoIntermediaryParameters() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.setIntermediaryParameters(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } + + @Test + void testNoParticipantId() { + final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters(); + participantParameters.getIntermediaryParameters().setParticipantId(null); + assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty(); + } +} diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameterHandler.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameterHandler.java deleted file mode 100644 index 2eb833204..000000000 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameterHandler.java +++ /dev/null @@ -1,64 +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.dcae.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 to perform unit test of {@link ParticipantParameterHandler}. - * - */ -class TestParticipantDcaeParameterHandler { - - @Test - void testParameterHandlerNoParameterFile() throws ControlLoopException { - final String path = "src/test/resources/parameters/NoParametersFile.json"; - - assertThatThrownBy(() -> new ParticipantDcaeParameterHandler().toParticipantDcaeParameters(path)) - .hasCauseInstanceOf(CoderException.class) - .hasRootCauseInstanceOf(FileNotFoundException.class); - } - - @Test - void testParameterHandlerInvalidParameters() throws ControlLoopException { - final String path = "src/test/resources/parameters/InvalidParameters.json"; - - assertThatThrownBy(() -> new ParticipantDcaeParameterHandler().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 ParticipantDcaeParameters parGroup = new ParticipantDcaeParameterHandler() - .toParticipantDcaeParameters(path); - assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, parGroup.getName()); - } -} diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameters.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameters.java deleted file mode 100644 index 2320ae07b..000000000 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameters.java +++ /dev/null @@ -1,88 +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.dcae.main.parameters; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.Map; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters; -import org.onap.policy.common.endpoints.parameters.TopicParameterGroup; -import org.onap.policy.common.parameters.ValidationResult; - -/** - * Class to perform unit test of {@link ParticipantParameterGroup}. - * - */ -class TestParticipantDcaeParameters { - CommonTestData commonTestData = new CommonTestData(); - - @Test - void testParticipantParameterGroup_Named() { - final ParticipantDcaeParameters participantParameters = new ParticipantDcaeParameters("my-name"); - assertEquals("my-name", participantParameters.getName()); - } - - @Test - void testParticipantParameterGroup() { - final ParticipantDcaeParameters participantParameters = commonTestData.toObject( - commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME), - ParticipantDcaeParameters.class); - final ParticipantIntermediaryParameters participantIntermediaryParameters = participantParameters - .getIntermediaryParameters(); - final TopicParameterGroup topicParameterGroup = participantParameters.getIntermediaryParameters() - .getClampControlLoopTopics(); - final ValidationResult validationResult = participantParameters.validate(); - assertTrue(validationResult.isValid()); - assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, participantParameters.getName()); - assertEquals(CommonTestData.TIME_INTERVAL, participantIntermediaryParameters.getReportingTimeInterval()); - assertEquals(CommonTestData.DESCRIPTION, participantIntermediaryParameters.getDescription()); - assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks()); - assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources()); - } - - @Test - void testParticipantParameterGroup_EmptyParticipantIntermediaryParameters() { - final Map<String, Object> map = - commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME); - map.replace("intermediaryParameters", commonTestData.getIntermediaryParametersMap(true)); - final ParticipantDcaeParameters participantParameters = - commonTestData.toObject(map, ParticipantDcaeParameters.class); - final ValidationResult validationResult = participantParameters.validate(); - assertNull(validationResult.getResult()); - } - - @Test - void testParticipantParameterGroup_EmptyTopicParameters() { - final Map<String, Object> map = - commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME); - final Map<String, Object> intermediaryParametersMap = commonTestData.getIntermediaryParametersMap(false); - intermediaryParametersMap.put("clampControlLoopTopics", commonTestData.getTopicParametersMap(true)); - map.replace("intermediaryParameters", intermediaryParametersMap); - - final ParticipantDcaeParameters participantParameters = - commonTestData.toObject(map, ParticipantDcaeParameters.class); - final ValidationResult validationResult = participantParameters.validate(); - assertNull(validationResult.getResult()); - } -} diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java index f414b7a10..0b2712b7a 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java @@ -34,7 +34,6 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange; -import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.CommonTestData; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -49,7 +48,6 @@ public class TestListenerUtils { private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); private static final Coder CODER = new StandardCoder(); private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml"; - static CommonTestData commonTestData = new CommonTestData(); /** * Method to create a controlLoop from a yaml file. diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/application_test.properties b/participant/participant-impl/participant-impl-dcae/src/test/resources/application_test.properties new file mode 100644 index 000000000..d585dd3c9 --- /dev/null +++ b/participant/participant-impl/participant-impl-dcae/src/test/resources/application_test.properties @@ -0,0 +1,41 @@ +spring.security.user.name=healthcheck +spring.security.user.password=zb!XztG34 + +server.servlet.context-path=/onap/participantsim +server.error.path=/error + +participant.name=ControlLoopParticipant Dcae Test +participant.clampClientParameters.clientName=Clamp +participant.clampClientParameters.hostname=0.0.0.0 +participant.clampClientParameters.port=8443 +participant.clampClientParameters.userName=admin +participant.clampClientParameters.password=password +participant.clampClientParameters.https=true +participant.clampClientParameters.aaf=false +participant.consulClientParameters.clientName=Consul +participant.consulClientParameters.hostname=consul +participant.consulClientParameters.port=31321 +participant.consulClientParameters.userName=admin +participant.consulClientParameters.password=password +participant.consulClientParameters.https=false +participant.consulClientParameters.aaf=false +participant.intermediaryParameters.name=Participant parameters +participant.intermediaryParameters.reportingTimeInterval=120000 +participant.intermediaryParameters.description=Participant Description +participant.intermediaryParameters.participantId.name=DCAEParticipant0 +participant.intermediaryParameters.participantId.version=1.0.0 +participant.intermediaryParameters.participantType.name=org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant +participant.intermediaryParameters.participantType.version=2.3.4 +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 + +participant.checkCount=10 diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/InvalidParameters.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/InvalidParameters.json deleted file mode 100644 index 1035ccb67..000000000 --- a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/InvalidParameters.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": " -} diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/MinimumParametersH2.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/MinimumParametersH2.json deleted file mode 100644 index 1ee2955b9..000000000 --- a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/MinimumParametersH2.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": "DCAEParticipant0", - "version": "1.0.0" - }, - "participantType": { - "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", - "version": "2.3.4" - }, - "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-dcae/src/test/resources/parameters/NoParameters.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/NoParameters.json deleted file mode 100644 index 7a73a41bf..000000000 --- a/participant/participant-impl/participant-impl-dcae/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-dcae/src/test/resources/parameters/TestParameters.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParameters.json deleted file mode 100644 index 580eea734..000000000 --- a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParameters.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "ControlLoopParticipantGroup", - "clampClientParameters": { - "clientName": "Clamp", - "hostname": "0.0.0.0", - "port": 8443, - "userName": "admin", - "password": "password", - "useHttps": true, - "allowSelfSignedCerts": false - }, - "consulClientParameters": { - "clientName": "Consul", - "hostname": "consul", - "port": 31321, - "userName": "admin", - "password": "password", - "useHttps": false - }, - "intermediaryParameters": { - "name": "Participant parameters", - "reportingTimeInterval": 120000, - "description": "Participant Description", - "participantId": { - "name": "DCAEParticipant0", - "version": "1.0.0" - }, - "participantType": { - "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", - "version": "2.3.4" - }, - "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-dcae/src/test/resources/parameters/TestParametersStd.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParametersStd.json deleted file mode 100644 index 789fc7bbd..000000000 --- a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParametersStd.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "name": "ControlLoopParticipantGroup", - "clampClientParameters": { - "name": "Clamp", - "host": "0.0.0.0", - "port": 8443, - "userName": "admin", - "password": "password", - "https": true, - "aaf": false - }, - "consulClientParameters": { - "name": "Clamp", - "host": "consul", - "port": 31321, - "userName": "admin", - "password": "password", - "https": false, - "aaf": false - }, - "intermediaryParameters": { - "name": "Participant parameters", - "reportingTimeInterval": 120000, - "description": "Participant Description", - "participantId": { - "name": "DCAEParticipant0", - "version": "1.0.0" - }, - "participantType": { - "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", - "version": "2.3.4" - }, - "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-dcae/src/test/resources/parameters/Unreadable.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/Unreadable.json deleted file mode 100644 index b918defe4..000000000 --- a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/Unreadable.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "ControlLoopRuntimeGroup", - "restServerParameters": { - "host": "0.0.0.0", - "port": ${port}, - "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": "${dbName}", - "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" - } - ] - } -} - - |