aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-05-21 16:11:39 +0000
committerliamfallon <liam.fallon@est.tech>2019-05-21 16:11:39 +0000
commitd5ed712cf50bcf270fed8cd597d78ff4ff9370a0 (patch)
tree2b5e7a828df7aa5316630c45b82cc5d9aa61767f /models-tosca/src/test
parent3b10bf7dbdc63d0a2424af34ee3c0d18087e6b91 (diff)
Add version on legacy get/delete
Issue-ID: POLICY-1777 Change-Id: I5b07ad1acdb4a614a50cb15978130c19bc5786f7 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/test')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java73
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java76
2 files changed, 104 insertions, 45 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java
index 2aadcd7b2..9487ed8aa 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java
@@ -98,20 +98,20 @@ public class LegacyProvider4LegacyGuardTest {
@Test
public void testPoliciesGet() throws Exception {
assertThatThrownBy(() -> {
- new LegacyProvider().getGuardPolicy(null, null);
+ new LegacyProvider().getGuardPolicy(null, null, null);
}).hasMessage("dao is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().getGuardPolicy(null, "");
+ new LegacyProvider().getGuardPolicy(null, null, "");
}).hasMessage("dao is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().getGuardPolicy(pfDao, null);
+ new LegacyProvider().getGuardPolicy(pfDao, null, null);
}).hasMessage("policyId is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().getGuardPolicy(pfDao, "I Dont Exist");
- }).hasMessage("no policy found for policy ID: I Dont Exist");
+ new LegacyProvider().getGuardPolicy(pfDao, "I Dont Exist", null);
+ }).hasMessage("no policy found for policy: I Dont Exist:null");
createPolicyTypes();
@@ -128,7 +128,7 @@ public class LegacyProvider4LegacyGuardTest {
createdGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
Map<String, LegacyGuardPolicyOutput> gotGopm =
- new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId());
+ new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null);
assertEquals(originalGip.getPolicyId(), gotGopm.keySet().iterator().next());
assertEquals(originalGip.getContent(),
@@ -139,6 +139,20 @@ public class LegacyProvider4LegacyGuardTest {
String actualJsonOutput = standardCoder.encode(gotGopm);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
+
+ gotGopm = new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), "1");
+
+ assertEquals(originalGip.getPolicyId(), gotGopm.keySet().iterator().next());
+ assertEquals(originalGip.getContent(),
+ gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
+
+ actualJsonOutput = standardCoder.encode(gotGopm);
+
+ assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
+
+ assertThatThrownBy(() -> {
+ new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), "2");
+ }).hasMessage("no policy found for policy: guard.frequency.scaleout:2");
}
@Test
@@ -170,7 +184,7 @@ public class LegacyProvider4LegacyGuardTest {
createdGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
Map<String, LegacyGuardPolicyOutput> gotGopm =
- new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId());
+ new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null);
assertEquals(originalGip.getPolicyId(), gotGopm.keySet().iterator().next());
assertEquals(originalGip.getContent(),
@@ -244,7 +258,7 @@ public class LegacyProvider4LegacyGuardTest {
createdGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
Map<String, LegacyGuardPolicyOutput> gotGopm =
- new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId());
+ new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null);
assertEquals(originalGip.getPolicyId(), gotGopm.keySet().iterator().next());
assertEquals(originalGip.getContent(),
@@ -257,7 +271,7 @@ public class LegacyProvider4LegacyGuardTest {
updatedGp.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
Map<String, LegacyGuardPolicyOutput> gotUpdatedGopm =
- new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId());
+ new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null);
assertEquals(originalGip.getPolicyId(), gotUpdatedGopm.keySet().iterator().next());
assertEquals(originalGip.getContent(),
gotUpdatedGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
@@ -269,21 +283,36 @@ public class LegacyProvider4LegacyGuardTest {
@Test
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
- new LegacyProvider().deleteGuardPolicy(null, null);
+ new LegacyProvider().deleteGuardPolicy(null, null, null);
+ }).hasMessage("dao is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new LegacyProvider().deleteGuardPolicy(null, null, "");
+ }).hasMessage("dao is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new LegacyProvider().deleteGuardPolicy(null, "", null);
}).hasMessage("dao is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().deleteGuardPolicy(null, "");
+ new LegacyProvider().deleteGuardPolicy(null, "", "");
}).hasMessage("dao is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().deleteGuardPolicy(pfDao, null);
+ new LegacyProvider().deleteGuardPolicy(pfDao, null, null);
}).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ new LegacyProvider().deleteGuardPolicy(pfDao, null, "");
+ }).hasMessage("policyId is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new LegacyProvider().deleteGuardPolicy(pfDao, "", null);
+ }).hasMessage("policyVersion is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().deleteGuardPolicy(pfDao, "I Dont Exist");
- }).hasMessage("no policy found for policy ID: I Dont Exist");
+ new LegacyProvider().deleteGuardPolicy(pfDao, "IDontExist", "");
+ }).hasMessage("no policy found for policy: IDontExist:");
createPolicyTypes();
@@ -299,7 +328,7 @@ public class LegacyProvider4LegacyGuardTest {
createdGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
Map<String, LegacyGuardPolicyOutput> gotGopm =
- new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId());
+ new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null);
assertEquals(originalGip.getPolicyId(), gotGopm.keySet().iterator().next());
assertEquals(originalGip.getContent(),
@@ -311,15 +340,19 @@ public class LegacyProvider4LegacyGuardTest {
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
+ assertThatThrownBy(() -> {
+ new LegacyProvider().deleteGuardPolicy(pfDao, originalGip.getPolicyId(), null);
+ }).hasMessage("policyVersion is marked @NonNull but is null");
+
Map<String, LegacyGuardPolicyOutput> deletedGopm =
- new LegacyProvider().deleteGuardPolicy(pfDao, originalGip.getPolicyId());
+ new LegacyProvider().deleteGuardPolicy(pfDao, originalGip.getPolicyId(), "1");
assertEquals(originalGip.getPolicyId(), deletedGopm.keySet().iterator().next());
assertEquals(originalGip.getContent(),
deletedGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
assertThatThrownBy(() -> {
- new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId());
- }).hasMessage("no policy found for policy ID: guard.frequency.scaleout");
+ new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null);
+ }).hasMessage("no policy found for policy: guard.frequency.scaleout:null");
LegacyGuardPolicyInput otherGip = new LegacyGuardPolicyInput();
otherGip.setPolicyId("guard.blacklist.b0");
@@ -332,8 +365,8 @@ public class LegacyProvider4LegacyGuardTest {
createdOtherGopm.get(otherGip.getPolicyId()).getProperties().values().iterator().next());
assertThatThrownBy(() -> {
- new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId());
- }).hasMessage("no policy found for policy ID: guard.frequency.scaleout");
+ new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId(), null);
+ }).hasMessage("no policy found for policy: guard.frequency.scaleout:null");
}
private void createPolicyTypes() throws CoderException, PfModelException {
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
index 7ab5c581e..17b912826 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
@@ -72,7 +72,7 @@ public class LegacyProvider4LegacyOperationalTest {
jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver");
jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb");
- daoParameters.setJdbcProperties(jdbcProperties );
+ daoParameters.setJdbcProperties(jdbcProperties);
pfDao = new PfDaoFactory().createPfDao(daoParameters);
pfDao.init(daoParameters);
@@ -94,20 +94,20 @@ public class LegacyProvider4LegacyOperationalTest {
@Test
public void testPoliciesGet() throws Exception {
assertThatThrownBy(() -> {
- new LegacyProvider().getOperationalPolicy(null, null);
+ new LegacyProvider().getOperationalPolicy(null, null, null);
}).hasMessage("dao is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().getOperationalPolicy(null, "");
+ new LegacyProvider().getOperationalPolicy(null, "", null);
}).hasMessage("dao is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().getOperationalPolicy(pfDao, null);
+ new LegacyProvider().getOperationalPolicy(pfDao, null, null);
}).hasMessage("policyId is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().getOperationalPolicy(pfDao, "I Dont Exist");
- }).hasMessage("no policy found for policy ID: I Dont Exist");
+ new LegacyProvider().getOperationalPolicy(pfDao, "I Dont Exist", null);
+ }).hasMessage("no policy found for policy: I Dont Exist:null");
createPolicyTypes();
@@ -121,7 +121,8 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals(originalLop, createdLop);
- LegacyOperationalPolicy gotLop = new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId());
+ LegacyOperationalPolicy gotLop =
+ new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId(), null);
assertEquals(gotLop, originalLop);
@@ -131,7 +132,8 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
LegacyOperationalPolicy createdLopV2 = new LegacyProvider().createOperationalPolicy(pfDao, originalLop);
- LegacyOperationalPolicy gotLopV2 = new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId());
+ LegacyOperationalPolicy gotLopV2 =
+ new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId(), null);
assertEquals(gotLopV2, createdLopV2);
}
@@ -161,7 +163,8 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals(originalLop, createdLop);
- LegacyOperationalPolicy gotLop = new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId());
+ LegacyOperationalPolicy gotLop =
+ new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId(), null);
assertEquals(gotLop, originalLop);
@@ -187,7 +190,7 @@ public class LegacyProvider4LegacyOperationalTest {
assertThatThrownBy(() -> {
new LegacyProvider().updateOperationalPolicy(pfDao, new LegacyOperationalPolicy());
- }).hasMessage("no policy found for policy ID: null");
+ }).hasMessage("name is marked @NonNull but is null");
createPolicyTypes();
@@ -200,7 +203,8 @@ public class LegacyProvider4LegacyOperationalTest {
LegacyOperationalPolicy createdLop = new LegacyProvider().createOperationalPolicy(pfDao, originalLop);
assertEquals(originalLop, createdLop);
- LegacyOperationalPolicy gotLop = new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId());
+ LegacyOperationalPolicy gotLop =
+ new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId(), null);
assertEquals(gotLop, originalLop);
originalLop.setContent("Some New Content");
@@ -208,7 +212,7 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals(originalLop, updatedLop);
LegacyOperationalPolicy gotUpdatedLop =
- new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId());
+ new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId(), null);
assertEquals(gotUpdatedLop, originalLop);
assertEquals("Some New Content", gotUpdatedLop.getContent());
}
@@ -216,21 +220,38 @@ public class LegacyProvider4LegacyOperationalTest {
@Test
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
- new LegacyProvider().deleteOperationalPolicy(null, null);
+ new LegacyProvider().deleteOperationalPolicy(null, null, null);
}).hasMessage("dao is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().deleteOperationalPolicy(null, "");
+ new LegacyProvider().deleteOperationalPolicy(null, null, "");
}).hasMessage("dao is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().deleteOperationalPolicy(pfDao, null);
+ new LegacyProvider().deleteOperationalPolicy(null, "", null);
+ }).hasMessage("dao is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new LegacyProvider().deleteOperationalPolicy(null, "", "");
+
+ }).hasMessage("dao is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new LegacyProvider().deleteOperationalPolicy(pfDao, null, null);
}).hasMessage("policyId is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().deleteOperationalPolicy(pfDao, "I Dont Exist");
- }).hasMessage("no policy found for policy ID: I Dont Exist");
+ new LegacyProvider().deleteOperationalPolicy(pfDao, null, "");
+ }).hasMessage("policyId is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new LegacyProvider().deleteOperationalPolicy(pfDao, "", null);
+ }).hasMessage("policyVersion is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new LegacyProvider().deleteOperationalPolicy(pfDao, "IDontExist", "");
+ }).hasMessage("no policy found for policy: IDontExist:");
createPolicyTypes();
@@ -243,7 +264,8 @@ public class LegacyProvider4LegacyOperationalTest {
LegacyOperationalPolicy createdLop = new LegacyProvider().createOperationalPolicy(pfDao, originalLop);
assertEquals(originalLop, createdLop);
- LegacyOperationalPolicy gotLop = new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId());
+ LegacyOperationalPolicy gotLop =
+ new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId(), null);
assertEquals(gotLop, originalLop);
@@ -252,13 +274,17 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
+ assertThatThrownBy(() -> {
+ new LegacyProvider().deleteOperationalPolicy(pfDao, originalLop.getPolicyId(), null);
+ }).hasMessage("policyVersion is marked @NonNull but is null");
+
LegacyOperationalPolicy deletedLop =
- new LegacyProvider().deleteOperationalPolicy(pfDao, originalLop.getPolicyId());
+ new LegacyProvider().deleteOperationalPolicy(pfDao, originalLop.getPolicyId(), "1");
assertEquals(originalLop, deletedLop);
assertThatThrownBy(() -> {
- new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId());
- }).hasMessage("no policy found for policy ID: operational.restart");
+ new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId(), null);
+ }).hasMessage("no policy found for policy: operational.restart:null");
LegacyOperationalPolicy otherLop = new LegacyOperationalPolicy();
otherLop.setPolicyId("another-policy");
@@ -269,13 +295,13 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals(otherLop, createdOtherLop);
assertThatThrownBy(() -> {
- new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId());
- }).hasMessage("no policy found for policy ID: operational.restart");
+ new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId(), null);
+ }).hasMessage("no policy found for policy: operational.restart:null");
}
private void createPolicyTypes() throws CoderException, PfModelException {
- Object yamlObject = new Yaml().load(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml"));
+ Object yamlObject = new Yaml()
+ .load(ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml"));
String yamlAsJsonString = new StandardCoder().encode(yamlObject);
ToscaServiceTemplate toscaServiceTemplatePolicyType =