import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
import org.yaml.snakeyaml.Yaml;
JpaToscaServiceTemplate createdServiceTemplate =
new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
+ assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size());
assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key));
assertEquals(null, createdServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
assertEquals(null, doesNotExistServiceTemplate.getDataTypes().get(dataType0Key));
}
+ @Test
+ public void testCreateUpdateGetDeletePolicyType() throws PfModelException {
+ JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+
+ PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1");
+ JpaToscaDataType dataType0 = new JpaToscaDataType();
+ dataType0.setKey(dataType0Key);
+ serviceTemplate.setDataTypes(new JpaToscaDataTypes());
+ serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0);
+
+ PfConceptKey policyType0Key = new PfConceptKey("PolicyType0", "0.0.1");
+ JpaToscaPolicyType policyType0 = new JpaToscaPolicyType();
+ policyType0.setKey(policyType0Key);
+ serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+ serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0);
+
+ JpaToscaServiceTemplate createdServiceTemplate =
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+
+ assertEquals(1, createdServiceTemplate.getPolicyTypes().getConceptMap().size());
+ assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ policyType0.setDescription("Updated Description");
+
+ JpaToscaServiceTemplate updatedServiceTemplate =
+ new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
+
+ assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description",
+ updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate gotServiceTemplate =
+ new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion());
+
+ assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate deletedServiceTemplate =
+ new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
+
+ assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description",
+ deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate doesNotExistServiceTemplate =
+ new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
+
+ assertEquals(null, doesNotExistServiceTemplate.getPolicyTypes().get(policyType0Key));
+ }
+
+ @Test
+ public void testCreateUpdateGetDeletePolicyTypeWithDataType() throws PfModelException {
+ JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+
+ PfConceptKey policyType0Key = new PfConceptKey("PolicyType0", "0.0.1");
+ JpaToscaPolicyType policyType0 = new JpaToscaPolicyType();
+ policyType0.setKey(policyType0Key);
+ serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+ serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0);
+
+ JpaToscaServiceTemplate createdServiceTemplate =
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+
+ assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ policyType0.setDescription("Updated Description");
+
+ JpaToscaServiceTemplate updatedServiceTemplate =
+ new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
+
+ assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description",
+ updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate gotServiceTemplate =
+ new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion());
+
+ assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate deletedServiceTemplate =
+ new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
+
+ assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description",
+ deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate doesNotExistServiceTemplate =
+ new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
+
+ assertEquals(null, doesNotExistServiceTemplate.getPolicyTypes().get(policyType0Key));
+ }
+
@Test
public void testPoliciesGet() throws Exception {
ToscaServiceTemplate toscaServiceTemplate =