2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pap.main.rest;
25 import static org.junit.Assert.assertEquals;
26 import static org.mockito.Mockito.when;
29 import java.util.List;
30 import org.apache.commons.lang3.tuple.Pair;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.onap.policy.common.utils.coder.Coder;
37 import org.onap.policy.common.utils.coder.CoderException;
38 import org.onap.policy.common.utils.coder.StandardCoder;
39 import org.onap.policy.common.utils.resources.ResourceUtils;
40 import org.onap.policy.common.utils.services.Registry;
41 import org.onap.policy.models.pdp.concepts.Pdp;
42 import org.onap.policy.models.pdp.concepts.PdpGroup;
43 import org.onap.policy.models.pdp.concepts.PdpGroups;
44 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
45 import org.onap.policy.models.pdp.concepts.Pdps;
46 import org.onap.policy.pap.main.service.PdpGroupService;
47 import org.springframework.http.HttpStatus;
50 * Class to perform unit test of {@link PdpGroupHealthCheckProvider}.
52 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
54 @RunWith(MockitoJUnitRunner.class)
55 public class TestPdpGroupHealthCheckProvider {
58 private PdpGroupService pdpGroupService;
59 private List<PdpGroup> groups;
60 private Coder coder = new StandardCoder();
63 * Configures DAO and mocks.
66 public void setUp() throws Exception {
68 Registry.newRegistry();
69 groups = loadFile("pdpGroup.json").getGroups();
71 when(pdpGroupService.getPdpGroups()).thenReturn(groups);
75 public void testFetchPdpGroupHealthStatus() throws Exception {
76 final PdpGroupHealthCheckProvider provider = new PdpGroupHealthCheckProvider(pdpGroupService);
77 final Pair<HttpStatus, Pdps> pair = provider.fetchPdpGroupHealthStatus();
78 assertEquals(HttpStatus.OK, pair.getLeft());
79 verifyPdps(pair.getRight().getPdpList(), groups);
82 private void verifyPdps(final List<Pdp> pdpList, final List<PdpGroup> groups) {
83 assertEquals(6, pdpList.size());
84 for (final PdpGroup group : groups) {
85 for (final PdpSubGroup subGroup : group.getPdpSubgroups()) {
86 pdpList.containsAll(subGroup.getPdpInstances());
91 private PdpGroups loadFile(final String fileName) {
92 final File propFile = new File(ResourceUtils.getFilePath4Resource("rest/" + fileName));
94 return coder.decode(propFile, PdpGroups.class);
96 } catch (final CoderException e) {
97 throw new RuntimeException(e);