Add end-to-end junits for PAP REST API
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / rest / e2e / StatisticsTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP PAP
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.pap.main.rest.e2e;
22
23 import static org.junit.Assert.assertEquals;
24
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;
32
33 public class StatisticsTest extends End2EndBase {
34     private static final String STATISTICS_ENDPOINT = "statistics";
35
36
37     @Test
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());
42
43         updateDistributionStatistics();
44
45         invocationBuilder = sendRequest(STATISTICS_ENDPOINT);
46         StatisticsReport report2 = invocationBuilder.get(StatisticsReport.class);
47
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());
57     }
58
59     private void updateDistributionStatistics() {
60         PapStatisticsManager mgr = Registry.get(PapConstants.REG_STATISTICS_MANAGER, PapStatisticsManager.class);
61
62         mgr.updateTotalPdpCount();
63         mgr.updateTotalPdpGroupCount();
64         mgr.updateTotalPolicyDeployCount();
65         mgr.updatePolicyDeploySuccessCount();
66         mgr.updatePolicyDeployFailureCount();
67         mgr.updateTotalPolicyDownloadCount();
68         mgr.updatePolicyDownloadSuccessCount();
69         mgr.updatePolicyDownloadFailureCount();
70     }
71 }