aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorChenfei Gao <cgao@research.att.com>2019-04-11 18:47:26 -0400
committerChenfei Gao <cgao@research.att.com>2019-04-11 20:11:06 -0400
commite696cd9f5bafd0830017ad38355c2e8fe64f980b (patch)
tree9dababf31b5c9972d807704d9ab8cb5811994b65 /main
parenta229e2bccfdcf40c56c4d87d9e3cc5cd9dabb2a8 (diff)
Add junit tests for endpoints
Add junit tests to improve code coverage to > 80%. Modify db setting and remove db authorization from persistence. Issue-ID: POLICY-1441 Change-Id: I6070ac9ba6adba836adeeb547610c27dccf577bd Signed-off-by: Chenfei Gao <cgao@research.att.com>
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java64
-rw-r--r--main/src/main/resources/META-INF/persistence.xml6
-rw-r--r--main/src/test/java/org/onap/policy/api/main/parameters/CommonTestData.java2
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java512
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java1
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java1
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java1
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java1
-rw-r--r--main/src/test/resources/META-INF/persistence.xml50
-rw-r--r--main/src/test/resources/parameters/ApiConfigParameters.json5
-rw-r--r--main/src/test/resources/parameters/ApiConfigParameters_Https.json1
-rw-r--r--main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json8
-rw-r--r--main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json1
-rw-r--r--main/src/test/resources/parameters/MinimumParameters.json1
-rw-r--r--main/src/test/resources/parameters/NoParameters.json1
-rw-r--r--main/src/test/resources/policies/vDNS.policy.guard.minmax.input.json2
-rw-r--r--main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.json86
-rw-r--r--main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.json83
18 files changed, 690 insertions, 136 deletions
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
index 0c46df4e..1863b23a 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
@@ -364,6 +364,66 @@ public class ApiRestController {
}
/**
+ * Retrieves latest version of a particular policy type.
+ *
+ * @param policyTypeId the ID of specified policy type
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @GET
+ @Path("/policytypes/{policyTypeId}/versions/latest")
+ @ApiOperation(value = "Retrieve latest version of a policy type",
+ notes = "Returns latest version for the specified policy type",
+ response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ description = "Used only to communicate a PATCH version in a response for"
+ + " troubleshooting purposes only, and will not be provided by"
+ + " the client on request",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion",
+ description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose",
+ response = UUID.class)
+ },
+ authorizations = @Authorization(value = "basicAuth"),
+ tags = { "PolicyType", },
+ extensions = {
+ @Extension(name = "interface info", properties = {
+ @ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")
+ })
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 401, message = "Authentication Error"),
+ @ApiResponse(code = 403, message = "Authorization Error"),
+ @ApiResponse(code = 404, message = "Resource Not Found"),
+ @ApiResponse(code = 500, message = "Internal Server Error")
+ })
+ public Response getLatestVersionOfPolicyType(
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+
+ try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
+ ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);
+ updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(serviceTemplate).build();
+ } catch (PfModelException | PfModelRuntimeException pfme) {
+ updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
+ return addLoggingHeaders(addVersionControlHeaders(
+ Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
+ .entity(pfme.getErrorResponse()).build();
+ }
+ }
+
+ /**
* Creates a new policy type.
*
* @param body the body of policy type following TOSCA definition
@@ -694,7 +754,7 @@ public class ApiRestController {
* @return the Response object containing the results of the API operation
*/
@GET
- @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/latest")
+ @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
@ApiOperation(value = "Retrieve the latest version of a particular policy",
notes = "Returns the latest version of specified policy",
response = ToscaServiceTemplate.class,
@@ -760,7 +820,7 @@ public class ApiRestController {
* @return the Response object containing the results of the API operation
*/
@GET
- @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/deployed")
+ @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/deployed")
@ApiOperation(value = "Retrieve deployed versions of a particular policy in pdp groups",
notes = "Returns deployed versions of specified policy in pdp groups",
response = ToscaPolicy.class, responseContainer = "List",
diff --git a/main/src/main/resources/META-INF/persistence.xml b/main/src/main/resources/META-INF/persistence.xml
index 7bda7dab..1d4abd42 100644
--- a/main/src/main/resources/META-INF/persistence.xml
+++ b/main/src/main/resources/META-INF/persistence.xml
@@ -33,14 +33,10 @@
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
<properties>
- <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
- <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://policydb:3306/policy" />
- <property name="javax.persistence.jdbc.user" value="policy_user" />
- <property name="javax.persistence.jdbc.password" value="policy_user" />
<property name="javax.persistence.schema-generation.database.action" value="create" />
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="INFO" />
</properties>
</persistence-unit>
-</persistence> \ No newline at end of file
+</persistence>
diff --git a/main/src/test/java/org/onap/policy/api/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/api/main/parameters/CommonTestData.java
index f0f971d4..50e484eb 100644
--- a/main/src/test/java/org/onap/policy/api/main/parameters/CommonTestData.java
+++ b/main/src/test/java/org/onap/policy/api/main/parameters/CommonTestData.java
@@ -42,6 +42,7 @@ public class CommonTestData {
private static final String PROVIDER_GROUP_NAME = "PolicyProviderParameterGroup";
private static final String PROVIDER_IMPL = "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl";
+ private static final String DATABASE_DRIVER = "org.h2.Driver";
private static final String DATABASE_URL = "jdbc:h2:mem:testdb";
private static final String DATABASE_USER = "policy";
private static final String DATABASE_PASSWORD = "P01icY";
@@ -76,6 +77,7 @@ public class CommonTestData {
databaseProviderParameters = new PolicyModelsProviderParameters();
databaseProviderParameters.setName(PROVIDER_GROUP_NAME);
databaseProviderParameters.setImplementation(PROVIDER_IMPL);
+ databaseProviderParameters.setDatabaseDriver(DATABASE_DRIVER);
databaseProviderParameters.setDatabaseUrl(DATABASE_URL);
databaseProviderParameters.setDatabaseUser(DATABASE_USER);
databaseProviderParameters.setDatabasePassword(DATABASE_PASSWORD);
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 4fb588c2..756c7ae0 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
@@ -21,7 +21,10 @@
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;
@@ -37,11 +40,14 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.ws.rs.client.Client;
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;
@@ -50,7 +56,14 @@ import org.onap.policy.api.main.parameters.CommonTestData;
import org.onap.policy.api.main.parameters.RestServerParameters;
import org.onap.policy.api.main.startstop.Main;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.errors.concepts.ErrorResponse;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,17 +79,93 @@ 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 HEALTHCHECK_ENDPOINT = "healthcheck";
private static final String STATISTICS_ENDPOINT = "statistics";
+
+ private static final String POLICYTYPES = "policytypes";
+ private static final String POLICYTYPES_TCA = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app";
+ private static final String POLICYTYPES_COLLECTOR =
+ "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server";
+ private static final String POLICYTYPES_TCA_VERSION =
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0";
+ private static final String POLICYTYPES_TCA_LATEST =
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/latest";
+ private static final String POLICYTYPES_COLLECTOR_VERSION =
+ "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server/versions/1.0.0";
+ private static final String POLICYTYPES_COLLECTOR_LATEST =
+ "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server/versions/latest";
+
+ private static final String POLICYTYPES_TCA_POLICIES =
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies";
+ private static final String POLICYTYPES_TCA_POLICIES_VCPE =
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca";
+ private static final String POLICYTYPES_TCA_POLICIES_VCPE_VERSION = "policytypes/"
+ + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/1.0.0";
+ private static final String POLICYTYPES_TCA_POLICIES_VCPE_LATEST = "policytypes/"
+ + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/latest";
+
+ private static final String GUARD_POLICIES =
+ "policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies";
+ private static final String GUARD_POLICIES_VDNS_FL =
+ "policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/guard.frequency.scaleout";
+ private static final String GUARD_POLICIES_VDNS_MINMAX =
+ "policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/guard.minmax.scaleout";
+ private static final String GUARD_POLICIES_VDNS_FL_VERSION = "policytypes/"
+ + "onap.policy.controlloop.guard/versions/1.0.0/policies/guard.frequency.scaleout/versions/1.0.0";
+ private static final String GUARD_POLICIES_VDNS_MINMAX_VERSION = "policytypes/"
+ + "onap.policy.controlloop.guard/versions/1.0.0/policies/guard.minmax.scaleout/versions/1.0.0";
+
+ private static final String OPS_POLICIES =
+ "policytypes/onap.policy.controlloop.operational/versions/1.0.0/policies";
+ private static final String OPS_POLICIES_VCPE =
+ "policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/operational.restart";
+ private static final String OPS_POLICIES_VDNS =
+ "policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/operational.scaleout";
+ private static final String OPS_POLICIES_VFIREWALL =
+ "policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/operational.modifyconfig";
+ private static final String OPS_POLICIES_VCPE_VERSION = "policytypes/"
+ + "onap.policy.controlloop.guard/versions/1.0.0/policies/operational.restart/versions/1.0.0";
+ private static final String OPS_POLICIES_VDNS_VERSION = "policytypes/"
+ + "onap.policy.controlloop.guard/versions/1.0.0/policies/operational.scaleout/versions/1.0.0";
+ private static final String OPS_POLICIES_VFIREWALL_VERSION = "policytypes/"
+ + "onap.policy.controlloop.guard/versions/1.0.0/policies/operational.modifyconfig/versions/1.0.0";
+
private static String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
private Main main;
private ApiRestServer restServer;
+ private StandardCoder standardCoder = new StandardCoder();
+
+ // @formatter:off
+ private String[] toscaPolicyResourceNames = {
+ "policies/vCPE.policy.monitoring.input.tosca.json",
+ "policies/vDNS.policy.monitoring.input.tosca.json",
+ "policies/vFirewall.policy.monitoring.input.tosca.json",
+ };
+
+ private String[] toscaPolicyTypeResourceNames = {
+ "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.json",
+ "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.json"
+ };
+
+ private String[] legacyGuardPolicyResourceNames = {
+ "policies/vDNS.policy.guard.frequency.input.json",
+ "policies/vDNS.policy.guard.minmax.input.json",
+ };
+
+ private String[] legacyOperationalPolicyResourceNames = {
+ "policies/vCPE.policy.operational.input.json",
+ "policies/vDNS.policy.operational.input.json",
+ "policies/vFirewall.policy.operational.input.json"
+ };
+ // @formatter:on
/**
* Method for cleanup after each test.
*/
@After
public void teardown() {
+
try {
if (NetworkUtil.isTcpPortOpen("localhost", 6969, 1, 1000L)) {
if (main != null) {
@@ -92,6 +181,7 @@ public class TestApiRestServer {
@Test
public void testHealthCheckSuccess() {
+
try {
main = startApiService(true);
final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT);
@@ -105,6 +195,7 @@ public class TestApiRestServer {
@Test
public void testHealthCheckFailure() throws InterruptedException, IOException {
+
final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
restServerParams.setName(CommonTestData.API_GROUP_NAME);
restServer = new ApiRestServer(restServerParams);
@@ -123,6 +214,7 @@ public class TestApiRestServer {
@Test
public void testHttpsHealthCheckSuccess() {
+
try {
main = startApiService(false);
final Invocation.Builder invocationBuilder = sendHttpsRequest(HEALTHCHECK_ENDPOINT);
@@ -136,6 +228,7 @@ public class TestApiRestServer {
@Test
public void testApiStatistics_200() {
+
try {
main = startApiService(true);
Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT);
@@ -154,6 +247,7 @@ public class TestApiRestServer {
@Test
public void testApiStatistics_500() {
+
final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
restServerParams.setName(CommonTestData.API_GROUP_NAME);
restServer = new ApiRestServer(restServerParams);
@@ -171,6 +265,7 @@ public class TestApiRestServer {
@Test
public void testHttpsApiStatistics() {
+
try {
main = startApiService(false);
final Invocation.Builder invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT);
@@ -184,6 +279,7 @@ public class TestApiRestServer {
@Test
public void testApiStatisticsConstructorIsPrivate() {
+
try {
final Constructor<ApiStatisticsManager> constructor = ApiStatisticsManager.class.getDeclaredConstructor();
assertTrue(Modifier.isPrivate(constructor.getModifiers()));
@@ -194,7 +290,411 @@ public class TestApiRestServer {
}
}
+ @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().get(0).isEmpty());
+ }
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testReadPolicyTypes() {
+
+ assertThatCode(() -> {
+ main = startApiService(true);
+ Response rawResponse = readResource(POLICYTYPES, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertTrue(response.getPolicyTypes().get(0).isEmpty());
+
+ rawResponse = readResource(POLICYTYPES_TCA, 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:null does not exist",
+ error.getErrorMessage());
+
+ rawResponse = readResource(POLICYTYPES_TCA_VERSION, true);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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();
+ }
+
+ @Test
+ public void testDeletePolicyType() {
+
+ assertThatCode(() -> {
+ main = startApiService(true);
+ Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, 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());
+
+ rawResponse = deleteResource(POLICYTYPES_COLLECTOR_VERSION, true);
+ 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();
+ }
+
+ @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 testReadPolicies() {
+
+ assertThatCode(() -> {
+ main = startApiService(true);
+ Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, true);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("policy with ID null:null and "
+ + "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
+ error.getErrorMessage());
+
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, true);
+ 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());
+
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ 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());
+
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, true);
+ 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();
+ }
+
+ @Test
+ public void testDeletePolicies() {
+
+ assertThatCode(() -> {
+ main = startApiService(true);
+ Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true);
+ 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();
+ }
+
+ @Test
+ public void testCreateGuardPolicies() {
+
+ assertThatCode(() -> {
+ main = startApiService(true);
+ for (String resrcName : legacyGuardPolicyResourceNames) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testCreateOperationalPolicies() {
+
+ assertThatCode(() -> {
+ main = startApiService(true);
+ for (String resrcName : legacyOperationalPolicyResourceNames) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testReadGuardPolicies() {
+
+ assertThatCode(() -> {
+ main = startApiService(true);
+ Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: guard.frequency.scaleout",
+ error.getErrorMessage());
+
+ rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: guard.frequency.scaleout",
+ error.getErrorMessage());
+
+ rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: guard.minmax.scaleout",
+ error.getErrorMessage());
+
+ rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: guard.minmax.scaleout",
+ error.getErrorMessage());
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testReadOperationalPolicies() {
+
+ assertThatCode(() -> {
+ main = startApiService(true);
+ Response rawResponse = readResource(OPS_POLICIES_VCPE, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: operational.restart",
+ error.getErrorMessage());
+
+ rawResponse = readResource(OPS_POLICIES_VCPE_VERSION, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: operational.restart",
+ error.getErrorMessage());
+
+ rawResponse = readResource(OPS_POLICIES_VDNS, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: operational.scaleout",
+ error.getErrorMessage());
+
+ rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: operational.scaleout",
+ error.getErrorMessage());
+
+ rawResponse = readResource(OPS_POLICIES_VFIREWALL, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: operational.modifyconfig",
+ error.getErrorMessage());
+
+ rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: operational.modifyconfig",
+ error.getErrorMessage());
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testDeleteGuardPolicy() {
+
+ assertThatCode(() -> {
+ main = startApiService(true);
+ Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: guard.frequency.scaleout",
+ error.getErrorMessage());
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testDeleteOperationalPolicy() {
+
+ assertThatCode(() -> {
+ main = startApiService(true);
+ Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy ID: operational.restart",
+ error.getErrorMessage());
+ }).doesNotThrowAnyException();
+ }
+
+ @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().get(0).isEmpty());
+ }
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testHttpsCreatePolicies() {
+
+ 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();
+ }
+
+ @Test
+ public void testHttpsCreateGuardPolicies() {
+
+ assertThatCode(() -> {
+ main = startApiService(false);
+ for (String resrcName : legacyGuardPolicyResourceNames) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, false);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testHttpsCreateOperationalPolicies() {
+
+ assertThatCode(() -> {
+ main = startApiService(false);
+ for (String resrcName : legacyOperationalPolicyResourceNames) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, false);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ }).doesNotThrowAnyException();
+ }
+
+ private Response createResource(String endpoint, String resourceName, boolean http) throws Exception {
+
+ ToscaServiceTemplate rawServiceTemplate = standardCoder.decode(
+ ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class);
+ final Invocation.Builder invocationBuilder;
+
+ if (http) {
+ invocationBuilder = sendHttpRequest(endpoint);
+ } else {
+ invocationBuilder = sendHttpsRequest(endpoint);
+ }
+
+ Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, MediaType.APPLICATION_JSON);
+ return invocationBuilder.post(entity);
+ }
+
+ private Response createGuardPolicy(String endpoint, String resourceName, boolean http) throws Exception {
+
+ LegacyGuardPolicyInput rawGuardPolicy = standardCoder.decode(
+ ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
+ final Invocation.Builder invocationBuilder;
+
+ if (http) {
+ invocationBuilder = sendHttpRequest(endpoint);
+ } else {
+ invocationBuilder = sendHttpsRequest(endpoint);
+ }
+
+ Entity<LegacyGuardPolicyInput> entity = Entity.entity(rawGuardPolicy, MediaType.APPLICATION_JSON);
+ return invocationBuilder.post(entity);
+ }
+
+ private Response createOperationalPolicy(String endpoint, String resourceName, boolean http) throws Exception {
+
+ LegacyOperationalPolicy rawOpsPolicy = standardCoder.decode(
+ ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class);
+ final Invocation.Builder invocationBuilder;
+
+ if (http) {
+ invocationBuilder = sendHttpRequest(endpoint);
+ } else {
+ invocationBuilder = sendHttpsRequest(endpoint);
+ }
+
+ Entity<LegacyOperationalPolicy> entity = Entity.entity(rawOpsPolicy, MediaType.APPLICATION_JSON);
+ return invocationBuilder.post(entity);
+ }
+
+ private Response readResource(String endpoint, boolean http) throws Exception {
+
+ final Invocation.Builder invocationBuilder;
+
+ if (http) {
+ invocationBuilder = sendHttpRequest(endpoint);
+ } else {
+ invocationBuilder = sendHttpsRequest(endpoint);
+ }
+
+ return invocationBuilder.get();
+
+ }
+
+ private Response deleteResource(String endpoint, boolean http) throws Exception {
+
+ final Invocation.Builder invocationBuilder;
+
+ if (http) {
+ invocationBuilder = sendHttpRequest(endpoint);
+ } else {
+ invocationBuilder = sendHttpsRequest(endpoint);
+ }
+
+ return invocationBuilder.delete();
+ }
+
private Main startApiService(final boolean http) {
+
final String[] apiConfigParameters = new String[2];
if (http) {
apiConfigParameters[0] = "-c";
@@ -211,16 +711,22 @@ public class TestApiRestServer {
}
private void stopApiService(final Main main) throws PolicyApiException {
+
main.shutdown();
}
private Invocation.Builder sendHttpRequest(final String endpoint) throws Exception {
+
final ClientConfig clientConfig = new ClientConfig();
final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34");
clientConfig.register(feature);
final Client client = ClientBuilder.newClient(clientConfig);
+
+ client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
+ client.register(GsonMessageBodyHandler.class);
+
final WebTarget webTarget = client.target("http://localhost:6969/policy/api/v1/" + endpoint);
final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
@@ -255,6 +761,9 @@ public class TestApiRestServer {
final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34");
client.register(feature);
+ client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
+ client.register(GsonMessageBodyHandler.class);
+
final WebTarget webTarget = client.target("https://localhost:6969/policy/api/v1/" + endpoint);
final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
@@ -266,6 +775,7 @@ public class TestApiRestServer {
}
private void updateApiStatistics() {
+
ApiStatisticsManager.updateTotalApiCallCount();
ApiStatisticsManager.updateApiCallSuccessCount();
ApiStatisticsManager.updateApiCallFailureCount();
@@ -284,11 +794,13 @@ public class TestApiRestServer {
}
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) {
+
assertEquals(name, report.getName());
assertEquals(url, report.getUrl());
assertEquals(healthy, report.isHealthy());
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 085255f3..76641aae 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
@@ -67,6 +67,7 @@ public class TestLegacyGuardPolicyProvider {
standardCoder = new StandardCoder();
providerParams = new PolicyModelsProviderParameters();
+ providerParams.setDatabaseDriver("org.h2.Driver");
providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
providerParams.setDatabaseUser("policy");
providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
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 e9adae7c..8aa19793 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
@@ -64,6 +64,7 @@ public class TestLegacyOperationalPolicyProvider {
standardCoder = new StandardCoder();
providerParams = new PolicyModelsProviderParameters();
+ providerParams.setDatabaseDriver("org.h2.Driver");
providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
providerParams.setDatabaseUser("policy");
providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
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 7720575a..653f467e 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
@@ -67,6 +67,7 @@ public class TestPolicyProvider {
standardCoder = new StandardCoder();
providerParams = new PolicyModelsProviderParameters();
+ providerParams.setDatabaseDriver("org.h2.Driver");
providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
providerParams.setDatabaseUser("policy");
providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
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 76825b20..9dc77267 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
@@ -64,6 +64,7 @@ public class TestPolicyTypeProvider {
standardCoder = new StandardCoder();
providerParams = new PolicyModelsProviderParameters();
+ providerParams.setDatabaseDriver("org.h2.Driver");
providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
providerParams.setDatabaseUser("policy");
providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
diff --git a/main/src/test/resources/META-INF/persistence.xml b/main/src/test/resources/META-INF/persistence.xml
index 8812ebf6..cfd7d16d 100644
--- a/main/src/test/resources/META-INF/persistence.xml
+++ b/main/src/test/resources/META-INF/persistence.xml
@@ -2,20 +2,19 @@
<!--
============LICENSE_START=======================================================
Copyright (C) 2019 Nordix Foundation.
- Copyright (C) 2019 AT&T Intellectual Property. 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.
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=========================================================
-->
@@ -34,49 +33,10 @@
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
<properties>
- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb" />
- <property name="javax.persistence.jdbc.user" value="policy" />
- <property name="javax.persistence.jdbc.password" value="P01icY" />
- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
- <property name="eclipselink.ddl-generation.output-mode" value="database" />
- <property name="eclipselink.logging.level" value="INFO" />
- </properties>
- </persistence-unit>
-
- <persistence-unit name="ToscaConceptMariaDBTest" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
- <class>org.onap.policy.models.dao.converters.CDataConditioner</class>
- <class>org.onap.policy.models.dao.converters.Uuid2String</class>
- <class>org.onap.policy.models.base.PfConceptKey</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
-
- <properties>
- <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
- <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/policy" />
- <property name="javax.persistence.jdbc.user" value="policy" />
- <property name="javax.persistence.jdbc.password" value="P01icY" />
<property name="javax.persistence.schema-generation.database.action" value="create" />
-
- <!-- property name="eclipselink.logging.level" value="ALL" />
- <property name="eclipselink.logging.level.jpa" value="ALL" />
- <property name="eclipselink.logging.level.ddl" value="ALL" />
- <property name="eclipselink.logging.level.connection" value="ALL" />
- <property name="eclipselink.logging.level.sql" value="ALL" />
- <property name="eclipselink.logging.level.transaction" value="ALL" />
- <property name="eclipselink.logging.level.sequencing" value="ALL" />
- <property name="eclipselink.logging.level.server" value="ALL" />
- <property name="eclipselink.logging.level.query" value="ALL" />
- <property name="eclipselink.logging.level.properties" value="ALL" /-->
-
- <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
+ <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="INFO" />
</properties>
</persistence-unit>
-</persistence>
+</persistence> \ No newline at end of file
diff --git a/main/src/test/resources/parameters/ApiConfigParameters.json b/main/src/test/resources/parameters/ApiConfigParameters.json
index c64271c7..be9f5811 100644
--- a/main/src/test/resources/parameters/ApiConfigParameters.json
+++ b/main/src/test/resources/parameters/ApiConfigParameters.json
@@ -9,9 +9,10 @@
"databaseProviderParameters": {
"name": "PolicyProviderParameterGroup",
"implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseUrl": "jdbc:mariadb://localhost:3306/policy",
+ "databaseDriver": "org.h2.Driver",
+ "databaseUrl": "jdbc:h2:mem:testdb",
"databaseUser": "policy",
"databasePassword": "UDAxaWNZ",
- "persistenceUnit": "ToscaConceptMariaDBTest"
+ "persistenceUnit": "ToscaConceptTest"
}
}
diff --git a/main/src/test/resources/parameters/ApiConfigParameters_Https.json b/main/src/test/resources/parameters/ApiConfigParameters_Https.json
index 878dc1ff..d7774fcd 100644
--- a/main/src/test/resources/parameters/ApiConfigParameters_Https.json
+++ b/main/src/test/resources/parameters/ApiConfigParameters_Https.json
@@ -10,6 +10,7 @@
"databaseProviderParameters": {
"name": "PolicyProviderParameterGroup",
"implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
+ "databaseDriver": "org.h2.Driver",
"databaseUrl": "jdbc:h2:mem:testdb",
"databaseUser": "policy",
"databasePassword": "UDAxaWNZ",
diff --git a/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json b/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json
index 80fb8232..24cc69f3 100644
--- a/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json
+++ b/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json
@@ -5,5 +5,13 @@
"port":6969,
"userName":"healthcheck",
"password":"zb!XztG34"
+ },
+ "databaseProviderParameters": {
+ "name": "PolicyProviderParameterGroup",
+ "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
+ "databaseUrl": "jdbc:h2:mem:testdb",
+ "databaseUser": "policy",
+ "databasePassword": "UDAxaWNZ",
+ "persistenceUnit": "ToscaConceptTest"
}
}
diff --git a/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json b/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json
index 67e461e0..339c20b6 100644
--- a/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json
+++ b/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json
@@ -9,6 +9,7 @@
"databaseProviderParameters": {
"name": "PolicyProviderParameterGroup",
"implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
+ "databaseDriver": "org.h2.Driver",
"databaseUrl": "jdbc:h2:mem:testdb",
"databaseUser": "policy",
"databasePassword": "UDAxaWNZ",
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
index 2600d20f..8ac10805 100644
--- a/main/src/test/resources/parameters/MinimumParameters.json
+++ b/main/src/test/resources/parameters/MinimumParameters.json
@@ -9,6 +9,7 @@
"databaseProviderParameters": {
"name": "PolicyProviderParameterGroup",
"implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
+ "databaseDriver": "org.h2.Driver",
"databaseUrl": "jdbc:h2:mem:testdb",
"databaseUser": "policy",
"databasePassword": "UDAxaWNZ",
diff --git a/main/src/test/resources/parameters/NoParameters.json b/main/src/test/resources/parameters/NoParameters.json
index ed2fbde2..6f933890 100644
--- a/main/src/test/resources/parameters/NoParameters.json
+++ b/main/src/test/resources/parameters/NoParameters.json
@@ -8,6 +8,7 @@
"databaseProviderParameters": {
"name": "PolicyProviderParameterGroup",
"implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
+ "databaseDriver": "org.h2.Driver",
"databaseUrl": "jdbc:h2:mem:testdb",
"databaseUser": "policy",
"databasePassword": "UDAxaWNZ",
diff --git a/main/src/test/resources/policies/vDNS.policy.guard.minmax.input.json b/main/src/test/resources/policies/vDNS.policy.guard.minmax.input.json
index 2dbfe8ce..45a7d41d 100644
--- a/main/src/test/resources/policies/vDNS.policy.guard.minmax.input.json
+++ b/main/src/test/resources/policies/vDNS.policy.guard.minmax.input.json
@@ -1,6 +1,6 @@
{
"policy-id" : "guard.minmax.scaleout",
- "contents" : {
+ "content" : {
"actor": "SO",
"recipe": "scaleOut",
"targets": ".*",
diff --git a/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.json b/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.json
index 2188cb2e..d2f9584e 100644
--- a/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.json
+++ b/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.json
@@ -1,48 +1,50 @@
{
"tosca_definitions_version": "tosca_simple_yaml_1_0_0",
- "policies": [
- {
- "onap.scaleout.tca": {
- "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
- "version": "1.0.0",
- "metadata": {
- "policy-id": "onap.scaleout.tca"
- },
- "properties": {
- "tca_policy": {
- "domain": "measurementsForVfScaling",
- "metricsPerEventName": [
- {
- "eventName": "vLoadBalancer",
- "controlLoopSchemaType": "VNF",
- "policyScope": "type=configuration",
- "policyName": "onap.scaleout.tca",
- "policyVersion": "v0.0.1",
- "thresholds": [
- {
- "closedLoopControlName": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
- "closedLoopEventStatus": "ONSET",
- "version": "1.0.2",
- "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
- "thresholdValue": 500,
- "direction": "LESS_OR_EQUAL",
- "severity": "MAJOR"
- },
- {
- "closedLoopControlName": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
- "closedLoopEventStatus": "ONSET",
- "version": "1.0.2",
- "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
- "thresholdValue": 5000,
- "direction": "GREATER_OR_EQUAL",
- "severity": "CRITICAL"
- }
- ]
- }
- ]
+ "topology_template": {
+ "policies": [
+ {
+ "onap.scaleout.tca": {
+ "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "onap.scaleout.tca"
+ },
+ "properties": {
+ "tca_policy": {
+ "domain": "measurementsForVfScaling",
+ "metricsPerEventName": [
+ {
+ "eventName": "vLoadBalancer",
+ "controlLoopSchemaType": "VNF",
+ "policyScope": "type=configuration",
+ "policyName": "onap.scaleout.tca",
+ "policyVersion": "v0.0.1",
+ "thresholds": [
+ {
+ "closedLoopControlName": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
+ "closedLoopEventStatus": "ONSET",
+ "version": "1.0.2",
+ "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
+ "thresholdValue": 500,
+ "direction": "LESS_OR_EQUAL",
+ "severity": "MAJOR"
+ },
+ {
+ "closedLoopControlName": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
+ "closedLoopEventStatus": "ONSET",
+ "version": "1.0.2",
+ "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
+ "thresholdValue": 5000,
+ "direction": "GREATER_OR_EQUAL",
+ "severity": "CRITICAL"
+ }
+ ]
+ }
+ ]
+ }
}
}
}
- }
- ]
+ ]
+ }
} \ No newline at end of file
diff --git a/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.json b/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.json
index 93545a0d..a0046fb5 100644
--- a/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.json
+++ b/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.json
@@ -1,45 +1,50 @@
{
"tosca_definitions_version": "tosca_simple_yaml_1_0_0",
- "policies": [
- {
- "onap.vfirewall.tca": {
- "type": "onap.policy.monitoring.cdap.tca.hi.lo.app",
- "version": "1.0.0",
- "properties": {
- "tca_policy": {
- "domain": "measurementsForVfScaling",
- "metricsPerEventName": [
- {
- "eventName": "vLoadBalancer",
- "controlLoopSchemaType": "VNF",
- "policyScope": "resource=vLoadBalancer;type=configuration",
- "policyName": "onap.vfirewall.tca",
- "policyVersion": "v0.0.1",
- "thresholds": [
- {
- "closedLoopControlName": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a",
- "closedLoopEventStatus": "ONSET",
- "version": "1.0.2",
- "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
- "thresholdValue": 500,
- "direction": "LESS_OR_EQUAL",
- "severity": "MAJOR"
- },
- {
- "closedLoopControlName": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a",
- "closedLoopEventStatus": "ONSET",
- "version": "1.0.2",
- "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
- "thresholdValue": 5000,
- "direction": "GREATER_OR_EQUAL",
- "severity": "CRITICAL"
- }
- ]
- }
- ]
+ "topology_template": {
+ "policies": [
+ {
+ "onap.vfirewall.tca": {
+ "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "onap.vfirewall.tca"
+ },
+ "properties": {
+ "tca_policy": {
+ "domain": "measurementsForVfScaling",
+ "metricsPerEventName": [
+ {
+ "eventName": "vLoadBalancer",
+ "controlLoopSchemaType": "VNF",
+ "policyScope": "resource=vLoadBalancer;type=configuration",
+ "policyName": "onap.vfirewall.tca",
+ "policyVersion": "v0.0.1",
+ "thresholds": [
+ {
+ "closedLoopControlName": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a",
+ "closedLoopEventStatus": "ONSET",
+ "version": "1.0.2",
+ "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
+ "thresholdValue": 500,
+ "direction": "LESS_OR_EQUAL",
+ "severity": "MAJOR"
+ },
+ {
+ "closedLoopControlName": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a",
+ "closedLoopEventStatus": "ONSET",
+ "version": "1.0.2",
+ "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
+ "thresholdValue": 5000,
+ "direction": "GREATER_OR_EQUAL",
+ "severity": "CRITICAL"
+ }
+ ]
+ }
+ ]
+ }
}
}
}
- }
- ]
+ ]
+ }
} \ No newline at end of file