diff options
author | adheli.tavares <adheli.tavares@est.tech> | 2021-07-08 15:36:25 +0100 |
---|---|---|
committer | adheli.tavares <adheli.tavares@est.tech> | 2021-07-12 14:10:10 +0100 |
commit | d58200919584dfa7f45a1c3ae94061aa91d341d8 (patch) | |
tree | 39a3dca977bc0768606acf3736749081cc7942d4 /services/services-engine/src/test | |
parent | 7ec6f6a88b3a90a0f865f2798ff70f13278e40c2 (diff) |
Update pdp statistics to count deploy/undeploy separately.
Issue-ID: POLICY-3383
Change-Id: Ie9c5c7178c4c4302a0ba63ab42732f7157d302f8
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'services/services-engine/src/test')
-rw-r--r-- | services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java new file mode 100644 index 000000000..4c541bd12 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.service.engine.main; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ApexPolicyStatisticsManagerTest { + + private ApexPolicyStatisticsManager statisticsManager; + + /** + * Starts the statisticsManager object for tests. + */ + @Before + public void setup() { + statisticsManager = new ApexPolicyStatisticsManager(); + } + + @Test + public void testUpdatePolicyDeployCounter() { + statisticsManager.updatePolicyDeployCounter(false); + assertDeploys(1, 0, 1); + + statisticsManager.updatePolicyDeployCounter(true); + statisticsManager.updatePolicyDeployCounter(true); + assertDeploys(3, 2, 1); + } + + @Test + public void testUpdatePolicyExecutedCounter() { + statisticsManager.updatePolicyExecutedCounter(true); + assertExecuted(1, 1, 0); + + statisticsManager.updatePolicyExecutedCounter(false); + assertExecuted(2, 1, 1); + } + + @Test + public void testUpdatePolicyUndeployCounter() { + statisticsManager.updatePolicyUndeployCounter(false); + assertUndeploys(1, 0, 1); + + statisticsManager.updatePolicyUndeployCounter(true); + assertUndeploys(2, 1, 1); + } + + @Test + public void testResetAllStatistics() { + statisticsManager.updatePolicyDeployCounter(true); + statisticsManager.updatePolicyDeployCounter(true); + statisticsManager.updatePolicyDeployCounter(false); + statisticsManager.updatePolicyUndeployCounter(false); + statisticsManager.updatePolicyExecutedCounter(true); + + assertDeploys(3, 2, 1); + assertUndeploys(1, 0, 1); + assertExecuted(1, 1, 0); + + statisticsManager.resetAllStatistics(); + + assertDeploys(0, 0, 0); + assertUndeploys(0, 0, 0); + assertExecuted(0, 0, 0); + + } + + private void assertDeploys(long count, long success, long fail) { + assertEquals(count, statisticsManager.getPolicyDeployCount()); + assertEquals(success, statisticsManager.getPolicyDeploySuccessCount()); + assertEquals(fail, statisticsManager.getPolicyDeployFailCount()); + } + + private void assertUndeploys(long count, long success, long fail) { + assertEquals(count, statisticsManager.getPolicyUndeployCount()); + assertEquals(success, statisticsManager.getPolicyUndeploySuccessCount()); + assertEquals(fail, statisticsManager.getPolicyUndeployFailCount()); + } + + private void assertExecuted(long count, long success, long fail) { + assertEquals(count, statisticsManager.getPolicyExecutedCount()); + assertEquals(success, statisticsManager.getPolicyExecutedSuccessCount()); + assertEquals(fail, statisticsManager.getPolicyExecutedFailCount()); + } + +} |