aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorChenfei Gao <cgao@research.att.com>2019-09-16 22:20:34 -0400
committerChenfei Gao <cgao@research.att.com>2019-09-16 22:26:07 -0400
commit20390c6ed94e2082cb688d76aacabe5366d908fe (patch)
treeb5904fc70141b2ce05c24a6fadb959f282c27c0a /main
parenteeb2aa12f0445829d0aedb91d729f61102c070d8 (diff)
Add changes to support application/yaml in api
Issue-ID: POLICY-2101 Change-Id: I0860ff11231b6a649f52355d8d9333eec7d78826 Signed-off-by: Chenfei Gao <cgao@research.att.com>
Diffstat (limited to 'main')
-rw-r--r--main/pom.xml5
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java4
-rw-r--r--main/src/test/java/org/onap/policy/api/main/ApiTestSupportUtilities.java48
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java1177
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java34
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java34
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java22
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java22
8 files changed, 819 insertions, 527 deletions
diff --git a/main/pom.xml b/main/pom.xml
index 07287e9f..d7552fcb 100644
--- a/main/pom.xml
+++ b/main/pom.xml
@@ -68,6 +68,11 @@
<version>${policy.models.version}</version>
</dependency>
<dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils</artifactId>
+ <version>${policy.common.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java
index 89ca042b..6a4e39d3 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java
@@ -64,8 +64,8 @@ import org.slf4j.LoggerFactory;
*/
@Path("/policy/api/v1")
@Api(value = "Legacy Policy Design API")
-@Produces("application/json")
-@Consumes("application/json")
+@Produces({"application/json", "application/yaml"})
+@Consumes({"application/json", "application/yaml"})
public class LegacyApiRestController extends CommonRestController {
private static final Logger LOGGER = LoggerFactory.getLogger(LegacyApiRestController.class);
diff --git a/main/src/test/java/org/onap/policy/api/main/ApiTestSupportUtilities.java b/main/src/test/java/org/onap/policy/api/main/ApiTestSupportUtilities.java
deleted file mode 100644
index 79a33ffb..00000000
--- a/main/src/test/java/org/onap/policy/api/main/ApiTestSupportUtilities.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.api.main;
-
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.yaml.snakeyaml.Yaml;
-
-/**
- * Utility class to support API tests.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-public final class ApiTestSupportUtilities {
- private ApiTestSupportUtilities() {
- // prevent instantiation of this class
- }
-
- /**
- * Convert a YAML string to a JSON string.
- *
- * @param yamlString the Yaml string.
- * @return the JSON string
- * @throws CoderException on encoding JSON errors
- */
- public static final String yaml2Json(final String yamlString) throws CoderException {
- Object yamlObject = new Yaml().load(yamlString);
- return new StandardCoder().encode(yamlObject);
- }
-}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
index 8b396fc7..b065277e 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
@@ -22,14 +22,12 @@
package org.onap.policy.api.main.rest;
-import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.security.SecureRandom;
@@ -45,15 +43,12 @@ import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.junit.After;
import org.junit.Test;
-import org.onap.policy.api.main.ApiTestSupportUtilities;
import org.onap.policy.api.main.exception.PolicyApiException;
import org.onap.policy.api.main.parameters.ApiParameterGroup;
import org.onap.policy.api.main.parameters.CommonTestData;
@@ -61,11 +56,13 @@ import org.onap.policy.api.main.rest.provider.PolicyProvider;
import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
import org.onap.policy.api.main.startstop.Main;
import org.onap.policy.common.endpoints.http.server.RestServer;
+import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
@@ -89,6 +86,8 @@ public class TestApiRestServer {
private static final String ALIVE = "alive";
private static final String SELF = "self";
private static final String NAME = "Policy API";
+ private static final String APP_JSON = "application/json";
+ private static final String APP_YAML = "application/yaml";
private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
private static final String STATISTICS_ENDPOINT = "statistics";
@@ -158,23 +157,42 @@ public class TestApiRestServer {
private Main main;
private RestServer restServer;
private StandardCoder standardCoder = new StandardCoder();
+ private StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
private int port;
// @formatter:off
private String[] toscaPolicyResourceNames = {
"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.yaml",
"policies/vFirewall.policy.monitoring.input.tosca.json",
+ "policies/vFirewall.policy.monitoring.input.tosca.yaml"
};
private String[] toscaPolicyTypeResourceNames = {
"policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml",
- "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml"
+ "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml",
+ "policytypes/onap.policies.Optimization.yaml",
+ "policytypes/onap.policies.controlloop.Operational.yaml",
+ "policytypes/onap.policies.controlloop.guard.Blacklist.yaml",
+ "policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml",
+ "policytypes/onap.policies.controlloop.guard.MinMax.yaml",
+ "policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml",
+ "policytypes/onap.policies.optimization.AffinityPolicy.yaml",
+ "policytypes/onap.policies.optimization.DistancePolicy.yaml",
+ "policytypes/onap.policies.optimization.HpaPolicy.yaml",
+ "policytypes/onap.policies.optimization.OptimizationPolicy.yaml",
+ "policytypes/onap.policies.optimization.PciPolicy.yaml",
+ "policytypes/onap.policies.optimization.QueryPolicy.yaml",
+ "policytypes/onap.policies.optimization.SubscriberPolicy.yaml",
+ "policytypes/onap.policies.optimization.Vim_fit.yaml",
+ "policytypes/onap.policies.optimization.VnfPolicy.yaml"
};
private String[] legacyGuardPolicyResourceNames = {
"policies/vDNS.policy.guard.frequency.input.json",
- "policies/vDNS.policy.guard.minmax.input.json",
+ "policies/vDNS.policy.guard.minmax.input.json"
};
private String[] legacyOperationalPolicyResourceNames = {
@@ -182,6 +200,7 @@ public class TestApiRestServer {
"policies/vDNS.policy.operational.input.json",
"policies/vFirewall.policy.operational.input.json"
};
+
private static PolicyModelsProviderParameters providerParams;
private static ApiParameterGroup apiParamGroup;
private static PolicyProvider policyProvider;
@@ -228,11 +247,179 @@ public class TestApiRestServer {
}
@Test
- public void testHealthCheckSuccess() {
+ public void testApiStatisticsConstructorIsPrivate() {
+
+ try {
+ final Constructor<ApiStatisticsManager> constructor = ApiStatisticsManager.class.getDeclaredConstructor();
+ assertTrue(Modifier.isPrivate(constructor.getModifiers()));
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ } catch (final Exception exp) {
+ assertTrue(exp.getCause().toString().contains("Instantiation of the class is not allowed"));
+ }
+ }
+
+ @Test
+ public void testCreatePolicyTypes() {
+ try {
+ main = startApiService(true);
+ for (String resrcName : toscaPolicyTypeResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testCreatePolicies() {
+ try {
+ main = startApiService(true);
+ for (String resrcName : toscaPolicyResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
+ error.getErrorMessage());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testCreateGuardPolicies() {
+ try {
+ main = startApiService(true);
+ for (String resrcName : legacyGuardPolicyResourceNames) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testCreateGuardPoliciesPersistent() {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);
+ for (String resrcName : legacyGuardPolicyResourceNames) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testCreateOperationalPolicies() {
+ try {
+ main = startApiService(true);
+ for (String resrcName : legacyOperationalPolicyResourceNames) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testCreateOperationalPoliciesPersistent() {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);
+ for (String resrcName : legacyOperationalPolicyResourceNames) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testHttpsCreatePolicyTypes() {
+ try {
+ main = startApiService(false);
+ for (String resrcName : toscaPolicyTypeResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName, false);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testHttpsCreatePolicies() {
+ try {
+ main = startApiService(false);
+ for (String resrcName : toscaPolicyResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, false);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
+ error.getErrorMessage());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testHttpsCreateGuardPolicies() {
+ try {
+ main = startApiService(false);
+ for (String resrcName : legacyGuardPolicyResourceNames) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, false);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testHttpsCreateOperationalPolicies() {
+ try {
+ main = startApiService(false);
+ for (String resrcName : legacyOperationalPolicyResourceNames) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, false);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testHealthCheckSuccessJson() {
+ testHealthCheckSuccess(APP_JSON);
+ }
+
+ @Test
+ public void testHealthCheckSuccessYaml() {
+ testHealthCheckSuccess(APP_YAML);
+ }
+
+
+
+ private void testHealthCheckSuccess(String mediaType) {
try {
main = startApiService(true);
- final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT);
+ final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT, mediaType);
final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
} catch (final Exception exp) {
@@ -242,271 +429,317 @@ public class TestApiRestServer {
}
@Test
- public void testHealthCheckFailure() throws InterruptedException, IOException {
+ public void testHealthCheckFailureJson() {
+ testHealthCheckFailure(APP_JSON);
+ }
- port = NetworkUtil.allocPort();
- final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false, port);
- restServerParams.setName(CommonTestData.API_GROUP_NAME);
- restServer = new RestServer(restServerParams, null, ApiRestController.class);
+ @Test
+ public void testHealthCheckFailureYaml() {
+ testHealthCheckFailure(APP_YAML);
+ }
+
+ private void testHealthCheckFailure(String mediaType) {
try {
+ port = NetworkUtil.allocPort();
+ final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false, port);
+ restServerParams.setName(CommonTestData.API_GROUP_NAME);
+ restServer = new RestServer(restServerParams, null, ApiRestController.class);
+
restServer.start();
- final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT);
+ final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT, mediaType);
final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
validateHealthCheckReport(NAME, SELF, false, 500, NOT_ALIVE, report);
assertTrue(restServer.isAlive());
assertTrue(restServer.toString().startsWith("RestServer [servers="));
- } catch (final Exception exp) {
- LOGGER.error("testHealthCheckFailure failed", exp);
+ } catch (Exception exp) {
fail("Test should not throw an exception");
}
}
@Test
- public void testHttpsHealthCheckSuccess() {
+ public void testHttpsHealthCheckSuccessJson() {
+ testHttpsHealthCheckSuccess(APP_JSON);
+ }
+ @Test
+ public void testHttpsHealthCheckSuccessYaml() {
+ testHttpsHealthCheckSuccess(APP_YAML);
+ }
+
+ private void testHttpsHealthCheckSuccess(String mediaType) {
try {
main = startApiService(false);
- final Invocation.Builder invocationBuilder = sendHttpsRequest(HEALTHCHECK_ENDPOINT);
+ final Invocation.Builder invocationBuilder = sendHttpsRequest(HEALTHCHECK_ENDPOINT, mediaType);
final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
- } catch (final Exception exp) {
- LOGGER.error("testHttpsHealthCheckSuccess failed", exp);
+ } catch (Exception exp) {
fail("Test should not throw an exception");
}
}
@Test
- public void testApiStatistics_200() {
+ public void testApiStatistics_200_Json() {
+ testApiStatistics_200(APP_JSON);
+ }
+
+ @Test
+ public void testApiStatistics_200_Yaml() {
+ testApiStatistics_200(APP_YAML);
+ }
+ private void testApiStatistics_200(String mediaType) {
try {
main = startApiService(true);
- Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT);
+ Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT, mediaType);
StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
validateStatisticsReport(report, 200);
updateApiStatistics();
- invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT);
+ invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT, mediaType);
report = invocationBuilder.get(StatisticsReport.class);
validateStatisticsReport(report, 200);
ApiStatisticsManager.resetAllStatistics();
- } catch (final Exception exp) {
- LOGGER.error("testApiStatistics_200 failed", exp);
+ } catch (Exception exp) {
fail("Test should not throw an exception");
}
}
@Test
- public void testApiStatistics_500() throws Exception {
-
- port = NetworkUtil.allocPort();
- final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false, port);
- restServerParams.setName(CommonTestData.API_GROUP_NAME);
- restServer = new RestServer(restServerParams, null, ApiRestController.class);
- try {
- restServer.start();
- final Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT);
- final StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
- validateStatisticsReport(report, 500);
- ApiStatisticsManager.resetAllStatistics();
- } catch (final Exception exp) {
- LOGGER.error("testApiStatistics_500 failed", exp);
- fail("Test should not throw an exception");
- }
+ public void testHttpsApiStatisticsJson() {
+ testHttpsApiStatistics(APP_JSON);
}
@Test
- public void testHttpsApiStatistics() {
+ public void testHttpsApiStatisticsYaml() {
+ testHttpsApiStatistics(APP_YAML);
+ }
+ private void testHttpsApiStatistics(String mediaType) {
try {
main = startApiService(false);
- final Invocation.Builder invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT);
+ final Invocation.Builder invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT, mediaType);
final StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
validateStatisticsReport(report, 200);
- } catch (final Exception exp) {
- LOGGER.error("testHttpsApiStatistics failed", exp);
+ } catch (Exception exp) {
fail("Test should not throw an exception");
}
}
@Test
- public void testApiStatisticsConstructorIsPrivate() {
+ public void testApiStatistics_500_Json() {
+ testApiStatistics_500(APP_JSON);
+ }
+
+ @Test
+ public void testApiStatistics_500_Yaml() {
+ testApiStatistics_500(APP_YAML);
+ }
+
+ private void testApiStatistics_500(String mediaType) {
try {
- final Constructor<ApiStatisticsManager> constructor = ApiStatisticsManager.class.getDeclaredConstructor();
- assertTrue(Modifier.isPrivate(constructor.getModifiers()));
- constructor.setAccessible(true);
- constructor.newInstance();
- } catch (final Exception exp) {
- assertTrue(exp.getCause().toString().contains("Instantiation of the class is not allowed"));
+ port = NetworkUtil.allocPort();
+ final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false, port);
+ restServerParams.setName(CommonTestData.API_GROUP_NAME);
+ restServer = new RestServer(restServerParams, null, ApiRestController.class);
+
+ restServer.start();
+ final Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT, mediaType);
+ final StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
+ validateStatisticsReport(report, 500);
+ ApiStatisticsManager.resetAllStatistics();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
}
}
- @Test
- public void testCreatePolicyTypes() {
- assertThatCode(() -> {
- main = startApiService(true);
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
- }).doesNotThrowAnyException();
+ @Test
+ public void testReadPolicyTypesJson() {
+ testReadPolicyTypes(APP_JSON);
}
@Test
- public void testReadPolicyTypes() {
+ public void testReadPolicyTypesYaml() {
+ testReadPolicyTypes(APP_YAML);
+ }
- assertThatCode(() -> {
+ private void testReadPolicyTypes(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = readResource(POLICYTYPES, true);
+ Response rawResponse = readResource(POLICYTYPES, true, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
assertTrue(response.getPolicyTypes().isEmpty());
- rawResponse = readResource(POLICYTYPES_TCA, true);
+ rawResponse = readResource(POLICYTYPES_TCA, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:null does not exist",
error.getErrorMessage());
- rawResponse = readResource(POLICYTYPES_TCA_VERSION, true);
+ rawResponse = readResource(POLICYTYPES_TCA_VERSION, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
error.getErrorMessage());
- rawResponse = readResource(POLICYTYPES_TCA_LATEST, true);
+ rawResponse = readResource(POLICYTYPES_TCA_LATEST, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:null does not exist",
error.getErrorMessage());
- rawResponse = readResource(POLICYTYPES_COLLECTOR, true);
+ rawResponse = readResource(POLICYTYPES_COLLECTOR, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("policy type with ID "
+ "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:null does not exist",
error.getErrorMessage());
- rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, true);
+ rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("policy type with ID "
+ "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:1.0.0 does not exist",
error.getErrorMessage());
- rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, true);
+ rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("policy type with ID "
+ "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:null does not exist",
error.getErrorMessage());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testReadPolicyTypesPersistent() throws Exception {
+ public void testReadPolicyTypesPersistentJson() {
+ testReadPolicyTypesPersistent(APP_JSON);
+ }
- setupParameters();
- main = startApiService(true);
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
+ @Test
+ public void testReadPolicyTypesPersistentYaml() {
+ testReadPolicyTypesPersistent(APP_YAML);
+ }
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
+ private void testReadPolicyTypesPersistent(String mediaType) {
+ try {
+ setupParameters();
+ main = startApiService(true);
+ for (String resrcName : toscaPolicyTypeResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
+ }
- Response rawResponse = readResource(POLICYTYPES_TCA, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ for (String resrcName : toscaPolicyResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
- rawResponse = readResource(POLICYTYPES_TCA_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ Response rawResponse = readResource(POLICYTYPES_TCA, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_TCA_VERSION, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_TCA_LATEST, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_TCA_LATEST, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_COLLECTOR, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_COLLECTOR, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testDeletePolicyType() {
+ public void testDeletePolicyTypeJson() {
+ testDeletePolicyType(APP_JSON);
+ }
- assertThatCode(() -> {
+ @Test
+ public void testDeletePolicyTypeYaml() {
+ testDeletePolicyType(APP_YAML);
+ }
+
+ private void testDeletePolicyType(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, true);
+ Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
error.getErrorMessage());
- rawResponse = deleteResource(POLICYTYPES_COLLECTOR_VERSION, true);
+ rawResponse = deleteResource(POLICYTYPES_COLLECTOR_VERSION, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("policy type with ID "
+ "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:1.0.0 does not exist",
error.getErrorMessage());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testDeletePolicyTypePersistent() throws Exception {
+ public void testDeletePolicyTypePersistentJson() {
+ testDeletePolicyTypePersistent(APP_JSON);
+ }
- setupParameters(); // setup DB
+ @Test
+ public void testDeletePolicyTypePersistentYaml() {
+ testDeletePolicyTypePersistent(APP_YAML);
+ }
- main = startApiService(true);// create policy types
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
+ private void testDeletePolicyTypePersistent(String mediaType) {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);// create policy types
+ for (String resrcName : toscaPolicyTypeResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
+ }
+ Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, true, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
}
- Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
}
- @Test
- public void testCreatePolicies() {
- assertThatCode(() -> {
- main = startApiService(true);
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
- }
- }).doesNotThrowAnyException();
+ @Test
+ public void testReadPoliciesJson() {
+ testReadPolicies(APP_JSON);
}
@Test
- public void testReadPolicies() {
+ public void testReadPoliciesYaml() {
+ testReadPolicies(APP_YAML);
+ }
- assertThatCode(() -> {
+ private void testReadPolicies(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, true);
+ Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
assertEquals(
@@ -514,7 +747,7 @@ public class TestApiRestServer {
+ "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
error.getErrorMessage());
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, true);
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals(
@@ -522,7 +755,7 @@ public class TestApiRestServer {
+ "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
error.getErrorMessage());
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true);
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals(
@@ -530,519 +763,637 @@ public class TestApiRestServer {
+ "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
error.getErrorMessage());
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, true);
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals(
"policy with ID onap.restart.tca:null and "
+ "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
error.getErrorMessage());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testReadPoliciesPersistent() throws Exception {
+ public void testReadPoliciesPersistentJson() {
+ testReadPoliciesPersistent(APP_JSON);
+ }
- setupParameters();
- main = startApiService(true);
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
+ @Test
+ public void testReadPoliciesPersistentYaml() {
+ testReadPoliciesPersistent(APP_YAML);
+ }
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
+ private void testReadPoliciesPersistent(String mediaType) {
+ try {
+ setupParameters();
+ main = startApiService(true);
+ for (String resrcName : toscaPolicyTypeResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
+ }
- Response rawResponse;
- rawResponse = readResource(POLICYTYPES_TCA, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ for (String resrcName : toscaPolicyResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ Response rawResponse;
+ rawResponse = readResource(POLICYTYPES_TCA, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+ @Test
+ public void testDeletePoliciesJson() {
+ testDeletePolicies(APP_JSON);
}
@Test
- public void testDeletePolicies() {
+ public void testDeletePoliciesYaml() {
+ testDeletePolicies(APP_YAML);
+ }
- assertThatCode(() -> {
+ private void testDeletePolicies(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true);
+ Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
assertEquals(
"policy with ID onap.restart.tca:1.0.0 and "
+ "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
error.getErrorMessage());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testDeletePolicyVersion() throws Exception {
-
- setupParameters(); // setup DB
-
- main = startApiService(true);// create policy types
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
- Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ public void testDeletePolicyVersionJson() {
+ testDeletePolicyVersion(APP_JSON);
}
@Test
- public void testGetAllVersionOfPolicy() throws Exception {
-
- setupParameters(); // setup DB
+ public void testDeletePolicyVersionYaml() {
+ testDeletePolicyVersion(APP_YAML);
+ }
- main = startApiService(true);// create policy types
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
+ private void testDeletePolicyVersion(String mediaType) {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);// create policy types
+ for (String resrcName : toscaPolicyTypeResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
+ }
+ for (String resrcName : toscaPolicyResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
}
- Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
}
@Test
- public void testCreateGuardPolicies() {
-
- assertThatCode(() -> {
- main = startApiService(true);
- for (String resrcName : legacyGuardPolicyResourceNames) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }
- }).doesNotThrowAnyException();
+ public void testGetAllVersionOfPolicyJson() {
+ testGetAllVersionOfPolicy(APP_JSON);
}
@Test
- public void testCreateGuardPolicies1() throws Exception {
-
- setupParameters(); // setup DB
+ public void testGetAllVersionOfPolicyYaml() {
+ testGetAllVersionOfPolicy(APP_YAML);
+ }
- main = startApiService(true);
- for (String resrcName : legacyGuardPolicyResourceNames) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
+ private void testGetAllVersionOfPolicy(String mediaType) {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);// create policy types
+ for (String resrcName : toscaPolicyTypeResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
+ }
+ for (String resrcName : toscaPolicyResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, true, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
}
-
}
- @Test
- public void testCreateOperationalPolicies() {
-
- assertThatCode(() -> {
- main = startApiService(true);
- for (String resrcName : legacyOperationalPolicyResourceNames) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }
- }).doesNotThrowAnyException();
- }
@Test
- public void testCreateOperationalPolicies1() throws Exception {
-
- setupParameters(); // setup DB
-
- main = startApiService(true);
- for (String resrcName : legacyOperationalPolicyResourceNames) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
-
+ public void testReadGuardPoliciesJson() {
+ testReadGuardPolicies(APP_JSON);
}
@Test
- public void testReadGuardPolicies() {
+ public void testReadGuardPoliciesYaml() {
+ testReadGuardPolicies(APP_YAML);
+ }
- assertThatCode(() -> {
+ private void testReadGuardPolicies(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, true);
+ Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: guard.frequency.scaleout:null", error.getErrorMessage());
- rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, true);
+ rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: guard.frequency.scaleout:1", error.getErrorMessage());
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, true);
+ rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: guard.minmax.scaleout:null", error.getErrorMessage());
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, true);
+ rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: guard.minmax.scaleout:1", error.getErrorMessage());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testReadGuardPolicies1() throws Exception {
+ public void testReadGuardPoliciesPersistentJson() {
+ testReadGuardPoliciesPersistent(APP_JSON);
+ }
- setupParameters(); // setup DB
+ @Test
+ public void testReadGuardPoliciesPersistentYaml() {
+ testReadGuardPoliciesPersistent(APP_YAML);
+ }
- main = startApiService(true);
- for (String resrcName : legacyGuardPolicyResourceNames) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
+ private void testReadGuardPoliciesPersistent(String mediaType) {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);
+ for (String resrcName : legacyGuardPolicyResourceNames) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+
+ Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, true, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
- Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ @Test
+ public void testReadOperationalPoliciesJson() {
+ testReadOperationalPolicies(APP_JSON);
}
@Test
- public void testReadOperationalPolicies() {
+ public void testReadOperationalPoliciesYaml() {
+ testReadOperationalPolicies(APP_YAML);
+ }
- assertThatCode(() -> {
+ private void testReadOperationalPolicies(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, true);
+ Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: operational.restart:null", error.getErrorMessage());
- rawResponse = readResource(OPS_POLICIES_VCPE_VERSION, true);
+ rawResponse = readResource(OPS_POLICIES_VCPE_VERSION, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: operational.restart:1", error.getErrorMessage());
- rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true);
+ rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: operational.scaleout:null", error.getErrorMessage());
- rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true);
+ rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: operational.scaleout:1", error.getErrorMessage());
- rawResponse = readResource(OPS_POLICIES_VFIREWALL_LATEST, true);
+ rawResponse = readResource(OPS_POLICIES_VFIREWALL_LATEST, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: operational.modifyconfig:null", error.getErrorMessage());
- rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, true);
+ rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: operational.modifyconfig:1", error.getErrorMessage());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testReadOperationalPolicies1() throws Exception {
-
- setupParameters(); // setup DB
+ public void testReadOperationalPoliciesPersistentJson() {
+ testReadOperationalPoliciesPersistent(APP_JSON);
+ }
- main = startApiService(true);
- for (String resrcName : legacyOperationalPolicyResourceNames) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
+ @Test
+ public void testReadOperationalPoliciesPersistentYaml() {
+ testReadOperationalPoliciesPersistent(APP_YAML);
+ }
- Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ private void testReadOperationalPoliciesPersistent(String mediaType) {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);
+ for (String resrcName : legacyOperationalPolicyResourceNames) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(OPS_POLICIES_VCPE_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(OPS_POLICIES_VCPE_VERSION, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(OPS_POLICIES_VFIREWALL_LATEST, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(OPS_POLICIES_VFIREWALL_LATEST, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, true, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+ @Test
+ public void testDeleteGuardPolicyJson() {
+ testDeleteGuardPolicy(APP_JSON);
}
@Test
- public void testDeleteGuardPolicy() {
+ public void testDeleteGuardPolicyYaml() {
+ testDeleteGuardPolicy(APP_YAML);
+ }
- assertThatCode(() -> {
+ private void testDeleteGuardPolicy(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, true);
+ Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: guard.frequency.scaleout:1", error.getErrorMessage());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testDeleteGuardPolicy1() throws Exception {
+ public void testDeleteGuardPolicyPersistentJson() {
+ testDeleteGuardPolicyPersistent(APP_JSON);
+ }
- setupParameters(); // setup DB
- main = startApiService(true);
+ @Test
+ public void testDeleteGuardPolicyPersistentYaml() {
+ testDeleteGuardPolicyPersistent(APP_YAML);
+ }
+
+ private void testDeleteGuardPolicyPersistent(String mediaType) {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);
+
+ for (String resrcName : legacyGuardPolicyResourceNames) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
- for (String resrcName : legacyGuardPolicyResourceNames) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
+ Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, true, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
}
+ }
- Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
+ @Test
+ public void testGetDeployedVersionsOfGuardPolicyJson() {
+ testGetDeployedVersionsOfGuardPolicy(APP_JSON);
}
@Test
- public void testGetDeployedVersionsOfGuardPolicy() {
- assertThatCode(() -> {
+ public void testGetDeployedVersionsOfGuardPolicyYaml() {
+ testGetDeployedVersionsOfGuardPolicy(APP_YAML);
+ }
+
+ private void testGetDeployedVersionsOfGuardPolicy(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_DEPLOYED, true);
+ Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_DEPLOYED, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testDeleteOperationalPolicy() {
+ public void testDeleteOperationalPolicyJson() {
+ testDeleteOperationalPolicy(APP_JSON);
+ }
+
+ @Test
+ public void testDeleteOperationalPolicyYaml() {
+ testDeleteOperationalPolicy(APP_YAML);
+ }
- assertThatCode(() -> {
+ private void testDeleteOperationalPolicy(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, true);
+ Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: operational.restart:1", error.getErrorMessage());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testDeleteOperationalPolicy1() throws Exception {
+ public void testDeleteOperationalPolicyPersistentJson() {
+ testDeleteOperationalPolicyPersistent(APP_JSON);
+ }
- setupParameters(); // setup DB
+ @Test
+ public void testDeleteOperationalPolicyPersistentYaml() {
+ testDeleteOperationalPolicyPersistent(APP_YAML);
+ }
- main = startApiService(true);
- for (String resrcName : legacyOperationalPolicyResourceNames) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
+ private void testDeleteOperationalPolicyPersistent(String mediaType) {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);
+ for (String resrcName : legacyOperationalPolicyResourceNames) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, true, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
}
- Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
}
- @Test
- public void testHttpsCreatePolicyTypes() {
- assertThatCode(() -> {
- main = startApiService(false);
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, false);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
- }).doesNotThrowAnyException();
+ @Test
+ public void testGetDeployedVersionsOfPolicyJson() {
+ testGetDeployedVersionsOfPolicy(APP_JSON);
}
@Test
- public void testHttpsCreatePolicies() {
+ public void testGetDeployedVersionsOfPolicyYaml() {
+ testGetDeployedVersionsOfPolicy(APP_YAML);
+ }
- assertThatCode(() -> {
- main = startApiService(false);
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, false);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
- }
- }).doesNotThrowAnyException();
+ private void testGetDeployedVersionsOfPolicy(String mediaType) {
+ try {
+ main = startApiService(true);
+ Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_DEPLOYED, true, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testHttpsCreateGuardPolicies() {
-
- assertThatCode(() -> {
- main = startApiService(false);
- for (String resrcName : legacyGuardPolicyResourceNames) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, false);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }
- }).doesNotThrowAnyException();
+ public void testGetLatestVersionOfOperationalPolicyJson() {
+ testGetLatestVersionOfOperationalPolicy(APP_JSON);
}
@Test
- public void testHttpsCreateOperationalPolicies() {
+ public void testGetLatestVersionOfOperationalPolicyYaml() {
+ testGetLatestVersionOfOperationalPolicy(APP_YAML);
+ }
- assertThatCode(() -> {
- main = startApiService(false);
- for (String resrcName : legacyOperationalPolicyResourceNames) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, false);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }
- }).doesNotThrowAnyException();
+ private void testGetLatestVersionOfOperationalPolicy(String mediaType) {
+ try {
+ main = startApiService(true);
+ Response rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true, mediaType);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testGetDeployedVersionsOfPolicy() {
- assertThatCode(() -> {
- main = startApiService(true);
- Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_DEPLOYED, true);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- }).doesNotThrowAnyException();
+ public void testGetSpecificVersionOfOperationalPolicyJson() {
+ testGetSpecificVersionOfOperationalPolicy(APP_JSON);
}
@Test
- public void testGetLatestVersionOfOperationalPolicy() {
- assertThatCode(() -> {
+ public void testGetSpecificVersionOfOperationalPolicyYaml() {
+ testGetSpecificVersionOfOperationalPolicy(APP_YAML);
+ }
+
+ private void testGetSpecificVersionOfOperationalPolicy(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true);
+ Response rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
@Test
- public void testGetSpecificVersionOfOperationalPolicy() {
- assertThatCode(() -> {
- main = startApiService(true);
- Response rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }).doesNotThrowAnyException();
+ public void testGetDeployedVersionsOfOperationalPolicyJson() {
+ testGetDeployedVersionsOfOperationalPolicy(APP_JSON);
}
@Test
- public void testGetDeployedVersionsOfOperationalPolicy() {
- assertThatCode(() -> {
+ public void testGetDeployedVersionsOfOperationalPolicyYaml() {
+ testGetDeployedVersionsOfOperationalPolicy(APP_YAML);
+ }
+
+ private void testGetDeployedVersionsOfOperationalPolicy(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = readResource(OPS_POLICIES_VCPE_DEPLOYED, true);
+ Response rawResponse = readResource(OPS_POLICIES_VCPE_DEPLOYED, true, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testDeleteSpecificVersionOfOperationalPolicyJson() {
+ testDeleteSpecificVersionOfOperationalPolicy(APP_JSON);
}
@Test
- public void testDeleteSpecificVersionOfOperationalPolicy() {
- assertThatCode(() -> {
+ public void testDeleteSpecificVersionOfOperationalPolicyYaml() {
+ testDeleteSpecificVersionOfOperationalPolicy(APP_YAML);
+ }
+
+ private void testDeleteSpecificVersionOfOperationalPolicy(String mediaType) {
+ try {
main = startApiService(true);
- Response rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, true);
+ Response rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, true, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }).doesNotThrowAnyException();
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
}
- private Response createResource(String endpoint, String resourceName, boolean http) throws Exception {
- String serviceTamplateAsJson =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(resourceName));
- ToscaServiceTemplate rawServiceTemplate =
- standardCoder.decode(serviceTamplateAsJson, ToscaServiceTemplate.class);
+ private Response createResource(String endpoint, String resourceName, boolean http)
+ throws Exception {
+
+ String mediaType = APP_JSON; // default media type
+ ToscaServiceTemplate rawServiceTemplate = new ToscaServiceTemplate();
+ if (resourceName.endsWith(".json")) {
+ rawServiceTemplate = standardCoder.decode(
+ ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class);
+ } else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) {
+ mediaType = APP_YAML;
+ rawServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class);
+ }
+
final Invocation.Builder invocationBuilder;
if (http) {
- invocationBuilder = sendHttpRequest(endpoint);
+ invocationBuilder = sendHttpRequest(endpoint, mediaType);
} else {
- invocationBuilder = sendHttpsRequest(endpoint);
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType);
}
- Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, MediaType.APPLICATION_JSON);
+ Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType);
return invocationBuilder.post(entity);
}
- private Response createGuardPolicy(String endpoint, String resourceName, boolean http) throws Exception {
+ private Response createGuardPolicy(String endpoint, String resourceName, boolean http)
+ throws Exception {
+
+ String mediaType = APP_JSON; // default media type
+ LegacyGuardPolicyInput rawGuardPolicy = new LegacyGuardPolicyInput();
+ if (resourceName.endsWith(".json")) {
+ rawGuardPolicy = standardCoder.decode(
+ ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
+ } else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) {
+ mediaType = APP_YAML;
+ rawGuardPolicy = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
+ }
- LegacyGuardPolicyInput rawGuardPolicy =
- standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
final Invocation.Builder invocationBuilder;
if (http) {
- invocationBuilder = sendHttpRequest(endpoint);
+ invocationBuilder = sendHttpRequest(endpoint, mediaType);
} else {
- invocationBuilder = sendHttpsRequest(endpoint);
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType);
}
- Entity<LegacyGuardPolicyInput> entity = Entity.entity(rawGuardPolicy, MediaType.APPLICATION_JSON);
+ Entity<LegacyGuardPolicyInput> entity = Entity.entity(rawGuardPolicy, mediaType);
return invocationBuilder.post(entity);
}
- private Response createOperationalPolicy(String endpoint, String resourceName, boolean http) throws Exception {
+ private Response createOperationalPolicy(String endpoint, String resourceName, boolean http)
+ throws Exception {
+
+ String mediaType = APP_JSON; // default media type
+ LegacyOperationalPolicy rawOpsPolicy = new LegacyOperationalPolicy();
+ if (resourceName.endsWith(".json")) {
+ rawOpsPolicy = standardCoder.decode(
+ ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class);
+ } else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) {
+ mediaType = APP_YAML;
+ rawOpsPolicy = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class);
+ }
- LegacyOperationalPolicy rawOpsPolicy =
- standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class);
final Invocation.Builder invocationBuilder;
if (http) {
- invocationBuilder = sendHttpRequest(endpoint);
+ invocationBuilder = sendHttpRequest(endpoint, mediaType);
} else {
- invocationBuilder = sendHttpsRequest(endpoint);
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType);
}
- Entity<LegacyOperationalPolicy> entity = Entity.entity(rawOpsPolicy, MediaType.APPLICATION_JSON);
+ Entity<LegacyOperationalPolicy> entity = Entity.entity(rawOpsPolicy, mediaType);
return invocationBuilder.post(entity);
}
- private Response readResource(String endpoint, boolean http) throws Exception {
+ private Response readResource(String endpoint, boolean http, String mediaType) throws Exception {
final Invocation.Builder invocationBuilder;
if (http) {
- invocationBuilder = sendHttpRequest(endpoint);
+ invocationBuilder = sendHttpRequest(endpoint, mediaType);
} else {
- invocationBuilder = sendHttpsRequest(endpoint);
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType);
}
return invocationBuilder.get();
}
- private Response deleteResource(String endpoint, boolean http) throws Exception {
+ private Response deleteResource(String endpoint, boolean http, String mediaType) throws Exception {
final Invocation.Builder invocationBuilder;
if (http) {
- invocationBuilder = sendHttpRequest(endpoint);
+ invocationBuilder = sendHttpRequest(endpoint, mediaType);
} else {
- invocationBuilder = sendHttpsRequest(endpoint);
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType);
}
return invocationBuilder.delete();
@@ -1075,7 +1426,7 @@ public class TestApiRestServer {
main.shutdown();
}
- private Invocation.Builder sendHttpRequest(final String endpoint) throws Exception {
+ private Invocation.Builder sendHttpRequest(final String endpoint, String mediaType) throws Exception {
final ClientConfig clientConfig = new ClientConfig();
@@ -1085,11 +1436,15 @@ public class TestApiRestServer {
final Client client = ClientBuilder.newClient(clientConfig);
client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
- client.register(GsonMessageBodyHandler.class);
+ if (APP_JSON.equalsIgnoreCase(mediaType)) {
+ client.register(GsonMessageBodyHandler.class);
+ } else if (APP_YAML.equalsIgnoreCase(mediaType)) {
+ client.register(YamlMessageBodyHandler.class);
+ }
final WebTarget webTarget = client.target("http://localhost:" + port + "/policy/api/v1/" + endpoint);
- final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
+ final Invocation.Builder invocationBuilder = webTarget.request(mediaType);
if (!NetworkUtil.isTcpPortOpen("localhost", port, 60, 1000L)) {
throw new IllegalStateException("cannot connect to port " + port);
@@ -1097,7 +1452,7 @@ public class TestApiRestServer {
return invocationBuilder;
}
- private Invocation.Builder sendHttpsRequest(final String endpoint) throws Exception {
+ private Invocation.Builder sendHttpsRequest(final String endpoint, String mediaType) throws Exception {
final TrustManager[] noopTrustManager = new TrustManager[] { new X509TrustManager() {
@@ -1122,11 +1477,15 @@ public class TestApiRestServer {
client.register(feature);
client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
- client.register(GsonMessageBodyHandler.class);
+ if (APP_JSON.equalsIgnoreCase(mediaType)) {
+ client.register(GsonMessageBodyHandler.class);
+ } else if (APP_YAML.equalsIgnoreCase(mediaType)) {
+ client.register(YamlMessageBodyHandler.class);
+ }
final WebTarget webTarget = client.target("https://localhost:" + port + "/policy/api/v1/" + endpoint);
- final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
+ final Invocation.Builder invocationBuilder = webTarget.request(mediaType);
if (!NetworkUtil.isTcpPortOpen("localhost", port, 60, 1000L)) {
throw new IllegalStateException("cannot connect to port " + port);
@@ -1167,4 +1526,4 @@ public class TestApiRestServer {
assertEquals(code, report.getCode());
assertEquals(message, report.getMessage());
}
-}
+} \ No newline at end of file
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java
index bfd126ea..f83acce7 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java
@@ -39,10 +39,10 @@ import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.api.main.ApiTestSupportUtilities;
import org.onap.policy.api.main.parameters.ApiParameterGroup;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.Pdp;
@@ -72,6 +72,7 @@ public class TestLegacyGuardPolicyProvider {
private static PolicyModelsProviderParameters providerParams;
private static ApiParameterGroup apiParamGroup;
private static StandardCoder standardCoder;
+ private static StandardYamlCoder standardYamlCoder;
private static final String POLICY_RESOURCE = "policies/vDNS.policy.guard.frequency.input.json";
private static final String POLICY_RESOURCE_VER1 = "policies/vDNS.policy.guard.frequency.input.ver1.json";
@@ -95,6 +96,7 @@ public class TestLegacyGuardPolicyProvider {
public void setupParameters() throws PfModelException {
standardCoder = new StandardCoder();
+ standardYamlCoder = new StandardYamlCoder();
providerParams = new PolicyModelsProviderParameters();
providerParams.setDatabaseDriver("org.h2.Driver");
providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
@@ -133,10 +135,8 @@ public class TestLegacyGuardPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_VER1);
@@ -225,10 +225,8 @@ public class TestLegacyGuardPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -281,10 +279,8 @@ public class TestLegacyGuardPolicyProvider {
}).hasMessage("policy type " + POLICY_TYPE_ID + " for policy " + POLICY_ID + " does not exist");
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
@@ -345,10 +341,8 @@ public class TestLegacyGuardPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -387,10 +381,8 @@ public class TestLegacyGuardPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java
index f1784a53..f80b1195 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java
@@ -38,10 +38,10 @@ import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.api.main.ApiTestSupportUtilities;
import org.onap.policy.api.main.parameters.ApiParameterGroup;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.Pdp;
@@ -70,6 +70,7 @@ public class TestLegacyOperationalPolicyProvider {
private static PolicyModelsProviderParameters providerParams;
private static ApiParameterGroup apiParamGroup;
private static StandardCoder standardCoder;
+ private static StandardYamlCoder standardYamlCoder;
private static final String POLICY_RESOURCE = "policies/vCPE.policy.operational.input.json";
private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.controlloop.Operational.yaml";
@@ -90,6 +91,7 @@ public class TestLegacyOperationalPolicyProvider {
public void setupParameters() throws PfModelException {
standardCoder = new StandardCoder();
+ standardYamlCoder = new StandardYamlCoder();
providerParams = new PolicyModelsProviderParameters();
providerParams.setDatabaseDriver("org.h2.Driver");
providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
@@ -127,10 +129,8 @@ public class TestLegacyOperationalPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
@@ -215,10 +215,8 @@ public class TestLegacyOperationalPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -273,10 +271,8 @@ public class TestLegacyOperationalPolicyProvider {
}).hasMessage("policy type " + POLICY_TYPE_ID + " for policy " + POLICY_ID + " does not exist");
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
@@ -334,10 +330,8 @@ public class TestLegacyOperationalPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -376,10 +370,8 @@ public class TestLegacyOperationalPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
index 282f8a08..e81cbf45 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
@@ -37,10 +37,10 @@ import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.api.main.ApiTestSupportUtilities;
import org.onap.policy.api.main.parameters.ApiParameterGroup;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.Pdp;
@@ -68,6 +68,7 @@ public class TestPolicyProvider {
private static PolicyModelsProviderParameters providerParams;
private static ApiParameterGroup apiParamGroup;
private static StandardCoder standardCoder;
+ private static StandardYamlCoder standardYamlCoder;
private static final String POLICY_RESOURCE = "policies/vCPE.policy.monitoring.input.tosca.json";
private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml";
@@ -84,6 +85,7 @@ public class TestPolicyProvider {
public void setupParameters() throws PfModelException {
standardCoder = new StandardCoder();
+ standardYamlCoder = new StandardYamlCoder();
providerParams = new PolicyModelsProviderParameters();
providerParams.setDatabaseDriver("org.h2.Driver");
providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
@@ -184,10 +186,8 @@ public class TestPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -238,10 +238,8 @@ public class TestPolicyProvider {
}).hasMessage("policy type with ID dummy:1.0.0 does not exist");
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -278,10 +276,8 @@ public class TestPolicyProvider {
}).hasMessage("policy with ID dummy:1.0.0 and type dummy:1.0.0 does not exist");
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
index 07675b79..69c1aa44 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
@@ -31,10 +31,10 @@ import java.util.Base64;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.policy.api.main.ApiTestSupportUtilities;
import org.onap.policy.api.main.parameters.ApiParameterGroup;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
@@ -51,7 +51,7 @@ public class TestPolicyTypeProvider {
private static PolicyProvider policyProvider;
private static PolicyModelsProviderParameters providerParams;
private static ApiParameterGroup apiParamGroup;
- private static StandardCoder standardCoder;
+ private static StandardYamlCoder standardYamlCoder;
private static final String POLICY_RESOURCE = "policies/vCPE.policy.monitoring.input.tosca.yaml";
private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml";
@@ -64,7 +64,7 @@ public class TestPolicyTypeProvider {
@BeforeClass
public static void setupParameters() throws PfModelException {
- standardCoder = new StandardCoder();
+ standardYamlCoder = new StandardYamlCoder();
providerParams = new PolicyModelsProviderParameters();
providerParams.setDatabaseDriver("org.h2.Driver");
providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
@@ -119,10 +119,8 @@ public class TestPolicyTypeProvider {
public void testCreatePolicyType() {
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
assertFalse(serviceTemplate.getPolicyTypes().isEmpty());
}).doesNotThrowAnyException();
@@ -132,17 +130,15 @@ public class TestPolicyTypeProvider {
public void testDeletePolicyType() {
assertThatCode(() -> {
- String policyTypeString =
- ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
- ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
assertFalse(serviceTemplate.getPolicyTypes().isEmpty());
}).doesNotThrowAnyException();
assertThatCode(() -> {
- String policyString = ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_RESOURCE));
- ToscaServiceTemplate policyServiceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_RESOURCE), ToscaServiceTemplate.class);
policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
}).doesNotThrowAnyException();