diff options
author | liamfallon <liam.fallon@est.tech> | 2020-01-07 10:24:12 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2020-01-07 14:45:06 +0000 |
commit | f69b6681486e4d1c5859f649a3293488c1859712 (patch) | |
tree | 92664e117820ab4a4cdfdc0b5694388e39752724 /models-tosca/src/test/java/org/onap | |
parent | 4fab7a327737ebdfaf7b55c39c49f0239ff627c8 (diff) |
Support persistence of data types
Data types must be persisted to the database in order for them to be
retrieved in policy type queries and later for policy validation.
Issue-ID: POLICY-2315
Change-Id: Iacb88501a597aeee8f6d8bcc3d9604c13dc09090
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/test/java/org/onap')
6 files changed, 317 insertions, 197 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java index 8b9003be0..36c66546a 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -60,7 +60,7 @@ public class AuthorativeToscaProviderPolicyTest { private static final String VCPE_JSON = "policies/vCPE.policy.monitoring.input.tosca.json"; private static final String POLICY_AND_VERSION = "onap.restart.tca:1.0.0"; private static final String POLICY1 = "onap.restart.tca"; - private static final String DAO_IS_NULL = "dao is marked @NonNull but is null"; + private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$"; private static final String VERSION_100 = "1.0.0"; private PfDao pfDao; private StandardCoder standardCoder; @@ -108,17 +108,16 @@ public class AuthorativeToscaProviderPolicyTest { public void testPoliciesGet() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().getPolicies(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getPolicyList(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); createPolicyTypes(); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = @@ -141,8 +140,7 @@ public class AuthorativeToscaProviderPolicyTest { assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); assertTrue(beforePolicy.getType().equals(gotPolicy.getType())); - List<ToscaPolicy> gotPolicyList = - new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100); + List<ToscaPolicy> gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); @@ -166,33 +164,32 @@ public class AuthorativeToscaProviderPolicyTest { public void testPoliciesGetFiltered() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicies(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicies(null, ToscaPolicyFilter.builder().build()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicies(pfDao, null); - }).hasMessage("filter is marked @NonNull but is null"); + }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyList(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyList(null, ToscaPolicyFilter.builder().build()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null); - }).hasMessage("filter is marked @NonNull but is null"); + }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); createPolicyTypes(); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = @@ -229,8 +226,7 @@ public class AuthorativeToscaProviderPolicyTest { assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); assertTrue(beforePolicy.getType().equals(gotPolicy.getType())); - List<ToscaPolicy> gotPolicyList = - new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100); + List<ToscaPolicy> gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); @@ -254,21 +250,20 @@ public class AuthorativeToscaProviderPolicyTest { public void testPolicyCreate() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicies(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicies(null, new ToscaServiceTemplate()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicies(pfDao, null); - }).hasMessage("serviceTemplate is marked @NonNull but is null"); + }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); createPolicyTypes(); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = @@ -288,25 +283,24 @@ public class AuthorativeToscaProviderPolicyTest { public void testPolicyUpdate() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicies(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().updatePolicies(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().updatePolicies(null, new ToscaServiceTemplate()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().updatePolicies(pfDao, null); - }).hasMessage("serviceTemplate is marked @NonNull but is null"); + }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); createPolicyTypes(); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = @@ -334,37 +328,36 @@ public class AuthorativeToscaProviderPolicyTest { public void testPoliciesDelete() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(null, null, VERSION); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(null, "name", null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(null, "name", VERSION); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(pfDao, null, null); - }).hasMessage("name is marked @NonNull but is null"); + }).hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(pfDao, null, VERSION); - }).hasMessage("name is marked @NonNull but is null"); + }).hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null); - }).hasMessage("version is marked @NonNull but is null"); + }).hasMessageMatching("^version is marked .*on.*ull but is null$"); createPolicyTypes(); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = @@ -399,7 +392,7 @@ public class AuthorativeToscaProviderPolicyTest { assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null); - }).hasMessage("version is marked @NonNull but is null"); + }).hasMessageMatching("^version is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java index 20b8e5d1e..c41f5e1f4 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,9 +27,11 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import com.google.gson.GsonBuilder; + import java.util.LinkedHashMap; import java.util.List; import java.util.Properties; + import org.apache.commons.lang3.ObjectUtils; import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; @@ -59,13 +61,12 @@ public class AuthorativeToscaProviderPolicyTypeTest { private static final String POLICY_AFFINITY_VERSION0 = "onap.policies.NoVersion:0.0.0"; private static final String POLICY_AFFINITY = "onap.policies.NoVersion"; private static final String MISSING_POLICY_TYPES = "no policy types specified on service template"; - private static final String DAO_IS_NULL = "dao is marked @NonNull but is null"; + private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$"; private static final String VERSION_000 = "0.0.0"; private static String yamlAsJsonString; private PfDao pfDao; private StandardCoder standardCoder; - /** * Read the policy type definition. * @@ -73,8 +74,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { */ @BeforeClass public static void readPolicyDefinition() { - String yamlString = - ResourceUtils.getResourceAsString("src/test/resources/onap.policies.NoVersion.yaml"); + String yamlString = ResourceUtils.getResourceAsString("src/test/resources/onap.policies.NoVersion.yaml"); Object yamlObject = new Yaml().load(yamlString); yamlAsJsonString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject); @@ -100,7 +100,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb"); - daoParameters.setJdbcProperties(jdbcProperties ); + daoParameters.setJdbcProperties(jdbcProperties); pfDao = new PfDaoFactory().createPfDao(daoParameters); pfDao.init(daoParameters); @@ -123,11 +123,11 @@ public class AuthorativeToscaProviderPolicyTypeTest { public void testPolicyTypesGet() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().getPolicyTypes(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getPolicyList(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); @@ -149,13 +149,12 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); - List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, - POLICY_AFFINITY, VERSION_000); + List<ToscaPolicyType> gotPolicyTypeList = + new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_AFFINITY, VERSION_000); assertEquals(1, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); - gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, - POLICY_AFFINITY, null); + gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_AFFINITY, null); assertEquals(1, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); @@ -168,32 +167,31 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); } - @Test public void testPolicyTypesGetFiltered() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyTypes(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyTypes(null, ToscaPolicyTypeFilter.builder().build()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, null); - }).hasMessage("filter is marked @NonNull but is null"); + }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, ToscaPolicyTypeFilter.builder().build()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, null); - }).hasMessage("filter is marked @NonNull but is null"); + }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); @@ -229,8 +227,8 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription())); - List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, - POLICY_AFFINITY, VERSION_000); + List<ToscaPolicyType> gotPolicyTypeList = + new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_AFFINITY, VERSION_000); assertEquals(1, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); @@ -259,15 +257,15 @@ public class AuthorativeToscaProviderPolicyTypeTest { public void testPolicyTypesCreate() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicyTypes(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicyTypes(null, new ToscaServiceTemplate()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicyTypes(pfDao, null); - }).hasMessage("serviceTemplate is marked @NonNull but is null"); + }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); ToscaServiceTemplate testToscaServiceTemplate = new ToscaServiceTemplate(); assertThatThrownBy(() -> { @@ -297,19 +295,19 @@ public class AuthorativeToscaProviderPolicyTypeTest { public void testPolicyTypesUpdate() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicyTypes(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().updatePolicyTypes(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().updatePolicyTypes(null, new ToscaServiceTemplate()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().updatePolicyTypes(pfDao, null); - }).hasMessage("serviceTemplate is marked @NonNull but is null"); + }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); @@ -336,31 +334,31 @@ public class AuthorativeToscaProviderPolicyTypeTest { public void testPolicyTypesDelete() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicyType(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicyType(null, null, VERSION); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicyType(null, "name", null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicyType(null, "name", VERSION); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicyType(pfDao, null, null); - }).hasMessage("name is marked @NonNull but is null"); + }).hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicyType(pfDao, null, VERSION); - }).hasMessage("name is marked @NonNull but is null"); + }).hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null); - }).hasMessage("version is marked @NonNull but is null"); + }).hasMessageMatching("^version is marked .*on.*ull but is null$"); ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); @@ -394,7 +392,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null); - }).hasMessage("version is marked @NonNull but is null"); + }).hasMessageMatching("^version is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java index cc510b74f..047ef4891 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -53,15 +53,14 @@ import org.yaml.snakeyaml.Yaml; * @author Liam Fallon (liam.fallon@est.tech) */ public class LegacyProvider4LegacyGuardTest { - private static final String POLICY_ID_IS_NULL = "policyId is marked @NonNull but is null"; + private static final String POLICY_ID_IS_NULL = "^policyId is marked .*on.*ull but is null$"; private static final String VDNS_OUTPUT_JSON = "policies/vDNS.policy.guard.frequency.output.json"; private static final String VDNS_INPUT_JSON = "policies/vDNS.policy.guard.frequency.input.json"; - private static final String LEGACY_POLICY_IS_NULL = "legacyGuardPolicy is marked @NonNull but is null"; - private static final String DAO_IS_NULL = "dao is marked @NonNull but is null"; + private static final String LEGACY_POLICY_IS_NULL = "^legacyGuardPolicy is marked .*on.*ull but is null$"; + private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$"; private PfDao pfDao; private StandardCoder standardCoder; - /** * Set up the DAO towards the database. * @@ -105,15 +104,15 @@ public class LegacyProvider4LegacyGuardTest { public void testPoliciesGet() throws Exception { assertThatThrownBy(() -> { new LegacyProvider().getGuardPolicy(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().getGuardPolicy(null, null, ""); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().getGuardPolicy(pfDao, null, null); - }).hasMessage(POLICY_ID_IS_NULL); + }).hasMessageMatching(POLICY_ID_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().getGuardPolicy(pfDao, "I Dont Exist", null); @@ -121,9 +120,8 @@ public class LegacyProvider4LegacyGuardTest { createPolicyTypes(); - LegacyGuardPolicyInput originalGip = standardCoder.decode( - ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), - LegacyGuardPolicyInput.class); + LegacyGuardPolicyInput originalGip = + standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class); assertNotNull(originalGip); @@ -140,8 +138,7 @@ public class LegacyProvider4LegacyGuardTest { assertEquals(originalGip.getContent(), gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - String expectedJsonOutput = - ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON); + String expectedJsonOutput = ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON); String actualJsonOutput = standardCoder.encode(gotGopm); assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", "")); @@ -165,21 +162,20 @@ public class LegacyProvider4LegacyGuardTest { public void testPolicyCreate() throws Exception { assertThatThrownBy(() -> { new LegacyProvider().createGuardPolicy(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().createGuardPolicy(null, new LegacyGuardPolicyInput()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().createGuardPolicy(pfDao, null); - }).hasMessage(LEGACY_POLICY_IS_NULL); + }).hasMessageMatching(LEGACY_POLICY_IS_NULL); createPolicyTypes(); - LegacyGuardPolicyInput originalGip = standardCoder.decode( - ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), - LegacyGuardPolicyInput.class); + LegacyGuardPolicyInput originalGip = + standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class); assertNotNull(originalGip); @@ -196,8 +192,7 @@ public class LegacyProvider4LegacyGuardTest { assertEquals(originalGip.getContent(), gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - String expectedJsonOutput = - ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON); + String expectedJsonOutput = ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON); String actualJsonOutput = standardCoder.encode(gotGopm); assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", "")); @@ -207,21 +202,20 @@ public class LegacyProvider4LegacyGuardTest { public void testPolicyCreateBad() throws Exception { assertThatThrownBy(() -> { new LegacyProvider().createGuardPolicy(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().createGuardPolicy(null, new LegacyGuardPolicyInput()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().createGuardPolicy(pfDao, null); - }).hasMessage(LEGACY_POLICY_IS_NULL); + }).hasMessageMatching(LEGACY_POLICY_IS_NULL); createPolicyTypes(); - LegacyGuardPolicyInput originalGip = standardCoder.decode( - ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), - LegacyGuardPolicyInput.class); + LegacyGuardPolicyInput originalGip = + standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class); assertNotNull(originalGip); @@ -236,15 +230,15 @@ public class LegacyProvider4LegacyGuardTest { public void testPolicyUpdate() throws Exception { assertThatThrownBy(() -> { new LegacyProvider().updateGuardPolicy(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().updateGuardPolicy(null, new LegacyGuardPolicyInput()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().updateGuardPolicy(pfDao, null); - }).hasMessage(LEGACY_POLICY_IS_NULL); + }).hasMessageMatching(LEGACY_POLICY_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().updateGuardPolicy(pfDao, new LegacyGuardPolicyInput()); @@ -252,9 +246,8 @@ public class LegacyProvider4LegacyGuardTest { createPolicyTypes(); - LegacyGuardPolicyInput originalGip = standardCoder.decode( - ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), - LegacyGuardPolicyInput.class); + LegacyGuardPolicyInput originalGip = + standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class); assertNotNull(originalGip); @@ -285,36 +278,35 @@ public class LegacyProvider4LegacyGuardTest { gotUpdatedGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next().getRecipe()); } - @Test public void testPoliciesDelete() throws Exception { assertThatThrownBy(() -> { new LegacyProvider().deleteGuardPolicy(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteGuardPolicy(null, null, ""); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteGuardPolicy(null, "", null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteGuardPolicy(null, "", ""); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteGuardPolicy(pfDao, null, null); - }).hasMessage(POLICY_ID_IS_NULL); + }).hasMessageMatching(POLICY_ID_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteGuardPolicy(pfDao, null, ""); - }).hasMessage(POLICY_ID_IS_NULL); + }).hasMessageMatching(POLICY_ID_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteGuardPolicy(pfDao, "", null); - }).hasMessage("policyVersion is marked @NonNull but is null"); + }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new LegacyProvider().deleteGuardPolicy(pfDao, "IDontExist", "0"); @@ -322,9 +314,8 @@ public class LegacyProvider4LegacyGuardTest { createPolicyTypes(); - LegacyGuardPolicyInput originalGip = standardCoder.decode( - ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), - LegacyGuardPolicyInput.class); + LegacyGuardPolicyInput originalGip = + standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class); assertNotNull(originalGip); @@ -340,15 +331,14 @@ public class LegacyProvider4LegacyGuardTest { assertEquals(originalGip.getContent(), gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next()); - String expectedJsonOutput = - ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON); + String expectedJsonOutput = ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON); String actualJsonOutput = standardCoder.encode(gotGopm); assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", "")); assertThatThrownBy(() -> { new LegacyProvider().deleteGuardPolicy(pfDao, originalGip.getPolicyId(), null); - }).hasMessage("policyVersion is marked @NonNull but is null"); + }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$"); Map<String, LegacyGuardPolicyOutput> deletedGopm = new LegacyProvider().deleteGuardPolicy(pfDao, originalGip.getPolicyId(), "1"); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java index 4dd998ee9..ec03122a6 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -50,10 +50,10 @@ import org.yaml.snakeyaml.Yaml; * @author Liam Fallon (liam.fallon@est.tech) */ public class LegacyProvider4LegacyOperationalTest { - private static final String POLICY_ID_IS_NULL = "policyId is marked @NonNull but is null"; + private static final String POLICY_ID_IS_NULL = "^policyId is marked .*on.*ull but is null$"; private static final String VCPE_OUTPUT_JSON = "policies/vCPE.policy.operational.output.json"; private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.operational.input.json"; - private static final String DAO_IS_NULL = "dao is marked @NonNull but is null"; + private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$"; private PfDao pfDao; private StandardCoder standardCoder; @@ -100,15 +100,15 @@ public class LegacyProvider4LegacyOperationalTest { public void testPoliciesGet() throws Exception { assertThatThrownBy(() -> { new LegacyProvider().getOperationalPolicy(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().getOperationalPolicy(null, "", null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().getOperationalPolicy(pfDao, null, null); - }).hasMessage(POLICY_ID_IS_NULL); + }).hasMessageMatching(POLICY_ID_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().getOperationalPolicy(pfDao, "I Dont Exist", null); @@ -117,8 +117,7 @@ public class LegacyProvider4LegacyOperationalTest { createPolicyTypes(); LegacyOperationalPolicy originalLop = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), - LegacyOperationalPolicy.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), LegacyOperationalPolicy.class); assertNotNull(originalLop); @@ -146,21 +145,20 @@ public class LegacyProvider4LegacyOperationalTest { public void testPolicyCreate() throws Exception { assertThatThrownBy(() -> { new LegacyProvider().createOperationalPolicy(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().createOperationalPolicy(null, new LegacyOperationalPolicy()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().createOperationalPolicy(pfDao, null); - }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null"); + }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$"); createPolicyTypes(); LegacyOperationalPolicy originalLop = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), - LegacyOperationalPolicy.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), LegacyOperationalPolicy.class); assertNotNull(originalLop); @@ -183,25 +181,24 @@ public class LegacyProvider4LegacyOperationalTest { public void testPolicyUpdate() throws Exception { assertThatThrownBy(() -> { new LegacyProvider().updateOperationalPolicy(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().updateOperationalPolicy(null, new LegacyOperationalPolicy()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().updateOperationalPolicy(pfDao, null); - }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null"); + }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new LegacyProvider().updateOperationalPolicy(pfDao, new LegacyOperationalPolicy()); - }).hasMessage("name is marked @NonNull but is null"); + }).hasMessageMatching("^name is marked .*on.*ull but is null$"); createPolicyTypes(); LegacyOperationalPolicy originalLop = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), - LegacyOperationalPolicy.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), LegacyOperationalPolicy.class); assertNotNull(originalLop); @@ -226,33 +223,32 @@ public class LegacyProvider4LegacyOperationalTest { public void testPoliciesDelete() throws Exception { assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(null, null, ""); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(null, "", null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(null, "", ""); - - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(pfDao, null, null); - }).hasMessage(POLICY_ID_IS_NULL); + }).hasMessageMatching(POLICY_ID_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(pfDao, null, ""); - }).hasMessage(POLICY_ID_IS_NULL); + }).hasMessageMatching(POLICY_ID_IS_NULL); assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(pfDao, "", null); - }).hasMessage("policyVersion is marked @NonNull but is null"); + }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(pfDao, "IDontExist", "0"); @@ -261,8 +257,7 @@ public class LegacyProvider4LegacyOperationalTest { createPolicyTypes(); LegacyOperationalPolicy originalLop = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), - LegacyOperationalPolicy.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), LegacyOperationalPolicy.class); assertNotNull(originalLop); @@ -281,7 +276,7 @@ public class LegacyProvider4LegacyOperationalTest { assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(pfDao, originalLop.getPolicyId(), null); - }).hasMessage("policyVersion is marked @NonNull but is null"); + }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$"); LegacyOperationalPolicy deletedLop = new LegacyProvider().deleteOperationalPolicy(pfDao, originalLop.getPolicyId(), "1"); 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 a3e3ba518..db6dc52b6 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,6 +27,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.Properties; + import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; import org.junit.Before; @@ -42,6 +43,8 @@ import org.onap.policy.models.dao.PfDaoFactory; import org.onap.policy.models.dao.impl.DefaultPfDao; 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; +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.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; @@ -53,9 +56,9 @@ import org.yaml.snakeyaml.Yaml; * @author Liam Fallon (liam.fallon@est.tech) */ public class SimpleToscaProviderTest { - private static final String TEMPLATE_IS_NULL = "serviceTemplate is marked @NonNull but is null"; + private static final String TEMPLATE_IS_NULL = "^serviceTemplate is marked .*on.*ull but is null$"; private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.monitoring.input.tosca.json"; - private static final String DAO_IS_NULL = "dao is marked @NonNull but is null"; + private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$"; private PfDao pfDao; private StandardCoder standardCoder; @@ -99,10 +102,50 @@ public class SimpleToscaProviderTest { } @Test + public void testCreateUpdateGetDeleteDataType() 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); + + JpaToscaServiceTemplate createdServiceTemplate = + new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); + + assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key)); + assertEquals(null, createdServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); + + dataType0.setDescription("Updated Description"); + + JpaToscaServiceTemplate updatedServiceTemplate = + new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate); + + assertEquals(dataType0, updatedServiceTemplate.getDataTypes().get(dataType0Key)); + assertEquals("Updated Description", updatedServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); + + JpaToscaServiceTemplate gotServiceTemplate = + new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion()); + + assertEquals(dataType0, gotServiceTemplate.getDataTypes().get(dataType0Key)); + assertEquals("Updated Description", gotServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); + + JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key); + + assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key)); + assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); + + JpaToscaServiceTemplate doesNotExistServiceTemplate = + new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key); + + assertEquals(null, doesNotExistServiceTemplate.getDataTypes().get(dataType0Key)); + } + + @Test public void testPoliciesGet() throws Exception { - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -127,9 +170,8 @@ public class SimpleToscaProviderTest { @Test public void testPolicyCreate() throws Exception { - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -145,9 +187,8 @@ public class SimpleToscaProviderTest { @Test public void testPolicyUpdate() throws Exception { - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -163,9 +204,8 @@ public class SimpleToscaProviderTest { @Test public void testPoliciesDelete() throws Exception { - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -195,98 +235,138 @@ public class SimpleToscaProviderTest { JpaToscaServiceTemplate testServiceTemplate = new JpaToscaServiceTemplate(); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("topology template not specified on service template"); + .hasMessage("topology template not specified on service template"); testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("no policies specified on topology template of service template"); + .hasMessage("no policies specified on topology template of service template"); testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("list of policies specified on topology template of service template is empty"); + .hasMessage("list of policies specified on topology template of service template is empty"); } @Test public void testNonNulls() { assertThatThrownBy(() -> { + new SimpleToscaProvider().getDataTypes(null, null, null); + }).hasMessageMatching(DAO_IS_NULL); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().createDataTypes(null, null); + }).hasMessageMatching(DAO_IS_NULL); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().createDataTypes(null, new JpaToscaServiceTemplate()); + }).hasMessageMatching(DAO_IS_NULL); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().createDataTypes(pfDao, null); + }).hasMessageMatching(TEMPLATE_IS_NULL); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().updateDataTypes(null, null); + }).hasMessageMatching(DAO_IS_NULL); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().updateDataTypes(null, new JpaToscaServiceTemplate()); + }).hasMessageMatching(DAO_IS_NULL); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().updateDataTypes(pfDao, null); + }).hasMessageMatching(TEMPLATE_IS_NULL); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().deleteDataType(null, null); + }).hasMessageMatching(DAO_IS_NULL); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().deleteDataType(null, new PfConceptKey()); + }).hasMessageMatching(DAO_IS_NULL); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().deleteDataType(pfDao, null); + }).hasMessageMatching("^dataTypeKey is marked .*on.*ull but is null$"); + + assertThatThrownBy(() -> { new SimpleToscaProvider().getPolicyTypes(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().createPolicyTypes(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().createPolicyTypes(null, new JpaToscaServiceTemplate()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().createPolicyTypes(pfDao, null); - }).hasMessage(TEMPLATE_IS_NULL); + }).hasMessageMatching(TEMPLATE_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().updatePolicyTypes(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().updatePolicyTypes(null, new JpaToscaServiceTemplate()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().updatePolicyTypes(pfDao, null); - }).hasMessage(TEMPLATE_IS_NULL); + }).hasMessageMatching(TEMPLATE_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().deletePolicyType(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().deletePolicyType(null, new PfConceptKey()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().deletePolicyType(pfDao, null); - }).hasMessage("policyTypeKey is marked @NonNull but is null"); + }).hasMessageMatching("^policyTypeKey is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new SimpleToscaProvider().getPolicies(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().createPolicies(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().createPolicies(pfDao, null); - }).hasMessage(TEMPLATE_IS_NULL); + }).hasMessageMatching(TEMPLATE_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().updatePolicies(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().updatePolicies(pfDao, null); - }).hasMessage(TEMPLATE_IS_NULL); + }).hasMessageMatching(TEMPLATE_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().deletePolicy(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().deletePolicy(null, new PfConceptKey()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new SimpleToscaProvider().deletePolicy(pfDao, null); - }).hasMessage("policyKey is marked @NonNull but is null"); + }).hasMessageMatching("^policyKey is marked .*on.*ull but is null$"); } private void createPolicyTypes() throws CoderException, PfModelException { diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java index 40a2fd29a..b7c814a5e 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,16 @@ package org.onap.policy.models.tosca.utils; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.Test; +import org.onap.policy.models.base.PfConceptKey; +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.JpaToscaPolicyTypes; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; /** * Import the {@link ToscaUtils} class. @@ -34,12 +39,71 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; public class ToscaUtilsTest { @Test - public void test() { + public void testAssertDataTypes() { JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate(); + + assertThatThrownBy(() -> { + ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate); + }).hasMessage("no data types specified on service template"); + + jpaToscaServiceTemplate.setDataTypes(new JpaToscaDataTypes()); + + assertThatThrownBy(() -> { + ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate); + }).hasMessage("list of data types specified on service template is empty"); + + jpaToscaServiceTemplate.getDataTypes().getConceptMap().put(new PfConceptKey(), null); + + assertThatCode(() -> { + ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate); + }).doesNotThrowAnyException(); + } + + @Test + public void testAssertPolicyTypes() { + JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate(); + + assertThatThrownBy(() -> { + ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate); + }).hasMessage("no policy types specified on service template"); + jpaToscaServiceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); assertThatThrownBy(() -> { ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate); }).hasMessage("list of policy types specified on service template is empty"); + + jpaToscaServiceTemplate.getPolicyTypes().getConceptMap().put(new PfConceptKey(), null); + + assertThatCode(() -> { + ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate); + }).doesNotThrowAnyException(); + } + + @Test + public void testAssertPolicies() { + JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate(); + + assertThatThrownBy(() -> { + ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate); + }).hasMessage("topology template not specified on service template"); + + jpaToscaServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); + + assertThatThrownBy(() -> { + ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate); + }).hasMessage("no policies specified on topology template of service template"); + + jpaToscaServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); + + assertThatThrownBy(() -> { + ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate); + }).hasMessage("list of policies specified on topology template of service template is empty"); + + jpaToscaServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(new PfConceptKey(), null); + + assertThatCode(() -> { + ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate); + }).doesNotThrowAnyException(); } } |