diff options
Diffstat (limited to 'models-tosca/src/test/java')
2 files changed, 73 insertions, 8 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java index c5952546a..aeba9bb80 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java @@ -55,9 +55,13 @@ public class JpaToscaPolicyTest { assertNotNull(new JpaToscaPolicy(new PfConceptKey(), new PfConceptKey())); assertNotNull(new JpaToscaPolicy(new JpaToscaPolicy())); - ToscaPolicy pol = new ToscaPolicy(); + final ToscaPolicy pol = new ToscaPolicy(); pol.setType("type"); - assertNotNull(new JpaToscaPolicy(pol)); + assertThatThrownBy(() -> { + new JpaToscaPolicy(pol); + }).hasMessage( + "PolicyType version not specified, the version of the PolicyType for this policy must be specified in the " + + "type_version field"); assertThatThrownBy(() -> { new JpaToscaPolicy((PfConceptKey) null); @@ -170,12 +174,12 @@ public class JpaToscaPolicyTest { tp.fromAuthorative(null); }).hasMessageMatching("toscaPolicy is marked .*on.*ull but is null"); - pol = new ToscaPolicy(); - pol.setName("policy"); - pol.setVersion("1.2.3"); - pol.setType("poltype"); - pol.setTypeVersion("2.2.3"); - tp.fromAuthorative(pol); + ToscaPolicy pol1 = new ToscaPolicy(); + pol1.setName("policy"); + pol1.setVersion("1.2.3"); + pol1.setType("poltype"); + pol1.setTypeVersion("2.2.3"); + tp.fromAuthorative(pol1); assertEquals("2.2.3", tp.getType().getVersion()); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java index f2da23c02..a258eedea 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java @@ -41,6 +41,7 @@ import org.onap.policy.models.dao.DaoParameters; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.dao.PfDaoFactory; import org.onap.policy.models.dao.impl.DefaultPfDao; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider; import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; @@ -373,6 +374,66 @@ public class SimpleToscaProviderTest { } @Test + public void testPolicyCreateTypeAndVersion() throws Exception { + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + + createPolicyTypes(); + + ToscaPolicy toscaPolicy = + toscaServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().values().iterator().next(); + + JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate(); + + final String originalPolicyType = toscaPolicy.getType(); + final String originalPolicyTypeVersion = toscaPolicy.getTypeVersion(); + toscaPolicy.setType(null); + toscaPolicy.setTypeVersion(null); + + assertThatThrownBy(() -> { + originalServiceTemplate.fromAuthorative(toscaServiceTemplate); + }).hasMessage("PolicyType type not specified, the type of the PolicyType for this policy must be " + + "specified in the type field"); + + toscaPolicy.setType("IDontExist"); + assertThatThrownBy(() -> { + originalServiceTemplate.fromAuthorative(toscaServiceTemplate); + }).hasMessage("PolicyType version not specified, the version of the PolicyType for this policy must be " + + "specified in the type_version field"); + + toscaPolicy.setTypeVersion("hello"); + assertThatThrownBy(() -> { + originalServiceTemplate.fromAuthorative(toscaServiceTemplate); + }).hasMessageContaining("value \"hello\", does not match regular expression"); + + toscaPolicy.setTypeVersion("99.100.101"); + originalServiceTemplate.fromAuthorative(toscaServiceTemplate); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + }).hasMessageContaining("policy type IDontExist:99.100.101 referenced in policy not found"); + + toscaPolicy.setType("IDontExist"); + originalServiceTemplate.fromAuthorative(toscaServiceTemplate); + + toscaPolicy.setType(null); + + assertThatThrownBy(() -> { + originalServiceTemplate.fromAuthorative(toscaServiceTemplate); + }).hasMessage("PolicyType type not specified, the type of the PolicyType for this policy must be " + + "specified in the type field"); + + toscaPolicy.setType(originalPolicyType); + toscaPolicy.setTypeVersion(originalPolicyTypeVersion); + + originalServiceTemplate.fromAuthorative(toscaServiceTemplate); + JpaToscaServiceTemplate createdServiceTemplate = + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(), + createdServiceTemplate.getTopologyTemplate().getPolicies()); + } + + @Test public void testPolicyUpdate() throws Exception { ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); |