2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2022 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.models.acm.persistence.repository;
23 import static org.assertj.core.api.Assertions.assertThat;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.concurrent.atomic.AtomicInteger;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30 import org.onap.policy.clamp.models.acm.concepts.Participant;
31 import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
32 import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
33 import org.onap.policy.common.utils.coder.Coder;
34 import org.onap.policy.common.utils.coder.StandardCoder;
35 import org.onap.policy.common.utils.resources.ResourceUtils;
36 import org.onap.policy.models.dao.PfDao;
37 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
38 import org.onap.policy.models.provider.impl.ModelsProvider;
40 class FilterRepositoryImplTest {
41 private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json";
42 private final List<Participant> inputParticipants = new ArrayList<>();
43 private List<JpaParticipant> jpaParticipantList;
44 private final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
45 private static final Coder CODER = new StandardCoder();
47 private static final AtomicInteger dbNameCounter = new AtomicInteger();
51 void beforeSetupDao() throws Exception {
52 var parameters = new PolicyModelsProviderParameters();
53 parameters.setDatabaseDriver("org.h2.Driver");
54 parameters.setName("PolicyProviderParameterGroup");
55 parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl");
56 parameters.setDatabaseUrl("jdbc:h2:mem:automationCompositionProviderTestDb" + dbNameCounter.getAndDecrement());
57 parameters.setDatabaseUser("policy");
58 parameters.setDatabasePassword("P01icY");
59 parameters.setPersistenceUnit("ToscaConceptTest");
61 pfDao = ModelsProvider.init(parameters);
62 inputParticipants.add(CODER.decode(originalJson, Participant.class));
63 jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant");
64 pfDao.createCollection(jpaParticipantList);
69 assertThat(new FilterRepositoryImpl().getPfDao()).isNotNull();
73 void testGetFilteredParams() {
74 var filterRepositoryImpl = new FilterRepositoryImpl() {
76 protected PfDao getPfDao() {
80 var result = filterRepositoryImpl.getFiltered(JpaParticipant.class, null, null);
81 assertThat(result).hasSize(1);
83 result = filterRepositoryImpl.getFiltered(JpaParticipant.class, jpaParticipantList.get(0).getName(), null);
84 assertThat(result).hasSize(1);