2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
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=========================================================
21 package org.onap.policy.apex.service.engine.main;
23 import static org.junit.Assert.assertEquals;
25 import org.junit.Before;
26 import org.junit.Test;
28 public class ApexPolicyStatisticsManagerTest {
30 private ApexPolicyStatisticsManager statisticsManager;
33 * Starts the statisticsManager object for tests.
37 statisticsManager = new ApexPolicyStatisticsManager();
41 public void testUpdatePolicyDeployCounter() {
42 statisticsManager.updatePolicyDeployCounter(false);
43 assertDeploys(1, 0, 1);
45 statisticsManager.updatePolicyDeployCounter(true);
46 statisticsManager.updatePolicyDeployCounter(true);
47 assertDeploys(3, 2, 1);
51 public void testUpdatePolicyExecutedCounter() {
52 statisticsManager.updatePolicyExecutedCounter(true);
53 assertExecuted(1, 1, 0);
55 statisticsManager.updatePolicyExecutedCounter(false);
56 assertExecuted(2, 1, 1);
60 public void testUpdatePolicyUndeployCounter() {
61 statisticsManager.updatePolicyUndeployCounter(false);
62 assertUndeploys(1, 0, 1);
64 statisticsManager.updatePolicyUndeployCounter(true);
65 assertUndeploys(2, 1, 1);
69 public void testResetAllStatistics() {
70 statisticsManager.updatePolicyDeployCounter(true);
71 statisticsManager.updatePolicyDeployCounter(true);
72 statisticsManager.updatePolicyDeployCounter(false);
73 statisticsManager.updatePolicyUndeployCounter(false);
74 statisticsManager.updatePolicyExecutedCounter(true);
76 assertDeploys(3, 2, 1);
77 assertUndeploys(1, 0, 1);
78 assertExecuted(1, 1, 0);
80 statisticsManager.resetAllStatistics();
82 assertDeploys(0, 0, 0);
83 assertUndeploys(0, 0, 0);
84 assertExecuted(0, 0, 0);
88 private void assertDeploys(long count, long success, long fail) {
89 assertEquals(count, statisticsManager.getPolicyDeployCount());
90 assertEquals(success, statisticsManager.getPolicyDeploySuccessCount());
91 assertEquals(fail, statisticsManager.getPolicyDeployFailCount());
94 private void assertUndeploys(long count, long success, long fail) {
95 assertEquals(count, statisticsManager.getPolicyUndeployCount());
96 assertEquals(success, statisticsManager.getPolicyUndeploySuccessCount());
97 assertEquals(fail, statisticsManager.getPolicyUndeployFailCount());
100 private void assertExecuted(long count, long success, long fail) {
101 assertEquals(count, statisticsManager.getPolicyExecutedCount());
102 assertEquals(success, statisticsManager.getPolicyExecutedSuccessCount());
103 assertEquals(fail, statisticsManager.getPolicyExecutedFailCount());