aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java14
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfKey.java2
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java6
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java2
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java2
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java21
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java24
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java12
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java78
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java24
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java8
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java4
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java4
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java174
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java14
-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
17 files changed, 324 insertions, 214 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
index 9bfe8abc9..dfc356060 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
@@ -27,9 +27,10 @@ import java.util.List;
import javax.persistence.Column;
import javax.persistence.Embeddable;
-import lombok.Data;
import lombok.EqualsAndHashCode;
+import lombok.Getter;
import lombok.NonNull;
+import lombok.ToString;
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfValidationResult.ValidationResult;
@@ -43,7 +44,8 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
* regular expressions respectively.
*/
@Embeddable
-@Data
+@Getter
+@ToString
@EqualsAndHashCode(callSuper = false)
public class PfConceptKey extends PfKey {
private static final long serialVersionUID = 8932717618579392561L;
@@ -118,6 +120,14 @@ public class PfConceptKey extends PfKey {
return this;
}
+ public void setName(@NonNull final String name) {
+ this.name = Assertions.validateStringParameter(NAME_TOKEN, name, NAME_REGEXP);
+ }
+
+ public void setVersion(@NonNull final String version) {
+ this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, VERSION_REGEXP);
+ }
+
@Override
public List<PfKey> getKeys() {
final List<PfKey> keyList = new ArrayList<>();
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfKey.java
index 5407030ba..72b8b5844 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfKey.java
@@ -33,7 +33,7 @@ public abstract class PfKey extends PfConcept {
public static final String NAME_REGEXP = "[A-Za-z0-9\\-_\\.]+";
/** Regular expression to specify the structure of key versions. */
- public static final String VERSION_REGEXP = "[A-Za-z0-9.]+";
+ public static final String VERSION_REGEXP = "[0-9.]+";
/** Regular expression to specify the structure of key IDs. */
public static final String KEY_ID_REGEXP = "[A-Za-z0-9\\-_\\.]+:[0-9].[0-9].[0-9]";
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
index 55f59f640..44ec51019 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
@@ -198,7 +198,7 @@ public class PfConceptContainerTest {
public void testAuthorative() {
Map<String, DummyAuthorativeConcept> dacMap = new LinkedHashMap<>();
dacMap.put("name0", new DummyAuthorativeConcept("name0", "1.2.3", "Hello"));
- dacMap.put("name1", new DummyAuthorativeConcept(null, null, "Hi"));
+ dacMap.put("name1", new DummyAuthorativeConcept(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "Hi"));
dacMap.put("name2", new DummyAuthorativeConcept("name2", "1.2.3", "Howdy"));
List<Map<String, DummyAuthorativeConcept>> authorativeList = new ArrayList<>();
@@ -208,13 +208,13 @@ public class PfConceptContainerTest {
container.fromAuthorative(authorativeList);
assertEquals("Hello", container.getConceptMap().get(new PfConceptKey("name0:1.2.3")).getDescription());
- assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("name1:0.0.0")).getDescription());
+ assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("NULL:0.0.0")).getDescription());
assertEquals("Howdy", container.getConceptMap().get(new PfConceptKey("name2:1.2.3")).getDescription());
List<Map<String, DummyAuthorativeConcept>> outMapList = container.toAuthorative();
assertEquals(dacMap.get("name0"), outMapList.get(0).get("name0"));
- assertEquals(dacMap.get("name1").getDescription(), outMapList.get(0).get("name1").getDescription());
+ assertEquals(dacMap.get("name1").getDescription(), outMapList.get(0).get("NULL").getDescription());
assertEquals(dacMap.get("name2"), outMapList.get(0).get("name2"));
DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer();
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
index 797dba0cf..7e7a40998 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
@@ -233,7 +233,7 @@ public class PfKeyTest {
versionField.setAccessible(false);
assertEquals(
"version invalid-parameter version with value Key Version "
- + "does not match regular expression [A-Za-z0-9.]+",
+ + "does not match regular expression [0-9.]+",
validationResult.getMessageList().get(0).getMessage());
} catch (Exception validationException) {
fail("test should not throw an exception");
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
index edf4466f8..494e2a1e2 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
@@ -178,7 +178,7 @@ public class PfReferenceKeyTest {
parentVersionField.setAccessible(false);
assertEquals(
"parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version "
- + "does not match regular expression [A-Za-z0-9.]+",
+ + "does not match regular expression [0-9.]+",
validationResult.getMessageList().get(0).getMessage());
} catch (Exception validationException) {
fail("test should not throw an exception");
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
index a7d414533..9b494d1ab 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
@@ -200,11 +200,13 @@ public interface PolicyModelsProvider extends AutoCloseable {
/**
* Get legacy operational policy.
*
- * @param policyId ID of the policy.
+ * @param policyId ID of the policy
+ * @param policyVersion version of the policy, set to null to get the latest policy
* @return the policies found
* @throws PfModelException on errors getting policies
*/
- public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException;
+ public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId, final String policyVersion)
+ throws PfModelException;
/**
* Create legacy operational policy.
@@ -230,19 +232,23 @@ public interface PolicyModelsProvider extends AutoCloseable {
* Delete legacy operational policy.
*
* @param policyId ID of the policy.
+ * @param policyVersion version of the policy, set to null to get the latest policy
* @return the deleted policy
* @throws PfModelException on errors deleting policies
*/
- public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException;
+ public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId,
+ @NonNull final String policyVersion) throws PfModelException;
/**
* Get legacy guard policy.
*
- * @param policyId ID of the policy.
+ * @param policyId ID of the policy
+ * @param policyVersion version of the policy, set to null to get the latest policy
* @return the policies found
* @throws PfModelException on errors getting policies
*/
- public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException;
+ public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId,
+ final String policyVersion) throws PfModelException;
/**
* Create legacy guard policy.
@@ -268,11 +274,12 @@ public interface PolicyModelsProvider extends AutoCloseable {
* Delete legacy guard policy.
*
* @param policyId ID of the policy.
+ * @param policyVersion version of the policy, set to null to get the latest policy
* @return the deleted policy
* @throws PfModelException on errors deleting policies
*/
- public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
- throws PfModelException;
+ public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId,
+ @NonNull final String policyVersion) throws PfModelException;
/**
* Get PDP groups.
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
index a6e8f325b..af1a6ca3b 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
@@ -231,9 +231,10 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
+ public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId, final String policyVersion)
+ throws PfModelException {
assertInitilized();
- return new LegacyProvider().getOperationalPolicy(pfDao, policyId);
+ return new LegacyProvider().getOperationalPolicy(pfDao, policyId, policyVersion);
}
@Override
@@ -251,15 +252,17 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
+ public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId,
+ @NonNull final String policyVersion) throws PfModelException {
assertInitilized();
- return new LegacyProvider().deleteOperationalPolicy(pfDao, policyId);
+ return new LegacyProvider().deleteOperationalPolicy(pfDao, policyId, policyVersion);
}
@Override
- public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId,
+ final String policyVersion) throws PfModelException {
assertInitilized();
- return new LegacyProvider().getGuardPolicy(pfDao, policyId);
+ return new LegacyProvider().getGuardPolicy(pfDao, policyId, policyVersion);
}
@Override
@@ -277,10 +280,10 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
- throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId,
+ @NonNull final String policyVersion) throws PfModelException {
assertInitilized();
- return new LegacyProvider().deleteGuardPolicy(pfDao, policyId);
+ return new LegacyProvider().deleteGuardPolicy(pfDao, policyId, policyVersion);
}
@Override
@@ -336,8 +339,7 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpType,
@NonNull final String pdpInstanceId, @NonNull final PdpStatistics pdpStatistics) throws PfModelException {
assertInitilized();
- new PdpProvider().updatePdpStatistics(pfDao, pdpGroupName, pdpType, pdpInstanceId,
- pdpStatistics);
+ new PdpProvider().updatePdpStatistics(pfDao, pdpGroupName, pdpType, pdpInstanceId, pdpStatistics);
}
/**
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
index 9b1ca7669..afa4277cb 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
@@ -144,7 +144,8 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
@Override
- public LegacyOperationalPolicy getOperationalPolicy(final String policyId) throws PfModelException {
+ public LegacyOperationalPolicy getOperationalPolicy(final String policyId, final String policyVersion)
+ throws PfModelException {
return new LegacyOperationalPolicy();
}
@@ -161,12 +162,14 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public LegacyOperationalPolicy deleteOperationalPolicy(final String policyId) throws PfModelException {
+ public LegacyOperationalPolicy deleteOperationalPolicy(final String policyId, final String policyVersion)
+ throws PfModelException {
return new LegacyOperationalPolicy();
}
@Override
- public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(final String policyId) throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(final String policyId, final String policyVersion)
+ throws PfModelException {
return new HashMap<>();
}
@@ -183,7 +186,8 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(final String policyId) throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(final String policyId, final String policyVersion)
+ throws PfModelException {
return new HashMap<>();
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
index ccdf45af4..6fac58706 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
@@ -190,10 +190,18 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessage("version is marked @NonNull but is null");
assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy(null);
+ databaseProvider.getOperationalPolicy(null, null);
}).hasMessage("policyId is marked @NonNull but is null");
assertThatThrownBy(() -> {
+ databaseProvider.getOperationalPolicy(null, "");
+ }).hasMessage("policyId is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.getOperationalPolicy("", null);
+ }).hasMessage("no policy found for policy: :null");
+
+ assertThatThrownBy(() -> {
databaseProvider.createOperationalPolicy(null);
}).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
@@ -202,14 +210,30 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy(null);
+ databaseProvider.deleteOperationalPolicy(null, null);
+ }).hasMessage("policyId is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteOperationalPolicy(null, "");
+ }).hasMessage("policyId is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteOperationalPolicy("", null);
+ }).hasMessage("policyVersion is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.getGuardPolicy(null, null);
}).hasMessage("policyId is marked @NonNull but is null");
assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy(null);
+ databaseProvider.getGuardPolicy(null, "");
}).hasMessage("policyId is marked @NonNull but is null");
assertThatThrownBy(() -> {
+ databaseProvider.getGuardPolicy("", null);
+ }).hasMessage("no policy found for policy: :null");
+
+ assertThatThrownBy(() -> {
databaseProvider.createGuardPolicy(null);
}).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
@@ -218,10 +242,18 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy(null);
+ databaseProvider.deleteGuardPolicy(null, null);
+ }).hasMessage("policyId is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteGuardPolicy(null, "");
}).hasMessage("policyId is marked @NonNull but is null");
assertThatThrownBy(() -> {
+ databaseProvider.deleteGuardPolicy("", null);
+ }).hasMessage("policyVersion is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
databaseProvider.getFilteredPdpGroups(null);
}).hasMessage("filter is marked @NonNull but is null");
@@ -367,8 +399,8 @@ public class DatabasePolicyModelsProviderTest {
try (PolicyModelsProvider databaseProvider =
new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
- assertEquals(0, databaseProvider.getPolicyTypes("name", "version").getPolicyTypes().get(0).size());
- assertEquals(0, databaseProvider.getPolicyTypeList("name", "version").size());
+ assertEquals(0, databaseProvider.getPolicyTypes("name", "1.0.0").getPolicyTypes().get(0).size());
+ assertEquals(0, databaseProvider.getPolicyTypeList("name", "1.0.0").size());
assertEquals(0, databaseProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build())
.getPolicyTypes().get(0).size());
assertEquals(0, databaseProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()).size());
@@ -381,13 +413,13 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.updatePolicyTypes(new ToscaServiceTemplate());
}).hasMessage("no policy types specified on service template");
- assertEquals(0, databaseProvider.deletePolicyType("name", "version").getPolicyTypes().get(0).size());
+ assertEquals(0, databaseProvider.deletePolicyType("name", "1.0.0").getPolicyTypes().get(0).size());
- assertEquals(0, databaseProvider.deletePolicyType("name", "version").getPolicyTypes().get(0).size());
+ assertEquals(0, databaseProvider.deletePolicyType("name", "1.0.0").getPolicyTypes().get(0).size());
- assertEquals(0, databaseProvider.getPolicies("name", "version").getToscaTopologyTemplate().getPolicies()
+ assertEquals(0, databaseProvider.getPolicies("name", "1.0.0").getToscaTopologyTemplate().getPolicies()
.get(0).size());
- assertEquals(0, databaseProvider.getPolicyList("name", "version").size());
+ assertEquals(0, databaseProvider.getPolicyList("name", "1.0.0").size());
assertEquals(0, databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build())
.getToscaTopologyTemplate().getPolicies().get(0).size());
assertEquals(0, databaseProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()).size());
@@ -404,8 +436,12 @@ public class DatabasePolicyModelsProviderTest {
.get(0).size());
assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy("policy_id");
- }).hasMessage("no policy found for policy ID: policy_id");
+ databaseProvider.getOperationalPolicy("policy_id", null);
+ }).hasMessage("no policy found for policy: policy_id:null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.getOperationalPolicy("policy_id", "10.9.8");
+ }).hasMessage("no policy found for policy: policy_id:10.9.8");
assertThatThrownBy(() -> {
databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy());
@@ -413,15 +449,19 @@ public class DatabasePolicyModelsProviderTest {
assertThatThrownBy(() -> {
databaseProvider.updateOperationalPolicy(new LegacyOperationalPolicy());
- }).hasMessage("no policy found for policy ID: null");
+ }).hasMessage("name is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteOperationalPolicy("policy_id", "55.44.33");
+ }).hasMessage("no policy found for policy: policy_id:55.44.33");
assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy("policy_id");
- }).hasMessage("no policy found for policy ID: policy_id");
+ databaseProvider.getGuardPolicy("policy_id", null);
+ }).hasMessage("no policy found for policy: policy_id:null");
assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy("policy_id");
- }).hasMessage("no policy found for policy ID: policy_id");
+ databaseProvider.getGuardPolicy("policy_id", "6.7.5");
+ }).hasMessage("no policy found for policy: policy_id:6.7.5");
assertThatThrownBy(() -> {
databaseProvider.createGuardPolicy(new LegacyGuardPolicyInput());
@@ -432,8 +472,8 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessage("policy type for guard policy \"null\" unknown");
assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy("policy_id");
- }).hasMessage("no policy found for policy ID: policy_id");
+ databaseProvider.deleteGuardPolicy("policy_id", "33.22.11");
+ }).hasMessage("no policy found for policy: policy_id:33.22.11");
assertEquals(0, databaseProvider.getPdpGroups("name").size());
assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size());
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
index 3e182c02d..4f4c1c3fb 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
@@ -103,7 +103,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public LegacyOperationalPolicy getOperationalPolicy(@NonNull String policyId) throws PfModelException {
+ public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId, final String policyVersion)
+ throws PfModelException {
return null;
}
@@ -120,12 +121,14 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId) throws PfModelException {
+ public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId, final String policyVersion)
+ throws PfModelException {
return null;
}
@Override
- public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull String policyId) throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull String policyId, final String policyVersion)
+ throws PfModelException {
return null;
}
@@ -142,7 +145,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull String policyId) throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull String policyId, final String policyVersion)
+ throws PfModelException {
return null;
}
@@ -162,8 +166,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpSubGroup,
- @NonNull Pdp pdp) throws PfModelException {}
+ public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpSubGroup, @NonNull Pdp pdp)
+ throws PfModelException {}
@Override
public PdpGroup deletePdpGroup(@NonNull String name) throws PfModelException {
@@ -207,8 +211,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public void updatePdpSubGroup(@NonNull String pdpGroupName,
- @NonNull PdpSubGroup pdpSubGroup) throws PfModelException {}
+ public void updatePdpSubGroup(@NonNull String pdpGroupName, @NonNull PdpSubGroup pdpSubGroup)
+ throws PfModelException {}
@Override
public List<PdpStatistics> getPdpStatistics(String name) throws PfModelException {
@@ -216,6 +220,6 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public void updatePdpStatistics(@NonNull String pdpGroupName,
- @NonNull String pdpType, @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {}
+ public void updatePdpStatistics(@NonNull String pdpGroupName, @NonNull String pdpType,
+ @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {}
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
index 9f02fd7a4..93cb89165 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
@@ -94,15 +94,15 @@ public class DummyPolicyModelsProviderTest {
assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
assertNotNull(dummyProvider.deletePolicy("name", "version"));
- assertNotNull(dummyProvider.getOperationalPolicy("policy_id"));
+ assertNotNull(dummyProvider.getOperationalPolicy("policy_id", "1"));
assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
assertNotNull(dummyProvider.updateOperationalPolicy(new LegacyOperationalPolicy()));
- assertNotNull(dummyProvider.deleteOperationalPolicy("policy_id"));
+ assertNotNull(dummyProvider.deleteOperationalPolicy("policy_id", "1"));
- assertNotNull(dummyProvider.getGuardPolicy("policy_id"));
+ assertNotNull(dummyProvider.getGuardPolicy("policy_id", "1"));
assertNotNull(dummyProvider.createGuardPolicy(new LegacyGuardPolicyInput()));
assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicyInput()));
- assertNotNull(dummyProvider.deleteGuardPolicy("policy_id"));
+ assertNotNull(dummyProvider.deleteGuardPolicy("policy_id", "1"));
assertTrue(dummyProvider.getPdpGroups("name").isEmpty());
assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty());
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
index c5052dad7..fbbbaed9a 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
@@ -138,7 +138,7 @@ public class PolicyLegacyGuardPersistenceTest {
assertEquals(gip.getContent(),
createdGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
- Map<String, LegacyGuardPolicyOutput> gotGopm = databaseProvider.getGuardPolicy(gip.getPolicyId());
+ Map<String, LegacyGuardPolicyOutput> gotGopm = databaseProvider.getGuardPolicy(gip.getPolicyId(), null);
assertEquals(gip.getPolicyId(), gotGopm.keySet().iterator().next());
assertEquals(gip.getContent(),
gotGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
@@ -148,7 +148,7 @@ public class PolicyLegacyGuardPersistenceTest {
assertEquals(gip.getContent(),
updatedGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
- Map<String, LegacyGuardPolicyOutput> deletedGopm = databaseProvider.deleteGuardPolicy(gip.getPolicyId());
+ Map<String, LegacyGuardPolicyOutput> deletedGopm = databaseProvider.deleteGuardPolicy(gip.getPolicyId(), "1");
assertEquals(gip.getPolicyId(), deletedGopm.keySet().iterator().next());
assertEquals(gip.getContent(),
deletedGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
index c1cda4d05..77a0cac9c 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
@@ -136,13 +136,13 @@ public class PolicyLegacyOperationalPersistenceTest {
LegacyOperationalPolicy createdLop = databaseProvider.createOperationalPolicy(lop);
assertEquals(createdLop, lop);
- LegacyOperationalPolicy gotLop = databaseProvider.getOperationalPolicy(lop.getPolicyId());
+ LegacyOperationalPolicy gotLop = databaseProvider.getOperationalPolicy(lop.getPolicyId(), null);
assertEquals(gotLop, lop);
LegacyOperationalPolicy updatedLop = databaseProvider.updateOperationalPolicy(lop);
assertEquals(gotLop, updatedLop);
- LegacyOperationalPolicy deletedLop = databaseProvider.deleteOperationalPolicy(lop.getPolicyId());
+ LegacyOperationalPolicy deletedLop = databaseProvider.deleteOperationalPolicy(lop.getPolicyId(), "1");
assertEquals(gotLop, deletedLop);
String actualRetrievedJson = standardCoder.encode(gotLop);
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java
index a394cec3e..23406b473 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java
@@ -20,7 +20,6 @@
package org.onap.policy.models.tosca.legacy.provider;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -28,6 +27,7 @@ import javax.ws.rs.core.Response;
import lombok.NonNull;
+import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.dao.PfDao;
@@ -53,36 +53,25 @@ public class LegacyProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(LegacyProvider.class);
private static final String FIRST_POLICY_VERSION = "1";
+ private static final String LEGACY_MINOR_PATCH_SUFFIX = ".0.0";
// Recurring constants
- private static final String NO_POLICY_FOUND_FOR_POLICY_ID = "no policy found for policy ID: ";
+ private static final String NO_POLICY_FOUND_FOR_POLICY = "no policy found for policy: ";
/**
* Get legacy operational policy.
*
* @param dao the DAO to use to access the database
* @param policyId ID of the policy.
+ * @param policyVersion version of the policy.
* @return the policies found
* @throws PfModelException on errors getting policies
*/
- public LegacyOperationalPolicy getOperationalPolicy(@NonNull final PfDao dao, @NonNull final String policyId)
- throws PfModelException {
+ public LegacyOperationalPolicy getOperationalPolicy(@NonNull final PfDao dao, @NonNull final String policyId,
+ final String policyVersion) throws PfModelException {
- JpaToscaPolicy newestPolicy = getLatestPolicy(dao, policyId);
-
- if (newestPolicy == null) {
- String errorMessage = NO_POLICY_FOUND_FOR_POLICY_ID + policyId;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- }
-
- // Create the structure of the TOSCA service template to contain the policy type
- JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
- serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
- serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
- serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(newestPolicy.getKey(), newestPolicy);
-
- return new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
+ return new LegacyOperationalPolicyMapper()
+ .fromToscaServiceTemplate(getLegacyPolicy(dao, policyId, policyVersion));
}
/**
@@ -125,22 +114,10 @@ public class LegacyProvider {
public LegacyOperationalPolicy updateOperationalPolicy(@NonNull final PfDao dao,
@NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
- // We need to find the latest policy and use the major version, if there is no policy with this ID, then
- // we have an error
- JpaToscaPolicy newestPolicy = getLatestPolicy(dao, legacyOperationalPolicy.getPolicyId());
-
- if (newestPolicy == null) {
- String errorMessage = NO_POLICY_FOUND_FOR_POLICY_ID + legacyOperationalPolicy.getPolicyId();
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- } else {
- legacyOperationalPolicy.setPolicyVersion(Integer.toString(newestPolicy.getKey().getMajorVersion()));
- }
-
JpaToscaServiceTemplate incomingServiceTemplate =
new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy);
JpaToscaServiceTemplate outgoingingServiceTemplate =
- new SimpleToscaProvider().createPolicies(dao, incomingServiceTemplate);
+ new SimpleToscaProvider().updatePolicies(dao, incomingServiceTemplate);
return new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(outgoingingServiceTemplate);
}
@@ -150,42 +127,15 @@ public class LegacyProvider {
*
* @param dao the DAO to use to access the database
* @param policyId ID of the policy.
+ * @param policyVersion version of the policy.
* @return the deleted policy
* @throws PfModelException on errors deleting policies
*/
- public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final PfDao dao, @NonNull final String policyId)
- throws PfModelException {
-
- // Get all the policies in the database and check the policy ID against the policies returned
- List<JpaToscaPolicy> policyList = dao.getAll(JpaToscaPolicy.class);
-
- // Find the latest policy that matches the ID
- List<JpaToscaPolicy> policyDeleteList = new ArrayList<>();
-
- for (JpaToscaPolicy policy : policyList) {
- if (policyId.equals(policy.getKey().getName())) {
- policyDeleteList.add(policy);
- }
- }
-
- if (policyDeleteList.isEmpty()) {
- String errorMessage = NO_POLICY_FOUND_FOR_POLICY_ID + policyId;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- }
-
- // Create the structure of the TOSCA service template to contain the policy type
- JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
- serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
- serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
-
- for (JpaToscaPolicy deletePolicy : policyDeleteList) {
- dao.delete(deletePolicy);
- serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(deletePolicy.getKey(),
- deletePolicy);
- }
+ public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final PfDao dao, @NonNull final String policyId,
+ @NonNull final String policyVersion) throws PfModelException {
- return new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
+ return new LegacyOperationalPolicyMapper()
+ .fromToscaServiceTemplate(deleteLegacyPolicy(dao, policyId, policyVersion));
}
/**
@@ -193,27 +143,14 @@ public class LegacyProvider {
*
* @param dao the DAO to use to access the database
* @param policyId ID of the policy.
+ * @param policyVersion version of the policy.
* @return the policies found
* @throws PfModelException on errors getting policies
*/
- public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final PfDao dao, @NonNull final String policyId)
- throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final PfDao dao, @NonNull final String policyId,
+ final String policyVersion) throws PfModelException {
- JpaToscaPolicy newestPolicy = getLatestPolicy(dao, policyId);
-
- if (newestPolicy == null) {
- String errorMessage = NO_POLICY_FOUND_FOR_POLICY_ID + policyId;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- }
-
- // Create the structure of the TOSCA service template to contain the policy type
- JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
- serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
- serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
- serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(newestPolicy.getKey(), newestPolicy);
-
- return new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
+ return new LegacyGuardPolicyMapper().fromToscaServiceTemplate(getLegacyPolicy(dao, policyId, policyVersion));
}
/**
@@ -249,7 +186,7 @@ public class LegacyProvider {
JpaToscaServiceTemplate incomingServiceTemplate =
new LegacyGuardPolicyMapper().toToscaServiceTemplate(legacyGuardPolicy);
JpaToscaServiceTemplate outgoingingServiceTemplate =
- new SimpleToscaProvider().createPolicies(dao, incomingServiceTemplate);
+ new SimpleToscaProvider().updatePolicies(dao, incomingServiceTemplate);
return new LegacyGuardPolicyMapper().fromToscaServiceTemplate(outgoingingServiceTemplate);
}
@@ -260,26 +197,37 @@ public class LegacyProvider {
*
* @param dao the DAO to use to access the database
* @param policyId ID of the policy.
+ * @param policyVersion version of the policy.
* @return the deleted policy
* @throws PfModelException on errors deleting policies
*/
public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final PfDao dao,
- @NonNull final String policyId) throws PfModelException {
-
- // Get all the policies in the database and check the policy ID against the policies returned
- List<JpaToscaPolicy> policyList = dao.getAll(JpaToscaPolicy.class);
+ @NonNull final String policyId, @NonNull final String policyVersion) throws PfModelException {
- // Find the latest policy that matches the ID
- List<JpaToscaPolicy> policyDeleteList = new ArrayList<>();
+ return new LegacyGuardPolicyMapper().fromToscaServiceTemplate(deleteLegacyPolicy(dao, policyId, policyVersion));
+ }
- for (JpaToscaPolicy policy : policyList) {
- if (policyId.equals(policy.getKey().getName())) {
- policyDeleteList.add(policy);
- }
+ /**
+ * Get the JPA Policy for a policy ID and version.
+ *
+ * @param dao The DAO to search
+ * @param policyId the policy ID to search for
+ * @param policyVersion the policy version to search for
+ * @return the JPA policy found
+ * @throws PfModelRuntimeException if a policy is not found
+ */
+ private JpaToscaServiceTemplate getLegacyPolicy(final PfDao dao, final String policyId,
+ final String policyVersion) {
+ JpaToscaPolicy foundPolicy = null;
+ if (policyVersion == null) {
+ foundPolicy = getLatestPolicy(dao, policyId);
+ } else {
+ foundPolicy = dao.get(JpaToscaPolicy.class,
+ new PfConceptKey(policyId, policyVersion + LEGACY_MINOR_PATCH_SUFFIX));
}
- if (policyDeleteList.isEmpty()) {
- String errorMessage = NO_POLICY_FOUND_FOR_POLICY_ID + policyId;
+ if (foundPolicy == null) {
+ String errorMessage = NO_POLICY_FOUND_FOR_POLICY + policyId + ':' + policyVersion;
LOGGER.warn(errorMessage);
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
}
@@ -288,14 +236,41 @@ public class LegacyProvider {
JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+ serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(foundPolicy.getKey(), foundPolicy);
+
+ return serviceTemplate;
+ }
+
+ /**
+ * Delete a legacy policy.
+ *
+ * @param dao the DAO to use for the deletion
+ * @param policyId the policy ID
+ * @param policyVersion the policy version
+ * @return a service template containing the policy that has been deleted
+ */
+ private JpaToscaServiceTemplate deleteLegacyPolicy(final PfDao dao, final String policyId,
+ final String policyVersion) {
+
+ final JpaToscaPolicy deletePolicy =
+ dao.get(JpaToscaPolicy.class, new PfConceptKey(policyId, policyVersion + LEGACY_MINOR_PATCH_SUFFIX));
- for (JpaToscaPolicy deletePolicy : policyDeleteList) {
- dao.delete(deletePolicy);
- serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(deletePolicy.getKey(),
- deletePolicy);
+ if (deletePolicy == null) {
+ String errorMessage = NO_POLICY_FOUND_FOR_POLICY + policyId + ':' + policyVersion;
+ LOGGER.warn(errorMessage);
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
}
- return new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
+ // Delete the policy
+ dao.delete(deletePolicy);
+
+ // Create the structure of the TOSCA service template to contain the policy type
+ JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+ serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
+ serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+ serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(deletePolicy.getKey(), deletePolicy);
+
+ return serviceTemplate;
}
/**
@@ -325,4 +300,5 @@ public class LegacyProvider {
}
return newestPolicy;
}
+
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
index eebacd1d6..30ad2b246 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
@@ -186,9 +186,17 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
public void fromAuthorative(@NonNull final ToscaPolicy toscaPolicy) {
super.fromAuthorative(toscaPolicy);
- type.setName(toscaPolicy.getType());
- type.setVersion(toscaPolicy.getTypeVersion());
- if (type.getVersion() == null) {
+ if (toscaPolicy.getType() != null) {
+ type.setName(toscaPolicy.getType());
+ }
+ else {
+ type.setName(PfKey.NULL_KEY_NAME);
+ }
+
+ if (toscaPolicy.getTypeVersion() != null) {
+ type.setVersion(toscaPolicy.getTypeVersion());
+ }
+ else {
type.setVersion(PfKey.NULL_KEY_VERSION);
}
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 =