import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.util.Properties;
-
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
import org.junit.Before;
deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0v2.getKey());
- assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key));
- assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
+ assertEquals(dataType0v2, deletedServiceTemplate.getDataTypes().get(dataType0v2.getKey()));
+ assertNull(deletedServiceTemplate.getDataTypes().get(dataType0v2.getKey()).getDescription());
assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
.hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2");
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
.hasMessage("no policy types found");
+
+ JpaToscaServiceTemplate newServiceTemplate =
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+ assertEquals(serviceTemplate, newServiceTemplate);
}
@Test
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, policyKey))
.hasMessage("no policies found");
+
+ new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
}
@Test
}).hasMessageMatching("^policyKey is marked .*on.*ull but is null$");
}
+ @Test
+ public void testDeleteServiceTemplate() throws PfModelException {
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().deleteServiceTemplate(null);
+ }).hasMessageMatching("^dao is marked .*on.*ull but is null$");
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().deleteServiceTemplate(pfDao);
+ }).hasMessage("service template not found in database");
+
+ 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);
+
+ 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());
+
+ JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteServiceTemplate(pfDao);
+
+ assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key));
+ }
+
+ @Test
+ public void testNullParameters() {
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getCascadedDataTypes(null, null, null);
+ }).hasMessageMatching("^dbServiceTemplate is marked .*on.*ull but is null$");
+ }
+
private void createPolicyTypes() throws CoderException, PfModelException {
Object yamlObject = new Yaml()
- .load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
+ .load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml"));
String yamlAsJsonString = new StandardCoder().encode(yamlObject);
ToscaServiceTemplate toscaServiceTemplatePolicyType =