2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.main.rest.e2e;
23 import static org.junit.Assert.assertEquals;
25 import java.net.HttpURLConnection;
26 import javax.ws.rs.client.Invocation;
27 import org.junit.Test;
28 import org.onap.policy.common.utils.services.Registry;
29 import org.onap.policy.pap.main.PapConstants;
30 import org.onap.policy.pap.main.rest.PapStatisticsManager;
31 import org.onap.policy.pap.main.rest.StatisticsReport;
33 public class StatisticsTest extends End2EndBase {
34 private static final String STATISTICS_ENDPOINT = "statistics";
38 public void test() throws Exception {
39 Invocation.Builder invocationBuilder = sendRequest(STATISTICS_ENDPOINT);
40 StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
41 assertEquals(HttpURLConnection.HTTP_OK, report.getCode());
43 updateDistributionStatistics();
45 invocationBuilder = sendRequest(STATISTICS_ENDPOINT);
46 StatisticsReport report2 = invocationBuilder.get(StatisticsReport.class);
48 assertEquals(HttpURLConnection.HTTP_OK, report.getCode());
49 assertEquals(report.getTotalPdpCount() + 1, report2.getTotalPdpCount());
50 assertEquals(report.getTotalPdpGroupCount() + 1, report2.getTotalPdpGroupCount());
51 assertEquals(report.getTotalPolicyDeployCount() + 1, report2.getTotalPolicyDeployCount());
52 assertEquals(report.getPolicyDeploySuccessCount() + 1, report2.getPolicyDeploySuccessCount());
53 assertEquals(report.getPolicyDeployFailureCount() + 1, report2.getPolicyDeployFailureCount());
54 assertEquals(report.getTotalPolicyDownloadCount() + 1, report2.getTotalPolicyDownloadCount());
55 assertEquals(report.getPolicyDeploySuccessCount() + 1, report2.getPolicyDeploySuccessCount());
56 assertEquals(report.getPolicyDeployFailureCount() + 1, report2.getPolicyDeployFailureCount());
59 private void updateDistributionStatistics() {
60 PapStatisticsManager mgr = Registry.get(PapConstants.REG_STATISTICS_MANAGER, PapStatisticsManager.class);
62 mgr.updateTotalPdpCount();
63 mgr.updateTotalPdpGroupCount();
64 mgr.updateTotalPolicyDeployCount();
65 mgr.updatePolicyDeploySuccessCount();
66 mgr.updatePolicyDeployFailureCount();
67 mgr.updateTotalPolicyDownloadCount();
68 mgr.updatePolicyDownloadSuccessCount();
69 mgr.updatePolicyDownloadFailureCount();