Set all cross references of policy/pap
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / rest / TestPapStatisticsManager.java
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019-2020 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 package org.onap.policy.pap.main.rest;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.function.ToLongFunction;
26 import org.junit.Test;
27
28 public class TestPapStatisticsManager {
29
30     @Test
31     public void testTotalPdpCount() {
32         verifyCount(PapStatisticsManager::getTotalPdpCount,
33                         PapStatisticsManager::updateTotalPdpCount);
34     }
35
36     @Test
37     public void testTotalPdpGroupCount() {
38         verifyCount(PapStatisticsManager::getTotalPdpGroupCount,
39                         PapStatisticsManager::updateTotalPdpGroupCount);
40     }
41
42     @Test
43     public void testTotalPolicyDeployCount() {
44         verifyCount(PapStatisticsManager::getTotalPolicyDeployCount,
45                         PapStatisticsManager::updateTotalPolicyDeployCount);
46     }
47
48     @Test
49     public void testPolicyDeploySuccessCount() {
50         verifyCount(PapStatisticsManager::getPolicyDeploySuccessCount,
51                         PapStatisticsManager::updatePolicyDeploySuccessCount);
52     }
53
54     @Test
55     public void testPolicyDeployFailureCount() {
56         verifyCount(PapStatisticsManager::getPolicyDeployFailureCount,
57                         PapStatisticsManager::updatePolicyDeployFailureCount);
58     }
59
60     @Test
61     public void testTotalPolicyDownloadCount() {
62         verifyCount(PapStatisticsManager::getTotalPolicyDownloadCount,
63                         PapStatisticsManager::updateTotalPolicyDownloadCount);
64     }
65
66     @Test
67     public void testPolicyDownloadSuccessCount() {
68         verifyCount(PapStatisticsManager::getPolicyDownloadSuccessCount,
69                         PapStatisticsManager::updatePolicyDownloadSuccessCount);
70     }
71
72     @Test
73     public void testPolicyDownloadFailureCount() {
74         verifyCount(PapStatisticsManager::getPolicyDownloadFailureCount,
75                         PapStatisticsManager::updatePolicyDownloadFailureCount);
76     }
77
78     private void verifyCount(ToLongFunction<PapStatisticsManager> getCount,
79                     ToLongFunction<PapStatisticsManager> updateCount) {
80
81         PapStatisticsManager mgr = new PapStatisticsManager();
82
83         assertEquals(0, getCount.applyAsLong(mgr));
84         assertEquals(1, updateCount.applyAsLong(mgr));
85         assertEquals(1, getCount.applyAsLong(mgr));
86
87         assertEquals(2, updateCount.applyAsLong(mgr));
88         assertEquals(2, getCount.applyAsLong(mgr));
89
90         // now check reset
91         mgr.resetAllStatistics();
92
93         assertEquals(0, getCount.applyAsLong(mgr));
94     }
95 }