abc87383859281b34b225379c66df2f59a5fb1de
[policy/api.git] / main / src / test / java / org / onap / policy / api / main / rest / TestApiRestServer.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4  *  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5  *  Modifications Copyright (C) 2019 Nordix Foundation.
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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.api.main.rest;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 import java.io.File;
31 import java.lang.reflect.Constructor;
32 import java.lang.reflect.Modifier;
33 import java.security.SecureRandom;
34 import java.util.Base64;
35 import java.util.Collections;
36 import java.util.Properties;
37
38 import javax.net.ssl.SSLContext;
39 import javax.net.ssl.TrustManager;
40 import javax.ws.rs.client.Client;
41 import javax.ws.rs.client.ClientBuilder;
42 import javax.ws.rs.client.Entity;
43 import javax.ws.rs.client.Invocation;
44 import javax.ws.rs.client.WebTarget;
45 import javax.ws.rs.core.Response;
46
47 import org.glassfish.jersey.client.ClientProperties;
48 import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
49 import org.junit.AfterClass;
50 import org.junit.Before;
51 import org.junit.BeforeClass;
52 import org.junit.Test;
53 import org.onap.policy.api.main.parameters.ApiParameterGroup;
54 import org.onap.policy.api.main.parameters.CommonTestData;
55 import org.onap.policy.api.main.rest.provider.PolicyProvider;
56 import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
57 import org.onap.policy.api.main.startstop.Main;
58 import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
59 import org.onap.policy.common.endpoints.report.HealthCheckReport;
60 import org.onap.policy.common.gson.GsonMessageBodyHandler;
61 import org.onap.policy.common.parameters.ParameterService;
62 import org.onap.policy.common.utils.coder.StandardCoder;
63 import org.onap.policy.common.utils.coder.StandardYamlCoder;
64 import org.onap.policy.common.utils.network.NetworkUtil;
65 import org.onap.policy.common.utils.resources.ResourceUtils;
66 import org.onap.policy.common.utils.resources.TextFileUtils;
67 import org.onap.policy.models.base.PfModelException;
68 import org.onap.policy.models.errors.concepts.ErrorResponse;
69 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
70 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
71 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
72 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
73 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
74
75 /**
76  * Class to perform unit test of {@link ApiRestServer}.
77  *
78  * @author Chenfei Gao (cgao@research.att.com)
79  */
80 public class TestApiRestServer {
81     private static final String ALIVE = "alive";
82     private static final String SELF = NetworkUtil.getHostname();
83     private static final String NAME = "Policy API";
84     private static final String APP_JSON = "application/json";
85     private static final String APP_YAML = "application/yaml";
86
87     private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
88     private static final String STATISTICS_ENDPOINT = "statistics";
89
90     private static final String POLICYTYPES = "policytypes";
91     private static final String POLICYTYPES_TCA = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app";
92     private static final String POLICYTYPES_COLLECTOR =
93             "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server";
94     private static final String POLICYTYPES_TCA_VERSION =
95             "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0";
96     private static final String POLICYTYPES_TCA_LATEST =
97             "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/latest";
98     private static final String POLICYTYPES_COLLECTOR_VERSION =
99             "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server/versions/1.0.0";
100     private static final String POLICYTYPES_COLLECTOR_LATEST =
101             "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server/versions/latest";
102
103     private static final String POLICYTYPES_TCA_POLICIES =
104             "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies";
105     private static final String POLICYTYPES_TCA_POLICIES_VCPE =
106             "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca";
107     private static final String POLICYTYPES_TCA_POLICIES_VCPE_VERSION = "policytypes/"
108             + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/1.0.0";
109     private static final String POLICYTYPES_TCA_POLICIES_VCPE_LATEST = "policytypes/"
110             + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/latest";
111     private static final String POLICYTYPES_TCA_POLICIES_VCPE_DEPLOYED = "policytypes/"
112             + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/deployed";
113
114     private static final String GUARD_POLICIES = "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies";
115     private static final String GUARD_POLICIES_VDNS_FL_LATEST =
116             "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout"
117                     + "/versions/latest";
118     private static final String GUARD_POLICIES_VDNS_FL_DEPLOYED =
119             "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout"
120                     + "/versions/deployed";
121     private static final String GUARD_POLICIES_VDNS_MINMAX_LATEST =
122             "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout"
123                     + "/versions/latest";
124     private static final String GUARD_POLICIES_VDNS_FL_VERSION = "policytypes/"
125             + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout/versions/1";
126     private static final String GUARD_POLICIES_VDNS_MINMAX_VERSION =
127             "policytypes/" + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout/versions/1";
128
129     private static final String OPS_POLICIES =
130             "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies";
131     private static final String OPS_POLICIES_VCPE_LATEST =
132             "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.restart"
133                     + "/versions/latest";
134     private static final String OPS_POLICIES_VCPE_DEPLOYED =
135             "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.restart"
136                     + "/versions/deployed";
137     private static final String OPS_POLICIES_VDNS_LATEST =
138             "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.scaleout"
139                     + "/versions/latest";
140     private static final String OPS_POLICIES_VFIREWALL_LATEST =
141             "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.modifyconfig"
142                     + "/versions/latest";
143     private static final String OPS_POLICIES_VCPE_VERSION = "policytypes/"
144             + "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.restart/versions/1";
145     private static final String OPS_POLICIES_VDNS_VERSION = "policytypes/"
146             + "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.scaleout/versions/1";
147     private static final String OPS_POLICIES_VFIREWALL_VERSION = "policytypes/"
148             + "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.modifyconfig/versions/1";
149     private static final String POLICIES = "policies";
150
151     private static final String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
152
153     // @formatter:off
154     private static final String[] TOSCA_POLICY_RESOURCE_NAMES = {
155         "policies/vCPE.policy.monitoring.input.tosca.json",
156         "policies/vCPE.policy.monitoring.input.tosca.yaml",
157         "policies/vDNS.policy.monitoring.input.tosca.json",
158         "policies/vDNS.policy.monitoring.input.tosca.yaml",
159         "policies/vFirewall.policy.monitoring.input.tosca.json",
160         "policies/vFirewall.policy.monitoring.input.tosca.yaml"
161     };
162
163     private static final String[] TOSCA_POLICIES_RESOURCE_NAMES = {
164         "policies/vCPE.policies.optimization.input.tosca.json",
165         "policies/vCPE.policies.optimization.input.tosca.yaml"
166     };
167
168     private static final String[] TOSCA_PPOLICYTYPE_RESOURCE_NAMES = {
169         "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml",
170         "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml",
171         "policytypes/onap.policies.Optimization.yaml",
172         "policytypes/onap.policies.controlloop.Operational.yaml",
173         "policytypes/onap.policies.controlloop.guard.Blacklist.yaml",
174         "policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml",
175         "policytypes/onap.policies.controlloop.guard.MinMax.yaml",
176         "policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml",
177         "policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml",
178         "policytypes/onap.policies.optimization.resource.DistancePolicy.yaml",
179         "policytypes/onap.policies.optimization.resource.HpaPolicy.yaml",
180         "policytypes/onap.policies.optimization.resource.OptimizationPolicy.yaml",
181         "policytypes/onap.policies.optimization.resource.PciPolicy.yaml",
182         "policytypes/onap.policies.optimization.service.QueryPolicy.yaml",
183         "policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml",
184         "policytypes/onap.policies.optimization.resource.Vim_fit.yaml",
185         "policytypes/onap.policies.optimization.resource.VnfPolicy.yaml"
186     };
187
188     private static final String[] LEGACY_GUARD_POLICY_RESOURCE_NAMES = {
189         "policies/vDNS.policy.guard.frequency.input.json",
190         "policies/vDNS.policy.guard.minmax.input.json"
191     };
192
193     private static final String[] LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES = {
194         "policies/vCPE.policy.operational.input.json",
195         "policies/vDNS.policy.operational.input.json",
196         "policies/vFirewall.policy.operational.input.json"
197     };
198
199     private static PolicyModelsProviderParameters providerParams;
200     private static ApiParameterGroup apiParamGroup;
201     private static PolicyProvider policyProvider;
202     private static PolicyTypeProvider policyTypeProvider;
203
204     // @formatter:on
205
206     private static final StandardCoder standardCoder = new StandardCoder();
207
208     private static int apiPort;
209     private static Main apiMain;
210
211     private static StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
212
213     /**
214      * Initializes parameters.
215      *
216      * @throws PfModelException the PfModel parsing exception
217      */
218     @BeforeClass
219     public static void setupParameters() throws PfModelException {
220         providerParams = new PolicyModelsProviderParameters();
221         providerParams.setDatabaseDriver("org.h2.Driver");
222         providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
223         providerParams.setDatabaseUser("policy");
224         providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
225         providerParams.setPersistenceUnit("ToscaConceptTest");
226         apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, Collections.emptyList());
227         ParameterService.register(apiParamGroup, true);
228
229         policyTypeProvider = new PolicyTypeProvider();
230         policyProvider = new PolicyProvider();
231     }
232
233     /**
234      * Set up test environemnt.
235      *
236      * @throws Exception on test setup exceptions
237      */
238     @BeforeClass
239     public static void beforeStartApiService() throws Exception {
240         apiPort = NetworkUtil.allocPort();
241
242         final String[] apiConfigParameters = new String[2];
243         final Properties systemProps = System.getProperties();
244         systemProps.put("javax.net.ssl.keyStore", KEYSTORE);
245         systemProps.put("javax.net.ssl.keyStorePassword", "Pol1cy_0nap");
246         System.setProperties(systemProps);
247         new CommonTestData().makeParameters("src/test/resources/parameters/ApiConfigParameters_Https.json",
248                 "src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json", apiPort);
249         apiConfigParameters[0] = "-c";
250         apiConfigParameters[1] = "src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json";
251         apiMain = new Main(apiConfigParameters);
252     }
253
254     /**
255      * Method for cleanup after each test.
256      */
257     @AfterClass
258     public static void teardown() throws Exception {
259         policyTypeProvider.close();
260         policyProvider.close();
261
262         if (apiMain != null) {
263             apiMain.shutdown();
264         }
265     }
266
267     /**
268      * Clear the database before each test.
269      *
270      * @throws Exception on clearing exceptions
271      */
272     @Before
273     public void beforeClearDatabase() throws Exception {
274         Response rawResponse = readResource(POLICYTYPES, APP_JSON);
275         ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
276
277         for (ToscaEntityKey policyTypeKey : response.getPolicyTypesAsMap().keySet()) {
278             String getPoliciesPath =
279                     "policytypes/" + policyTypeKey.getName() + "/versions/" + policyTypeKey.getVersion() + "/policies";
280
281             Response rawPolicyResponse = readResource(getPoliciesPath, APP_JSON);
282             if (Response.Status.OK.getStatusCode() == rawPolicyResponse.getStatus()) {
283                 ToscaServiceTemplate policyResponse = rawPolicyResponse.readEntity(ToscaServiceTemplate.class);
284
285                 for (ToscaEntityKey policyKey : policyResponse.getToscaTopologyTemplate().getPoliciesAsMap().keySet()) {
286                     String deletePolicyPath =
287                             "policytypes/" + policyTypeKey.getName() + "/versions/" + policyTypeKey.getVersion()
288                                     + "/policies/" + policyKey.getName() + "/versions/" + policyKey.getVersion();
289                     deleteResource(deletePolicyPath, APP_JSON);
290                 }
291             }
292
293             String deletePolicyTypePath =
294                     "policytypes/" + policyTypeKey.getName() + "/versions/" + policyTypeKey.getVersion();
295             deleteResource(deletePolicyTypePath, APP_JSON);
296         }
297     }
298
299     @Test
300     public void testApiStatisticsConstructorIsPrivate() {
301
302         try {
303             final Constructor<ApiStatisticsManager> constructor = ApiStatisticsManager.class.getDeclaredConstructor();
304             assertTrue(Modifier.isPrivate(constructor.getModifiers()));
305             constructor.setAccessible(true);
306             constructor.newInstance();
307
308         } catch (final Exception exp) {
309             assertTrue(exp.getCause().toString().contains("Instantiation of the class is not allowed"));
310         }
311     }
312
313     @Test
314     public void testCreatePolicyTypes() throws Exception {
315         for (String resrcName : TOSCA_PPOLICYTYPE_RESOURCE_NAMES) {
316             Response rawResponse = createResource(POLICYTYPES, resrcName);
317             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
318             ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
319             assertNotNull(response);
320             assertFalse(response.getPolicyTypes().isEmpty());
321         }
322
323         // Send a policy type with a null value to trigger an error
324         Response rawResponse = readResource(POLICYTYPES, APP_JSON);
325         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
326         ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
327         String firstPolicyType = response.getPolicyTypes().keySet().iterator().next();
328         response.getPolicyTypes().put(firstPolicyType, null);
329         Response rawResponse2 = createResource(POLICYTYPES, standardCoder.encode(response));
330         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse2.getStatus());
331         ErrorResponse errorResponse = rawResponse2.readEntity(ErrorResponse.class);
332         assertEquals("no policy types specified on service template", errorResponse.getErrorMessage());
333     }
334
335     @Test
336     public void testCreatePolicies() throws Exception {
337         createPolicyTypes();
338
339         for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) {
340             Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName);
341             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
342         }
343
344         new File("src/test/resources/policies/BadTestPolicy.yaml").deleteOnExit();
345
346         // Send a policy with no policy type trigger an error
347         String toscaPolicy = ResourceUtils
348                 .getResourceAsString(TOSCA_POLICY_RESOURCE_NAMES[TOSCA_POLICIES_RESOURCE_NAMES.length - 1]);
349
350         toscaPolicy = toscaPolicy.replaceAll("onap.policies.monitoring.cdap.tca.hi.lo.app", "");
351         TextFileUtils.putStringAsTextFile(toscaPolicy, "src/test/resources/policies/BadTestPolicy.yaml");
352
353         Response rawResponse2 =
354                 createResource(POLICYTYPES_TCA_POLICIES, "src/test/resources/policies/BadTestPolicy.yaml");
355         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse2.getStatus());
356         ErrorResponse errorResponse = rawResponse2.readEntity(ErrorResponse.class);
357         assertEquals("policy type id does not match", errorResponse.getErrorMessage());
358     }
359
360     @Test
361     public void testSimpleCreatePolicies() throws Exception {
362         testCreatePolicyTypes();
363
364         for (String resrcName : TOSCA_POLICIES_RESOURCE_NAMES) {
365             Response rawResponse = createResource(POLICIES, resrcName);
366             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
367         }
368
369         new File("src/test/resources/policies/BadTestPolicy.yaml").deleteOnExit();
370
371         // Send a policy with no policy type trigger an error
372         String toscaPolicy = ResourceUtils
373                 .getResourceAsString(TOSCA_POLICY_RESOURCE_NAMES[TOSCA_POLICIES_RESOURCE_NAMES.length - 1]);
374
375         toscaPolicy = toscaPolicy.replaceAll("onap.policies.monitoring.cdap.tca.hi.lo.app", "");
376         TextFileUtils.putStringAsTextFile(toscaPolicy, "src/test/resources/policies/BadTestPolicy.yaml");
377
378         Response rawResponse2 = createResource(POLICIES, "src/test/resources/policies/BadTestPolicy.yaml");
379         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse2.getStatus());
380         ErrorResponse errorResponse = rawResponse2.readEntity(ErrorResponse.class);
381         assertEquals("policy type NULL:0.0.0 for policy onap.restart.tca:1.0.0 does not exist",
382                 errorResponse.getErrorMessage());
383     }
384
385     @Test
386     public void testCreateGuardPolicies() throws Exception {
387         createPolicyTypes();
388
389         for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
390             Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
391             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
392         }
393     }
394
395     @Test
396     public void testCreateOperationalPolicies() throws Exception {
397         createPolicyTypes();
398
399         for (String resrcName : LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES) {
400             Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName);
401             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
402         }
403     }
404
405     @Test
406     public void testHealthCheckSuccessJson() throws Exception {
407         testHealthCheckSuccess(APP_JSON);
408     }
409
410     @Test
411     public void testHealthCheckSuccessYaml() throws Exception {
412         testHealthCheckSuccess(APP_YAML);
413     }
414
415     private void testHealthCheckSuccess(String mediaType) throws Exception {
416         final Invocation.Builder invocationBuilder = sendHttpsRequest(HEALTHCHECK_ENDPOINT, mediaType);
417         final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
418         validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
419     }
420
421     @Test
422     public void testApiStatistics_200_Json() throws Exception {
423         testApiStatistics_200(APP_JSON);
424     }
425
426     @Test
427     public void testApiStatistics_200_Yaml() throws Exception {
428         testApiStatistics_200(APP_YAML);
429     }
430
431     private void testApiStatistics_200(String mediaType) throws Exception {
432         Invocation.Builder invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT, mediaType);
433         StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
434         validateStatisticsReport(report, 200);
435         updateApiStatistics();
436         invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT, mediaType);
437         report = invocationBuilder.get(StatisticsReport.class);
438         validateStatisticsReport(report, 200);
439         ApiStatisticsManager.resetAllStatistics();
440     }
441
442     @Test
443     public void testReadPolicyTypesJson() throws Exception {
444         testReadPolicyTypes(APP_JSON);
445     }
446
447     @Test
448     public void testReadPolicyTypesYaml() throws Exception {
449         testReadPolicyTypes(APP_YAML);
450     }
451
452     private void testReadPolicyTypes(String mediaType) throws Exception {
453         createPolicyTypes();
454
455         Response rawResponse = readResource(POLICYTYPES, mediaType);
456         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
457         ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
458         assertFalse(response.getPolicyTypes().isEmpty());
459
460         rawResponse = readResource(POLICYTYPES_TCA, mediaType);
461         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
462
463         rawResponse = readResource(POLICYTYPES_TCA_VERSION, mediaType);
464         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
465
466         rawResponse = readResource(POLICYTYPES_TCA_LATEST, mediaType);
467         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
468
469         rawResponse = readResource(POLICYTYPES_COLLECTOR, mediaType);
470         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
471
472         rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, mediaType);
473         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
474
475         rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, mediaType);
476         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
477     }
478
479     @Test
480     public void testDeletePolicyTypeJson() throws Exception {
481         testDeletePolicyType(APP_JSON);
482     }
483
484     @Test
485     public void testDeletePolicyTypeYaml() throws Exception {
486         testDeletePolicyType(APP_YAML);
487     }
488
489     private void testDeletePolicyType(String mediaType) throws Exception {
490         createPolicyTypes();
491
492         Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, mediaType);
493         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
494
495         rawResponse = readResource(POLICYTYPES_TCA_VERSION, mediaType);
496         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
497
498         rawResponse = deleteResource(POLICYTYPES_COLLECTOR_VERSION, mediaType);
499         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
500
501         rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, mediaType);
502         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
503
504         rawResponse = readResource(POLICYTYPES_COLLECTOR, mediaType);
505         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
506
507         rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, mediaType);
508         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
509         ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
510         assertEquals("policy type with ID "
511                 + "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:null does not exist",
512                 errorResponse.getErrorMessage());
513     }
514
515     @Test
516     public void testReadPoliciesJson() throws Exception {
517         testReadPolicies(APP_JSON);
518     }
519
520     @Test
521     public void testReadPoliciesYaml() throws Exception {
522         testReadPolicies(APP_YAML);
523     }
524
525     private void testReadPolicies(String mediaType) throws Exception {
526         testCreatePolicies();
527
528         Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, mediaType);
529         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
530
531         rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, mediaType);
532         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
533
534         rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, mediaType);
535         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
536
537         rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, mediaType);
538         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
539     }
540
541     @Test
542     public void testDeletePoliciesJson() throws Exception {
543         testDeletePolicies(APP_JSON);
544     }
545
546     @Test
547     public void testDeletePoliciesYaml() throws Exception {
548         testDeletePolicies(APP_YAML);
549     }
550
551     private void testDeletePolicies(String mediaType) throws Exception {
552         createPolicyTypes();
553
554         Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, mediaType);
555         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
556         ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
557         assertEquals(
558                 "policy with ID onap.restart.tca:1.0.0 and "
559                         + "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
560                 error.getErrorMessage());
561     }
562
563     @Test
564     public void testDeletePolicyVersionJson() throws Exception {
565         testDeletePolicyVersion(APP_JSON);
566     }
567
568     @Test
569     public void testDeletePolicyVersionYaml() throws Exception {
570         testDeletePolicyVersion(APP_YAML);
571     }
572
573     private void testDeletePolicyVersion(String mediaType) throws Exception {
574         for (String resrcName : TOSCA_PPOLICYTYPE_RESOURCE_NAMES) {
575             Response rawResponse = createResource(POLICYTYPES, resrcName);
576             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
577             ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
578             assertNotNull(response);
579             assertFalse(response.getPolicyTypes().isEmpty());
580         }
581         for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) {
582             Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName);
583             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
584         }
585         Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, mediaType);
586         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
587
588         rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, mediaType);
589         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
590         ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
591         assertEquals(
592                 "policy with ID onap.restart.tca:1.0.0 and type "
593                         + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
594                 errorResponse.getErrorMessage());
595
596         rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, mediaType);
597         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
598         errorResponse = rawResponse.readEntity(ErrorResponse.class);
599         assertEquals(
600                 "policy with ID onap.restart.tca:null and type "
601                         + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
602                 errorResponse.getErrorMessage());
603
604         rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, mediaType);
605         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
606         errorResponse = rawResponse.readEntity(ErrorResponse.class);
607         assertEquals(
608                 "policy with ID onap.restart.tca:null and type "
609                         + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
610                 errorResponse.getErrorMessage());
611     }
612
613     @Test
614     public void testGetAllVersionOfPolicyJson() throws Exception {
615         testGetAllVersionOfPolicy(APP_JSON);
616     }
617
618     @Test
619     public void testGetAllVersionOfPolicyYaml() throws Exception {
620         testGetAllVersionOfPolicy(APP_YAML);
621     }
622
623     private void testGetAllVersionOfPolicy(String mediaType) throws Exception {
624         for (String resrcName : TOSCA_PPOLICYTYPE_RESOURCE_NAMES) {
625             Response rawResponse = createResource(POLICYTYPES, resrcName);
626             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
627             ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
628             assertNotNull(response);
629             assertFalse(response.getPolicyTypes().isEmpty());
630         }
631         for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) {
632             Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName);
633             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
634         }
635         Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, mediaType);
636         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
637     }
638
639     @Test
640     public void testReadGuardPoliciesJson() throws Exception {
641         testReadGuardPolicies(APP_JSON);
642     }
643
644     @Test
645     public void testReadGuardPoliciesYaml() throws Exception {
646         testReadGuardPolicies(APP_YAML);
647     }
648
649     private void testReadGuardPolicies(String mediaType) throws Exception {
650         createGuardPolicies();
651
652         Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, mediaType);
653         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
654
655         rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType);
656         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
657
658         rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, mediaType);
659         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
660
661         rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, mediaType);
662         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
663     }
664
665     @Test
666     public void testReadOperationalPoliciesJson() throws Exception {
667         testReadOperationalPolicies(APP_JSON);
668     }
669
670     @Test
671     public void testReadOperationalPoliciesYaml() throws Exception {
672         testReadOperationalPolicies(APP_YAML);
673     }
674
675     private void testReadOperationalPolicies(String mediaType) throws Exception {
676         createOperationalPolicies();
677
678         Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, mediaType);
679         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
680
681         rawResponse = readResource(OPS_POLICIES_VCPE_VERSION, mediaType);
682         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
683
684         rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, mediaType);
685         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
686
687         rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, mediaType);
688         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
689
690         rawResponse = readResource(OPS_POLICIES_VFIREWALL_LATEST, mediaType);
691         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
692
693         rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, mediaType);
694         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
695     }
696
697     @Test
698     public void testDeleteGuardPolicyJson() throws Exception {
699         testDeleteGuardPolicy(APP_JSON);
700     }
701
702     @Test
703     public void testDeleteGuardPolicyYaml() throws Exception {
704         testDeleteGuardPolicy(APP_YAML);
705     }
706
707     private void testDeleteGuardPolicy(String mediaType) throws Exception {
708         createGuardPolicies();
709
710         Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType);
711         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
712     }
713
714     @Test
715     public void testGetDeployedVersionsOfGuardPolicyJson() throws Exception {
716         testGetDeployedVersionsOfGuardPolicy(APP_JSON);
717     }
718
719     @Test
720     public void testGetDeployedVersionsOfGuardPolicyYaml() throws Exception {
721         testGetDeployedVersionsOfGuardPolicy(APP_YAML);
722     }
723
724     private void testGetDeployedVersionsOfGuardPolicy(String mediaType) throws Exception {
725         Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_DEPLOYED, mediaType);
726         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
727         ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
728         assertEquals(
729                 "could not find policy with ID guard.frequency.scaleout and type "
730                         + "onap.policies.controlloop.guard.FrequencyLimiter:1.0.0 deployed in any pdp group",
731                 errorResponse.getErrorMessage());
732     }
733
734     @Test
735     public void testDeleteOperationalPolicyJson() throws Exception {
736         testDeleteOperationalPolicy(APP_JSON);
737     }
738
739     @Test
740     public void testDeleteOperationalPolicyYaml() throws Exception {
741         testDeleteOperationalPolicy(APP_YAML);
742     }
743
744     private void testDeleteOperationalPolicy(String mediaType) throws Exception {
745         createPolicyTypes();
746
747         Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, mediaType);
748         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
749         ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
750         assertEquals("no policy found for policy: operational.restart:1", error.getErrorMessage());
751     }
752
753     @Test
754     public void testGetDeployedVersionsOfPolicyJson() throws Exception {
755         testGetDeployedVersionsOfPolicy(APP_JSON);
756     }
757
758     @Test
759     public void testGetDeployedVersionsOfPolicyYaml() throws Exception {
760         testGetDeployedVersionsOfPolicy(APP_YAML);
761     }
762
763     private void testGetDeployedVersionsOfPolicy(String mediaType) throws Exception {
764         Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_DEPLOYED, mediaType);
765         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
766         ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
767         assertEquals(
768                 "could not find policy with ID onap.restart.tca and type "
769                         + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 deployed in any pdp group",
770                 errorResponse.getErrorMessage());
771     }
772
773     @Test
774     public void testGetLatestVersionOfOperationalPolicyJson() throws Exception {
775         testGetLatestVersionOfOperationalPolicy(APP_JSON);
776     }
777
778     @Test
779     public void testGetLatestVersionOfOperationalPolicyYaml() throws Exception {
780         testGetLatestVersionOfOperationalPolicy(APP_YAML);
781     }
782
783     private void testGetLatestVersionOfOperationalPolicy(String mediaType) throws Exception {
784         Response rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, mediaType);
785         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
786         ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
787         assertEquals("no policy found for policy: operational.scaleout:null", errorResponse.getErrorMessage());
788     }
789
790     @Test
791     public void testGetSpecificVersionOfOperationalPolicyJson() throws Exception {
792         testGetSpecificVersionOfOperationalPolicy(APP_JSON);
793     }
794
795     @Test
796     public void testGetSpecificVersionOfOperationalPolicyYaml() throws Exception {
797         testGetSpecificVersionOfOperationalPolicy(APP_YAML);
798     }
799
800     private void testGetSpecificVersionOfOperationalPolicy(String mediaType) throws Exception {
801         Response rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, mediaType);
802         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
803         ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
804         assertEquals("no policy found for policy: operational.scaleout:1", errorResponse.getErrorMessage());
805     }
806
807     @Test
808     public void testGetDeployedVersionsOfOperationalPolicyJson() throws Exception {
809         testGetDeployedVersionsOfOperationalPolicy(APP_JSON);
810     }
811
812     @Test
813     public void testGetDeployedVersionsOfOperationalPolicyYaml() throws Exception {
814         testGetDeployedVersionsOfOperationalPolicy(APP_YAML);
815     }
816
817     private void testGetDeployedVersionsOfOperationalPolicy(String mediaType) throws Exception {
818         Response rawResponse = readResource(OPS_POLICIES_VCPE_DEPLOYED, mediaType);
819         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
820         ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
821         assertEquals(
822                 "could not find policy with ID operational.restart and type "
823                         + "onap.policies.controlloop.Operational:1.0.0 deployed in any pdp group",
824                 errorResponse.getErrorMessage());
825     }
826
827     @Test
828     public void testDeleteSpecificVersionOfOperationalPolicy() throws Exception {
829         createOperationalPolicies();
830
831         Response rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, APP_JSON);
832         assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
833
834         rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, APP_YAML);
835         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
836         ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
837         assertEquals("no policy found for policy: operational.scaleout:1", errorResponse.getErrorMessage());
838     }
839
840     private Response createResource(String endpoint, String resourceName) throws Exception {
841
842         String mediaType = APP_JSON; // default media type
843         ToscaServiceTemplate rawServiceTemplate = new ToscaServiceTemplate();
844         if (resourceName.endsWith(".json")) {
845             rawServiceTemplate =
846                     standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class);
847         } else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) {
848             mediaType = APP_YAML;
849             rawServiceTemplate = standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName),
850                     ToscaServiceTemplate.class);
851         }
852
853         final Invocation.Builder invocationBuilder;
854
855         invocationBuilder = sendHttpsRequest(endpoint, mediaType);
856
857         Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType);
858         return invocationBuilder.post(entity);
859     }
860
861     private Response createGuardPolicy(String endpoint, String resourceName) throws Exception {
862
863         String mediaType = APP_JSON; // default media type
864         LegacyGuardPolicyInput rawGuardPolicy = new LegacyGuardPolicyInput();
865         if (resourceName.endsWith(".json")) {
866             rawGuardPolicy =
867                     standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
868         } else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) {
869             mediaType = APP_YAML;
870             rawGuardPolicy = standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName),
871                     LegacyGuardPolicyInput.class);
872         }
873
874         final Invocation.Builder invocationBuilder;
875
876         invocationBuilder = sendHttpsRequest(endpoint, mediaType);
877
878         Entity<LegacyGuardPolicyInput> entity = Entity.entity(rawGuardPolicy, mediaType);
879         return invocationBuilder.post(entity);
880     }
881
882     private Response createOperationalPolicy(String endpoint, String resourceName) throws Exception {
883
884         String mediaType = APP_JSON; // default media type
885         LegacyOperationalPolicy rawOpsPolicy = new LegacyOperationalPolicy();
886         if (resourceName.endsWith(".json")) {
887             rawOpsPolicy = standardCoder.decode(ResourceUtils.getResourceAsString(resourceName),
888                     LegacyOperationalPolicy.class);
889         } else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) {
890             mediaType = APP_YAML;
891             rawOpsPolicy = standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName),
892                     LegacyOperationalPolicy.class);
893         }
894
895         final Invocation.Builder invocationBuilder;
896
897         invocationBuilder = sendHttpsRequest(endpoint, mediaType);
898
899         Entity<LegacyOperationalPolicy> entity = Entity.entity(rawOpsPolicy, mediaType);
900         return invocationBuilder.post(entity);
901     }
902
903     private Response readResource(String endpoint, String mediaType) throws Exception {
904
905         final Invocation.Builder invocationBuilder;
906
907         invocationBuilder = sendHttpsRequest(endpoint, mediaType);
908
909         return invocationBuilder.get();
910
911     }
912
913     private Response deleteResource(String endpoint, String mediaType) throws Exception {
914
915         final Invocation.Builder invocationBuilder;
916
917         invocationBuilder = sendHttpsRequest(endpoint, mediaType);
918
919         return invocationBuilder.delete();
920     }
921
922     private void createPolicyTypes() throws Exception {
923         for (String resrcName : TOSCA_PPOLICYTYPE_RESOURCE_NAMES) {
924             Response rawResponse = createResource(POLICYTYPES, resrcName);
925             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
926         }
927     }
928
929     private void createGuardPolicies() throws Exception {
930         createPolicyTypes();
931
932         for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
933             Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
934             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
935         }
936     }
937
938     private void createOperationalPolicies() throws Exception {
939         createPolicyTypes();
940
941         for (String resrcName : LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES) {
942             Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName);
943             assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
944         }
945     }
946
947     private Invocation.Builder sendHttpsRequest(final String endpoint, String mediaType) throws Exception {
948
949         final TrustManager[] noopTrustManager = NetworkUtil.getAlwaysTrustingManager();
950
951         final SSLContext sc = SSLContext.getInstance("TLSv1.2");
952         sc.init(null, noopTrustManager, new SecureRandom());
953         final ClientBuilder clientBuilder =
954                 ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true);
955         final Client client = clientBuilder.build();
956         final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34");
957         client.register(feature);
958
959         client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
960         if (APP_JSON.equalsIgnoreCase(mediaType)) {
961             client.register(GsonMessageBodyHandler.class);
962         } else if (APP_YAML.equalsIgnoreCase(mediaType)) {
963             client.register(YamlMessageBodyHandler.class);
964         }
965
966         final WebTarget webTarget = client.target("https://localhost:" + apiPort + "/policy/api/v1/" + endpoint);
967
968         final Invocation.Builder invocationBuilder = webTarget.request(mediaType);
969
970         if (!NetworkUtil.isTcpPortOpen("localhost", apiPort, 60, 1000L)) {
971             throw new IllegalStateException("cannot connect to port " + apiPort);
972         }
973         return invocationBuilder;
974     }
975
976     private void updateApiStatistics() {
977
978         ApiStatisticsManager.updateTotalApiCallCount();
979         ApiStatisticsManager.updateApiCallSuccessCount();
980         ApiStatisticsManager.updateApiCallFailureCount();
981         ApiStatisticsManager.updateTotalPolicyGetCount();
982         ApiStatisticsManager.updateTotalPolicyPostCount();
983         ApiStatisticsManager.updateTotalPolicyTypeGetCount();
984         ApiStatisticsManager.updateTotalPolicyTypePostCount();
985         ApiStatisticsManager.updatePolicyGetSuccessCount();
986         ApiStatisticsManager.updatePolicyGetFailureCount();
987         ApiStatisticsManager.updatePolicyPostSuccessCount();
988         ApiStatisticsManager.updatePolicyPostFailureCount();
989         ApiStatisticsManager.updatePolicyTypeGetSuccessCount();
990         ApiStatisticsManager.updatePolicyTypeGetFailureCount();
991         ApiStatisticsManager.updatePolicyTypePostSuccessCount();
992         ApiStatisticsManager.updatePolicyTypePostFailureCount();
993     }
994
995     private void validateStatisticsReport(final StatisticsReport report, final int code) {
996
997         assertEquals(code, report.getCode());
998     }
999
1000     private void validateHealthCheckReport(final String name, final String url, final boolean healthy, final int code,
1001             final String message, final HealthCheckReport report) {
1002
1003         assertEquals(name, report.getName());
1004         assertEquals(url, report.getUrl());
1005         assertEquals(healthy, report.isHealthy());
1006         assertEquals(code, report.getCode());
1007         assertEquals(message, report.getMessage());
1008     }
1009 }