diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-01-17 10:54:33 +0000 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2023-01-17 11:06:12 +0000 |
commit | a991c1a124824e9976aecfc52c34148bf1cd9e11 (patch) | |
tree | afaeff39b2b240a36f13b6f199b1572ed0ad169b /models/src/test/java/org/onap | |
parent | adfe6d2d2e5b11a24208b3bce5383f1c38cec61e (diff) |
Remove FilterRepository in ACM
As part of participantId refactoring, FilterRepository and related
implementation could be removed.
Issue-ID: POLICY-4522
Change-Id: Idb078989871f1f65615a7df90aea69f7cd822dae
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/test/java/org/onap')
2 files changed, 11 insertions, 108 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java index 6e6637c7e..ccb20ea8e 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java @@ -24,13 +24,13 @@ 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.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.Participant; @@ -60,7 +60,7 @@ class ParticipantProviderTest { } @Test - void testParticipantSave() throws Exception { + void testParticipantSave() { var participantRepository = mock(ParticipantRepository.class); for (var participant : jpaParticipantList) { when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion()))) @@ -78,7 +78,7 @@ class ParticipantProviderTest { } @Test - void testParticipantUpdate() throws Exception { + void testParticipantUpdate() { var participantRepository = mock(ParticipantRepository.class); for (var participant : jpaParticipantList) { when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion()))) @@ -97,22 +97,10 @@ class ParticipantProviderTest { } @Test - void testGetAutomationCompositions() throws Exception { + void testGetAutomationCompositions() { var participantRepository = mock(ParticipantRepository.class); var participantProvider = new ParticipantProvider(participantRepository); - // Return empty list when no data present in db - List<Participant> getResponse = participantProvider.getParticipants(null, null); - assertThat(getResponse).isEmpty(); - - String name = inputParticipants.get(0).getName(); - String version = inputParticipants.get(0).getVersion(); - when(participantRepository.getFiltered(any(), eq(name), eq(version))) - .thenReturn(List.of(jpaParticipantList.get(0))); - assertEquals(1, participantProvider.getParticipants(name, version).size()); - - assertThat(participantProvider.getParticipants("invalid_name", "1.0.1")).isEmpty(); - assertThat(participantProvider.findParticipant(INVALID_ID)).isEmpty(); when(participantRepository.findAll()).thenReturn(jpaParticipantList); @@ -122,23 +110,24 @@ class ParticipantProviderTest { Optional.ofNullable(jpaParticipantList.get(0))); var participant = participantProvider.getParticipantById(inputParticipants.get(0) - .getParticipantId().toString()); + .getParticipantId()); assertThat(participant).isEqualTo(inputParticipants.get(0)); } @Test - void testDeleteParticipant() throws Exception { + void testDeleteParticipant() { var participantRepository = mock(ParticipantRepository.class); var participantProvider = new ParticipantProvider(participantRepository); - assertThatThrownBy(() -> participantProvider.deleteParticipant(INVALID_ID)) + var participantId = UUID.randomUUID(); + assertThatThrownBy(() -> participantProvider.deleteParticipant(participantId)) .hasMessageMatching(".*.failed, participant does not exist"); - when(participantRepository.findById(any())).thenReturn(Optional.of(jpaParticipantList.get(0))); + when(participantRepository.findByParticipantId(participantId.toString())) + .thenReturn(Optional.of(jpaParticipantList.get(0))); - Participant deletedParticipant = - participantProvider.deleteParticipant(inputParticipants.get(0).getDefinition()); + var deletedParticipant = participantProvider.deleteParticipant(participantId); assertEquals(inputParticipants.get(0), deletedParticipant); } } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java deleted file mode 100644 index c441c2fe8..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java +++ /dev/null @@ -1,86 +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.models.acm.persistence.repository; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant; -import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.dao.PfDao; -import org.onap.policy.models.provider.PolicyModelsProviderParameters; -import org.onap.policy.models.provider.impl.ModelsProvider; - -class FilterRepositoryImplTest { - private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json"; - private final List<Participant> inputParticipants = new ArrayList<>(); - private List<JpaParticipant> jpaParticipantList; - private final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON); - private static final Coder CODER = new StandardCoder(); - - private static final AtomicInteger dbNameCounter = new AtomicInteger(); - private PfDao pfDao; - - @BeforeEach - void beforeSetupDao() throws Exception { - var parameters = new PolicyModelsProviderParameters(); - parameters.setDatabaseDriver("org.h2.Driver"); - parameters.setName("PolicyProviderParameterGroup"); - parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl"); - parameters.setDatabaseUrl("jdbc:h2:mem:automationCompositionProviderTestDb" + dbNameCounter.getAndDecrement()); - parameters.setDatabaseUser("policy"); - parameters.setDatabasePassword("P01icY"); - parameters.setPersistenceUnit("ToscaConceptTest"); - - pfDao = ModelsProvider.init(parameters); - inputParticipants.add(CODER.decode(originalJson, Participant.class)); - jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant"); - pfDao.createCollection(jpaParticipantList); - } - - @Test - void testGetPfDao() { - assertThat(new FilterRepositoryImpl().getPfDao()).isNotNull(); - } - - @Test - void testGetFilteredParams() { - var filterRepositoryImpl = new FilterRepositoryImpl() { - @Override - protected PfDao getPfDao() { - return pfDao; - } - }; - var result = filterRepositoryImpl.getFiltered(JpaParticipant.class, null, null); - assertThat(result).hasSize(1); - - result = filterRepositoryImpl.getFiltered(JpaParticipant.class, jpaParticipantList.get(0).getName(), null); - assertThat(result).hasSize(1); - } -} |