diff options
Diffstat (limited to 'models-tosca')
10 files changed, 501 insertions, 13 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java index e89b31635..f5a178a37 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java @@ -54,7 +54,7 @@ public class ToscaEntity implements PfNameVersion { private String description; /** - * Copy COnstructor. + * Copy Constructor. * * @param copyObject object to copy from */ diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java index 75f17ea5b..3a3b1476d 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java @@ -23,10 +23,14 @@ package org.onap.policy.models.tosca.authorative.concepts; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.Map.Entry; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.NonNull; /** * Class to represent TOSCA policy type matching input/output from/to client. @@ -39,6 +43,22 @@ import lombok.NoArgsConstructor; public class ToscaPolicyType extends ToscaEntity implements Comparable<ToscaPolicyType> { private Map<String, ToscaProperty> properties; + /** + * Copy Constructor. + * + * @param copyObject object to copy from + */ + public ToscaPolicyType(@NonNull ToscaPolicyType copyObject) { + super(copyObject); + + if (copyObject.properties != null) { + properties = new LinkedHashMap<>(); + for (final Entry<String, ToscaProperty> propertyEntry : copyObject.properties.entrySet()) { + properties.put(propertyEntry.getKey(), propertyEntry.getValue()); + } + } + } + @Override public int compareTo(final ToscaPolicyType other) { return compareNameVersion(this, other); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestPojos.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/PojosTest.java index 15240665d..d850052b4 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestPojos.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/PojosTest.java @@ -39,7 +39,7 @@ import org.onap.policy.common.utils.validation.ToStringTester; * @author Chenfei Gao (cgao@research.att.com) * */ -public class TestPojos { +public class PojosTest { private static final String POJO_PACKAGE = "org.onap.policy.models.tosca.authorative.concepts"; diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java new file mode 100644 index 000000000..4653296b7 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java @@ -0,0 +1,214 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.authorative.concepts; + +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.assertTrue; + +import com.google.gson.GsonBuilder; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; + +/** + * Test of the {@link ToscaPolicyFilter} class. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaPolicyFilterTest { + // Logger for this class + private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyFilterTest.class); + + // @formatter:off + private static final String[] policyResourceNames = { + "policies/vCPE.policies.optimization.input.tosca.yaml", + "policies/vCPE.policy.monitoring.input.tosca.json", + "policies/vCPE.policy.monitoring.input.tosca.yaml", + "policies/vCPE.policy.operational.input.tosca.yaml", + "policies/vDNS.policy.guard.frequency.input.tosca.json", + "policies/vDNS.policy.guard.frequency.input.tosca.yaml", + "policies/vDNS.policy.guard.minmax.input.tosca.yaml", + "policies/vDNS.policy.monitoring.input.tosca.json", + "policies/vDNS.policy.monitoring.input.tosca.yaml", + "policies/vDNS.policy.operational.input.tosca.yaml", + "policies/vFirewall.policy.monitoring.input.tosca.json", + "policies/vFirewall.policy.monitoring.input.tosca.yaml", + "policies/vFirewall.policy.operational.input.tosca.json", + "policies/vFirewall.policy.operational.input.tosca.yaml" + }; + // @formatter:on + + private static List<ToscaPolicy> policyList = new ArrayList<>(); + + /** + * Set up a Tosca Policy type list for filtering. + * + * @throws CoderException on JSON decoding errors + */ + @BeforeClass + public static void setupTypeList() throws CoderException { + for (String policyResourceName : policyResourceNames) { + String policyString = ResourceUtils.getResourceAsString(policyResourceName); + if (policyResourceName.endsWith("yaml")) { + Object yamlObject = new Yaml().load(policyString); + policyString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject); + } + + ToscaServiceTemplate serviceTemplate = new StandardCoder().decode(policyString, ToscaServiceTemplate.class); + assertNotNull(serviceTemplate); + + for (Map<String, ToscaPolicy> foundPolicyMap : serviceTemplate.getToscaTopologyTemplate().getPolicies()) { + for (Entry<String, ToscaPolicy> policyEntry : foundPolicyMap.entrySet()) { + ToscaPolicy policy = policyEntry.getValue(); + if (policy.getName() == null) { + policy.setName(policyEntry.getKey()); + } + if (policy.getVersion() == null) { + policy.setVersion(PfKey.NULL_KEY_VERSION); + } + if (policy.getTypeVersion() == null) { + policy.setTypeVersion(PfKey.NULL_KEY_VERSION); + } + if (!policyList.contains(policy)) { + policyList.add(policy); + } + } + } + } + + for (ToscaPolicy policy : policyList) { + LOGGER.info("using policy-" + policy.getName() + ":" + policy.getVersion() + ", type-" + policy.getType() + + ":" + policy.getTypeVersion()); + } + } + + @Test + public void testNullList() { + ToscaPolicyFilter filter = ToscaPolicyFilter.builder().build(); + + assertThatThrownBy(() -> { + filter.filter(null); + }).hasMessage("originalList is marked @NonNull but is null"); + } + + @Test + public void testFilterNothing() { + ToscaPolicyFilter filter = ToscaPolicyFilter.builder().build(); + + List<ToscaPolicy> filteredList = filter.filter(policyList); + assertTrue(filteredList.containsAll(policyList)); + } + + @Test + public void testFilterLatestVersion() { + ToscaPolicyFilter filter = ToscaPolicyFilter.builder().version(ToscaPolicyFilter.LATEST_VERSION).build(); + + List<ToscaPolicy> filteredList = filter.filter(policyList); + assertEquals(15, filteredList.size()); + assertEquals("1.0.0", filteredList.get(7).getVersion()); + assertEquals("1.0.0", filteredList.get(12).getVersion()); + + assertEquals(17, policyList.size()); + assertEquals(15, filteredList.size()); + + policyList.get(10).setVersion("2.0.0"); + policyList.get(16).setVersion("3.4.5"); + filteredList = filter.filter(policyList); + assertEquals(15, filteredList.size()); + assertEquals("2.0.0", filteredList.get(7).getVersion()); + assertEquals("3.4.5", filteredList.get(12).getVersion()); + + policyList.get(10).setVersion("1.0.0"); + policyList.get(16).setVersion("1.0.0"); + filteredList = filter.filter(policyList); + assertEquals(15, filteredList.size()); + assertEquals("1.0.0", filteredList.get(7).getVersion()); + assertEquals("1.0.0", filteredList.get(12).getVersion()); + } + + @Test + public void testFilterNameVersion() { + ToscaPolicyFilter filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").build(); + List<ToscaPolicy> filteredList = filter.filter(policyList); + assertEquals(2, filteredList.size()); + + filter = ToscaPolicyFilter.builder().name("guard.frequency.scaleout").build(); + filteredList = filter.filter(policyList); + assertEquals(2, filteredList.size()); + + filter = ToscaPolicyFilter.builder().name("guard.frequency.scalein").build(); + filteredList = filter.filter(policyList); + assertEquals(0, filteredList.size()); + + filter = ToscaPolicyFilter.builder().version("1.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(17, filteredList.size()); + + filter = ToscaPolicyFilter.builder().name("OSDF_CASABLANCA.SubscriberPolicy_v1").version("1.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(1, filteredList.size()); + + filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").version("1.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(2, filteredList.size()); + } + + @Test + public void testFilterTypeVersion() { + ToscaPolicyFilter filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").build(); + List<ToscaPolicy> filteredList = filter.filter(policyList); + assertEquals(4, filteredList.size()); + + filter = ToscaPolicyFilter.builder().type("onap.policies.monitoring.cdap.tca.hi.lo.app").build(); + filteredList = filter.filter(policyList); + assertEquals(2, filteredList.size()); + + filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.NonOperational").build(); + filteredList = filter.filter(policyList); + assertEquals(0, filteredList.size()); + + filter = ToscaPolicyFilter.builder().typeVersion("0.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(17, filteredList.size()); + + filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.HpaPolicy").typeVersion("0.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(1, filteredList.size()); + + filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").typeVersion("0.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(4, filteredList.size()); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyIdentifierOptVersion.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java index 999dca565..561b4fb21 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyIdentifierOptVersion.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java @@ -28,13 +28,13 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; /** - * Test the other constructors, as {@link TestPojos} tests the other methods. + * Test the other constructors, as {@link PojosTest} tests the other methods. */ -public class TestToscaPolicyIdentifierOptVersion extends ToscaIdentifierTestBase<ToscaPolicyIdentifierOptVersion> { +public class ToscaPolicyIdentifierOptVersionTest extends ToscaIdentifierTestBase<ToscaPolicyIdentifierOptVersion> { private static final String NAME = "my-name"; private static final String VERSION = "1.2.3"; - public TestToscaPolicyIdentifierOptVersion() { + public ToscaPolicyIdentifierOptVersionTest() { super(ToscaPolicyIdentifierOptVersion.class); } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyIdentifier.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java index 0dc9eb13c..a53af7b1f 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyIdentifier.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java @@ -26,13 +26,13 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; /** - * Test the other constructors, as {@link TestPojos} tests the other methods. + * Test the other constructors, as {@link PojosTest} tests the other methods. */ -public class TestToscaPolicyIdentifier extends ToscaIdentifierTestBase<ToscaPolicyIdentifier> { +public class ToscaPolicyIdentifierTest extends ToscaIdentifierTestBase<ToscaPolicyIdentifier> { private static final String NAME = "my-name"; private static final String VERSION = "1.2.3"; - public TestToscaPolicyIdentifier() { + public ToscaPolicyIdentifierTest() { super(ToscaPolicyIdentifier.class); } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicy.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java index 881a69d07..f5be66c4a 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicy.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java @@ -20,17 +20,25 @@ package org.onap.policy.models.tosca.authorative.concepts; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; +import java.util.LinkedHashMap; + import org.junit.Test; /** - * Tests methods not tested by {@link TestPojos}. + * Tests methods not tested by {@link PojosTest}. */ -public class TestToscaPolicy { +public class ToscaPolicyTest { @Test public void testGetIdentifier_testGetTypeIdentifier() { + assertThatThrownBy(() -> { + new ToscaPolicy(null); + }).hasMessage("copyObject is marked @NonNull but is null"); + + ToscaPolicy policy = new ToscaPolicy(); policy.setName("my_name"); @@ -45,5 +53,13 @@ public class TestToscaPolicy { ToscaPolicyTypeIdentifier type = policy.getTypeIdentifier(); assertEquals("my_type", type.getName()); assertEquals("3.2.1", type.getVersion()); + + ToscaPolicy clonedPolicy0 = new ToscaPolicy(policy); + assertEquals(0, policy.compareTo(clonedPolicy0)); + + policy.setProperties(new LinkedHashMap<String, Object>()); + policy.getProperties().put("PropertyKey", "PropertyValue"); + ToscaPolicy clonedPolicy1 = new ToscaPolicy(policy); + assertEquals(0, policy.compareTo(clonedPolicy1)); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java new file mode 100644 index 000000000..12d81ed53 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java @@ -0,0 +1,175 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.authorative.concepts; + +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.assertTrue; + +import com.google.gson.GsonBuilder; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; + +/** + * Test of the {@link ToscaPolicyTypeFilter} class. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaPolicyTypeFilterTest { + // Logger for this class + private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyTypeFilterTest.class); + + // @formatter:off + private static final String[] policyTypeResourceNames = { + "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml", + "policytypes/onap.policies.optimization.AffinityPolicy.yaml", + "policytypes/onap.policies.optimization.DistancePolicy.yaml", + "policytypes/onap.policies.optimization.HpaPolicy.yaml", + "policytypes/onap.policies.optimization.OptimizationPolicy.yaml", + "policytypes/onap.policies.optimization.PciPolicy.yaml", + "policytypes/onap.policies.optimization.QueryPolicy.yaml", + "policytypes/onap.policies.optimization.SubscriberPolicy.yaml", + "policytypes/onap.policies.optimization.Vim_fit.yaml", + "policytypes/onap.policies.optimization.VnfPolicy.yaml", + "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml" + }; + // @formatter:on + + private static List<ToscaPolicyType> typeList = new ArrayList<>(); + + /** + * Set up a Tosca Policy type list for filtering. + * + * @throws CoderException on JSON decoding errors + */ + @BeforeClass + public static void setupTypeList() throws CoderException { + for (String policyTypeResourceName : policyTypeResourceNames) { + String policyTypeString = ResourceUtils.getResourceAsString(policyTypeResourceName); + Object yamlObject = new Yaml().load(policyTypeString); + String yamlAsJsonString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject); + + ToscaServiceTemplate serviceTemplate = + new StandardCoder().decode(yamlAsJsonString, ToscaServiceTemplate.class); + assertNotNull(serviceTemplate); + + for (Map<String, ToscaPolicyType> foundPolicyTypeMap : serviceTemplate.getPolicyTypes()) { + for (Entry<String, ToscaPolicyType> policyTypeEntry : foundPolicyTypeMap.entrySet()) { + ToscaPolicyType policyType = policyTypeEntry.getValue(); + if (policyType.getName() == null) { + policyType.setName(policyTypeEntry.getKey()); + } + if (policyType.getVersion() == null) { + policyType.setVersion(PfKey.NULL_KEY_VERSION); + } + if (!typeList.contains(policyType)) { + typeList.add(policyType); + } + } + } + } + + for (ToscaPolicyType type : typeList) { + LOGGER.info("using policy type-" + type.getName() + ":" + type.getVersion()); + } + } + + @Test + public void testNullList() { + ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().build(); + + assertThatThrownBy(() -> { + filter.filter(null); + }).hasMessage("originalList is marked @NonNull but is null"); + } + + @Test + public void testFilterNothing() { + ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().build(); + + List<ToscaPolicyType> filteredList = filter.filter(typeList); + assertTrue(filteredList.containsAll(typeList)); + } + + @Test + public void testFilterLatestVersion() { + ToscaPolicyTypeFilter filter = + ToscaPolicyTypeFilter.builder().version(ToscaPolicyTypeFilter.LATEST_VERSION).build(); + + List<ToscaPolicyType> filteredList = filter.filter(typeList); + assertEquals(13, filteredList.size()); + assertEquals("1.0.0", filteredList.get(0).getVersion()); + assertEquals("0.0.0", filteredList.get(4).getVersion()); + + typeList.get(12).setVersion("2.0.0"); + filteredList = filter.filter(typeList); + assertEquals(13, filteredList.size()); + assertEquals("2.0.0", filteredList.get(0).getVersion()); + assertEquals("0.0.0", filteredList.get(4).getVersion()); + + typeList.get(12).setVersion("1.0.0"); + filteredList = filter.filter(typeList); + assertEquals(13, filteredList.size()); + assertEquals("1.0.0", filteredList.get(0).getVersion()); + assertEquals("0.0.0", filteredList.get(4).getVersion()); + } + + @Test + public void testFilterNameVersion() { + ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().name("onap.policies.Monitoring").build(); + List<ToscaPolicyType> filteredList = filter.filter(typeList); + assertEquals(2, filteredList.size()); + + filter = ToscaPolicyTypeFilter.builder().name("onap.policy.monitoring.cdap.tca.hi.lo.app").build(); + filteredList = filter.filter(typeList); + assertEquals(1, filteredList.size()); + + filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.LpaPolicy").build(); + filteredList = filter.filter(typeList); + assertEquals(0, filteredList.size()); + + filter = ToscaPolicyTypeFilter.builder().version("0.0.0").build(); + filteredList = filter.filter(typeList); + assertEquals(9, filteredList.size()); + + filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.Vim_fit").version("0.0.0").build(); + filteredList = filter.filter(typeList); + assertEquals(1, filteredList.size()); + + filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.Vim_fit").version("0.0.1").build(); + filteredList = filter.filter(typeList); + assertEquals(0, filteredList.size()); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyTypeIdentifier.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java index 778d60c09..8388f1061 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyTypeIdentifier.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java @@ -26,13 +26,13 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; /** - * Test the other constructors, as {@link TestPojos} tests the other methods. + * Test the other constructors, as {@link PojosTest} tests the other methods. */ -public class TestToscaPolicyTypeIdentifier extends ToscaIdentifierTestBase<ToscaPolicyTypeIdentifier> { +public class ToscaPolicyTypeIdentifierTest extends ToscaIdentifierTestBase<ToscaPolicyTypeIdentifier> { private static final String NAME = "my-name"; private static final String VERSION = "1.2.3"; - public TestToscaPolicyTypeIdentifier() { + public ToscaPolicyTypeIdentifierTest() { super(ToscaPolicyTypeIdentifier.class); } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java new file mode 100644 index 000000000..59a5a3336 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.authorative.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import java.util.LinkedHashMap; + +import org.junit.Test; + +/** + * Test of the {@link ToscaPolicyType} class. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaPolicyTypeTest { + + @Test + public void testToscaPolicyType() { + assertThatThrownBy(() -> { + new ToscaPolicyType(null); + }).hasMessage("copyObject is marked @NonNull but is null"); + + ToscaPolicyType tpt = new ToscaPolicyType(); + tpt.setName("AType"); + tpt.setVersion("1.2.3"); + tpt.setDerivedFrom("AParentType"); + tpt.setDescription("Desc"); + + ToscaPolicyType clonedTpt0 = new ToscaPolicyType(tpt); + assertEquals(0, tpt.compareTo(clonedTpt0)); + + tpt.setMetadata(new LinkedHashMap<>()); + tpt.setProperties(new LinkedHashMap<>()); + + tpt.getMetadata().put("MetaKey0", "Metavalue 0"); + + ToscaProperty tp = new ToscaProperty(); + tpt.getProperties().put("Property0", tp); + + ToscaPolicyType clonedTpt1 = new ToscaPolicyType(tpt); + assertEquals(0, tpt.compareTo(clonedTpt1)); + } +} |