2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. 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=========================================================
22 package org.onap.policy.pdpx.main.rest;
24 import static org.junit.Assert.assertEquals;
26 import org.junit.Test;
27 import org.onap.policy.pdpx.main.CommonRest;
28 import org.onap.policy.pdpx.main.rest.model.StatisticsReport;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * Class to perform unit test of {@link XacmlPdpRestController}.
36 public class TestXacmlPdpStatistics extends CommonRest {
38 private static final Logger LOGGER = LoggerFactory.getLogger(TestXacmlPdpStatistics.class);
40 private int nupdates = 0;
43 public void testXacmlPdpStatistics_200() throws Exception {
44 LOGGER.info("*************************** Running testXacmlPdpStatistics_200 ***************************");
45 StatisticsReport report = getXacmlPdpStatistics();
46 validateReport(report, 0, 200);
47 updateXacmlPdpStatistics();
48 report = getXacmlPdpStatistics();
49 validateReport(report, 1, 200);
53 public void testXacmlPdpStatistics_500() throws Exception {
54 LOGGER.info("***************************** Running testXacmlPdpStatistics_500 *****************************");
58 final StatisticsReport report = getXacmlPdpStatistics();
59 validateReport(report, 0, 500);
62 private StatisticsReport getXacmlPdpStatistics() throws Exception {
63 return sendHttpsRequest("statistics").get(StatisticsReport.class);
66 private void updateXacmlPdpStatistics() {
67 XacmlPdpStatisticsManager stats = XacmlPdpStatisticsManager.getCurrent();
70 stats.setTotalPolicyCount(nupdates);
71 stats.setTotalPolicyTypesCount(nupdates);
72 stats.updatePermitDecisionsCount();
73 stats.updateDenyDecisionsCount();
74 stats.updateIndeterminantDecisionsCount();
75 stats.updateNotApplicableDecisionsCount();
78 private void validateReport(final StatisticsReport report, final int count, final int code) {
79 assertEquals(code, report.getCode());
80 assertEquals(count, report.getTotalPoliciesCount());
81 assertEquals(count, report.getTotalPolicyTypesCount());
82 assertEquals(count, report.getPermitDecisionsCount());
83 assertEquals(count, report.getDenyDecisionsCount());
84 assertEquals(count, report.getIndeterminantDecisionsCount());
85 assertEquals(count, report.getNotApplicableDecisionsCount());