2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Bell Canada. All rights reserved.
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.api.main.service;
23 import static org.assertj.core.api.Assertions.assertThatCode;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.mockito.Mockito.when;
27 import java.util.ArrayList;
28 import java.util.List;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.policy.api.main.repository.PdpGroupRepository;
36 import org.onap.policy.common.utils.coder.CoderException;
37 import org.onap.policy.common.utils.coder.StandardCoder;
38 import org.onap.policy.common.utils.resources.ResourceUtils;
39 import org.onap.policy.models.pdp.concepts.PdpGroups;
40 import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup;
42 @RunWith(MockitoJUnitRunner.class)
43 public class TestPdpGroupService {
46 private PdpGroupRepository pdpGroupRepository;
49 private PdpGroupService pdpGroupService;
53 * @throws CoderException decode errors
56 public void setUp() throws CoderException {
57 var pdpGroups = new StandardCoder().decode(ResourceUtils.getResourceAsString("pdpgroups/PdpGroups.json"),
58 PdpGroups.class).getGroups();
59 List<JpaPdpGroup> jpaPdpGroupList = new ArrayList<>();
60 pdpGroups.forEach(pdpGroup -> jpaPdpGroupList.add(new JpaPdpGroup(pdpGroup)));
62 when(pdpGroupRepository.findAll()).thenReturn(jpaPdpGroupList);
66 public void testAssertPolicyTypeNotSupportedInPdpGroup() {
67 assertThatCode(() -> pdpGroupService.assertPolicyTypeNotSupportedInPdpGroup("policy_type_not_supported",
68 "1.0.0")).doesNotThrowAnyException();
70 assertThatThrownBy(() -> pdpGroupService.assertPolicyTypeNotSupportedInPdpGroup(
71 "onap.policies.controlloop.guard.common.FrequencyLimiter", "1.0.0"))
72 .hasMessage("policy type is in use, it is referenced in PDP group defaultGroup subgroup xacml");
76 public void testAssertPolicyNotDeployedInPdpGroup() {
77 assertThatCode(() -> pdpGroupService.assertPolicyNotDeployedInPdpGroup("policy_not_deployed", "1.0.0"))
78 .doesNotThrowAnyException();
80 assertThatThrownBy(() -> pdpGroupService.assertPolicyNotDeployedInPdpGroup(
81 "onap.policies.controlloop.operational.common.apex.SampleDomain", "1.0.0"))
82 .hasMessage("policy is in use, it is deployed in PDP group defaultGroup subgroup apex");