* ============LICENSE_START=======================================================
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020,2022-2023 Nordix Foundation.
- * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2019-2020, 2022-2023 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2023 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.api.main.rest;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.core.Response.Status;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.api.main.PolicyApiApplication;
-import org.onap.policy.api.main.rest.provider.statistics.ApiStatisticsManager;
-import org.onap.policy.api.main.rest.provider.statistics.StatisticsReport;
import org.onap.policy.api.main.rest.utils.CommonTestRestController;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.security.SelfSignedKeyStore;
import org.onap.policy.models.errors.concepts.ErrorResponse;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
/**
* Class to perform unit test of {@link ApiRestController}.
*
* @author Chenfei Gao (cgao@research.att.com)
*/
-@RunWith(SpringRunner.class)
@SpringBootTest(classes = PolicyApiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({ "test", "default" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
-public class TestApiRestServer extends CommonTestRestController {
+class TestApiRestServer extends CommonTestRestController {
private static final String ALIVE = "alive";
private static final String SELF = NetworkUtil.getHostname();
private static final String APP_YAML = "application/yaml";
private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
- private static final String STATISTICS_ENDPOINT = "statistics";
private static final String OP_POLICY_NAME_VCPE = "operational.restart";
private static final String POLICIES = "policies";
+ private static final String TOSCA_POLICY_VER_RESOURCE =
+ "policytypes/onap.restart.tca.snapshot.yaml";
// @formatter:off
+
private static final String[] TOSCA_POLICY_RESOURCE_NAMES = {"policies/vCPE.policy.monitoring.input.tosca.json",
"policies/vCPE.policy.monitoring.input.tosca.yaml", "policies/vDNS.policy.monitoring.input.tosca.json",
"policies/vDNS.policy.monitoring.input.tosca.v2.yaml"};
private static final String TOSCA_POLICYTYPE_OP_RESOURCE =
"policytypes/onap.policies.controlloop.operational.Common.yaml";
+ private static final String TOSCA_POLICYTYPE_VER_RESOURCE =
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.snapshot.yaml";
+
private static final String[] TOSCA_POLICYTYPE_RESOURCE_NAMES = {
"policytypes/onap.policies.monitoring.tcagen2.yaml",
"policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml",
@LocalServerPort
private int apiPort;
- @Autowired
- private ApiStatisticsManager mgr;
-
/**
* Initializes parameters and set up test environment.
*
* @throws IOException on I/O exceptions
* @throws InterruptedException if interrupted
*/
- @BeforeClass
- public static void setupParameters() throws IOException, InterruptedException {
+ @BeforeAll
+ static void setupParameters() throws IOException, InterruptedException {
keystore = new SelfSignedKeyStore();
}
}
@Test
- public void testSwagger() throws Exception {
+ void testSwagger() throws Exception {
super.testSwagger(apiPort);
}
@Test
- public void testCreatePolicyTypes() throws Exception {
+ void testCreatePolicyTypes() throws Exception {
for (String resrcName : TOSCA_POLICYTYPE_RESOURCE_NAMES) {
Response rawResponse = createResource(POLICYTYPES, resrcName, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
- public void testCreatePolicies() throws Exception {
+ void testCreatePolicies() throws Exception {
for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) {
Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
- public void testSimpleCreatePolicies() throws Exception {
+ void testSimpleCreatePolicies() throws Exception {
for (String resrcName : TOSCA_POLICIES_RESOURCE_NAMES) {
Response rawResponse = createResource(POLICIES, resrcName, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
.contains("item \"policy type\" value \"IDontExist:1.0.0\" INVALID, not found");
}
+ @Test
+ void testPoliciesVersioning() throws Exception {
+ var rawResponse = createResource(POLICYTYPES, TOSCA_POLICYTYPE_VER_RESOURCE, apiPort);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = createResource(POLICIES, TOSCA_POLICY_VER_RESOURCE, apiPort);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+
@SuppressWarnings("unchecked")
@Test
- public void testToscaCompliantOpDroolsPolicies() throws Exception {
+ void testToscaCompliantOpDroolsPolicies() throws Exception {
Response rawResponse = createResource(POLICYTYPES, TOSCA_POLICYTYPE_OP_RESOURCE, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
- public void testHealthCheckSuccessJson() throws Exception {
+ void testHealthCheckSuccessJson() throws Exception {
testHealthCheckSuccess(APP_JSON);
}
@Test
- public void testHealthCheckSuccessYaml() throws Exception {
+ void testHealthCheckSuccessYaml() throws Exception {
testHealthCheckSuccess(APP_YAML);
}
private void testHealthCheckSuccess(String mediaType) throws Exception {
final Invocation.Builder invocationBuilder = sendHttpsRequest(
- CONTEXT_PATH, HEALTHCHECK_ENDPOINT, mediaType, apiPort);
+ HEALTHCHECK_ENDPOINT, mediaType, apiPort);
final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
}
@Test
- public void testApiStatistics_200_Json() throws Exception {
- testApiStatistics_200(APP_JSON);
- }
-
- @Test
- public void testApiStatistics_200_Yaml() throws Exception {
- testApiStatistics_200(APP_YAML);
- }
-
- private void testApiStatistics_200(String mediaType) throws Exception {
- Invocation.Builder invocationBuilder = sendHttpsRequest(CONTEXT_PATH, STATISTICS_ENDPOINT, mediaType, apiPort);
- StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
- validateStatisticsReport(report, 200);
- updateApiStatistics();
- invocationBuilder = sendHttpsRequest(CONTEXT_PATH, STATISTICS_ENDPOINT, mediaType, apiPort);
- report = invocationBuilder.get(StatisticsReport.class);
- validateStatisticsReport(report, 200);
- // ApiStatisticsManager.resetAllStatistics();
- }
-
- @Test
- public void testReadPolicyTypesJson() throws Exception {
+ void testReadPolicyTypesJson() throws Exception {
testReadPolicyTypes(APP_JSON);
}
@Test
- public void testReadPolicyTypesYaml() throws Exception {
+ void testReadPolicyTypesYaml() throws Exception {
testReadPolicyTypes(APP_YAML);
}
}
@Test
- public void testDeletePolicyTypeJson() throws Exception {
+ void testDeletePolicyTypeJson() throws Exception {
testDeletePolicyType(APP_JSON);
}
@Test
- public void testDeletePolicyTypeYaml() throws Exception {
+ void testDeletePolicyTypeYaml() throws Exception {
testDeletePolicyType(APP_YAML);
}
}
@Test
- public void testReadPoliciesJson() throws Exception {
+ void testReadPoliciesJson() throws Exception {
testReadPolicies(APP_JSON);
}
@Test
- public void testReadPoliciesYaml() throws Exception {
+ void testReadPoliciesYaml() throws Exception {
testReadPolicies(APP_YAML);
}
}
@Test
- public void testNamingPolicyGet() throws Exception {
+ void testNamingPolicyGet() throws Exception {
Response rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/"
+ "policies/SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP/versions/1.0.0", APP_JSON, apiPort);
}
@Test
- public void testDeletePoliciesJson() throws Exception {
+ void testDeletePoliciesJson() throws Exception {
testDeletePolicies(APP_JSON);
}
@Test
- public void testDeletePoliciesYaml() throws Exception {
+ void testDeletePoliciesYaml() throws Exception {
testDeletePolicies(APP_YAML);
}
}
@Test
- public void testDeletePolicyVersionJson() throws Exception {
+ void testDeletePolicyVersionJson() throws Exception {
testDeletePolicyVersion(APP_JSON);
}
@Test
- public void testDeletePolicyVersionYaml() throws Exception {
+ void testDeletePolicyVersionYaml() throws Exception {
testDeletePolicyVersion(APP_YAML);
}
}
@Test
- public void testGetAllVersionOfPolicyJson() throws Exception {
+ void testGetAllVersionOfPolicyJson() throws Exception {
testGetAllVersionOfPolicy(APP_JSON);
}
@Test
- public void testGetAllVersionOfPolicyYaml() throws Exception {
+ void testGetAllVersionOfPolicyYaml() throws Exception {
testGetAllVersionOfPolicy(APP_YAML);
}
}
@Test
- public void testGetPoliciesJson() throws Exception {
+ void testGetPoliciesJson() throws Exception {
getPolicies(APP_JSON);
}
@Test
- public void testGetPoliciesYaml() throws Exception {
+ void testGetPoliciesYaml() throws Exception {
getPolicies(APP_YAML);
}
}
@Test
- public void testGetSpecificPolicyJson() throws Exception {
+ void testGetSpecificPolicyJson() throws Exception {
getSpecificPolicy(APP_JSON);
}
@Test
- public void testGetSpecificPolicyYaml() throws Exception {
+ void testGetSpecificPolicyYaml() throws Exception {
getSpecificPolicy(APP_YAML);
}
}
@Test
- public void testDeleteSpecificPolicy() throws Exception {
+ void testDeleteSpecificPolicy() throws Exception {
Response rawResponse;
for (String resrcName : TOSCA_POLICYTYPE_RESOURCE_NAMES) {
rawResponse = createResource(POLICYTYPES, resrcName, apiPort);
}
- private void updateApiStatistics() {
- mgr.updateTotalApiCallCount();
- mgr.updateApiCallSuccessCount();
- mgr.updateApiCallFailureCount();
- mgr.updateTotalPolicyGetCount();
- mgr.updateTotalPolicyPostCount();
- mgr.updateTotalPolicyTypeGetCount();
- mgr.updateTotalPolicyTypePostCount();
- mgr.updatePolicyGetSuccessCount();
- mgr.updatePolicyGetFailureCount();
- mgr.updatePolicyPostSuccessCount();
- mgr.updatePolicyPostFailureCount();
- mgr.updatePolicyTypeGetSuccessCount();
- mgr.updatePolicyTypeGetFailureCount();
- mgr.updatePolicyTypePostSuccessCount();
- mgr.updatePolicyTypePostFailureCount();
- }
-
- private void validateStatisticsReport(final StatisticsReport report, final int code) {
-
- assertEquals(code, report.getCode());
- }
-
private void validateHealthCheckReport(final String name, final String url, final boolean healthy, final int code,
final String message, final HealthCheckReport report) {