Refactor xacml-pdp to remove various statics
[policy/xacml-pdp.git] / main / src / test / java / org / onap / policy / pdpx / main / rest / TestXacmlPdpStatistics.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21
22 package org.onap.policy.pdpx.main.rest;
23
24 import static org.junit.Assert.assertEquals;
25
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;
31
32 /**
33  * Class to perform unit test of {@link XacmlPdpRestController}.
34  *
35  */
36 public class TestXacmlPdpStatistics extends CommonRest {
37
38     private static final Logger LOGGER = LoggerFactory.getLogger(TestXacmlPdpStatistics.class);
39
40     @Test
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);
48     }
49
50     @Test
51     public void testXacmlPdpStatistics_500() throws Exception {
52         LOGGER.info("***************************** Running testXacmlPdpStatistics_500 *****************************");
53
54         markActivatorDead();
55
56         final StatisticsReport report = getXacmlPdpStatistics();
57         validateReport(report, 0, 500);
58     }
59
60     private StatisticsReport getXacmlPdpStatistics() throws Exception {
61         return sendHttpsRequest("statistics").get(StatisticsReport.class);
62     }
63
64     private void updateXacmlPdpStatistics() {
65         XacmlPdpStatisticsManager stats = XacmlPdpStatisticsManager.getCurrent();
66
67         stats.updateTotalPoliciesCount();
68         stats.updatePermitDecisionsCount();
69         stats.updateDenyDecisionsCount();
70         stats.updateIndeterminantDecisionsCount();
71         stats.updateNotApplicableDecisionsCount();
72     }
73
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());
81     }
82 }