aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java143
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java432
-rw-r--r--main/src/test/resources/parameters/ApiConfigParameters_Https.json7
-rw-r--r--main/src/test/resources/policies/vCPE.policies.optimization.input.tosca.v2.yaml2
-rw-r--r--main/src/test/resources/policies/vCPE.policy.bad.policytypeid.json2
-rw-r--r--main/src/test/resources/policies/vCPE.policy.bad.policytypeversion.json2
-rw-r--r--main/src/test/resources/policies/vCPE.policy.different.policy.fields.json2
-rw-r--r--main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml2
-rw-r--r--main/src/test/resources/policies/vCPE.policy.no.policyversion.json2
-rw-r--r--main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json15
-rw-r--r--main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json15
-rw-r--r--main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json14
-rw-r--r--main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml2
-rw-r--r--main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.v2.yaml2
-rw-r--r--main/src/test/resources/policytypes/onap.policies.Test.yaml2
-rw-r--r--main/src/test/resources/policytypes/onap.policies.optimization.Resource.no.version.yaml2
16 files changed, 18 insertions, 628 deletions
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 95a20692..9474814d 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
@@ -69,7 +69,6 @@ import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.errors.concepts.ErrorResponse;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
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;
/**
@@ -121,27 +120,10 @@ public class TestApiRestServer {
+ "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/2.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 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 POLICYTYPES_DROOLS_POLICIES_VCPE_VERSION =
POLICYTYPES_DROOLS_VERSION + "/policies/" + OP_POLICY_NAME_VCPE + "/versions/1.0.0";
- 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";
- private static final String GUARD_POLICIES_VDNS_FL_DEPLOYED =
- "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout"
- + "/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";
- 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";
-
private static final String OPS_POLICIES =
"policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies";
private static final String OPS_POLICIES_VCPE_LATEST =
@@ -192,9 +174,10 @@ public class TestApiRestServer {
LEGACY_POLICYTYPE_OP_RESOURCE,
TOSCA_POLICYTYPE_OP_RESOURCE,
"policytypes/onap.policies.controlloop.operational.common.Drools.yaml",
- "policytypes/onap.policies.controlloop.guard.Blacklist.yaml",
- "policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml",
- "policytypes/onap.policies.controlloop.guard.MinMax.yaml",
+ "policytypes/onap.policies.controlloop.guard.Common.yaml",
+ "policytypes/onap.policies.controlloop.guard.common.Blacklist.yaml",
+ "policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter.yaml",
+ "policytypes/onap.policies.controlloop.guard.common.MinMax.yaml",
"policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml",
"policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml",
"policytypes/onap.policies.optimization.resource.DistancePolicy.yaml",
@@ -213,11 +196,6 @@ public class TestApiRestServer {
private static final String TOSCA_POLICY_OP_DROOLS_VCPE_RESOURSE_YAML =
"policies/vCPE.policy.operational.input.tosca.yaml";
- private static final String[] LEGACY_GUARD_POLICY_RESOURCE_NAMES = {
- "policies/vDNS.policy.guard.frequency.input.json",
- "policies/vDNS.policy.guard.minmax.input.json"
- };
-
private static final String[] LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES = {
"policies/vCPE.policy.operational.legacy.input.json",
"policies/vDNS.policy.operational.legacy.input.json",
@@ -371,20 +349,6 @@ public class TestApiRestServer {
}
@Test
- public void testCreateGuardPolicies() throws Exception {
- for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
-
- Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, APP_JSON);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
- rawResponse = deleteResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, APP_JSON);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
-
- @Test
public void testCreateOperationalPolicies() throws Exception {
for (String resrcName : LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES) {
Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName);
@@ -740,41 +704,6 @@ public class TestApiRestServer {
}
@Test
- public void testReadGuardPoliciesJson() throws Exception {
- testReadGuardPolicies(APP_JSON);
- }
-
- @Test
- public void testReadGuardPoliciesYaml() throws Exception {
- testReadGuardPolicies(APP_YAML);
- }
-
- private void testReadGuardPolicies(String mediaType) throws Exception {
- for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
-
- Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
- rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
- rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
- rawResponse = deleteResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, APP_JSON);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
-
- @Test
public void testReadOperationalPoliciesJson() throws Exception {
testReadOperationalPolicies(APP_JSON);
}
@@ -820,49 +749,6 @@ public class TestApiRestServer {
}
@Test
- public void testDeleteGuardPolicyJson() throws Exception {
- testDeleteGuardPolicy(APP_JSON);
- }
-
- @Test
- public void testDeleteGuardPolicyYaml() throws Exception {
- testDeleteGuardPolicy(APP_YAML);
- }
-
- private void testDeleteGuardPolicy(String mediaType) throws Exception {
- for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
-
- Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
- rawResponse = deleteResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, APP_JSON);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
-
- @Test
- public void testGetDeployedVersionsOfGuardPolicyJson() throws Exception {
- testGetDeployedVersionsOfGuardPolicy(APP_JSON);
- }
-
- @Test
- public void testGetDeployedVersionsOfGuardPolicyYaml() throws Exception {
- testGetDeployedVersionsOfGuardPolicy(APP_YAML);
- }
-
- private void testGetDeployedVersionsOfGuardPolicy(String mediaType) throws Exception {
- Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_DEPLOYED, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
- assertEquals(
- "could not find policy with ID guard.frequency.scaleout and type "
- + "onap.policies.controlloop.guard.FrequencyLimiter:1.0.0 deployed in any pdp group",
- errorResponse.getErrorMessage());
- }
-
- @Test
public void testDeleteOperationalPolicyJson() throws Exception {
testDeleteOperationalPolicy(APP_JSON);
}
@@ -962,27 +848,6 @@ public class TestApiRestServer {
return invocationBuilder.post(entity);
}
- private Response createGuardPolicy(String endpoint, String resourceName) throws Exception {
-
- String mediaType = APP_JSON; // default media type
- LegacyGuardPolicyInput rawGuardPolicy = new LegacyGuardPolicyInput();
- if (resourceName.endsWith(".json")) {
- rawGuardPolicy =
- standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
- } else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) {
- mediaType = APP_YAML;
- rawGuardPolicy = standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName),
- LegacyGuardPolicyInput.class);
- }
-
- final Invocation.Builder invocationBuilder;
-
- invocationBuilder = sendHttpsRequest(endpoint, mediaType);
-
- Entity<LegacyGuardPolicyInput> entity = Entity.entity(rawGuardPolicy, mediaType);
- return invocationBuilder.post(entity);
- }
-
private Response createOperationalPolicy(String endpoint, String resourceName) throws Exception {
String mediaType = APP_JSON; // default media type
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
deleted file mode 100644
index dfe29cfc..00000000
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java
+++ /dev/null
@@ -1,432 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy API
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 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.rest.provider;
-
-import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.Base64;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.api.main.parameters.ApiParameterGroup;
-import org.onap.policy.common.parameters.ParameterService;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.coder.StandardYamlCoder;
-import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.pdp.concepts.Pdp;
-import org.onap.policy.models.pdp.concepts.PdpGroup;
-import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
-import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.enums.PdpHealthStatus;
-import org.onap.policy.models.pdp.enums.PdpState;
-import org.onap.policy.models.provider.PolicyModelsProvider;
-import org.onap.policy.models.provider.PolicyModelsProviderFactory;
-import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyContent;
-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}.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class TestLegacyGuardPolicyProvider {
-
- private static LegacyGuardPolicyProvider guardPolicyProvider;
- private static PolicyTypeProvider policyTypeProvider;
- private static PolicyModelsProviderParameters providerParams;
- private static ApiParameterGroup apiParamGroup;
- private static StandardCoder standardCoder;
- private static StandardYamlCoder standardYamlCoder;
-
- private static final String POLICY_RESOURCE = "policies/vDNS.policy.guard.frequency.input.json";
- private static final String POLICY_RESOURCE_VER1 = "policies/vDNS.policy.guard.frequency.input.ver1.json";
- private static final String POLICY_RESOURCE_VER2 = "policies/vDNS.policy.guard.frequency.input.ver2.json";
- private static final String POLICY_RESOURCE_WITH_NO_VERSION =
- "policies/vDNS.policy.guard.frequency.no.policyversion.json";
- private static final String POLICY_TYPE_RESOURCE =
- "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";
- private static final String POLICY_NAME = "guard.frequency.scaleout";
- private static final String POLICY_VERSION = "1";
- private static final String LEGACY_MINOR_PATCH_SUFFIX = ".0.0";
-
- /**
- * Initializes parameters.
- *
- * @throws PfModelException the PfModel parsing exception
- */
- @Before
- public void setupParameters() throws PfModelException {
- standardCoder = new StandardCoder();
- standardYamlCoder = new StandardYamlCoder();
- providerParams = new PolicyModelsProviderParameters();
- providerParams.setDatabaseDriver("org.h2.Driver");
- providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
- providerParams.setDatabaseUser("policy");
- providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
- providerParams.setPersistenceUnit("ToscaConceptTest");
- apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams,
- Collections.emptyList(), Collections.emptyList());
- ParameterService.register(apiParamGroup, true);
- guardPolicyProvider = new LegacyGuardPolicyProvider();
- policyTypeProvider = new PolicyTypeProvider();
- }
-
- /**
- * Closes up DB connections and deregisters API parameter group.
- *
- * @throws PfModelException the PfModel parsing exception
- */
- @After
- public void tearDown() throws PfModelException {
- guardPolicyProvider.close();
- policyTypeProvider.close();
- ParameterService.deregister(apiParamGroup);
- }
-
- @Test
- public void testFetchGuardPolicy() {
-
- assertThatThrownBy(() -> {
- guardPolicyProvider.fetchGuardPolicy("dummy", null);
- }).hasMessage("no policy found for policy: dummy:null");
-
- assertThatThrownBy(() -> {
- guardPolicyProvider.fetchGuardPolicy("dummy", "dummy");
- }).hasMessageContaining("parameter \"version\": value \"dummy.0.0\", does not match regular expression");
-
- assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
- .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
- policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
-
- String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_VER1);
- LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
- Map<String, LegacyGuardPolicyOutput> createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate);
- assertNotNull(createdPolicy);
- assertFalse(createdPolicy.isEmpty());
-
- policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_VER2);
- policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
- createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate);
- assertNotNull(createdPolicy);
- assertFalse(createdPolicy.isEmpty());
-
- Map<String, LegacyGuardPolicyOutput> firstVersion =
- guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "1");
- assertNotNull(firstVersion);
- assertEquals("1",
- firstVersion.get("guard.frequency.scaleout").getMetadata().get("policy-version").toString());
-
- Map<String, LegacyGuardPolicyOutput> latestVersion =
- guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", null);
- assertNotNull(latestVersion);
- assertEquals("2",
- latestVersion.get("guard.frequency.scaleout").getMetadata().get("policy-version").toString());
- }).doesNotThrowAnyException();
-
- assertThatThrownBy(() -> {
- guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "1.0.0");
- }).hasMessageContaining("parameter \"version\": value \"1.0.0.0.0\", does not match regular expression");
-
- assertThatThrownBy(() -> {
- guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "latest");
- }).hasMessageContaining("parameter \"version\": value \"latest.0.0\", does not match regular expression");
-
- assertThatCode(() -> {
- guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1");
- guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "2");
- policyTypeProvider.deletePolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0");
- }).doesNotThrowAnyException();
- }
-
- @Test
- public void testFetchDeployedGuardPolicies() {
-
- assertThatThrownBy(() -> {
- guardPolicyProvider.fetchDeployedGuardPolicies("dummy");
- }).hasMessage("No policy type defined for dummy");
-
- try (PolicyModelsProvider databaseProvider =
- new PolicyModelsProviderFactory().createPolicyModelsProvider(providerParams)) {
- assertEquals(0, databaseProvider.getPdpGroups("name").size());
- assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size());
-
- assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>()));
- assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>()));
-
- PdpGroup pdpGroup = new PdpGroup();
- pdpGroup.setName("group");
- pdpGroup.setVersion("1.2.3");
- pdpGroup.setPdpGroupState(PdpState.ACTIVE);
- pdpGroup.setPdpSubgroups(new ArrayList<>());
- List<PdpGroup> groupList = new ArrayList<>();
- groupList.add(pdpGroup);
-
- PdpSubGroup pdpSubGroup = new PdpSubGroup();
- pdpSubGroup.setPdpType("type");
- pdpSubGroup.setDesiredInstanceCount(123);
- pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
- pdpSubGroup.getSupportedPolicyTypes()
- .add(new ToscaPolicyTypeIdentifier(POLICY_TYPE_NAME, POLICY_TYPE_VERSION));
- pdpGroup.getPdpSubgroups().add(pdpSubGroup);
-
- Pdp pdp = new Pdp();
- pdp.setInstanceId("type-0");
- pdp.setMessage("Hello");
- pdp.setPdpState(PdpState.ACTIVE);
- pdp.setHealthy(PdpHealthStatus.UNKNOWN);
- pdpSubGroup.setPdpInstances(new ArrayList<>());
- pdpSubGroup.getPdpInstances().add(pdp);
-
- // Create Pdp Groups
- assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
- .getDesiredInstanceCount());
- assertEquals(1, databaseProvider.getPdpGroups("group").size());
-
- // Create Policy Type
- assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
- .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
- policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
- }).doesNotThrowAnyException();
-
- // Create Policy
- assertThatCode(() -> {
- String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- LegacyGuardPolicyInput policyToCreate =
- standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
- 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");
-
- // 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());
-
- // Test fetchDeployedPolicies
- assertThatCode(() -> {
- guardPolicyProvider.fetchDeployedGuardPolicies(POLICY_NAME);
- }).doesNotThrowAnyException();
-
- // Test validateDeleteEligibility exception path(!pdpGroups.isEmpty())
- assertThatThrownBy(() -> {
- guardPolicyProvider.deleteGuardPolicy(POLICY_NAME, POLICY_VERSION);
- }).hasMessageContaining("policy is in use, it is deployed in PDP group group subgroup type");
- } catch (Exception exc) {
- fail("Test should not throw an exception");
- }
- }
-
- @Test
- public void testCreateGuardPolicy() throws Exception {
- assertThatThrownBy(() -> {
- String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
- guardPolicyProvider.createGuardPolicy(policyToCreate);
- }).hasMessageContaining(
- "no policy types are defined on the service template for the policies in the topology template");
-
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
- .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
- policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
-
- String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
- Map<String, LegacyGuardPolicyOutput> createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate);
- assertNotNull(createdPolicy);
- assertFalse(createdPolicy.isEmpty());
- assertTrue(createdPolicy.containsKey("guard.frequency.scaleout"));
- assertEquals("onap.policies.controlloop.guard.FrequencyLimiter",
- createdPolicy.get("guard.frequency.scaleout").getType());
- assertEquals("1.0.0", createdPolicy.get("guard.frequency.scaleout").getVersion());
-
- String defaultPolicyVersionString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_NO_VERSION);
- LegacyGuardPolicyInput defaultVersionPolicy =
- standardCoder.decode(defaultPolicyVersionString, LegacyGuardPolicyInput.class);
- createdPolicy = guardPolicyProvider.createGuardPolicy(defaultVersionPolicy);
- assertEquals("1.0.0", createdPolicy.get("guard.frequency.scaleout.noversion").getVersion());
-
- assertThatCode(() -> {
- String duplicatePolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- LegacyGuardPolicyInput duplicatePolicyToCreate =
- standardCoder.decode(duplicatePolicyString, LegacyGuardPolicyInput.class);
- guardPolicyProvider.createGuardPolicy(duplicatePolicyToCreate);
- }).doesNotThrowAnyException();
-
- assertThatThrownBy(() -> {
- String duplicatePolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- LegacyGuardPolicyInput duplicatePolicyToCreate =
- standardCoder.decode(duplicatePolicyString, LegacyGuardPolicyInput.class);
- duplicatePolicyToCreate.setContent(new LegacyGuardPolicyContent());
- guardPolicyProvider.createGuardPolicy(duplicatePolicyToCreate);
- }).hasMessageContaining("INVALID:entity in incoming fragment does not equal existing entity");
- }
-
- @Test
- public void testDeleteGuardPolicyException() {
- String policyId = "guard.frequency.scaleout";
- String policyVersion = "1";
- String policyTypeVersion = "1.0.0";
- String policyTypeId = "onap.policies.controlloop.guard.FrequencyLimiter";
- String legacyMinorPatchSuffix = ".0.0";
-
- try (PolicyModelsProvider databaseProvider =
- new PolicyModelsProviderFactory().createPolicyModelsProvider(providerParams)) {
- assertEquals(0, databaseProvider.getPdpGroups("name").size());
- assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size());
-
- assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>()));
- assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>()));
-
- PdpGroup pdpGroup = new PdpGroup();
- pdpGroup.setName("group");
- pdpGroup.setVersion("1.2.3");
- pdpGroup.setPdpGroupState(PdpState.ACTIVE);
- pdpGroup.setPdpSubgroups(new ArrayList<>());
- List<PdpGroup> groupList = new ArrayList<>();
- groupList.add(pdpGroup);
-
- PdpSubGroup pdpSubGroup = new PdpSubGroup();
- pdpSubGroup.setPdpType("type");
- pdpSubGroup.setDesiredInstanceCount(123);
- pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
- pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion));
- pdpGroup.getPdpSubgroups().add(pdpSubGroup);
-
- Pdp pdp = new Pdp();
- pdp.setInstanceId("type-0");
- pdp.setMessage("Hello");
- pdp.setPdpState(PdpState.ACTIVE);
- pdp.setHealthy(PdpHealthStatus.UNKNOWN);
- pdpSubGroup.setPdpInstances(new ArrayList<>());
- pdpSubGroup.getPdpInstances().add(pdp);
-
- // Create Pdp Groups
- assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
- .getDesiredInstanceCount());
- assertEquals(1, databaseProvider.getPdpGroups("group").size());
-
- // Create Policy Type
- assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
- .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
- policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
- }).doesNotThrowAnyException();
-
- // Create Policy
- assertThatCode(() -> {
- String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- LegacyGuardPolicyInput policyToCreate =
- standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
- Map<String, LegacyGuardPolicyOutput> createdPolicy =
- guardPolicyProvider.createGuardPolicy(policyToCreate);
- assertNotNull(createdPolicy);
- assertFalse(createdPolicy.isEmpty());
- }).doesNotThrowAnyException();
-
- // 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());
- assertThatThrownBy(() -> {
- guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1");
- }).hasMessageContaining("policy is in use, it is deployed in PDP group group subgroup type");
- } catch (Exception exc) {
- fail("Test should not throw an exception");
- }
- }
-
- @Test
- public void testDeleteGuardPolicy() {
- assertThatThrownBy(() -> {
- guardPolicyProvider.deleteGuardPolicy("dummy", null);
- }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
-
- assertThatThrownBy(() -> {
- guardPolicyProvider.deleteGuardPolicy("dummy", "1.0.0");
- }).hasMessageContaining("parameter \"version\": value \"1.0.0.0.0\", does not match regular expression");
-
- assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
- .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
- policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
-
- String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
- LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
- Map<String, LegacyGuardPolicyOutput> createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate);
- assertNotNull(createdPolicy);
- assertFalse(createdPolicy.isEmpty());
-
- Map<String, LegacyGuardPolicyOutput> deletedPolicy =
- guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1");
- assertNotNull(deletedPolicy);
- assertFalse(deletedPolicy.isEmpty());
- assertTrue(deletedPolicy.containsKey("guard.frequency.scaleout"));
- assertEquals("onap.policies.controlloop.guard.FrequencyLimiter",
- deletedPolicy.get("guard.frequency.scaleout").getType());
- assertEquals("1",
- deletedPolicy.get("guard.frequency.scaleout").getMetadata().get("policy-version").toString());
-
- }).doesNotThrowAnyException();
-
- assertThatThrownBy(() -> {
- guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1");
- }).hasMessage("no policy found for policy: guard.frequency.scaleout:1");
-
- assertThatCode(() -> {
- policyTypeProvider.deletePolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0");
- }).doesNotThrowAnyException();
- }
-}
diff --git a/main/src/test/resources/parameters/ApiConfigParameters_Https.json b/main/src/test/resources/parameters/ApiConfigParameters_Https.json
index c5562432..e9c387db 100644
--- a/main/src/test/resources/parameters/ApiConfigParameters_Https.json
+++ b/main/src/test/resources/parameters/ApiConfigParameters_Https.json
@@ -31,9 +31,10 @@
"policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml",
"policytypes/onap.policies.optimization.resource.Vim_fit.yaml",
"policytypes/onap.policies.optimization.resource.VnfPolicy.yaml",
- "policytypes/onap.policies.controlloop.guard.Blacklist.yaml",
- "policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml",
- "policytypes/onap.policies.controlloop.guard.MinMax.yaml",
+ "policytypes/onap.policies.controlloop.guard.Common.yaml",
+ "policytypes/onap.policies.controlloop.guard.common.Blacklist.yaml",
+ "policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter.yaml",
+ "policytypes/onap.policies.controlloop.guard.common.MinMax.yaml",
"policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml",
"policytypes/onap.policies.controlloop.Operational.yaml",
"policytypes/onap.policies.Naming.yaml",
diff --git a/main/src/test/resources/policies/vCPE.policies.optimization.input.tosca.v2.yaml b/main/src/test/resources/policies/vCPE.policies.optimization.input.tosca.v2.yaml
index a946ba4e..e87e353d 100644
--- a/main/src/test/resources/policies/vCPE.policies.optimization.input.tosca.v2.yaml
+++ b/main/src/test/resources/policies/vCPE.policies.optimization.input.tosca.v2.yaml
@@ -1,4 +1,4 @@
-tosca_definitions_version: tosca_simple_yaml_1_0_0
+tosca_definitions_version: tosca_simple_yaml_1_1_0
topology_template:
policies:
-
diff --git a/main/src/test/resources/policies/vCPE.policy.bad.policytypeid.json b/main/src/test/resources/policies/vCPE.policy.bad.policytypeid.json
index 4eb84aa5..a9407955 100644
--- a/main/src/test/resources/policies/vCPE.policy.bad.policytypeid.json
+++ b/main/src/test/resources/policies/vCPE.policy.bad.policytypeid.json
@@ -1,5 +1,5 @@
{
- "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
"topology_template": {
"policies": [
{
diff --git a/main/src/test/resources/policies/vCPE.policy.bad.policytypeversion.json b/main/src/test/resources/policies/vCPE.policy.bad.policytypeversion.json
index 23195a97..c0286822 100644
--- a/main/src/test/resources/policies/vCPE.policy.bad.policytypeversion.json
+++ b/main/src/test/resources/policies/vCPE.policy.bad.policytypeversion.json
@@ -1,5 +1,5 @@
{
- "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
"topology_template": {
"policies": [
{
diff --git a/main/src/test/resources/policies/vCPE.policy.different.policy.fields.json b/main/src/test/resources/policies/vCPE.policy.different.policy.fields.json
index cc7e4ee4..cda5dce6 100644
--- a/main/src/test/resources/policies/vCPE.policy.different.policy.fields.json
+++ b/main/src/test/resources/policies/vCPE.policy.different.policy.fields.json
@@ -1,5 +1,5 @@
{
- "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
"topology_template": {
"policies": [
{
diff --git a/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml b/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml
index 459dcf7d..dc1991e8 100644
--- a/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml
+++ b/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml
@@ -1,4 +1,4 @@
-tosca_definitions_version: tosca_simple_yaml_1_0_0
+tosca_definitions_version: tosca_simple_yaml_1_1_0
topology_template:
policies:
-
diff --git a/main/src/test/resources/policies/vCPE.policy.no.policyversion.json b/main/src/test/resources/policies/vCPE.policy.no.policyversion.json
index b70d5965..1faa3aad 100644
--- a/main/src/test/resources/policies/vCPE.policy.no.policyversion.json
+++ b/main/src/test/resources/policies/vCPE.policy.no.policyversion.json
@@ -1,5 +1,5 @@
{
- "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
"topology_template": {
"policies": [
{
diff --git a/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json b/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json
deleted file mode 100644
index 6dc54cb8..00000000
--- a/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "policy-id" : "guard.frequency.scaleout",
- "policy-version" : "1",
- "content" : {
- "actor": "SO",
- "recipe": "scaleOut",
- "targets": ".*",
- "clname": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
- "limit": "1",
- "timeWindow": "10",
- "timeUnits": "minute",
- "guardActiveStart": "00:00:01-05:00",
- "guardActiveEnd": "23:59:59-05:00"
- }
-}
diff --git a/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json b/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json
deleted file mode 100644
index a8c325fb..00000000
--- a/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "policy-id" : "guard.frequency.scaleout",
- "policy-version" : "2",
- "content" : {
- "actor": "SO",
- "recipe": "scaleOut",
- "targets": ".*",
- "clname": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
- "limit": "1",
- "timeWindow": "10",
- "timeUnits": "minute",
- "guardActiveStart": "00:00:01-05:00",
- "guardActiveEnd": "23:59:59-05:00"
- }
-}
diff --git a/main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json b/main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json
deleted file mode 100644
index 518f09e8..00000000
--- a/main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "policy-id" : "guard.frequency.scaleout.noversion",
- "content" : {
- "actor": "SO",
- "recipe": "VF Module Create",
- "targets": ".*",
- "clname": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
- "limit": "1",
- "timeWindow": "10",
- "timeUnits": "minute",
- "guardActiveStart": "00:00:01-05:00",
- "guardActiveEnd": "23:59:59-05:00"
- }
-}
diff --git a/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml b/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml
index 208c656f..03ad85f7 100644
--- a/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml
+++ b/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml
@@ -1,4 +1,4 @@
-tosca_definitions_version: tosca_simple_yaml_1_0_0
+tosca_definitions_version: tosca_simple_yaml_1_1_0
topology_template:
policies:
- onap.scaleout.tca:
diff --git a/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.v2.yaml b/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.v2.yaml
index d76dc53e..780b4321 100644
--- a/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.v2.yaml
+++ b/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.v2.yaml
@@ -1,4 +1,4 @@
-tosca_definitions_version: tosca_simple_yaml_1_0_0
+tosca_definitions_version: tosca_simple_yaml_1_1_0
topology_template:
policies:
-
diff --git a/main/src/test/resources/policytypes/onap.policies.Test.yaml b/main/src/test/resources/policytypes/onap.policies.Test.yaml
index c8850a13..a029ca8f 100644
--- a/main/src/test/resources/policytypes/onap.policies.Test.yaml
+++ b/main/src/test/resources/policytypes/onap.policies.Test.yaml
@@ -1,4 +1,4 @@
-tosca_definitions_version: tosca_simple_yaml_1_0_0
+tosca_definitions_version: tosca_simple_yaml_1_1_0
policy_types:
onap.policies.Test:
derived_from: tosca.policies.Root
diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.Resource.no.version.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.Resource.no.version.yaml
index cab66238..7e6b2698 100644
--- a/main/src/test/resources/policytypes/onap.policies.optimization.Resource.no.version.yaml
+++ b/main/src/test/resources/policytypes/onap.policies.optimization.Resource.no.version.yaml
@@ -1,4 +1,4 @@
-tosca_definitions_version: tosca_simple_yaml_1_0_0
+tosca_definitions_version: tosca_simple_yaml_1_1_0
policy_types:
onap.policies.optimization.Resource:
derived_from: onap.policies.Optimization