aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2019-08-14 12:53:43 +0000
committerGerrit Code Review <gerrit@onap.org>2019-08-14 12:53:43 +0000
commitaa311cfc02de32534bc3dade0e3910648eb48add (patch)
tree275c577061435fb35d0f360031bfa81de8c80d3b /main/src/test/java/org
parent55ed172dbeb93801f419836fc08bf30c504a5dc0 (diff)
parent5b4fbae502f73a4ad58135a58ef348b704cc6ad3 (diff)
Merge "Add get deployed endpoints for legacy policies"
Diffstat (limited to 'main/src/test/java/org')
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java59
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java101
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java104
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java4
4 files changed, 243 insertions, 25 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 665616b5..442f9dba 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
@@ -105,12 +105,17 @@ public class TestApiRestServer {
+ "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/1.0.0";
private static final String POLICYTYPES_TCA_POLICIES_VCPE_LATEST = "policytypes/"
+ "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/latest";
+ private static final String 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_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";
@@ -122,33 +127,23 @@ public class TestApiRestServer {
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.Guard/versions/1.0.0/policies/operational.restart"
+ "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.restart"
+ "/versions/latest";
+ private static final String OPS_POLICIES_VCPE_DEPLOYED =
+ "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.restart"
+ + "/versions/deployed";
private static final String OPS_POLICIES_VDNS_LATEST =
- "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.scaleout"
+ "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.scaleout"
+ "/versions/latest";
private static final String OPS_POLICIES_VFIREWALL_LATEST =
- "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.modifyconfig"
+ "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.modifyconfig"
+ "/versions/latest";
private static final String OPS_POLICIES_VCPE_VERSION = "policytypes/"
- + "onap.policies.controlloop.Guard/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.Guard/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.Guard/versions/1.0.0/policies/operational.modifyconfig/versions/1";
-
- private static final String GET_DEPLOYED_VERSION_OF_POLICY =
- "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/"
- + "1.0.0/policies/onap.restart.tca/versions/deployed";
- private static final String GET_LATEST_VERSION_OF_OPERATIONAL_POLICY =
- "policytypes/onap.policies.controlloop.Operational/versions/"
- + "1.0.0/policies/operational.scaleout/versions/latest";
- private static final String GET_SPECIFIC_VERSION_OF_OPERATIONAL_POLICY =
- "policytypes/onap.policies.controlloop.Operational/versions/"
- + "1.0.0/policies/operational.scaleout/versions/3";
- private static final String DEL_SPECIFIC_VERSION_OF_OPERATIONAL_POLICY =
- "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
- + "policies/operational.scaleout/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();
@@ -568,6 +563,15 @@ public class TestApiRestServer {
}
@Test
+ public void testGetDeployedVersionsOfGuardPolicy() {
+ assertThatCode(() -> {
+ main = startApiService(true);
+ Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_DEPLOYED, true);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
public void testDeleteOperationalPolicy() {
assertThatCode(() -> {
@@ -638,7 +642,7 @@ public class TestApiRestServer {
public void testGetDeployedVersionsOfPolicy() {
assertThatCode(() -> {
main = startApiService(true);
- Response rawResponse = readResource(GET_DEPLOYED_VERSION_OF_POLICY, true);
+ Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_DEPLOYED, true);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
}).doesNotThrowAnyException();
}
@@ -647,7 +651,7 @@ public class TestApiRestServer {
public void testGetLatestVersionOfOperationalPolicy() {
assertThatCode(() -> {
main = startApiService(true);
- Response rawResponse = readResource(GET_LATEST_VERSION_OF_OPERATIONAL_POLICY, true);
+ Response rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
}).doesNotThrowAnyException();
}
@@ -656,16 +660,25 @@ public class TestApiRestServer {
public void testGetSpecificVersionOfOperationalPolicy() {
assertThatCode(() -> {
main = startApiService(true);
- Response rawResponse = readResource(GET_SPECIFIC_VERSION_OF_OPERATIONAL_POLICY, true);
+ Response rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
}).doesNotThrowAnyException();
}
@Test
+ public void testGetDeployedVersionsOfOperationalPolicy() {
+ assertThatCode(() -> {
+ main = startApiService(true);
+ Response rawResponse = readResource(OPS_POLICIES_VCPE_DEPLOYED, true);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
public void testDeleteSpecificVersionOfOperationalPolicy() {
assertThatCode(() -> {
main = startApiService(true);
- Response rawResponse = deleteResource(DEL_SPECIFIC_VERSION_OF_OPERATIONAL_POLICY, true);
+ Response rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
}).doesNotThrowAnyException();
}
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 6091e1d2..1f0077db 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
@@ -77,7 +77,12 @@ public class TestLegacyGuardPolicyProvider {
private static final String POLICY_TYPE_RESOURCE =
"policytypes/onap.policies.controlloop.guard.FrequencyLimiter.json";
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_ID = "guard.frequency.scaleout: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.
@@ -172,6 +177,102 @@ public class TestLegacyGuardPolicyProvider {
}
@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(() -> {
+ String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ ToscaServiceTemplate policyTypeServiceTemplate =
+ 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);
+ 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 with ID " + POLICY_NAME + ":" + POLICY_VERSION
+ + " cannot be deleted as it is deployed in pdp groups");
+ }
+ catch (Exception exc) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
public void testCreateGuardPolicy() {
assertThatThrownBy(() -> {
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 2915f129..2479223e 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
@@ -25,6 +25,7 @@ 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;
@@ -72,6 +73,11 @@ public class TestLegacyOperationalPolicyProvider {
private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.controlloop.Operational.json";
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";
+ private static final String POLICY_VERSION = "1";
+ private static final String POLICY_TYPE_NAME = "onap.policies.controlloop.Operational";
+ private static final String POLICY_TYPE_VERSION = "1.0.0";
+ private static final String LEGACY_MINOR_PATCH_SUFFIX = ".0.0";
/**
* Initializes parameters.
@@ -163,6 +169,104 @@ public class TestLegacyOperationalPolicyProvider {
}
@Test
+ public void testFetchDeployedOperationalPolicies() {
+
+ assertThatThrownBy(() -> {
+ operationalPolicyProvider.fetchDeployedOperationalPolicies("dummy");
+ }).hasMessage("could not find policy with ID dummy and type " + POLICY_TYPE_ID + " deployed in any pdp group");
+
+ 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(() -> {
+ String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ ToscaServiceTemplate policyTypeServiceTemplate =
+ standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+ }).doesNotThrowAnyException();
+
+ // Create Policy
+ assertThatCode(() -> {
+ String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
+ LegacyOperationalPolicy policyToCreate =
+ standardCoder.decode(policyString, LegacyOperationalPolicy.class);
+ 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");
+
+
+ // 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(
+ () -> {
+ 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
+ + " cannot be deleted as it is deployed in pdp groups");
+ }
+ catch (Exception exc) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
public void testCreateOperationalPolicy() {
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 3954106a..ea886370 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
@@ -141,8 +141,8 @@ public class TestPolicyProvider {
//Basic Exception Throw
assertThatThrownBy(() -> {
- policyProvider.fetchDeployedPolicies("dummy", "dummy", "dummy");
- }).hasMessage("could not find policy with ID dummy and type dummy:dummy deployed in any pdp group");
+ 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");
try (PolicyModelsProvider databaseProvider =
new PolicyModelsProviderFactory().createPolicyModelsProvider(providerParams)) {