diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2022-10-26 14:34:46 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2022-10-27 12:53:12 +0100 |
commit | 9082093f00a3f21b2f824251c5ce60b775ad312c (patch) | |
tree | 3c7321f71bc742982a5011012d140c4beebde1db /runtime-acm/src/test | |
parent | 75a69e67d03a55d3961d0f6a9f7925868dd39aa6 (diff) |
Remove old implementation of statistics in ACM-runtime
The old implementation of statistics in ACM-runtime
can be removed due the Prometheus metrics support.
Issue-ID: POLICY-4419
Change-Id: Idecad04b4a5dd32ce2ebc1149eb99e4fdc6f0db1
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/test')
4 files changed, 15 insertions, 584 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/monitoring/TestMonitoringProvider.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/monitoring/TestMonitoringProvider.java deleted file mode 100644 index 9dc77e793..000000000 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/monitoring/TestMonitoringProvider.java +++ /dev/null @@ -1,314 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.acm.runtime.monitoring; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyMap; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.time.Instant; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import javax.ws.rs.core.Response; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import org.onap.policy.clamp.models.acm.concepts.AcElementStatisticsList; -import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.ParticipantStatisticsList; -import org.onap.policy.clamp.models.acm.persistence.provider.AcElementStatisticsProvider; -import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; -import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantStatisticsProvider; -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.PfModelRuntimeException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class TestMonitoringProvider { - - private static final String AC_PARTICIPANT_STATISTICS_JSON = - "src/test/resources/rest/monitoring/TestParticipantStatistics.json"; - private static final String INVALID_PARTICIPANT_JSON_INPUT = - "src/test/resources/rest/monitoring/TestParticipantStatistics_Invalid.json"; - private static final String AC_ELEMENT_STATISTICS_JSON = - "src/test/resources/rest/monitoring/TestAcElementStatistics.json"; - private static final String INVALID_AC_ELEMENT_JSON_INPUT = - "src/test/resources/rest/monitoring/TestAcElementStatistics_Invalid.json"; - private static final Coder CODER = new StandardCoder(); - - private static final String STAT_LIST_IS_NULL = ".*StatisticsList is marked .*ull but is null"; - private static final String PARTICIPANT_STAT_LIST_IS_NULL = - "participantStatisticsList is marked .*null but is null"; - private static final String NAME_IS_NULL = "name is marked .*null but is null"; - private static final String AC_LIST_IS_NULL = "acElementStatisticsList is marked .*null but is null"; - private static final String ID_VERSION1 = "1.001"; - private static final String ID_VERSION2 = "1.002"; - private static final String ID_NAME1 = "name1"; - private static final String ID_NAME2 = "name2"; - private static final String SORT_DESC = "DESC"; - private static final String ID_NAME3 = "testACName"; - private static final String ID_INVALID_NAME = "invalidACName"; - private static ParticipantStatisticsList inputParticipantStatistics; - private static ParticipantStatisticsList invalidParticipantInput; - private static AcElementStatisticsList inputAcElementStatistics; - private static AcElementStatisticsList invalidAcElementInput; - - @BeforeAll - public static void beforeSetupStatistics() throws CoderException { - // Reading input json for statistics data - inputParticipantStatistics = - CODER.decode(new File(AC_PARTICIPANT_STATISTICS_JSON), ParticipantStatisticsList.class); - invalidParticipantInput = - CODER.decode(new File(INVALID_PARTICIPANT_JSON_INPUT), ParticipantStatisticsList.class); - inputAcElementStatistics = CODER.decode(new File(AC_ELEMENT_STATISTICS_JSON), AcElementStatisticsList.class); - invalidAcElementInput = CODER.decode(new File(INVALID_AC_ELEMENT_JSON_INPUT), AcElementStatisticsList.class); - } - - @Test - void testCreateParticipantStatistics() throws Exception { - var participantStatisticsProvider = mock(ParticipantStatisticsProvider.class); - var acElementStatisticsProvider = mock(AcElementStatisticsProvider.class); - var acProvider = mock(AutomationCompositionProvider.class); - MonitoringProvider provider = - new MonitoringProvider(participantStatisticsProvider, acElementStatisticsProvider, acProvider); - - when(participantStatisticsProvider.createParticipantStatistics(any())) - .thenReturn(inputParticipantStatistics.getStatisticsList()); - - when(participantStatisticsProvider.createParticipantStatistics(eq(null))) - .thenThrow(new PfModelRuntimeException(Response.Status.BAD_REQUEST, PARTICIPANT_STAT_LIST_IS_NULL)); - - // Creating statistics data in db with null input - - assertThatThrownBy(() -> provider.createParticipantStatistics(null)).hasMessageMatching(STAT_LIST_IS_NULL); - - assertThatThrownBy(() -> provider.createParticipantStatistics(invalidParticipantInput.getStatisticsList())) - .hasMessageMatching(PARTICIPANT_STAT_LIST_IS_NULL); - - // Creating statistics data from input json - ParticipantStatisticsList createResponse = - provider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList()); - - assertThat(createResponse.getStatisticsList()).hasSize(3); - assertEquals(createResponse.getStatisticsList().toString().replaceAll("\\s+", ""), - inputParticipantStatistics.getStatisticsList().toString().replaceAll("\\s+", "")); - } - - @Test - void testGetParticipantStatistics() throws Exception { - var participantStatisticsProvider = mock(ParticipantStatisticsProvider.class); - when(participantStatisticsProvider.getFilteredParticipantStatistics(eq(ID_NAME1), any(), any(), any(), eq(null), - eq(SORT_DESC), eq(0))).thenReturn(List.of(inputParticipantStatistics.getStatisticsList().get(0))); - - when(participantStatisticsProvider.getFilteredParticipantStatistics(eq(ID_NAME1), any(), - eq(Instant.parse("2021-01-11T12:00:00.000Z")), eq(Instant.parse("2021-01-11T16:00:00.000Z")), eq(null), - eq(SORT_DESC), eq(0))).thenReturn(List.of()); - - when(participantStatisticsProvider.getFilteredParticipantStatistics(eq(ID_NAME2), any(), any(), any(), eq(null), - eq(SORT_DESC), eq(1))).thenReturn(List.of(inputParticipantStatistics.getStatisticsList().get(2))); - - var acProvider = mock(AutomationCompositionProvider.class); - var acElementStatisticsProvider = mock(AcElementStatisticsProvider.class); - MonitoringProvider provider = - new MonitoringProvider(participantStatisticsProvider, acElementStatisticsProvider, acProvider); - provider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList()); - - assertThatThrownBy(() -> provider.fetchFilteredParticipantStatistics(null, null, 0, null, null)) - .hasMessageMatching(NAME_IS_NULL); - - // Fetch specific statistics record with name, version and record count - ParticipantStatisticsList getResponse = - provider.fetchFilteredParticipantStatistics(ID_NAME2, ID_VERSION1, 1, null, null); - assertThat(getResponse.getStatisticsList()).hasSize(1); - assertEquals(getResponse.getStatisticsList().get(0).toString().replaceAll("\\s+", ""), - inputParticipantStatistics.getStatisticsList().get(2).toString().replaceAll("\\s+", "")); - - // Fetch statistics using timestamp - getResponse = provider.fetchFilteredParticipantStatistics(ID_NAME1, ID_VERSION1, 0, null, - Instant.parse("2021-01-10T15:00:00.000Z")); - assertThat(getResponse.getStatisticsList()).hasSize(1); - - getResponse = provider.fetchFilteredParticipantStatistics(ID_NAME1, ID_VERSION1, 0, - Instant.parse("2021-01-11T12:00:00.000Z"), Instant.parse("2021-01-11T16:00:00.000Z")); - - assertThat(getResponse.getStatisticsList()).isEmpty(); - } - - @Test - void testCreateAcElementStatistics() throws Exception { - var acElementStatisticsProvider = mock(AcElementStatisticsProvider.class); - when(acElementStatisticsProvider.createAcElementStatistics(any())) - .thenReturn(inputAcElementStatistics.getAcElementStatistics()); - - when(acElementStatisticsProvider.createAcElementStatistics(eq(null))) - .thenThrow(new PfModelRuntimeException(Response.Status.BAD_REQUEST, AC_LIST_IS_NULL)); - - var acProvider = mock(AutomationCompositionProvider.class); - - var participantStatisticsProvider = mock(ParticipantStatisticsProvider.class); - MonitoringProvider provider = - new MonitoringProvider(participantStatisticsProvider, acElementStatisticsProvider, acProvider); - // Creating statistics data in db with null input - assertThatThrownBy(() -> provider.createAcElementStatistics(null)).hasMessageMatching(STAT_LIST_IS_NULL); - - assertThatThrownBy(() -> provider.createAcElementStatistics(invalidAcElementInput.getAcElementStatistics())) - .hasMessageMatching(AC_LIST_IS_NULL); - - // Creating acElement statistics data from input json - AcElementStatisticsList createResponse = - provider.createAcElementStatistics(inputAcElementStatistics.getAcElementStatistics()); - - assertThat(createResponse.getAcElementStatistics()).hasSize(4); - assertEquals(createResponse.getAcElementStatistics().toString().replaceAll("\\s+", ""), - inputAcElementStatistics.getAcElementStatistics().toString().replaceAll("\\s+", "")); - } - - @Test - void testGetAcElementStatistics() throws Exception { - var participantStatisticsProvider = mock(ParticipantStatisticsProvider.class); - var acElementStatisticsProvider = mock(AcElementStatisticsProvider.class); - var acProvider = mock(AutomationCompositionProvider.class); - - when(acElementStatisticsProvider.getFilteredAcElementStatistics(eq(ID_NAME1), any(), any(), any(), anyMap(), - eq(SORT_DESC), eq(0))) - .thenReturn(List.of(inputAcElementStatistics.getAcElementStatistics().get(0), - inputAcElementStatistics.getAcElementStatistics().get(1))); - - when(acElementStatisticsProvider.getFilteredAcElementStatistics(eq(ID_NAME1), any(), any(), any(), anyMap(), - eq(SORT_DESC), eq(0))) - .thenReturn(List.of(inputAcElementStatistics.getAcElementStatistics().get(0), - inputAcElementStatistics.getAcElementStatistics().get(1))); - - MonitoringProvider provider = - new MonitoringProvider(participantStatisticsProvider, acElementStatisticsProvider, acProvider); - assertThatThrownBy(() -> provider - .fetchFilteredAcElementStatistics(null, null, null, null, null, 0)) - .hasMessageMatching(NAME_IS_NULL); - - provider.createAcElementStatistics(inputAcElementStatistics.getAcElementStatistics()); - - AcElementStatisticsList getResponse = - provider.fetchFilteredAcElementStatistics(ID_NAME1, null, null, null, null, 0); - - assertThat(getResponse.getAcElementStatistics()).hasSize(2); - assertEquals(getResponse.getAcElementStatistics().get(0).toString().replaceAll("\\s+", ""), - inputAcElementStatistics.getAcElementStatistics().get(0).toString().replaceAll("\\s+", "")); - - // Fetch specific statistics record with name, id and record count - getResponse = provider.fetchFilteredAcElementStatistics(ID_NAME1, ID_VERSION1, - "709c62b3-8918-41b9-a747-d21eb79c6c20", null, null, 0); - assertThat(getResponse.getAcElementStatistics()).hasSize(2); - - // Fetch statistics using timestamp - getResponse = provider.fetchFilteredAcElementStatistics(ID_NAME1, ID_VERSION1, null, - Instant.parse("2021-01-10T13:45:00.000Z"), null, 0); - assertThat(getResponse.getAcElementStatistics()).hasSize(2); - } - - @Test - void testGetParticipantStatsPerAc() throws Exception { - var participantStatisticsProvider = mock(ParticipantStatisticsProvider.class); - var acElementStatisticsProvider = mock(AcElementStatisticsProvider.class); - var mockAcProvider = Mockito.mock(AutomationCompositionProvider.class); - var provider = - new MonitoringProvider(participantStatisticsProvider, acElementStatisticsProvider, mockAcProvider); - - provider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList()); - - var automationComposition = new AutomationComposition(); - var element = new AutomationCompositionElement(); - element.setParticipantId(new ToscaConceptIdentifier(ID_NAME1, ID_VERSION1)); - automationComposition.setElements(Map.of(UUID.randomUUID(), element)); - when(mockAcProvider.findAutomationComposition(new ToscaConceptIdentifier(ID_NAME2, ID_VERSION1))) - .thenReturn(Optional.of(automationComposition)); - - when(participantStatisticsProvider.getFilteredParticipantStatistics(eq(ID_NAME1), eq(ID_VERSION1), any(), any(), - eq(null), eq(SORT_DESC), eq(0))) - .thenReturn(List.of(inputParticipantStatistics.getStatisticsList().get(0), - inputParticipantStatistics.getStatisticsList().get(1))); - - ParticipantStatisticsList getResponse = - provider.fetchParticipantStatsPerAutomationComposition(ID_NAME2, ID_VERSION1); - assertThat(getResponse.getStatisticsList()).hasSize(2); - assertEquals(getResponse.getStatisticsList().get(0).toString().replaceAll("\\s+", ""), - inputParticipantStatistics.getStatisticsList().get(0).toString().replaceAll("\\s+", "")); - assertThat( - provider.fetchParticipantStatsPerAutomationComposition(ID_INVALID_NAME, ID_VERSION2).getStatisticsList()) - .isEmpty(); - } - - @Test - void testAcElementStatsPerAc() throws Exception { - // Setup a dummy automation composition data - var mockAcElement = new AutomationCompositionElement(); - mockAcElement.setId(inputAcElementStatistics.getAcElementStatistics().get(0).getId()); - mockAcElement.setParticipantId(new ToscaConceptIdentifier( - inputAcElementStatistics.getAcElementStatistics().get(0).getParticipantId().getName(), - inputAcElementStatistics.getAcElementStatistics().get(0).getParticipantId().getVersion())); - var mockAc = new AutomationComposition(); - mockAc.setElements(new LinkedHashMap<>()); - mockAc.getElements().put(mockAcElement.getId(), mockAcElement); - - var participantStatisticsProvider = mock(ParticipantStatisticsProvider.class); - var acElementStatisticsProvider = mock(AcElementStatisticsProvider.class); - var mockAcProvider = Mockito.mock(AutomationCompositionProvider.class); - var monitoringProvider = - new MonitoringProvider(participantStatisticsProvider, acElementStatisticsProvider, mockAcProvider); - - // Mock automation composition data to be returned for the given AC Id - when(mockAcProvider.findAutomationComposition(new ToscaConceptIdentifier(ID_NAME3, ID_VERSION1))) - .thenReturn(Optional.of(mockAc)); - - when(acElementStatisticsProvider.getFilteredAcElementStatistics(eq(ID_NAME1), eq(ID_VERSION1), any(), any(), - anyMap(), eq(SORT_DESC), eq(0))) - .thenReturn(List.of(inputAcElementStatistics.getAcElementStatistics().get(0), - inputAcElementStatistics.getAcElementStatistics().get(1))); - - monitoringProvider.createAcElementStatistics(inputAcElementStatistics.getAcElementStatistics()); - - AcElementStatisticsList getResponse = - monitoringProvider.fetchAcElementStatsPerAutomationComposition(ID_NAME3, ID_VERSION1); - - assertThat(getResponse.getAcElementStatistics()).hasSize(2); - assertEquals(getResponse.getAcElementStatistics().get(1).toString().replaceAll("\\s+", ""), - inputAcElementStatistics.getAcElementStatistics().get(1).toString().replaceAll("\\s+", "")); - - assertThat(monitoringProvider.fetchAcElementStatsPerAutomationComposition(ID_INVALID_NAME, ID_VERSION2) - .getAcElementStatistics()).isEmpty(); - - Map<String, ToscaConceptIdentifier> acElementIds = - monitoringProvider.getAllAcElementsIdPerAutomationComposition(ID_NAME3, ID_VERSION1); - assertThat(acElementIds) - .containsKey(inputAcElementStatistics.getAcElementStatistics().get(0).getId().toString()); - } -} diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/monitoring/rest/MonitoringQueryControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/monitoring/rest/MonitoringQueryControllerTest.java deleted file mode 100644 index e8a8ad0c9..000000000 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/monitoring/rest/MonitoringQueryControllerTest.java +++ /dev/null @@ -1,242 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 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.acm.runtime.monitoring.rest; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.io.File; -import java.time.Instant; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.Response; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.onap.policy.clamp.acm.runtime.monitoring.MonitoringProvider; -import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController; -import org.onap.policy.clamp.models.acm.concepts.AcElementStatisticsList; -import org.onap.policy.clamp.models.acm.concepts.ParticipantStatisticsList; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") -class MonitoringQueryControllerTest extends CommonRestController { - - private static final String AC_PARTICIPANT_STATISTICS_JSON = - "src/test/resources/rest/monitoring/TestParticipantStatistics.json"; - private static final String AC_ELEMENT_STATISTICS_JSON = - "src/test/resources/rest/monitoring/TestAcElementStatistics.json"; - - private static final Coder CODER = new StandardCoder(); - - private static ParticipantStatisticsList inputParticipantStatistics; - private static AcElementStatisticsList inputAcElementStatistics; - - private static ParticipantStatisticsList participantStatisticsList; - private static AcElementStatisticsList acElementStatisticsList; - - private static final String AC_ELEMENT_STATS_ENDPOINT = "monitoring/acelement"; - private static final String PARTICIPANT_STATS_ENDPOINT = "monitoring/participant"; - private static final String PARTICIPANT_STATS_PER_AC_ENDPOINT = "monitoring/participants/automationcomposition"; - private static final String AC_ELEMENT_STATS_PER_AC_ENDPOINT = "monitoring/acelements/automationcomposition"; - - @Autowired - private MonitoringProvider monitoringProvider; - - @LocalServerPort - private int randomServerPort; - - /** - * starts Main. - * - * @throws Exception if an error occurs - */ - @BeforeAll - public static void setUpBeforeAll() throws Exception { - - inputParticipantStatistics = - CODER.decode(new File(AC_PARTICIPANT_STATISTICS_JSON), ParticipantStatisticsList.class); - inputAcElementStatistics = CODER.decode(new File(AC_ELEMENT_STATISTICS_JSON), AcElementStatisticsList.class); - } - - @BeforeEach - public void setUpBeforeEach() throws Exception { - super.setHttpPrefix(randomServerPort); - - // Insert Participant statistics to DB - participantStatisticsList = - monitoringProvider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList()); - // Insert AC Element statistics to DB - acElementStatisticsList = - monitoringProvider.createAcElementStatistics(inputAcElementStatistics.getAcElementStatistics()); - } - - @Test - void testQuery_Unauthorized_for_AcElementStats() { - assertUnauthorizedGet(AC_ELEMENT_STATS_ENDPOINT); - } - - @Test - void testQuery_Unauthorized_for_AcParticipantStats() { - assertUnauthorizedGet(PARTICIPANT_STATS_ENDPOINT); - } - - @Test - void testQuery_Unauthorized_for_ParticipantStatsPerAc() { - assertUnauthorizedGet(PARTICIPANT_STATS_PER_AC_ENDPOINT); - } - - @Test - void testQuery_Unauthorized_for_AcElementStatsPerAc() { - assertUnauthorizedGet(AC_ELEMENT_STATS_PER_AC_ENDPOINT); - } - - @Test - void testSwagger_AcStats() { - super.testSwagger(AC_ELEMENT_STATS_ENDPOINT); - super.testSwagger(PARTICIPANT_STATS_ENDPOINT); - super.testSwagger(AC_ELEMENT_STATS_PER_AC_ENDPOINT); - super.testSwagger(PARTICIPANT_STATS_PER_AC_ENDPOINT); - } - - @Test - void testAcElementStatisticsEndpoint() { - // Filter statistics only based on participant Id and UUID - Invocation.Builder invokeRequest1 = super.sendRequest(AC_ELEMENT_STATS_ENDPOINT + "?name=" - + acElementStatisticsList.getAcElementStatistics().get(0).getParticipantId().getName() + "&version=" - + acElementStatisticsList.getAcElementStatistics().get(0).getParticipantId().getVersion() + "&id=" - + acElementStatisticsList.getAcElementStatistics().get(0).getId()); - Response response1 = invokeRequest1.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), response1.getStatus()); - - AcElementStatisticsList result1 = response1.readEntity(AcElementStatisticsList.class); - - assertNotNull(result1); - assertThat(result1.getAcElementStatistics()).hasSize(2); - - var acElementStat0 = acElementStatisticsList.getAcElementStatistics().get(0); - for (var acElement : result1.getAcElementStatistics()) { - assertEquals(acElement.getParticipantId().asConceptKey(), acElementStat0.getParticipantId().asConceptKey()); - assertEquals(acElement.getId(), acElementStat0.getId()); - } - - // Filter statistics based on timestamp - Invocation.Builder invokeRequest2 = super.sendRequest(AC_ELEMENT_STATS_ENDPOINT + "?name=" - + acElementStatisticsList.getAcElementStatistics().get(1).getParticipantId().getName() + "&version=" - + acElementStatisticsList.getAcElementStatistics().get(1).getParticipantId().getVersion() - + "&startTime=" + Instant.parse("2021-01-10T13:00:00.000Z") + "&endTime=" - + Instant.parse("2021-01-10T14:00:00.000Z")); - Response response2 = invokeRequest2.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), response2.getStatus()); - AcElementStatisticsList result2 = response2.readEntity(AcElementStatisticsList.class); - - assertNotNull(result2); - assertThat(result2.getAcElementStatistics()).hasSize(1); - assertEquals(result2.getAcElementStatistics().get(0), acElementStat0); - } - - @Test - void testAcElementStats_BadRequest() { - Invocation.Builder invokeRequest1 = super.sendRequest(AC_ELEMENT_STATS_ENDPOINT + "?version=1.0.0"); - Response response1 = invokeRequest1.buildGet().invoke(); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response1.getStatus()); - } - - @Test - void testParticipantStatisticsEndpoint() { - - // Filter statistics only based on participant Id - Invocation.Builder invokeRequest1 = super.sendRequest(PARTICIPANT_STATS_ENDPOINT + "?name=" - + participantStatisticsList.getStatisticsList().get(0).getParticipantId().getName() + "&version=" - + participantStatisticsList.getStatisticsList().get(0).getParticipantId().getVersion()); - Response response1 = invokeRequest1.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), response1.getStatus()); - ParticipantStatisticsList result1 = response1.readEntity(ParticipantStatisticsList.class); - - assertNotNull(result1); - assertThat(result1.getStatisticsList()).hasSize(2); - assertThat(result1.getStatisticsList()).contains(participantStatisticsList.getStatisticsList().get(0)); - - // Filter statistics based on timestamp - Invocation.Builder invokeRequest2 = super.sendRequest(PARTICIPANT_STATS_ENDPOINT + "?name=" - + participantStatisticsList.getStatisticsList().get(1).getParticipantId().getName() + "&version=" - + participantStatisticsList.getStatisticsList().get(1).getParticipantId().getVersion() + "&startTime=" - + Instant.parse("2021-01-10T13:00:00.000Z") + "&endTime=" + Instant.parse("2021-01-10T14:00:00.000Z")); - Response response2 = invokeRequest2.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), response2.getStatus()); - ParticipantStatisticsList result2 = response2.readEntity(ParticipantStatisticsList.class); - - assertNotNull(result2); - assertThat(result2.getStatisticsList()).hasSize(1); - assertEquals(result2.getStatisticsList().get(0), participantStatisticsList.getStatisticsList().get(0)); - } - - @Test - void testParticipantStats_BadRequest() { - Invocation.Builder invokeRequest1 = super.sendRequest(PARTICIPANT_STATS_ENDPOINT + "?version=0.0"); - Response response1 = invokeRequest1.buildGet().invoke(); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response1.getStatus()); - } - - @Test - void testParticipantStatsPerAcEndpoint() { - Invocation.Builder invokeRequest1 = - super.sendRequest(PARTICIPANT_STATS_PER_AC_ENDPOINT + "?name=dummyName&version=1.001"); - Response response1 = invokeRequest1.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), response1.getStatus()); - ParticipantStatisticsList result1 = response1.readEntity(ParticipantStatisticsList.class); - assertThat(result1.getStatisticsList()).isEmpty(); - } - - @Test - void testParticipantStatsPerAc_BadRequest() { - Invocation.Builder invokeRequest1 = super.sendRequest(PARTICIPANT_STATS_PER_AC_ENDPOINT); - Response response1 = invokeRequest1.buildGet().invoke(); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response1.getStatus()); - } - - @Test - void testAcElementStatisticsPerAcEndpoint() { - Invocation.Builder invokeRequest1 = - super.sendRequest(AC_ELEMENT_STATS_PER_AC_ENDPOINT + "?name=dummyName&version=1.001"); - Response response1 = invokeRequest1.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), response1.getStatus()); - AcElementStatisticsList result1 = response1.readEntity(AcElementStatisticsList.class); - assertThat(result1.getAcElementStatistics()).isEmpty(); - } - - @Test - void testAcElementStatsPerAc_BadRequest() { - Invocation.Builder invokeRequest1 = super.sendRequest(AC_ELEMENT_STATS_PER_AC_ENDPOINT); - Response response1 = invokeRequest1.buildGet().invoke(); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response1.getStatus()); - } -} diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java index a80d39ebc..7e9b102a8 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java @@ -22,7 +22,6 @@ package org.onap.policy.clamp.acm.runtime.supervision; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -37,7 +36,6 @@ import java.util.UUID; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; -import org.onap.policy.clamp.acm.runtime.monitoring.MonitoringProvider; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionUpdatePublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher; @@ -50,7 +48,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; -import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; @@ -87,7 +84,7 @@ class SupervisionHandlerTest { var automationCompositionProvider = mock(AutomationCompositionProvider.class); var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class); var handler = createSupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class), - mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), automationCompositionUpdatePublisher, mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); @@ -130,7 +127,7 @@ class SupervisionHandlerTest { var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var handler = new SupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class), - mock(MonitoringProvider.class), serviceTemplateProvider, mock(AutomationCompositionUpdatePublisher.class), + serviceTemplateProvider, mock(AutomationCompositionUpdatePublisher.class), automationCompositionStateChangePublisher, mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), mock(ParticipantUpdatePublisher.class)); @@ -170,7 +167,7 @@ class SupervisionHandlerTest { void testHandleAutomationCompositionStateChangeAckMessage() throws PfModelException, CoderException { var automationCompositionProvider = mock(AutomationCompositionProvider.class); var handler = createSupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class), - mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); @@ -194,7 +191,7 @@ class SupervisionHandlerTest { automationCompositionAckMessage.setAutomationCompositionId(identifier); var automationCompositionProvider = mock(AutomationCompositionProvider.class); var handler = createSupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class), - mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); @@ -221,7 +218,7 @@ class SupervisionHandlerTest { participantDeregisterMessage.setParticipantType(participantType); var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class); var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider, - mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher, mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); @@ -246,7 +243,7 @@ class SupervisionHandlerTest { var participantProvider = mock(ParticipantProvider.class); var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class); var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider, - mock(MonitoringProvider.class), participantRegisterAckPublisher, + participantRegisterAckPublisher, mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); @@ -274,7 +271,7 @@ class SupervisionHandlerTest { participantUpdateAckMessage.setParticipantType(participantType); participantUpdateAckMessage.setState(ParticipantState.PASSIVE); var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider, - mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); @@ -291,19 +288,16 @@ class SupervisionHandlerTest { participantStatusMessage.setParticipantType(participantType); participantStatusMessage.setState(ParticipantState.PASSIVE); participantStatusMessage.setHealthStatus(ParticipantHealthStatus.HEALTHY); - participantStatusMessage.setParticipantStatistics(new ParticipantStatistics()); var participantProvider = mock(ParticipantProvider.class); - var monitoringProvider = mock(MonitoringProvider.class); var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider, - monitoringProvider, mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); handler.handleParticipantMessage(participantStatusMessage); verify(participantProvider).saveParticipant(any()); - verify(monitoringProvider).createParticipantStatistics(anyList()); } @Test @@ -311,7 +305,7 @@ class SupervisionHandlerTest { var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class); var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), mock(ParticipantProvider.class), - mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class), participantUpdatePublisher, AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); @@ -326,7 +320,7 @@ class SupervisionHandlerTest { var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class); var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), mock(ParticipantProvider.class), - mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class), participantUpdatePublisher, AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); @@ -338,13 +332,13 @@ class SupervisionHandlerTest { private SupervisionHandler createSupervisionHandler(AutomationCompositionOrderedState orderedState, AutomationCompositionState state) throws PfModelException, CoderException { return createSupervisionHandler(mock(AutomationCompositionProvider.class), mock(ParticipantProvider.class), - mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class), orderedState, state); } private SupervisionHandler createSupervisionHandler(AutomationCompositionProvider automationCompositionProvider, - ParticipantProvider participantProvider, MonitoringProvider monitoringProvider, + ParticipantProvider participantProvider, ParticipantRegisterAckPublisher participantRegisterAckPublisher, ParticipantDeregisterAckPublisher participantDeregisterAckPublisher, AutomationCompositionUpdatePublisher automationCompositionUpdatePublisher, @@ -371,7 +365,7 @@ class SupervisionHandlerTest { var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); - return new SupervisionHandler(automationCompositionProvider, participantProvider, monitoringProvider, + return new SupervisionHandler(automationCompositionProvider, participantProvider, serviceTemplateProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher, participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java index 6545fe395..ad97201e2 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,7 +35,6 @@ import java.util.UUID; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import org.onap.policy.clamp.acm.runtime.monitoring.MonitoringProvider; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler; import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; @@ -44,10 +43,8 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDe import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck; -import org.onap.policy.clamp.models.acm.persistence.provider.AcElementStatisticsProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; -import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantStatisticsProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; @@ -70,10 +67,6 @@ class SupervisionMessagesTest extends CommonRestController { @BeforeAll public static void setupDbProviderParameters() throws PfModelException { var acProvider = mock(AutomationCompositionProvider.class); - var participantStatisticsProvider = mock(ParticipantStatisticsProvider.class); - var acElementStatisticsProvider = mock(AcElementStatisticsProvider.class); - var monitoringProvider = - new MonitoringProvider(participantStatisticsProvider, acElementStatisticsProvider, acProvider); var participantProvider = mock(ParticipantProvider.class); var serviceTemplateProvider = Mockito.mock(ServiceTemplateProvider.class); var automationCompositionUpdatePublisher = Mockito.mock(AutomationCompositionUpdatePublisher.class); @@ -81,7 +74,7 @@ class SupervisionMessagesTest extends CommonRestController { var participantRegisterAckPublisher = Mockito.mock(ParticipantRegisterAckPublisher.class); var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class); var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class); - supervisionHandler = new SupervisionHandler(acProvider, participantProvider, monitoringProvider, + supervisionHandler = new SupervisionHandler(acProvider, participantProvider, serviceTemplateProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher, participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher); } |