aboutsummaryrefslogtreecommitdiffstats
path: root/models-provider/src
diff options
context:
space:
mode:
Diffstat (limited to 'models-provider/src')
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java38
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java40
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java36
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java76
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java19
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java6
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java41
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java32
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java33
9 files changed, 175 insertions, 146 deletions
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 e390a04f0..a8d8483e3 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
@@ -24,13 +24,12 @@ import java.util.Map;
import lombok.NonNull;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
/**
* This interface describes the operations that are provided to users and components for reading objects from and
@@ -49,12 +48,13 @@ public interface PolicyModelsProvider extends AutoCloseable {
/**
* Get policy types.
*
- * @param policyTypeKey the policy type key for the policy types to be retrieved. A null key name returns all policy
- * types. A null key version returns all versions of the policy type name specified in the key.
+ * @param name the name of the policy type to get.
+ * @param version the version of the policy type to get.
* @return the policy types found
* @throws PfModelException on errors getting policy types
*/
- public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException;
+ public ToscaServiceTemplate getPolicyTypes(@NonNull final String name, @NonNull final String version)
+ throws PfModelException;
/**
* Create policy types.
@@ -63,7 +63,7 @@ public interface PolicyModelsProvider extends AutoCloseable {
* @return the TOSCA service template containing the created policy types
* @throws PfModelException on errors creating policy types
*/
- public JpaToscaServiceTemplate createPolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException;
/**
@@ -73,28 +73,30 @@ public interface PolicyModelsProvider extends AutoCloseable {
* @return the TOSCA service template containing the modified policy types
* @throws PfModelException on errors updating policy types
*/
- public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException;
/**
* Delete policy types.
*
- * @param policyTypeKey the policy type key for the policy types to be deleted, if the version of the key is null,
- * all versions of the policy type are deleted.
+ * @param name the name of the policy type to delete.
+ * @param version the version of the policy type to delete.
* @return the TOSCA service template containing the policy types that were deleted
* @throws PfModelException on errors deleting policy types
*/
- public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException;
+ public ToscaServiceTemplate deletePolicyTypes(@NonNull final String name, @NonNull final String version)
+ throws PfModelException;
/**
* Get policies.
*
- * @param policyKey the policy key for the policies to be retrieved. The parent name and version must be specified.
- * A null local name returns all policies for a parent policy type.
+ * @param name the name of the policy to get.
+ * @param version the version of the policy to get.
* @return the policies found
* @throws PfModelException on errors getting policies
*/
- public JpaToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException;
+ public ToscaServiceTemplate getPolicies(@NonNull final String name, @NonNull final String version)
+ throws PfModelException;
/**
* Create policies.
@@ -103,7 +105,7 @@ public interface PolicyModelsProvider extends AutoCloseable {
* @return the TOSCA service template containing the policy types that were created
* @throws PfModelException on errors creating policies
*/
- public JpaToscaServiceTemplate createPolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException;
@@ -114,17 +116,19 @@ public interface PolicyModelsProvider extends AutoCloseable {
* @return the TOSCA service template containing the policies that were updated
* @throws PfModelException on errors updating policies
*/
- public JpaToscaServiceTemplate updatePolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException;
/**
* Delete policies.
*
- * @param policyKey the policy key
+ * @param name the name of the policy to delete.
+ * @param version the version of the policy to delete.
* @return the TOSCA service template containing the policy types that were deleted
* @throws PfModelException on errors deleting policies
*/
- public JpaToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException;
+ public ToscaServiceTemplate deletePolicies(@NonNull final String name, @NonNull final String version)
+ throws PfModelException;
/**
* Get legacy operational policy.
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 85c4d139c..9a32feb65 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
@@ -29,7 +29,6 @@ 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.DaoParameters;
@@ -40,12 +39,12 @@ import org.onap.policy.models.pdp.concepts.PdpGroups;
import org.onap.policy.models.pdp.persistence.provider.PdpProvider;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
import org.onap.policy.models.tosca.legacy.provider.LegacyProvider;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -138,56 +137,59 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
+ public ToscaServiceTemplate getPolicyTypes(@NonNull final String name, @NonNull final String version)
+ throws PfModelException {
assertInitilized();
- return new SimpleToscaProvider().getPolicyTypes(pfDao, policyTypeKey);
+ return new AuthorativeToscaProvider().getPolicyTypes(pfDao, name, version);
}
@Override
- public JpaToscaServiceTemplate createPolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException {
assertInitilized();
- return new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+ return new AuthorativeToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
}
@Override
- public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException {
assertInitilized();
- return new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
+ return new AuthorativeToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
}
@Override
- public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey)
+ public ToscaServiceTemplate deletePolicyTypes(@NonNull final String name, @NonNull final String version)
throws PfModelException {
assertInitilized();
- return new SimpleToscaProvider().deletePolicyTypes(pfDao, policyTypeKey);
+ return new AuthorativeToscaProvider().deletePolicyTypes(pfDao, name, version);
}
@Override
- public JpaToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
+ public ToscaServiceTemplate getPolicies(@NonNull final String name, @NonNull final String version)
+ throws PfModelException {
assertInitilized();
- return new SimpleToscaProvider().getPolicies(pfDao, policyKey);
+ return new AuthorativeToscaProvider().getPolicies(pfDao, name, version);
}
@Override
- public JpaToscaServiceTemplate createPolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException {
assertInitilized();
- return new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
+ return new AuthorativeToscaProvider().createPolicies(pfDao, serviceTemplate);
}
@Override
- public JpaToscaServiceTemplate updatePolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException {
assertInitilized();
- return new SimpleToscaProvider().updatePolicies(pfDao, serviceTemplate);
+ return new AuthorativeToscaProvider().updatePolicies(pfDao, serviceTemplate);
}
@Override
- public JpaToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
+ public ToscaServiceTemplate deletePolicies(@NonNull final String name, @NonNull final String version)
+ throws PfModelException {
assertInitilized();
- return new SimpleToscaProvider().deletePolicies(pfDao, policyKey);
+ return new AuthorativeToscaProvider().deletePolicies(pfDao, name, version);
}
@Override
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 e37b1d632..8881ed08e 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
@@ -21,25 +21,23 @@
package org.onap.policy.models.provider.impl;
-import com.google.gson.Gson;
-
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.Response;
import lombok.NonNull;
+
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-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.pdp.concepts.PdpGroups;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
/**
* This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
@@ -66,47 +64,50 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
+ public ToscaServiceTemplate getPolicyTypes(@NonNull final String name, @NonNull final String version)
+ throws PfModelException {
return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
}
@Override
- public JpaToscaServiceTemplate createPolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException {
return serviceTemplate;
}
@Override
- public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException {
return serviceTemplate;
}
@Override
- public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey)
+ public ToscaServiceTemplate deletePolicyTypes(@NonNull final String name, @NonNull final String version)
throws PfModelException {
return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
}
@Override
- public JpaToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
+ public ToscaServiceTemplate getPolicies(@NonNull final String name, @NonNull final String version)
+ throws PfModelException {
return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
}
@Override
- public JpaToscaServiceTemplate createPolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException {
return serviceTemplate;
}
@Override
- public JpaToscaServiceTemplate updatePolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException {
return serviceTemplate;
}
@Override
- public JpaToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
+ public ToscaServiceTemplate deletePolicies(@NonNull final String name, @NonNull final String version)
+ throws PfModelException {
return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
}
@@ -182,12 +183,13 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
* @param fileName the file name containing the dummy response
* @return the ToscaServiceTemplate with the dummy response
*/
- protected JpaToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
- Gson gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
- JpaToscaServiceTemplate serviceTemplate;
+ protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
+ StandardCoder standardCoder = new StandardCoder();
+ ToscaServiceTemplate serviceTemplate;
try {
- serviceTemplate = gson.fromJson(ResourceUtils.getResourceAsString(fileName), JpaToscaServiceTemplate.class);
+ serviceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
if (serviceTemplate == null) {
throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
}
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 335233476..7eb712236 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
@@ -28,14 +28,13 @@ import java.util.Base64;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.pdp.concepts.PdpGroups;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -120,9 +119,16 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.init();
assertThatThrownBy(() -> {
- databaseProvider.getPolicyTypes(null);
- }).hasMessage("policyTypeKey is marked @NonNull but is null");
+ databaseProvider.getPolicyTypes(null, null);
+ }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getPolicyTypes("aaa", null);
+ }).hasMessage("version is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.getPolicyTypes(null, "aaa");
+ }).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
databaseProvider.createPolicyTypes(null);
@@ -133,12 +139,28 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessage("serviceTemplate is marked @NonNull but is null");
assertThatThrownBy(() -> {
- databaseProvider.deletePolicyTypes(null);
- }).hasMessage("policyTypeKey is marked @NonNull but is null");
+ databaseProvider.deletePolicyTypes(null, null);
+ }).hasMessage("name is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicyTypes("aaa", null);
+ }).hasMessage("version is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicyTypes(null, "aaa");
+ }).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
- databaseProvider.getPolicies(null);
- }).hasMessage("policyKey is marked @NonNull but is null");
+ databaseProvider.getPolicies(null, null);
+ }).hasMessage("name is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.getPolicies(null, "aaa");
+ }).hasMessage("name is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.getPolicies("aaa", null);
+ }).hasMessage("version is marked @NonNull but is null");
assertThatThrownBy(() -> {
databaseProvider.createPolicies(null);
@@ -149,8 +171,16 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessage("serviceTemplate is marked @NonNull but is null");
assertThatThrownBy(() -> {
- databaseProvider.deletePolicies(null);
- }).hasMessage("policyKey is marked @NonNull but is null");
+ databaseProvider.deletePolicies(null, null);
+ }).hasMessage("name is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicies(null, "aaa");
+ }).hasMessage("name is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicies("aaa", null);
+ }).hasMessage("version is marked @NonNull but is null");
assertThatThrownBy(() -> {
databaseProvider.getOperationalPolicy(null);
@@ -210,7 +240,7 @@ public class DatabasePolicyModelsProviderTest {
new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
assertThatThrownBy(() -> {
- databaseProvider.getPolicyTypes(new PfConceptKey());
+ databaseProvider.getPolicyTypes("name", "version");
}).hasMessage("policy models provider is not initilaized");
}
@@ -221,36 +251,36 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.init();
assertThatThrownBy(() -> {
- databaseProvider.getPolicyTypes(new PfConceptKey());
- }).hasMessage("policy type not found: NULL:0.0.0");
+ databaseProvider.getPolicyTypes("name", "version");
+ }).hasMessage("policy type not found: name:version");
assertThatThrownBy(() -> {
- databaseProvider.createPolicyTypes(new JpaToscaServiceTemplate());
+ databaseProvider.createPolicyTypes(new ToscaServiceTemplate());
}).hasMessage("no policy types specified on service template");
assertThatThrownBy(() -> {
- databaseProvider.updatePolicyTypes(new JpaToscaServiceTemplate());
+ databaseProvider.updatePolicyTypes(new ToscaServiceTemplate());
}).hasMessage("no policy types specified on service template");
assertThatThrownBy(() -> {
- databaseProvider.deletePolicyTypes(new PfConceptKey());
- }).hasMessage("policy type not found: NULL:0.0.0");
+ databaseProvider.deletePolicyTypes("name", "version");
+ }).hasMessage("policy type not found: name:version");
assertThatThrownBy(() -> {
- databaseProvider.getPolicies(new PfConceptKey());
- }).hasMessage("policy not found: NULL:0.0.0");
+ databaseProvider.getPolicies("name", "version");
+ }).hasMessage("policy not found: name:version");
assertThatThrownBy(() -> {
- databaseProvider.createPolicies(new JpaToscaServiceTemplate());
+ databaseProvider.createPolicies(new ToscaServiceTemplate());
}).hasMessage("topology template not specified on service template");
assertThatThrownBy(() -> {
- databaseProvider.updatePolicies(new JpaToscaServiceTemplate());
+ databaseProvider.updatePolicies(new ToscaServiceTemplate());
}).hasMessage("topology template not specified on service template");
assertThatThrownBy(() -> {
- databaseProvider.deletePolicies(new PfConceptKey());
- }).hasMessage("policy not found: NULL:0.0.0");
+ databaseProvider.deletePolicies("name", "version");
+ }).hasMessage("policy not found: name:version");
assertThatThrownBy(() -> {
databaseProvider.getOperationalPolicy("policy_id");
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 2ee210c13..a9a0d13e3 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
@@ -26,15 +26,14 @@ 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.pdp.concepts.PdpGroups;
import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
/**
* Dummy implementation of {@link PolicyModelsProvider} with bad constructor.
@@ -53,46 +52,46 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
public void init() throws PfModelException {}
@Override
- public JpaToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
+ public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
return null;
}
@Override
- public JpaToscaServiceTemplate createPolicyTypes(@NonNull JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
throws PfModelException {
return null;
}
@Override
- public JpaToscaServiceTemplate updatePolicyTypes(@NonNull JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
throws PfModelException {
return null;
}
@Override
- public JpaToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
+ public ToscaServiceTemplate deletePolicyTypes(final String name, final String version) throws PfModelException {
return null;
}
@Override
- public JpaToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
+ public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
return null;
}
@Override
- public JpaToscaServiceTemplate createPolicies(@NonNull JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate)
throws PfModelException {
return null;
}
@Override
- public JpaToscaServiceTemplate updatePolicies(@NonNull JpaToscaServiceTemplate serviceTemplate)
+ public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate)
throws PfModelException {
return null;
}
@Override
- public JpaToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
+ public ToscaServiceTemplate deletePolicies(final String name, final String version) throws PfModelException {
return null;
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java
index 66c7762f8..797b1ac36 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java
@@ -23,7 +23,7 @@ package org.onap.policy.models.provider.impl;
import lombok.NonNull;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
* Sub class to check getDummyResponse() method in base class.
@@ -40,11 +40,11 @@ public class DummyPolicyModelsProviderSubImpl extends DummyPolicyModelsProviderI
super(parameters);
}
- public JpaToscaServiceTemplate getBadDummyResponse1() {
+ public ToscaServiceTemplate getBadDummyResponse1() {
return super.getDummyResponse("/i/dont/exist");
}
- public JpaToscaServiceTemplate getBadDummyResponse2() {
+ public ToscaServiceTemplate getBadDummyResponse2() {
return super.getDummyResponse(null);
}
}
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 af76edbcb..3e13d854c 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
@@ -26,14 +26,13 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.junit.Test;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.pdp.concepts.PdpGroups;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
/**
* Test the dummy models provider implementation.
@@ -53,10 +52,10 @@ public class DummyPolicyModelsProviderTest {
dummyProvider.init();
- JpaToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies(new PfConceptKey());
+ ToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies("onap.vcpe.tca", "1.0.0");
assertNotNull(serviceTemplate);
- assertEquals("onap.vcpe.tca:1.0.0",
- serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vcpe.tca").getId());
+ assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app",
+ serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get("onap.vcpe.tca").getType());
dummyProvider.close();
}
@@ -71,15 +70,15 @@ public class DummyPolicyModelsProviderTest {
PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
dummyProvider.init();
- assertNotNull(dummyProvider.getPolicyTypes(new PfConceptKey()));
- assertNotNull(dummyProvider.createPolicyTypes(new JpaToscaServiceTemplate()));
- assertNotNull(dummyProvider.updatePolicyTypes(new JpaToscaServiceTemplate()));
- assertNotNull(dummyProvider.deletePolicyTypes(new PfConceptKey()));
+ assertNotNull(dummyProvider.getPolicyTypes("name", "version"));
+ assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.deletePolicyTypes("name", "version"));
- assertNotNull(dummyProvider.getPolicies(new PfConceptKey()));
- assertNotNull(dummyProvider.createPolicies(new JpaToscaServiceTemplate()));
- assertNotNull(dummyProvider.updatePolicies(new JpaToscaServiceTemplate()));
- assertNotNull(dummyProvider.deletePolicies(new PfConceptKey()));
+ assertNotNull(dummyProvider.getPolicies("name", "version"));
+ assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.deletePolicies("name", "version"));
assertNotNull(dummyProvider.getOperationalPolicy("policy_id"));
assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
@@ -97,8 +96,8 @@ public class DummyPolicyModelsProviderTest {
assertNotNull(dummyProvider.deletePdpGroups("filter"));
assertThatThrownBy(() -> {
- dummyProvider.getPolicyTypes(null);
- }).hasMessage("policyTypeKey is marked @NonNull but is null");
+ dummyProvider.getPolicyTypes(null, null);
+ }).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
dummyProvider.createPolicyTypes(null);
}).hasMessage("serviceTemplate is marked @NonNull but is null");
@@ -106,12 +105,12 @@ public class DummyPolicyModelsProviderTest {
dummyProvider.updatePolicyTypes(null);
}).hasMessage("serviceTemplate is marked @NonNull but is null");
assertThatThrownBy(() -> {
- dummyProvider.deletePolicyTypes(null);
- }).hasMessage("policyTypeKey is marked @NonNull but is null");
+ dummyProvider.deletePolicyTypes(null, null);
+ }).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
- dummyProvider.getPolicies(null);
- }).hasMessage("policyKey is marked @NonNull but is null");
+ dummyProvider.getPolicies(null, null);
+ }).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
dummyProvider.createPolicies(null);
}).hasMessage("serviceTemplate is marked @NonNull but is null");
@@ -119,8 +118,8 @@ public class DummyPolicyModelsProviderTest {
dummyProvider.updatePolicies(null);
}).hasMessage("serviceTemplate is marked @NonNull but is null");
assertThatThrownBy(() -> {
- dummyProvider.deletePolicies(null);
- }).hasMessage("policyKey is marked @NonNull but is null");
+ dummyProvider.deletePolicies(null, null);
+ }).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
dummyProvider.getOperationalPolicy(null);
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
index e0aba8a9e..b29e1d642 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
@@ -22,29 +22,26 @@ package org.onap.policy.models.provider.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.Base64;
+import java.util.Map;
import lombok.NonNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
@@ -58,7 +55,7 @@ public class PolicyPersistenceTest {
// Logger for this class
private static final Logger LOGGER = LoggerFactory.getLogger(PolicyPersistenceTest.class);
- private Gson gson;
+ private StandardCoder standardCoder;
private PolicyModelsProvider databaseProvider;
@@ -101,7 +98,7 @@ public class PolicyPersistenceTest {
*/
@Before
public void setupGson() {
- gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+ standardCoder = new StandardCoder();
}
@After
@@ -141,19 +138,20 @@ public class PolicyPersistenceTest {
* @throws Exception any exception thrown
*/
public void testJsonStringPolicyPersistence(@NonNull final String policyString) throws Exception {
- JpaToscaServiceTemplate serviceTemplate = gson.fromJson(policyString, JpaToscaServiceTemplate.class);
+ ToscaServiceTemplate serviceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
assertNotNull(serviceTemplate);
- LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
- assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
databaseProvider.createPolicies(serviceTemplate);
- for (PfConceptKey policyKey : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().keySet()) {
- JpaToscaPolicy incomingPolicy = serviceTemplate.getTopologyTemplate().getPolicies().get(policyKey);
- JpaToscaPolicy databasePolicy =
- databaseProvider.getPolicies(policyKey).getTopologyTemplate().getPolicies().get(policyKey);
- assertEquals(incomingPolicy, databasePolicy);
+ for (Map<String, ToscaPolicy> policyMap : serviceTemplate.getToscaTopologyTemplate().getPolicies()) {
+ for (ToscaPolicy policy : policyMap.values()) {
+ ToscaServiceTemplate goToscaServiceTemplate =
+ databaseProvider.getPolicies(policy.getName(), policy.getVersion());
+
+ assertEquals(goToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0)
+ .get(policy.getName()).getType(), policy.getType());
+ }
}
}
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
index bd85358b3..f2b867604 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
@@ -22,10 +22,8 @@ package org.onap.policy.models.provider.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.Base64;
@@ -35,16 +33,14 @@ import lombok.NonNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
@@ -58,7 +54,7 @@ public class PolicyToscaPersistenceTest {
// Logger for this class
private static final Logger LOGGER = LoggerFactory.getLogger(PolicyToscaPersistenceTest.class);
- private Gson gson;
+ private StandardCoder standardCoder;
private PolicyModelsProvider databaseProvider;
@@ -97,11 +93,11 @@ public class PolicyToscaPersistenceTest {
}
/**
- * Set up GSON.
+ * Set up the standard coder.
*/
@Before
- public void setupGson() {
- gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+ public void setupStandardCoder() {
+ standardCoder = new StandardCoder();
}
@After
@@ -141,19 +137,18 @@ public class PolicyToscaPersistenceTest {
* @throws Exception any exception thrown
*/
public void testJsonStringPolicyPersistence(@NonNull final String policyString) throws Exception {
- JpaToscaServiceTemplate serviceTemplate = gson.fromJson(policyString, JpaToscaServiceTemplate.class);
+ ToscaServiceTemplate serviceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
assertNotNull(serviceTemplate);
- LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
- assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
databaseProvider.createPolicies(serviceTemplate);
- for (PfConceptKey policyKey : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().keySet()) {
- JpaToscaPolicy incomingPolicy = serviceTemplate.getTopologyTemplate().getPolicies().get(policyKey);
- JpaToscaPolicy databasePolicy =
- databaseProvider.getPolicies(policyKey).getTopologyTemplate().getPolicies().get(policyKey);
- assertEquals(incomingPolicy, databasePolicy);
+ for (String policyKey : serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).keySet()) {
+ ToscaPolicy incomingPolicy = serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey);
+ ToscaPolicy databasePolicy =
+ databaseProvider.getPolicies(incomingPolicy.getName(), incomingPolicy.getVersion())
+ .getToscaTopologyTemplate().getPolicies().get(0).get(policyKey);
+ assertEquals(incomingPolicy.getType(), databasePolicy.getType());
}
}
}