summaryrefslogtreecommitdiffstats
path: root/models-provider/src/test/java/org
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-04-01 00:34:34 +0000
committerliamfallon <liam.fallon@est.tech>2019-04-01 00:34:34 +0000
commit2e9186e1eb441b3ec47cf2a959e34b9409134aba (patch)
treea83a9e904c767db38ffc3f7d34aca6ece395e0f6 /models-provider/src/test/java/org
parentfbed360c0acdc127fdf56a99401c1aea691ce57e (diff)
Refactor to authorative TOSCA serializtion
This review refactors the TOSCA support to use authorative serialization and mapping. It removes the JPA entities from the Proider interface It brings the mapping support from and to authorative concepts out of the JSON serialization classes directly into the JPA classes It adapts the unit tests to work with the refactored structure. Apologies for the review size but it all had to be done in a single block of work. Issue-ID: POLICY-1095 Change-Id: I4827d1dc67ef7aac98cba230ffcd79c6de71e805 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-provider/src/test/java/org')
-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
6 files changed, 114 insertions, 93 deletions
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());
}
}
}