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);
41 public void testXacmlPdpStatistics_200() throws Exception {
42 LOGGER.info("*************************** Running testXacmlPdpStatistics_200 ***************************");
43 StatisticsReport report = getXacmlPdpStatistics();
44 validateReport(report, 0, 200);
45 updateXacmlPdpStatistics();
46 report = getXacmlPdpStatistics();
47 validateReport(report, 1, 200);
51 public void testXacmlPdpStatistics_500() throws Exception {
52 LOGGER.info("***************************** Running testXacmlPdpStatistics_500 *****************************");
56 final StatisticsReport report = getXacmlPdpStatistics();
57 validateReport(report, 0, 500);
60 private StatisticsReport getXacmlPdpStatistics() throws Exception {
61 return sendHttpsRequest("statistics").get(StatisticsReport.class);
64 private void updateXacmlPdpStatistics() {
65 XacmlPdpStatisticsManager stats = XacmlPdpStatisticsManager.getCurrent();
67 stats.updateTotalPoliciesCount();
68 stats.updatePermitDecisionsCount();
69 stats.updateDenyDecisionsCount();
70 stats.updateIndeterminantDecisionsCount();
71 stats.updateNotApplicableDecisionsCount();
74 private void validateReport(final StatisticsReport report, final int count, final int code) {
75 assertEquals(code, report.getCode());
76 assertEquals(count, report.getTotalPoliciesCount());
77 assertEquals(count, report.getPermitDecisionsCount());
78 assertEquals(count, report.getDenyDecisionsCount());
79 assertEquals(count, report.getIndeterminantDecisionsCount());
80 assertEquals(count, report.getNotApplicableDecisionsCount());