aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-09-05 22:25:55 +0000
committerliamfallon <liam.fallon@est.tech>2019-09-05 22:25:55 +0000
commit5b7f107c2120100b502e1e82ab644b3da5a80a22 (patch)
tree6db33b71943b88187868535eb025de8341eaff23 /main/src/test/java/org
parent834ab314c29303e71c14fc9f55f626b21ccc6fcf (diff)
Knock on of changing policy types to map
This review adapts policy-api for the change in the structure of the toasca service template from a list of maps to a plain map. DUplication of policy types and policies removed and policy-models examples used instead. Issue-ID: POLICY-2047 Change-Id: Ie1fdeef79289348005314c5de9b2e37c0c45d786 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'main/src/test/java/org')
-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.java163
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java6
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java87
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java92
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java75
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java38
7 files changed, 272 insertions, 237 deletions
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
new file mode 100644
index 00000000..79a33ffb
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/api/main/ApiTestSupportUtilities.java
@@ -0,0 +1,48 @@
+/*-
+ * ============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 81547295..8b396fc7 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
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -52,6 +53,7 @@ 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;
@@ -109,48 +111,47 @@ public class TestApiRestServer {
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";
+ + "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";
+ + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/latest";
private static final String POLICYTYPES_TCA_POLICIES_VCPE_DEPLOYED = "policytypes/"
+ "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/deployed";
- private static final String GUARD_POLICIES =
- "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies";
+ private static final String GUARD_POLICIES = "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies";
private static final String GUARD_POLICIES_VDNS_FL_LATEST =
"policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout"
- + "/versions/latest";
+ + "/versions/latest";
private static final String GUARD_POLICIES_VDNS_FL_DEPLOYED =
"policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout"
- + "/versions/deployed";
+ + "/versions/deployed";
private static final String GUARD_POLICIES_VDNS_MINMAX_LATEST =
"policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout"
- + "/versions/latest";
+ + "/versions/latest";
private static final String GUARD_POLICIES_VDNS_FL_VERSION = "policytypes/"
- + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout/versions/1";
- private static final String GUARD_POLICIES_VDNS_MINMAX_VERSION = "policytypes/"
- + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout/versions/1";
+ + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout/versions/1";
+ private static final String GUARD_POLICIES_VDNS_MINMAX_VERSION =
+ "policytypes/" + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout/versions/1";
private static final String OPS_POLICIES =
"policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies";
private static final String OPS_POLICIES_VCPE_LATEST =
"policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.restart"
- + "/versions/latest";
+ + "/versions/latest";
private static final String OPS_POLICIES_VCPE_DEPLOYED =
"policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.restart"
- + "/versions/deployed";
+ + "/versions/deployed";
private static final String OPS_POLICIES_VDNS_LATEST =
"policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.scaleout"
- + "/versions/latest";
+ + "/versions/latest";
private static final String OPS_POLICIES_VFIREWALL_LATEST =
"policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.modifyconfig"
- + "/versions/latest";
+ + "/versions/latest";
private static final String OPS_POLICIES_VCPE_VERSION = "policytypes/"
- + "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.restart/versions/1";
+ + "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.restart/versions/1";
private static final String OPS_POLICIES_VDNS_VERSION = "policytypes/"
- + "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.scaleout/versions/1";
+ + "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.scaleout/versions/1";
private static final String OPS_POLICIES_VFIREWALL_VERSION = "policytypes/"
- + "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.modifyconfig/versions/1";
+ + "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.modifyconfig/versions/1";
private static final String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
@@ -167,8 +168,8 @@ public class TestApiRestServer {
};
private String[] toscaPolicyTypeResourceNames = {
- "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.json",
- "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.json"
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml",
+ "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml"
};
private String[] legacyGuardPolicyResourceNames = {
@@ -349,7 +350,7 @@ public class TestApiRestServer {
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
assertNotNull(response);
- assertFalse(response.getPolicyTypes().get(0).isEmpty());
+ assertFalse(response.getPolicyTypes().isEmpty());
}
}).doesNotThrowAnyException();
}
@@ -386,21 +387,21 @@ public class TestApiRestServer {
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",
+ + "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",
+ + "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",
+ + "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:null does not exist",
error.getErrorMessage());
}).doesNotThrowAnyException();
}
@@ -415,7 +416,7 @@ public class TestApiRestServer {
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
assertNotNull(response);
- assertFalse(response.getPolicyTypes().get(0).isEmpty());
+ assertFalse(response.getPolicyTypes().isEmpty());
}
for (String resrcName : toscaPolicyResourceNames) {
@@ -462,7 +463,7 @@ public class TestApiRestServer {
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",
+ + "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:1.0.0 does not exist",
error.getErrorMessage());
}).doesNotThrowAnyException();
}
@@ -470,7 +471,7 @@ public class TestApiRestServer {
@Test
public void testDeletePolicyTypePersistent() throws Exception {
- setupParameters(); //setup DB
+ setupParameters(); // setup DB
main = startApiService(true);// create policy types
for (String resrcName : toscaPolicyTypeResourceNames) {
@@ -478,7 +479,7 @@ public class TestApiRestServer {
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
assertNotNull(response);
- assertFalse(response.getPolicyTypes().get(0).isEmpty());
+ assertFalse(response.getPolicyTypes().isEmpty());
}
Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, true);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -508,29 +509,33 @@ public class TestApiRestServer {
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",
+ 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",
+ 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",
+ 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",
+ 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();
}
@@ -545,7 +550,7 @@ public class TestApiRestServer {
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
assertNotNull(response);
- assertFalse(response.getPolicyTypes().get(0).isEmpty());
+ assertFalse(response.getPolicyTypes().isEmpty());
}
for (String resrcName : toscaPolicyResourceNames) {
@@ -576,8 +581,9 @@ public class TestApiRestServer {
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",
+ 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();
}
@@ -585,7 +591,7 @@ public class TestApiRestServer {
@Test
public void testDeletePolicyVersion() throws Exception {
- setupParameters(); //setup DB
+ setupParameters(); // setup DB
main = startApiService(true);// create policy types
for (String resrcName : toscaPolicyTypeResourceNames) {
@@ -593,7 +599,7 @@ public class TestApiRestServer {
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
assertNotNull(response);
- assertFalse(response.getPolicyTypes().get(0).isEmpty());
+ assertFalse(response.getPolicyTypes().isEmpty());
}
for (String resrcName : toscaPolicyResourceNames) {
Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
@@ -606,7 +612,7 @@ public class TestApiRestServer {
@Test
public void testGetAllVersionOfPolicy() throws Exception {
- setupParameters(); //setup DB
+ setupParameters(); // setup DB
main = startApiService(true);// create policy types
for (String resrcName : toscaPolicyTypeResourceNames) {
@@ -614,7 +620,7 @@ public class TestApiRestServer {
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
assertNotNull(response);
- assertFalse(response.getPolicyTypes().get(0).isEmpty());
+ assertFalse(response.getPolicyTypes().isEmpty());
}
for (String resrcName : toscaPolicyResourceNames) {
Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
@@ -640,7 +646,7 @@ public class TestApiRestServer {
@Test
public void testCreateGuardPolicies1() throws Exception {
- setupParameters(); //setup DB
+ setupParameters(); // setup DB
main = startApiService(true);
for (String resrcName : legacyGuardPolicyResourceNames) {
@@ -665,7 +671,7 @@ public class TestApiRestServer {
@Test
public void testCreateOperationalPolicies1() throws Exception {
- setupParameters(); //setup DB
+ setupParameters(); // setup DB
main = startApiService(true);
for (String resrcName : legacyOperationalPolicyResourceNames) {
@@ -683,33 +689,29 @@ public class TestApiRestServer {
Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, true);
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());
+ assertEquals("no policy found for policy: guard.frequency.scaleout:null", 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: guard.frequency.scaleout:1",
- error.getErrorMessage());
+ assertEquals("no policy found for policy: guard.frequency.scaleout:1", error.getErrorMessage());
rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, true);
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());
+ assertEquals("no policy found for policy: guard.minmax.scaleout:null", 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: guard.minmax.scaleout:1",
- error.getErrorMessage());
+ assertEquals("no policy found for policy: guard.minmax.scaleout:1", error.getErrorMessage());
}).doesNotThrowAnyException();
}
@Test
public void testReadGuardPolicies1() throws Exception {
- setupParameters(); //setup DB
+ setupParameters(); // setup DB
main = startApiService(true);
for (String resrcName : legacyGuardPolicyResourceNames) {
@@ -741,45 +743,39 @@ public class TestApiRestServer {
Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, true);
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());
+ assertEquals("no policy found for policy: operational.restart:null", 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: operational.restart:1",
- error.getErrorMessage());
+ assertEquals("no policy found for policy: operational.restart:1", error.getErrorMessage());
rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: operational.scaleout:null",
- error.getErrorMessage());
+ assertEquals("no policy found for policy: operational.scaleout:null", 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: operational.scaleout:1",
- error.getErrorMessage());
+ assertEquals("no policy found for policy: operational.scaleout:1", error.getErrorMessage());
rawResponse = readResource(OPS_POLICIES_VFIREWALL_LATEST, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: operational.modifyconfig:null",
- error.getErrorMessage());
+ assertEquals("no policy found for policy: operational.modifyconfig:null", 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: operational.modifyconfig:1",
- error.getErrorMessage());
+ assertEquals("no policy found for policy: operational.modifyconfig:1", error.getErrorMessage());
}).doesNotThrowAnyException();
}
@Test
public void testReadOperationalPolicies1() throws Exception {
- setupParameters(); //setup DB
+ setupParameters(); // setup DB
main = startApiService(true);
for (String resrcName : legacyOperationalPolicyResourceNames) {
@@ -821,15 +817,14 @@ public class TestApiRestServer {
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: guard.frequency.scaleout:1",
- error.getErrorMessage());
+ assertEquals("no policy found for policy: guard.frequency.scaleout:1", error.getErrorMessage());
}).doesNotThrowAnyException();
}
@Test
public void testDeleteGuardPolicy1() throws Exception {
- setupParameters(); //setup DB
+ setupParameters(); // setup DB
main = startApiService(true);
for (String resrcName : legacyGuardPolicyResourceNames) {
@@ -859,15 +854,14 @@ public class TestApiRestServer {
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: operational.restart:1",
- error.getErrorMessage());
+ assertEquals("no policy found for policy: operational.restart:1", error.getErrorMessage());
}).doesNotThrowAnyException();
}
@Test
public void testDeleteOperationalPolicy1() throws Exception {
- setupParameters(); //setup DB
+ setupParameters(); // setup DB
main = startApiService(true);
for (String resrcName : legacyOperationalPolicyResourceNames) {
@@ -889,7 +883,7 @@ public class TestApiRestServer {
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
assertNotNull(response);
- assertFalse(response.getPolicyTypes().get(0).isEmpty());
+ assertFalse(response.getPolicyTypes().isEmpty());
}
}).doesNotThrowAnyException();
}
@@ -979,9 +973,10 @@ public class TestApiRestServer {
}
private Response createResource(String endpoint, String resourceName, boolean http) throws Exception {
-
- ToscaServiceTemplate rawServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class);
+ String serviceTamplateAsJson =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(resourceName));
+ ToscaServiceTemplate rawServiceTemplate =
+ standardCoder.decode(serviceTamplateAsJson, ToscaServiceTemplate.class);
final Invocation.Builder invocationBuilder;
if (http) {
@@ -996,8 +991,8 @@ public class TestApiRestServer {
private Response createGuardPolicy(String endpoint, String resourceName, boolean http) throws Exception {
- LegacyGuardPolicyInput rawGuardPolicy = standardCoder.decode(
- ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
+ LegacyGuardPolicyInput rawGuardPolicy =
+ standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
final Invocation.Builder invocationBuilder;
if (http) {
@@ -1012,8 +1007,8 @@ public class TestApiRestServer {
private Response createOperationalPolicy(String endpoint, String resourceName, boolean http) throws Exception {
- LegacyOperationalPolicy rawOpsPolicy = standardCoder.decode(
- ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class);
+ LegacyOperationalPolicy rawOpsPolicy =
+ standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class);
final Invocation.Builder invocationBuilder;
if (http) {
@@ -1059,7 +1054,7 @@ public class TestApiRestServer {
final String[] apiConfigParameters = new String[2];
if (http) {
COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters.json",
- "src/test/resources/parameters/ApiConfigParametersXXX.json", port);
+ "src/test/resources/parameters/ApiConfigParametersXXX.json", port);
apiConfigParameters[0] = "-c";
apiConfigParameters[1] = "src/test/resources/parameters/ApiConfigParametersXXX.json";
} else {
@@ -1068,7 +1063,7 @@ public class TestApiRestServer {
systemProps.put("javax.net.ssl.keyStorePassword", "Pol1cy_0nap");
System.setProperties(systemProps);
COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters_Https.json",
- "src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json", port);
+ "src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json", port);
apiConfigParameters[0] = "-c";
apiConfigParameters[1] = "src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json";
}
@@ -1120,8 +1115,8 @@ public class TestApiRestServer {
final SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, noopTrustManager, new SecureRandom());
- final ClientBuilder clientBuilder = ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host,
- session) -> true);
+ final ClientBuilder clientBuilder =
+ ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true);
final Client client = clientBuilder.build();
final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34");
client.register(feature);
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java
index f2999975..3b6fad5a 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java
@@ -3,6 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -31,10 +32,9 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import org.junit.Test;
-/*
+
+/**
* Class to perform unit testing of CommonRestController.
- *
- *
*/
public class TestCommonRestController {
private CommonRestController crc = new CommonRestController();
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 1f0077db..bfd126ea 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
@@ -3,6 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -38,6 +39,7 @@ 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;
@@ -59,7 +61,7 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
/**
- * This class performs unit test of {@link LegacyGuardPolicyProvider}
+ * This class performs unit test of {@link LegacyGuardPolicyProvider}.
*
* @author Chenfei Gao (cgao@research.att.com)
*/
@@ -75,7 +77,7 @@ public class TestLegacyGuardPolicyProvider {
private static final String POLICY_RESOURCE_VER1 = "policies/vDNS.policy.guard.frequency.input.ver1.json";
private static final String POLICY_RESOURCE_VER2 = "policies/vDNS.policy.guard.frequency.input.ver2.json";
private static final String POLICY_TYPE_RESOURCE =
- "policytypes/onap.policies.controlloop.guard.FrequencyLimiter.json";
+ "policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml";
private static final String POLICY_TYPE_ID = "onap.policies.controlloop.guard.FrequencyLimiter:1.0.0";
private static final String POLICY_TYPE_NAME = "onap.policies.controlloop.guard.FrequencyLimiter";
private static final String POLICY_TYPE_VERSION = "1.0.0";
@@ -131,7 +133,8 @@ public class TestLegacyGuardPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -203,8 +206,8 @@ public class TestLegacyGuardPolicyProvider {
pdpSubGroup.setPdpType("type");
pdpSubGroup.setDesiredInstanceCount(123);
pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
- pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier(
- POLICY_TYPE_NAME, POLICY_TYPE_VERSION));
+ pdpSubGroup.getSupportedPolicyTypes()
+ .add(new ToscaPolicyTypeIdentifier(POLICY_TYPE_NAME, POLICY_TYPE_VERSION));
pdpGroup.getPdpSubgroups().add(pdpSubGroup);
Pdp pdp = new Pdp();
@@ -222,7 +225,8 @@ public class TestLegacyGuardPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -233,41 +237,36 @@ public class TestLegacyGuardPolicyProvider {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
LegacyGuardPolicyInput policyToCreate =
standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
- Map<String, LegacyGuardPolicyOutput> policyCreated = guardPolicyProvider
- .createGuardPolicy(policyToCreate);
+ Map<String, LegacyGuardPolicyOutput> policyCreated =
+ guardPolicyProvider.createGuardPolicy(policyToCreate);
assertFalse(policyCreated.isEmpty());
}).doesNotThrowAnyException();
// Test fetchDeployedPolicies (deployedPolicyMap.isEmpty())==true
- assertThatThrownBy(
- () -> {
- guardPolicyProvider.fetchDeployedGuardPolicies(POLICY_NAME);
- }).hasMessage("could not find policy with ID " + POLICY_NAME + " and type "
- + POLICY_TYPE_ID + " deployed in any pdp group");
+ assertThatThrownBy(() -> {
+ guardPolicyProvider.fetchDeployedGuardPolicies(POLICY_NAME);
+ }) .hasMessage("could not find policy with ID " + POLICY_NAME + " and type " + POLICY_TYPE_ID
+ + " deployed in any pdp group");
// Update pdpSubGroup
pdpSubGroup.setPolicies(new ArrayList<>());
- pdpSubGroup.getPolicies().add(
- new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION + LEGACY_MINOR_PATCH_SUFFIX));
- assertEquals(1, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
- .getPolicies().size());
+ pdpSubGroup.getPolicies()
+ .add(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION + LEGACY_MINOR_PATCH_SUFFIX));
+ assertEquals(1,
+ databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size());
// Test fetchDeployedPolicies
- assertThatCode(
- () -> {
- guardPolicyProvider.fetchDeployedGuardPolicies(POLICY_NAME);
- }).doesNotThrowAnyException();
+ assertThatCode(() -> {
+ guardPolicyProvider.fetchDeployedGuardPolicies(POLICY_NAME);
+ }).doesNotThrowAnyException();
// Test validateDeleteEligibility exception path(!pdpGroups.isEmpty())
- assertThatThrownBy(
- () -> {
- guardPolicyProvider.deleteGuardPolicy(
- POLICY_NAME, POLICY_VERSION);
- }).hasMessageContaining("policy with ID " + POLICY_NAME + ":" + POLICY_VERSION
+ assertThatThrownBy(() -> {
+ guardPolicyProvider.deleteGuardPolicy(POLICY_NAME, POLICY_VERSION);
+ }) .hasMessageContaining("policy with ID " + POLICY_NAME + ":" + POLICY_VERSION
+ " cannot be deleted as it is deployed in pdp groups");
- }
- catch (Exception exc) {
+ } catch (Exception exc) {
fail("Test should not throw an exception");
}
}
@@ -282,7 +281,8 @@ public class TestLegacyGuardPolicyProvider {
}).hasMessage("policy type " + POLICY_TYPE_ID + " for policy " + POLICY_ID + " does not exist");
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -327,8 +327,7 @@ public class TestLegacyGuardPolicyProvider {
pdpSubGroup.setPdpType("type");
pdpSubGroup.setDesiredInstanceCount(123);
pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
- pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier(
- policyTypeId, policyTypeVersion));
+ pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion));
pdpGroup.getPdpSubgroups().add(pdpSubGroup);
Pdp pdp = new Pdp();
@@ -346,17 +345,18 @@ public class TestLegacyGuardPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
// Create Policy
assertThatCode(() -> {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString,
- LegacyGuardPolicyInput.class);
+ LegacyGuardPolicyInput policyToCreate =
+ standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
Map<String, LegacyGuardPolicyOutput> createdPolicy =
guardPolicyProvider.createGuardPolicy(policyToCreate);
assertNotNull(createdPolicy);
@@ -366,14 +366,12 @@ public class TestLegacyGuardPolicyProvider {
// Update pdpSubGroup
pdpSubGroup.setPolicies(new ArrayList<>());
pdpSubGroup.getPolicies().add(new ToscaPolicyIdentifier(policyId, policyVersion + legacyMinorPatchSuffix));
- assertEquals(1, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
- .getPolicies().size());
+ assertEquals(1,
+ databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size());
assertThatThrownBy(() -> {
- guardPolicyProvider
- .deleteGuardPolicy("guard.frequency.scaleout", "1");
+ guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1");
}).hasMessageContaining("cannot be deleted as it is deployed in pdp groups");
- }
- catch (Exception exc) {
+ } catch (Exception exc) {
fail("Test should not throw an exception");
}
}
@@ -389,7 +387,8 @@ public class TestLegacyGuardPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -400,8 +399,8 @@ public class TestLegacyGuardPolicyProvider {
assertNotNull(createdPolicy);
assertFalse(createdPolicy.isEmpty());
- Map<String, LegacyGuardPolicyOutput> deletedPolicy = guardPolicyProvider
- .deleteGuardPolicy("guard.frequency.scaleout", "1");
+ Map<String, LegacyGuardPolicyOutput> deletedPolicy =
+ guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1");
assertNotNull(deletedPolicy);
assertFalse(deletedPolicy.isEmpty());
assertTrue(deletedPolicy.containsKey("guard.frequency.scaleout"));
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 2479223e..f1784a53 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
@@ -3,6 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -37,6 +38,7 @@ 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;
@@ -57,7 +59,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
- * This class performs unit test of {@link LegacyOperationalPolicyProvider}
+ * This class performs unit test of {@link LegacyOperationalPolicyProvider}.
*
* @author Chenfei Gao (cgao@research.att.com)
*/
@@ -70,7 +72,7 @@ public class TestLegacyOperationalPolicyProvider {
private static StandardCoder standardCoder;
private static final String POLICY_RESOURCE = "policies/vCPE.policy.operational.input.json";
- private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.controlloop.Operational.json";
+ private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.controlloop.Operational.yaml";
private static final String POLICY_TYPE_ID = "onap.policies.controlloop.Operational:1.0.0";
private static final String POLICY_ID = "operational.restart:1.0.0";
private static final String POLICY_NAME = "operational.restart";
@@ -125,7 +127,8 @@ public class TestLegacyOperationalPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -143,14 +146,12 @@ public class TestLegacyOperationalPolicyProvider {
LegacyOperationalPolicy firstVersion =
operationalPolicyProvider.fetchOperationalPolicy("operational.restart", "1");
assertNotNull(firstVersion);
- assertEquals("1",
- firstVersion.getPolicyVersion());
+ assertEquals("1", firstVersion.getPolicyVersion());
LegacyOperationalPolicy latestVersion =
operationalPolicyProvider.fetchOperationalPolicy("operational.restart", null);
assertNotNull(latestVersion);
- assertEquals("2",
- latestVersion.getPolicyVersion());
+ assertEquals("2", latestVersion.getPolicyVersion());
}).doesNotThrowAnyException();
assertThatThrownBy(() -> {
@@ -195,8 +196,8 @@ public class TestLegacyOperationalPolicyProvider {
pdpSubGroup.setPdpType("type");
pdpSubGroup.setDesiredInstanceCount(123);
pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
- pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier(
- POLICY_TYPE_NAME, POLICY_TYPE_VERSION));
+ pdpSubGroup.getSupportedPolicyTypes()
+ .add(new ToscaPolicyTypeIdentifier(POLICY_TYPE_NAME, POLICY_TYPE_VERSION));
pdpGroup.getPdpSubgroups().add(pdpSubGroup);
Pdp pdp = new Pdp();
@@ -214,7 +215,8 @@ public class TestLegacyOperationalPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -225,43 +227,38 @@ public class TestLegacyOperationalPolicyProvider {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
LegacyOperationalPolicy policyToCreate =
standardCoder.decode(policyString, LegacyOperationalPolicy.class);
- LegacyOperationalPolicy policyCreated = operationalPolicyProvider
- .createOperationalPolicy(policyToCreate);
+ LegacyOperationalPolicy policyCreated =
+ operationalPolicyProvider.createOperationalPolicy(policyToCreate);
assertEquals("operational.restart", policyCreated.getPolicyId());
assertEquals("1", policyCreated.getPolicyVersion());
assertFalse(policyCreated.getContent() == null);
}).doesNotThrowAnyException();
// Test fetchDeployedPolicies (deployedPolicyMap.isEmpty())==true
- assertThatThrownBy(
- () -> {
- operationalPolicyProvider.fetchDeployedOperationalPolicies(POLICY_NAME);
- }).hasMessage("could not find policy with ID " + POLICY_NAME + " and type "
- + POLICY_TYPE_ID + " deployed in any pdp group");
+ assertThatThrownBy(() -> {
+ operationalPolicyProvider.fetchDeployedOperationalPolicies(POLICY_NAME);
+ }) .hasMessage("could not find policy with ID " + POLICY_NAME + " and type " + POLICY_TYPE_ID
+ + " deployed in any pdp group");
// Update pdpSubGroup
pdpSubGroup.setPolicies(new ArrayList<>());
- pdpSubGroup.getPolicies().add(
- new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION + LEGACY_MINOR_PATCH_SUFFIX));
- assertEquals(1, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
- .getPolicies().size());
+ pdpSubGroup.getPolicies()
+ .add(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION + LEGACY_MINOR_PATCH_SUFFIX));
+ assertEquals(1,
+ databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size());
// Test fetchDeployedPolicies
- assertThatCode(
- () -> {
- operationalPolicyProvider.fetchDeployedOperationalPolicies(POLICY_NAME);
- }).doesNotThrowAnyException();
+ assertThatCode(() -> {
+ operationalPolicyProvider.fetchDeployedOperationalPolicies(POLICY_NAME);
+ }).doesNotThrowAnyException();
// Test validateDeleteEligibility exception path(!pdpGroups.isEmpty())
- assertThatThrownBy(
- () -> {
- operationalPolicyProvider.deleteOperationalPolicy(
- POLICY_NAME, POLICY_VERSION);
- }).hasMessageContaining("policy with ID " + POLICY_NAME + ":" + POLICY_VERSION
+ assertThatThrownBy(() -> {
+ operationalPolicyProvider.deleteOperationalPolicy(POLICY_NAME, POLICY_VERSION);
+ }) .hasMessageContaining("policy with ID " + POLICY_NAME + ":" + POLICY_VERSION
+ " cannot be deleted as it is deployed in pdp groups");
- }
- catch (Exception exc) {
+ } catch (Exception exc) {
fail("Test should not throw an exception");
}
}
@@ -276,7 +273,8 @@ public class TestLegacyOperationalPolicyProvider {
}).hasMessage("policy type " + POLICY_TYPE_ID + " for policy " + POLICY_ID + " does not exist");
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -286,8 +284,7 @@ public class TestLegacyOperationalPolicyProvider {
LegacyOperationalPolicy createdPolicy = operationalPolicyProvider.createOperationalPolicy(policyToCreate);
assertNotNull(createdPolicy);
assertEquals("operational.restart", createdPolicy.getPolicyId());
- assertTrue(createdPolicy.getContent()
- .startsWith("controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20"));
+ assertTrue(createdPolicy.getContent().startsWith("controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20"));
}).doesNotThrowAnyException();
}
@@ -319,8 +316,7 @@ public class TestLegacyOperationalPolicyProvider {
pdpSubGroup.setPdpType("type");
pdpSubGroup.setDesiredInstanceCount(123);
pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
- pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier(
- policyTypeId, policyTypeVersion));
+ pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion));
pdpGroup.getPdpSubgroups().add(pdpSubGroup);
Pdp pdp = new Pdp();
@@ -338,9 +334,10 @@ public class TestLegacyOperationalPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
- standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -357,13 +354,12 @@ public class TestLegacyOperationalPolicyProvider {
// Update pdpSubGroup
pdpSubGroup.setPolicies(new ArrayList<>());
pdpSubGroup.getPolicies().add(new ToscaPolicyIdentifier(policyId, policyVersion + legacyMinorPatchSuffix));
- assertEquals(1, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
- .getPolicies().size());
+ assertEquals(1,
+ databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size());
assertThatThrownBy(() -> {
operationalPolicyProvider.deleteOperationalPolicy(policyId, policyVersion);
}).hasMessageContaining("cannot be deleted as it is deployed in pdp groups");
- }
- catch (Exception exc) {
+ } catch (Exception exc) {
fail("Test should not throw an exception");
}
}
@@ -380,7 +376,8 @@ public class TestLegacyOperationalPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -390,12 +387,11 @@ public class TestLegacyOperationalPolicyProvider {
LegacyOperationalPolicy createdPolicy = operationalPolicyProvider.createOperationalPolicy(policyToCreate);
assertNotNull(createdPolicy);
- LegacyOperationalPolicy deletedPolicy = operationalPolicyProvider
- .deleteOperationalPolicy("operational.restart", "1");
+ LegacyOperationalPolicy deletedPolicy =
+ operationalPolicyProvider.deleteOperationalPolicy("operational.restart", "1");
assertNotNull(deletedPolicy);
assertEquals("operational.restart", deletedPolicy.getPolicyId());
- assertTrue(deletedPolicy.getContent()
- .startsWith("controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20"));
+ assertTrue(deletedPolicy.getContent().startsWith("controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20"));
}).doesNotThrowAnyException();
assertThatThrownBy(() -> {
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 ea886370..282f8a08 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
@@ -3,6 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -36,6 +37,7 @@ 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;
@@ -55,7 +57,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
- * This class performs unit test of {@link PolicyProvider}
+ * This class performs unit test of {@link PolicyProvider}.
*
* @author Chenfei Gao (cgao@research.att.com)
*/
@@ -68,7 +70,7 @@ public class TestPolicyProvider {
private static StandardCoder standardCoder;
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.json";
+ private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml";
private static final String POLICY_RESOURCE_WITH_BAD_POLICYTYPE_ID = "policies/vCPE.policy.bad.policytypeid.json";
private static final String POLICY_RESOURCE_WITH_BAD_POLICYTYPE_VERSION =
"policies/vCPE.policy.bad.policytypeversion.json";
@@ -139,7 +141,7 @@ public class TestPolicyProvider {
String policyTypeVersion = "1.0.0";
String policyTypeId = "onap.policies.monitoring.cdap.tca.hi.lo.app";
- //Basic Exception Throw
+ // Basic Exception Throw
assertThatThrownBy(() -> {
policyProvider.fetchDeployedPolicies("dummy", "1.0.0", "dummy");
}).hasMessage("could not find policy with ID dummy and type dummy:1.0.0 deployed in any pdp group");
@@ -164,8 +166,7 @@ public class TestPolicyProvider {
pdpSubGroup.setPdpType("type");
pdpSubGroup.setDesiredInstanceCount(123);
pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
- pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier(
- policyTypeId, policyTypeVersion));
+ pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion));
pdpGroup.getPdpSubgroups().add(pdpSubGroup);
Pdp pdp = new Pdp();
@@ -183,7 +184,8 @@ public class TestPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -194,43 +196,36 @@ public class TestPolicyProvider {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
ToscaServiceTemplate policyServiceTemplate =
standardCoder.decode(policyString, ToscaServiceTemplate.class);
- ToscaServiceTemplate serviceTemplate = policyProvider
- .createPolicy(policyTypeId, policyTypeVersion, policyServiceTemplate);
+ ToscaServiceTemplate serviceTemplate =
+ policyProvider.createPolicy(policyTypeId, policyTypeVersion, policyServiceTemplate);
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
}).doesNotThrowAnyException();
// Test fetchDeployedPolicies (deployedPolicyMap.isEmpty())==true
- assertThatThrownBy(
- () -> {
- policyProvider.fetchDeployedPolicies(
- policyTypeId, policyTypeVersion, policyId);
- }).hasMessage("could not find policy with ID " + policyId + " and type "
- + policyTypeId + ":" + policyTypeVersion + " deployed in any pdp group");
+ assertThatThrownBy(() -> {
+ policyProvider.fetchDeployedPolicies(policyTypeId, policyTypeVersion, policyId);
+ }) .hasMessage("could not find policy with ID " + policyId + " and type " + policyTypeId + ":"
+ + policyTypeVersion + " deployed in any pdp group");
// Update pdpSubGroup
pdpSubGroup.setPolicies(new ArrayList<>());
pdpSubGroup.getPolicies().add(new ToscaPolicyIdentifier(policyId, policyVersion));
- assertEquals(1, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
- .getPolicies().size());
+ assertEquals(1,
+ databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size());
// Test fetchDeployedPolicies
- assertThatCode(
- () -> {
- policyProvider.fetchDeployedPolicies(
- policyTypeId, policyTypeVersion, policyId);
- }).doesNotThrowAnyException();
+ assertThatCode(() -> {
+ policyProvider.fetchDeployedPolicies(policyTypeId, policyTypeVersion, policyId);
+ }).doesNotThrowAnyException();
// Test validateDeleteEligibility exception path(!pdpGroups.isEmpty())
- assertThatThrownBy(
- () -> {
- policyProvider.deletePolicy(
- "onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
- "onap.restart.tca", "1.0.0");
- }).hasMessageContaining("policy with ID " + policyId + ":" + policyVersion
+ assertThatThrownBy(() -> {
+ policyProvider.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca",
+ "1.0.0");
+ }) .hasMessageContaining("policy with ID " + policyId + ":" + policyVersion
+ " cannot be deleted as it is deployed in pdp groups");
- }
- catch (Exception exc) {
+ } catch (Exception exc) {
fail("Test should not throw an exception");
}
}
@@ -243,7 +238,8 @@ public class TestPolicyProvider {
}).hasMessage("policy type with ID dummy:1.0.0 does not exist");
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -267,8 +263,7 @@ public class TestPolicyProvider {
assertThatCode(() -> {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- ToscaServiceTemplate policyServiceTemplate =
- standardCoder.decode(policyString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyServiceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyProvider
.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
@@ -283,7 +278,8 @@ public class TestPolicyProvider {
}).hasMessage("policy with ID dummy:1.0.0 and type dummy:1.0.0 does not exist");
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
@@ -291,24 +287,23 @@ public class TestPolicyProvider {
assertThatCode(() -> {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- ToscaServiceTemplate policyServiceTemplate =
- standardCoder.decode(policyString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyServiceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyProvider
.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
}).doesNotThrowAnyException();
assertThatCode(() -> {
- ToscaServiceTemplate serviceTemplate = policyProvider.deletePolicy(
- "onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0");
+ ToscaServiceTemplate serviceTemplate = policyProvider
+ .deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0");
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
}).doesNotThrowAnyException();
String exceptionMessage = "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";
+ + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist";
assertThatThrownBy(() -> {
- policyProvider.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
- "onap.restart.tca", "1.0.0");
+ policyProvider.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca",
+ "1.0.0");
}).hasMessage(exceptionMessage);
}
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 7865453f..07675b79 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
@@ -3,6 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -30,6 +31,7 @@ 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;
@@ -39,7 +41,7 @@ import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
- * This class performs unit test of {@link PolicyTypeProvider}
+ * This class performs unit test of {@link PolicyTypeProvider}.
*
* @author Chenfei Gao (cgao@research.att.com)
*/
@@ -51,8 +53,8 @@ public class TestPolicyTypeProvider {
private static ApiParameterGroup apiParamGroup;
private static StandardCoder standardCoder;
- 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.json";
+ 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";
/**
* Initializes parameters.
@@ -117,11 +119,12 @@ public class TestPolicyTypeProvider {
public void testCreatePolicyType() {
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
- assertFalse(serviceTemplate.getPolicyTypes().get(0).isEmpty());
+ assertFalse(serviceTemplate.getPolicyTypes().isEmpty());
}).doesNotThrowAnyException();
}
@@ -129,37 +132,36 @@ public class TestPolicyTypeProvider {
public void testDeletePolicyType() {
assertThatCode(() -> {
- String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ String policyTypeString =
+ ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE));
ToscaServiceTemplate policyTypeServiceTemplate =
standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
- assertFalse(serviceTemplate.getPolicyTypes().get(0).isEmpty());
+ assertFalse(serviceTemplate.getPolicyTypes().isEmpty());
}).doesNotThrowAnyException();
assertThatCode(() -> {
- String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- ToscaServiceTemplate policyServiceTemplate =
- standardCoder.decode(policyString, ToscaServiceTemplate.class);
- policyProvider.createPolicy(
- "onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
+ String policyString = ApiTestSupportUtilities.yaml2Json(ResourceUtils.getResourceAsString(POLICY_RESOURCE));
+ ToscaServiceTemplate policyServiceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
+ policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
}).doesNotThrowAnyException();
String exceptionMessage = "policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 "
- + "cannot be deleted as it is parameterized by policies onap.restart.tca:1.0.0";
+ + "cannot be deleted as it is parameterized by policies onap.restart.tca:1.0.0";
assertThatThrownBy(() -> {
policyTypeProvider.deletePolicyType("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0");
}).hasMessage(exceptionMessage);
assertThatCode(() -> {
- ToscaServiceTemplate serviceTemplate = policyProvider.deletePolicy(
- "onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0");
+ ToscaServiceTemplate serviceTemplate = policyProvider
+ .deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0");
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
}).doesNotThrowAnyException();
assertThatCode(() -> {
- ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(
- "onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0");
- assertFalse(serviceTemplate.getPolicyTypes().get(0).isEmpty());
+ ToscaServiceTemplate serviceTemplate =
+ policyTypeProvider.deletePolicyType("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0");
+ assertFalse(serviceTemplate.getPolicyTypes().isEmpty());
}).doesNotThrowAnyException();
assertThatThrownBy(() -> {