diff options
author | Jim Hahn <jrh3@att.com> | 2020-02-10 12:31:03 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-02-10 12:31:03 +0000 |
commit | d98e90fef90fbbc79536825699d1ea980c28eb1a (patch) | |
tree | 81149f853069d5df5dd59f5314284b91c3f392c1 /models-tosca/src | |
parent | e06578535f6afadac715c04ed03c74c05a075780 (diff) | |
parent | 532202ce2d8bf83299b3775bba184fb5b3b50df7 (diff) |
Merge "Add data type and policy type reference checking"
Diffstat (limited to 'models-tosca/src')
12 files changed, 311 insertions, 125 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java index a664010b8..b7ebdcec3 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.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. @@ -58,8 +58,7 @@ public class LegacyGuardPolicyMapper static { GUARD_POLICY_TYPE_MAP.put("guard.frequency.", new PfConceptKey("onap.policies.controlloop.guard.FrequencyLimiter:1.0.0")); - GUARD_POLICY_TYPE_MAP.put("guard.minmax.", - new PfConceptKey("onap.policies.controlloop.guard.MinMax:1.0.0")); + GUARD_POLICY_TYPE_MAP.put("guard.minmax.", new PfConceptKey("onap.policies.controlloop.guard.MinMax:1.0.0")); GUARD_POLICY_TYPE_MAP.put("guard.blacklist.", new PfConceptKey("onap.policies.controlloop.guard.Blacklist:1.0.0")); } @@ -93,7 +92,7 @@ public class LegacyGuardPolicyMapper toscaPolicy.setMetadata(metadata); final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); - serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0"); + serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0_0"); serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); @@ -104,8 +103,8 @@ public class LegacyGuardPolicyMapper } @Override - public Map<String, LegacyGuardPolicyOutput> fromToscaServiceTemplate( - final JpaToscaServiceTemplate serviceTemplate) { + public Map<String, LegacyGuardPolicyOutput> + fromToscaServiceTemplate(final JpaToscaServiceTemplate serviceTemplate) { ToscaUtils.assertPoliciesExist(serviceTemplate); final Map<String, LegacyGuardPolicyOutput> legacyGuardPolicyOutputMap = new LinkedHashMap<>(); @@ -126,7 +125,7 @@ public class LegacyGuardPolicyMapper final Map<String, Object> metadata = new LinkedHashMap<>(toscaPolicy.getMetadata()); // if version exists, convert it to int - metadata.computeIfPresent(POLICY_VERSION, (key,val) -> Integer.parseInt(val.toString())); + metadata.computeIfPresent(POLICY_VERSION, (key, val) -> Integer.parseInt(val.toString())); legacyGuardPolicyOutput.setMetadata(metadata); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java index e7dabf1b8..41792aeb9 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.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. @@ -71,7 +71,7 @@ public class LegacyOperationalPolicyMapper toscaPolicy.getProperties().put(CONTENT_PROPERTY, legacyOperationalPolicy.getContent()); final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); - serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0"); + serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0_0"); serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); @@ -105,7 +105,7 @@ public class LegacyOperationalPolicyMapper throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); } - String content = toscaPolicy.getProperties().get(CONTENT_PROPERTY); + String content = toscaPolicy.getProperties().get(CONTENT_PROPERTY); if (content == null) { String errorMessage = "property \"content\" not defined on TOSCA policy"; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java index 37e92b58a..43d7ad633 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java @@ -3,7 +3,7 @@ * ONAP Policy Model * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications 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. @@ -23,19 +23,26 @@ package org.onap.policy.models.tosca.simple.concepts; +import java.util.Collection; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; + import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.Lob; import javax.persistence.Table; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; + +import org.apache.commons.collections4.CollectionUtils; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; @@ -47,6 +54,7 @@ import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.base.PfValidationResult.ValidationResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; +import org.onap.policy.models.tosca.utils.ToscaUtils; /** * Class to represent the policy type in TOSCA definition. @@ -298,4 +306,29 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl return PfUtils.compareObjects(triggers, other.triggers); } + + /** + * Get the data types referenced in a policy type. + * + * @return the data types referenced in a policy type + */ + public Collection<PfConceptKey> getReferencedDataTypes() { + if (properties == null) { + return CollectionUtils.emptyCollection(); + } + + Set<PfConceptKey> referencedDataTypes = new LinkedHashSet<>(); + + for (JpaToscaProperty property : properties.values()) { + referencedDataTypes.add(property.getType()); + + if (property.getEntrySchema() != null) { + referencedDataTypes.add(property.getEntrySchema().getType()); + } + } + + referencedDataTypes.removeAll(ToscaUtils.getPredefinedDataTypes()); + + return referencedDataTypes; + } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java index f6139ab2d..786784c09 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java @@ -272,7 +272,18 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp result = policyTypes.validate(result); } - return (topologyTemplate != null ? topologyTemplate.validate(result) : result); + if (topologyTemplate != null) { + result = topologyTemplate.validate(result); + } + + // No point in validating cross references if the structure of the individual parts are not valid + if (!result.isOk()) { + return result; + } + + validateDatatypesInPolicyTypes(result); + + return validatePolicyTypesInPolicies(result); } @Override @@ -321,4 +332,57 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp return ObjectUtils.compare(toscaDefinitionsVersion, other.toscaDefinitionsVersion); } + + /** + * Validate that all data types referenced in policy types exist. + * + * @param result the validation result object to use for the validation result + * @return the validation result object + */ + private PfValidationResult validateDatatypesInPolicyTypes(final PfValidationResult result) { + if (policyTypes == null) { + return result; + } + + for (JpaToscaPolicyType policyType : policyTypes.getAll(null)) { + for (PfConceptKey datatypeKey : policyType.getReferencedDataTypes()) { + if (dataTypes == null || dataTypes.get(datatypeKey) == null) { + result.addValidationMessage( + new PfValidationMessage(policyType.getKey(), this.getClass(), ValidationResult.INVALID, + "data type " + datatypeKey + " referenced in policy type not found")); + } + } + } + + return result; + } + + /** + * Validate that all policy types referenced in policies exist. + * + * @param result the validation result object to use for the validation result + * @return the validation result object + */ + private PfValidationResult validatePolicyTypesInPolicies(PfValidationResult result) { + if (topologyTemplate == null || topologyTemplate.getPolicies() == null) { + return result; + } + + if (policyTypes == null) { + result.addValidationMessage(new PfValidationMessage(this.getKey(), this.getClass(), + ValidationResult.INVALID, + "no policy types are defined on the service template for the policies in the topology template")); + return result; + } + + for (JpaToscaPolicy policy : topologyTemplate.getPolicies().getAll(null)) { + if (policyTypes.get(policy.getType()) == null) { + result.addValidationMessage( + new PfValidationMessage(policy.getKey(), this.getClass(), ValidationResult.INVALID, + "policy type " + policy.getType().getId() + " referenced in policy not found")); + } + } + + return result; + } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java index 7e106fa53..fffad86e0 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java @@ -21,6 +21,7 @@ package org.onap.policy.models.tosca.utils; import java.util.Collection; +import java.util.LinkedHashSet; import java.util.Set; import java.util.function.Function; @@ -32,6 +33,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptContainer; import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.base.PfNameVersion; import org.onap.policy.models.base.PfValidationMessage; @@ -52,6 +54,21 @@ public final class ToscaUtils { private static final String ROOT_KEY_NAME_SUFFIX = ".Root"; + private static final Set<PfConceptKey> PREDEFINED_TOSCA_DATA_TYPES = new LinkedHashSet<>(); + + // @formatter:off + static { + PREDEFINED_TOSCA_DATA_TYPES.add(new PfConceptKey("string", PfKey.NULL_KEY_VERSION)); + PREDEFINED_TOSCA_DATA_TYPES.add(new PfConceptKey("integer", PfKey.NULL_KEY_VERSION)); + PREDEFINED_TOSCA_DATA_TYPES.add(new PfConceptKey("float", PfKey.NULL_KEY_VERSION)); + PREDEFINED_TOSCA_DATA_TYPES.add(new PfConceptKey("boolean", PfKey.NULL_KEY_VERSION)); + PREDEFINED_TOSCA_DATA_TYPES.add(new PfConceptKey("timestamp", PfKey.NULL_KEY_VERSION)); + PREDEFINED_TOSCA_DATA_TYPES.add(new PfConceptKey("null", PfKey.NULL_KEY_VERSION)); + PREDEFINED_TOSCA_DATA_TYPES.add(new PfConceptKey("list", PfKey.NULL_KEY_VERSION)); + PREDEFINED_TOSCA_DATA_TYPES.add(new PfConceptKey("map", PfKey.NULL_KEY_VERSION)); + } + // @formatter:off + /** * Private constructor to prevent subclassing. */ @@ -218,4 +235,13 @@ public final class ToscaUtils { } return ancestorEntitySet; } + + /** + * Get the predefined policy types. + * + * @return the predefined policy types + */ + public static Collection<?> getPredefinedDataTypes() { + return PREDEFINED_TOSCA_DATA_TYPES; + } } 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 index 64c3b1365..0bf371022 100644 --- 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 @@ -231,7 +231,7 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().typeVersion(VERSION_000).build(); filteredList = filter.filter(policyList); - assertEquals(7, filteredList.size()); + assertEquals(4, filteredList.size()); filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.resource.HpaPolicy") .typeVersion(VERSION_100).build(); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java index 82f75a721..a1a080df0 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java @@ -3,7 +3,7 @@ * ONAP Policy Model * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications 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. @@ -29,11 +29,13 @@ import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.utils.ToscaServiceTemplateUtils; import org.yaml.snakeyaml.Yaml; /** @@ -44,6 +46,7 @@ import org.yaml.snakeyaml.Yaml; public class ToscaServiceTemplateMappingTest { private StandardCoder standardCoder; + private YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator(); @Before public void setUp() { @@ -52,14 +55,25 @@ public class ToscaServiceTemplateMappingTest { @Test public void testPlainToscaPolicies() throws Exception { - String inputJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"); + String policyTypeInputJson = + ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"); + ToscaServiceTemplate plainPolicyTypes = + yamlJsonTranslator.fromYaml(policyTypeInputJson, ToscaServiceTemplate.class); - ToscaServiceTemplate plainPolicies = standardCoder.decode(inputJson, ToscaServiceTemplate.class); - JpaToscaServiceTemplate internalPolicies = new JpaToscaServiceTemplate(); - internalPolicies.fromAuthorative(plainPolicies); + String policyInputJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"); + ToscaServiceTemplate plainPolicies = standardCoder.decode(policyInputJson, ToscaServiceTemplate.class); - assertTrue(internalPolicies.validate(new PfValidationResult()).isValid()); - ToscaServiceTemplate plainPolicies2 = internalPolicies.toAuthorative(); + JpaToscaServiceTemplate policyTypeServiceTemplate = new JpaToscaServiceTemplate(); + policyTypeServiceTemplate.fromAuthorative(plainPolicyTypes); + + JpaToscaServiceTemplate policyFragmentServiceTemplate = new JpaToscaServiceTemplate(); + policyFragmentServiceTemplate.fromAuthorative(plainPolicies); + + JpaToscaServiceTemplate internalServiceTemplate = + ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, policyFragmentServiceTemplate); + + assertTrue(internalServiceTemplate.validate(new PfValidationResult()).isValid()); + ToscaServiceTemplate plainPolicies2 = internalServiceTemplate.toAuthorative(); ToscaPolicy pp1 = plainPolicies.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next(); ToscaPolicy pp2 = plainPolicies2.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next(); @@ -70,13 +84,12 @@ public class ToscaServiceTemplateMappingTest { @Test public void testPlainToscaPolicyTypes() throws Exception { Yaml yaml = new Yaml(); - String inputYaml = ResourceUtils.getResourceAsString( - "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"); + String inputYaml = + ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"); Object yamlObject = yaml.load(inputYaml); String yamlAsJsonString = standardCoder.encode(yamlObject); - ToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString, - ToscaServiceTemplate.class); + ToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); JpaToscaServiceTemplate internalPolicyTypes = new JpaToscaServiceTemplate(); internalPolicyTypes.fromAuthorative(plainPolicyTypes); assertTrue(internalPolicyTypes.validate(new PfValidationResult()).isValid()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java index e9761c669..0aa1da0d7 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.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"); @@ -31,15 +31,17 @@ import java.util.LinkedHashMap; import org.junit.Before; import org.junit.Test; import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; -import org.onap.policy.models.tosca.legacy.mapping.LegacyOperationalPolicyMapper; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; +import org.onap.policy.models.tosca.utils.ToscaServiceTemplateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,6 +55,7 @@ public class LegacyOperationalPolicyMapperTest { private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicyMapperTest.class); private StandardCoder standardCoder; + private YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator(); @Before public void setUp() { @@ -61,14 +64,23 @@ public class LegacyOperationalPolicyMapperTest { @Test public void testJsonDeserialization() throws Exception { - String vcpePolicyJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"); + String policyTypeInputJson = + ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml"); + ToscaServiceTemplate policyTypes = yamlJsonTranslator.fromYaml(policyTypeInputJson, ToscaServiceTemplate.class); + + JpaToscaServiceTemplate policyTypeServiceTemplate = new JpaToscaServiceTemplate(); + policyTypeServiceTemplate.fromAuthorative(policyTypes); + String vcpePolicyJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"); LegacyOperationalPolicy legacyOperationalPolicy = standardCoder.decode(vcpePolicyJson, LegacyOperationalPolicy.class); - JpaToscaServiceTemplate serviceTemplate = + JpaToscaServiceTemplate legacyPolicyFragmentServiceTemplate = new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy); + JpaToscaServiceTemplate serviceTemplate = + ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, legacyPolicyFragmentServiceTemplate); + assertNotNull(serviceTemplate); LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString()); assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java index 2ed03fa8d..a7ca3cc8b 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java @@ -35,6 +35,7 @@ import java.util.Map; import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; @@ -187,4 +188,53 @@ public class JpaToscaPolicyTypeTest { assertNotNull(new JpaToscaEntityType<ToscaPolicyType>(new ToscaPolicyType())); } + + @Test + public void testGetReferencedDataTypes() { + JpaToscaPolicyType pt0 = new JpaToscaPolicyType(new PfConceptKey("pt0", "0.0.1")); + + assertTrue(pt0.getReferencedDataTypes().isEmpty()); + + pt0.setProperties(new LinkedHashMap<>()); + assertTrue(pt0.getReferencedDataTypes().isEmpty()); + + JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop0")); + prop0.setType(new PfConceptKey("string", PfKey.NULL_KEY_VERSION)); + assertTrue(prop0.validate(new PfValidationResult()).isValid()); + + pt0.getProperties().put(prop0.getKey().getLocalName(), prop0); + assertTrue(pt0.getReferencedDataTypes().isEmpty()); + + JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop1")); + prop1.setType(new PfConceptKey("the.property.Type0", "0.0.1")); + assertTrue(prop1.validate(new PfValidationResult()).isValid()); + + pt0.getProperties().put(prop1.getKey().getLocalName(), prop1); + assertEquals(1, pt0.getReferencedDataTypes().size()); + + JpaToscaProperty prop2 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop2")); + prop2.setType(new PfConceptKey("the.property.Type0", "0.0.1")); + assertTrue(prop2.validate(new PfValidationResult()).isValid()); + + pt0.getProperties().put(prop2.getKey().getLocalName(), prop2); + assertEquals(1, pt0.getReferencedDataTypes().size()); + + JpaToscaProperty prop3 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop4")); + prop3.setType(new PfConceptKey("the.property.Type1", "0.0.1")); + prop3.setEntrySchema(new JpaToscaEntrySchema()); + prop3.getEntrySchema().setType(new PfConceptKey("the.property.Type3", "0.0.1")); + assertTrue(prop3.validate(new PfValidationResult()).isValid()); + + pt0.getProperties().put(prop3.getKey().getLocalName(), prop3); + assertEquals(3, pt0.getReferencedDataTypes().size()); + + JpaToscaProperty prop4 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop4")); + prop4.setType(new PfConceptKey("the.property.Type1", "0.0.1")); + prop4.setEntrySchema(new JpaToscaEntrySchema()); + prop4.getEntrySchema().setType(new PfConceptKey("the.property.Type2", "0.0.1")); + assertTrue(prop4.validate(new PfValidationResult()).isValid()); + + pt0.getProperties().put(prop4.getKey().getLocalName(), prop4); + assertEquals(3, pt0.getReferencedDataTypes().size()); + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java index f5722dded..f6f1b2c42 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,16 +31,18 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import java.util.Map; -import org.junit.Before; + 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.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.utils.ToscaServiceTemplateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; @@ -90,30 +92,40 @@ public class MonitoringPolicySerializationTest { private static final String VFW_MON_INPUT_JSON = "policies/vFirewall.policy.monitoring.input.tosca.json"; private static final String VFW_MON_INPUT_YAML = "policies/vFirewall.policy.monitoring.input.tosca.yaml"; - private StandardCoder standardCoder; - - @Before - public void setUp() { - standardCoder = new StandardCoder(); - } + private StandardCoder standardCoder = new StandardCoder(); + private YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator(); @Test public void testDeserialization() throws Exception { + String policyTypeInputJson = + ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"); + ToscaServiceTemplate plainPolicyTypes = + yamlJsonTranslator.fromYaml(policyTypeInputJson, ToscaServiceTemplate.class); + + JpaToscaServiceTemplate policyTypeServiceTemplate = new JpaToscaServiceTemplate(); + policyTypeServiceTemplate.fromAuthorative(plainPolicyTypes); + // vCPE JpaToscaServiceTemplate serviceTemplateFromJson = deserializeMonitoringInputJson(VCPE_MON_INPUT_JSON); - verifyVcpeMonitoringInputDeserialization(serviceTemplateFromJson); + JpaToscaServiceTemplate mergedServiceTemplate = + ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, serviceTemplateFromJson); + verifyVcpeMonitoringInputDeserialization(mergedServiceTemplate); JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(VCPE_MON_INPUT_YAML); assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0); // vDNS serviceTemplateFromJson = deserializeMonitoringInputJson(VDNS_MON_INPUT_JSON); - verifyVdnsMonitoringInputDeserialization(serviceTemplateFromJson); + mergedServiceTemplate = + ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, serviceTemplateFromJson); + verifyVdnsMonitoringInputDeserialization(mergedServiceTemplate); serviceTemplateFromYaml = deserializeMonitoringInputYaml(VDNS_MON_INPUT_YAML); assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0); // vFirewall serviceTemplateFromJson = deserializeMonitoringInputJson(VFW_MON_INPUT_JSON); - verifyVfwMonitoringInputDeserialization(serviceTemplateFromJson); + mergedServiceTemplate = + ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, serviceTemplateFromJson); + verifyVfwMonitoringInputDeserialization(mergedServiceTemplate); serviceTemplateFromYaml = deserializeMonitoringInputYaml(VFW_MON_INPUT_YAML); assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0); } @@ -142,8 +154,7 @@ public class MonitoringPolicySerializationTest { } } - private JpaToscaServiceTemplate deserializeMonitoringInputJson(String resourcePath) - throws Exception { + private JpaToscaServiceTemplate deserializeMonitoringInputJson(String resourcePath) throws Exception { String policyJson = ResourceUtils.getResourceAsString(resourcePath); ToscaServiceTemplate serviceTemplate = standardCoder.decode(policyJson, ToscaServiceTemplate.class); @@ -152,8 +163,7 @@ public class MonitoringPolicySerializationTest { return jpaToscaServiceTemplate; } - private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) - throws Exception { + private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws Exception { Yaml yaml = new Yaml(); String policyYaml = ResourceUtils.getResourceAsString(resourcePath); @@ -178,11 +188,10 @@ public class MonitoringPolicySerializationTest { assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); // Check tosca_definitions_version - assertEquals(YAML_VERSION, - serviceTemplate.getToscaDefinitionsVersion()); + assertEquals(YAML_VERSION, serviceTemplate.getToscaDefinitionsVersion()); - Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = serviceTemplate.getTopologyTemplate() - .getPolicies().getConceptMap(); + Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = + serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap(); // Check policies assertTrue(policiesConceptMap.size() == 1); @@ -211,11 +220,10 @@ public class MonitoringPolicySerializationTest { assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); // Check tosca_definitions_version - assertEquals(YAML_VERSION, - serviceTemplate.getToscaDefinitionsVersion()); + assertEquals(YAML_VERSION, serviceTemplate.getToscaDefinitionsVersion()); - Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = serviceTemplate.getTopologyTemplate() - .getPolicies().getConceptMap(); + Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = + serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap(); // Check policies assertTrue(policiesConceptMap.size() == 1); @@ -244,11 +252,10 @@ public class MonitoringPolicySerializationTest { assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); // Check tosca_definitions_version - assertEquals(YAML_VERSION, - serviceTemplate.getToscaDefinitionsVersion()); + assertEquals(YAML_VERSION, serviceTemplate.getToscaDefinitionsVersion()); - Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = serviceTemplate.getTopologyTemplate() - .getPolicies().getConceptMap(); + Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = + serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap(); // Check policies assertTrue(policiesConceptMap.size() == 1); @@ -272,10 +279,8 @@ public class MonitoringPolicySerializationTest { private void verifyVcpeMonitoringOutputserialization(String serializedServiceTemplate) { JsonObject serviceTemplateJsonObject = new JsonParser().parse(serializedServiceTemplate).getAsJsonObject(); - assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION) - .getAsString()); - JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE) - .getAsJsonObject(); + assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION).getAsString()); + JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE).getAsJsonObject(); JsonArray policiesJsonArray = topologyTemplateJsonObject.get(POLICIES).getAsJsonArray(); assertTrue(policiesJsonArray.size() == 1); JsonObject policy = policiesJsonArray.iterator().next().getAsJsonObject(); @@ -283,8 +288,7 @@ public class MonitoringPolicySerializationTest { JsonObject policyVal = policy.get(POLICY1).getAsJsonObject(); assertEquals(TYPE1, policyVal.get("type").getAsString()); assertEquals(VERSION_100, policyVal.get(VERSION).getAsString()); - assertEquals(POLICY1, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID) - .getAsString()); + assertEquals(POLICY1, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID).getAsString()); JsonObject properties = policyVal.get(PROPERTIES2).getAsJsonObject(); assertNotNull(properties.get(TCA_POLICY)); } @@ -292,8 +296,7 @@ public class MonitoringPolicySerializationTest { private void verifyVdnsMonitoringOutputserialization(String serializedServiceTemplate) { JsonObject serviceTemplateJsonObject = new JsonParser().parse(serializedServiceTemplate).getAsJsonObject(); - assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION) - .getAsString()); + assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION).getAsString()); JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE).getAsJsonObject(); JsonArray policiesJsonArray = topologyTemplateJsonObject.get(POLICIES).getAsJsonArray(); assertTrue(policiesJsonArray.size() == 1); @@ -302,8 +305,7 @@ public class MonitoringPolicySerializationTest { JsonObject policyVal = policy.get(POLICY2).getAsJsonObject(); assertEquals(TYPE1, policyVal.get("type").getAsString()); assertEquals(VERSION_100, policyVal.get(VERSION).getAsString()); - assertEquals(POLICY2, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID) - .getAsString()); + assertEquals(POLICY2, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID).getAsString()); JsonObject properties = policyVal.get(PROPERTIES2).getAsJsonObject(); assertNotNull(properties.get(TCA_POLICY)); } @@ -311,8 +313,7 @@ public class MonitoringPolicySerializationTest { private void verifyVfwMonitoringOutputserialization(String serializedServiceTemplate) { JsonObject serviceTemplateJsonObject = new JsonParser().parse(serializedServiceTemplate).getAsJsonObject(); - assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION) - .getAsString()); + assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION).getAsString()); JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE).getAsJsonObject(); JsonArray policiesJsonArray = topologyTemplateJsonObject.get(POLICIES).getAsJsonArray(); assertTrue(policiesJsonArray.size() == 1); @@ -321,8 +322,7 @@ public class MonitoringPolicySerializationTest { JsonObject policyVal = policy.get(POLICY3).getAsJsonObject(); assertEquals(TYPE1, policyVal.get("type").getAsString()); assertEquals(VERSION_100, policyVal.get(VERSION).getAsString()); - assertEquals(POLICY3, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID) - .getAsString()); + assertEquals(POLICY3, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID).getAsString()); JsonObject properties = policyVal.get(PROPERTIES2).getAsJsonObject(); assertNotNull(properties.get(TCA_POLICY)); } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java index 20ba756e9..01a52f7bd 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,11 +24,11 @@ package org.onap.policy.models.tosca.simple.serialization; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; + import org.junit.Before; import org.junit.Test; import org.onap.policy.common.utils.coder.CoderException; @@ -98,37 +98,31 @@ public class MonitoringPolicyTypeSerializationTest { } @Test - public void testSerialization() { - try { - // TCA - JpaToscaServiceTemplate tcaServiceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML); - String serializedServiceTemplateTca = serializeMonitoringServiceTemplate(tcaServiceTemplateFromYaml); - - ToscaServiceTemplate toscaServiceTemplateFromJsonTca = - coder.decode(serializedServiceTemplateTca, ToscaServiceTemplate.class); - - JpaToscaServiceTemplate serviceTemplateFromJsonTca = new JpaToscaServiceTemplate(); - serviceTemplateFromJsonTca.fromAuthorative(toscaServiceTemplateFromJsonTca); - String serializedServiceTemplateTcaOut = serializeMonitoringServiceTemplate(serviceTemplateFromJsonTca); - assertEquals(serializedServiceTemplateTca, serializedServiceTemplateTcaOut); - - // Collector - JpaToscaServiceTemplate collectorServiceTemplateFromYaml = - deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML); - String serializedServiceTemplateCollector = - serializeMonitoringServiceTemplate(collectorServiceTemplateFromYaml); - ToscaServiceTemplate toscaServiceTemplateFromJsonCollector = - coder.decode(serializedServiceTemplateCollector, ToscaServiceTemplate.class); - JpaToscaServiceTemplate serviceTemplateFromJsonCollector = new JpaToscaServiceTemplate(); - serviceTemplateFromJsonCollector.fromAuthorative(toscaServiceTemplateFromJsonCollector); - String serializedServiceTemplateCollectorsOut = - serializeMonitoringServiceTemplate(serviceTemplateFromJsonCollector); - assertEquals(serializedServiceTemplateCollector, serializedServiceTemplateCollectorsOut); - - } catch (Exception e) { - LOGGER.warn("No exception should be thrown", e); - fail("No exception should be thrown"); - } + public void testSerialization() throws Exception { + // TCA + JpaToscaServiceTemplate tcaServiceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML); + String serializedServiceTemplateTca = serializeMonitoringServiceTemplate(tcaServiceTemplateFromYaml); + + ToscaServiceTemplate toscaServiceTemplateFromJsonTca = + coder.decode(serializedServiceTemplateTca, ToscaServiceTemplate.class); + + JpaToscaServiceTemplate serviceTemplateFromJsonTca = new JpaToscaServiceTemplate(); + serviceTemplateFromJsonTca.fromAuthorative(toscaServiceTemplateFromJsonTca); + String serializedServiceTemplateTcaOut = serializeMonitoringServiceTemplate(serviceTemplateFromJsonTca); + assertEquals(serializedServiceTemplateTca, serializedServiceTemplateTcaOut); + + // Collector + JpaToscaServiceTemplate collectorServiceTemplateFromYaml = + deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML); + String serializedServiceTemplateCollector = + serializeMonitoringServiceTemplate(collectorServiceTemplateFromYaml); + ToscaServiceTemplate toscaServiceTemplateFromJsonCollector = + coder.decode(serializedServiceTemplateCollector, ToscaServiceTemplate.class); + JpaToscaServiceTemplate serviceTemplateFromJsonCollector = new JpaToscaServiceTemplate(); + serviceTemplateFromJsonCollector.fromAuthorative(toscaServiceTemplateFromJsonCollector); + String serializedServiceTemplateCollectorsOut = + serializeMonitoringServiceTemplate(serviceTemplateFromJsonCollector); + assertEquals(serializedServiceTemplateCollector, serializedServiceTemplateCollectorsOut); } private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws Exception { @@ -196,8 +190,7 @@ public class MonitoringPolicyTypeSerializationTest { Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().values().iterator(); JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next(); - assertEquals(METRICS, - firstDataTypeFirstProperty.getKey().getParentKeyName()); + assertEquals(METRICS, firstDataTypeFirstProperty.getKey().getParentKeyName()); assertEquals("controlLoopSchemaType", firstDataTypeFirstProperty.getKey().getLocalName()); assertEquals(STRING_TEXT, firstDataTypeFirstProperty.getType().getName()); assertTrue(firstDataTypeFirstProperty.isRequired()); @@ -210,47 +203,41 @@ public class MonitoringPolicyTypeSerializationTest { .getValidValues().size() == 2); JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next(); - assertEquals(METRICS, - firstDataTypeSecondProperty.getKey().getParentKeyName()); + assertEquals(METRICS, firstDataTypeSecondProperty.getKey().getParentKeyName()); assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName()); assertEquals(STRING_TEXT, firstDataTypeSecondProperty.getType().getName()); assertTrue(firstDataTypeSecondProperty.isRequired()); assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty.getDescription()); JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next(); - assertEquals(METRICS, - firstDataTypeThirdProperty.getKey().getParentKeyName()); + assertEquals(METRICS, firstDataTypeThirdProperty.getKey().getParentKeyName()); assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName()); assertEquals(STRING_TEXT, firstDataTypeThirdProperty.getType().getName()); assertTrue(firstDataTypeThirdProperty.isRequired()); assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription()); JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next(); - assertEquals(METRICS, - firstDataTypeFourthProperty.getKey().getParentKeyName()); + assertEquals(METRICS, firstDataTypeFourthProperty.getKey().getParentKeyName()); assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName()); assertEquals(STRING_TEXT, firstDataTypeFourthProperty.getType().getName()); assertTrue(firstDataTypeFourthProperty.isRequired()); assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription()); JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next(); - assertEquals(METRICS, - firstDataTypeFifthProperty.getKey().getParentKeyName()); + assertEquals(METRICS, firstDataTypeFifthProperty.getKey().getParentKeyName()); assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName()); assertEquals(STRING_TEXT, firstDataTypeFifthProperty.getType().getName()); assertTrue(firstDataTypeFifthProperty.isRequired()); assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription()); JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next(); - assertEquals(METRICS, - firstDataTypeSixthProperty.getKey().getParentKeyName()); + assertEquals(METRICS, firstDataTypeSixthProperty.getKey().getParentKeyName()); assertEquals("thresholds", firstDataTypeSixthProperty.getKey().getLocalName()); assertEquals("list", firstDataTypeSixthProperty.getType().getName()); assertTrue(firstDataTypeSixthProperty.isRequired()); assertEquals("Thresholds associated with eventName", firstDataTypeSixthProperty.getDescription()); assertNotNull(firstDataTypeSixthProperty.getEntrySchema()); - assertEquals(THRESHOLDS, - firstDataTypeSixthProperty.getEntrySchema().getType().getName()); + assertEquals(THRESHOLDS, firstDataTypeSixthProperty.getEntrySchema().getType().getName()); Entry<PfConceptKey, JpaToscaDataType> secondDataType = dataTypesIter.next(); assertEquals(TCA, secondDataType.getKey().getName()); @@ -281,8 +268,7 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("Contains eventName and threshold details that need to be applied to given eventName", secondDataTypeSecondProperty.getDescription()); assertNotNull(secondDataTypeSecondProperty.getEntrySchema()); - assertEquals(METRICS, - secondDataTypeSecondProperty.getEntrySchema().getType().getName()); + assertEquals(METRICS, secondDataTypeSecondProperty.getEntrySchema().getType().getName()); Entry<PfConceptKey, JpaToscaDataType> thirdDataType = dataTypesIter.next(); assertEquals(THRESHOLDS, thirdDataType.getKey().getName()); @@ -352,7 +338,8 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("JpaToscaConstraintValidValues(validValues=[CRITICAL, MAJOR, MINOR, WARNING, NORMAL])", thirdDataTypeFifthProperty.getConstraints().iterator().next().toString()); assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next())) - .getValidValues().size() == 5);; + .getValidValues().size() == 5); + ; JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next(); assertEquals(THRESHOLDS, thirdDataTypeSixthProperty.getKey().getParentKeyName()); @@ -393,8 +380,7 @@ public class MonitoringPolicyTypeSerializationTest { firstPolicyType.getValue().getDescription()); Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next(); - assertEquals(DCAE, - secondPolicyType.getKey().getName()); + assertEquals(DCAE, secondPolicyType.getKey().getName()); assertEquals(VERSION_100, secondPolicyType.getKey().getVersion()); assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName()); assertTrue(secondPolicyType.getValue().getProperties().size() == 2); @@ -402,16 +388,14 @@ public class MonitoringPolicyTypeSerializationTest { Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator(); JpaToscaProperty firstProperty = propertiesIter.next(); - assertEquals(DCAE, - firstProperty.getKey().getParentKeyName()); + assertEquals(DCAE, firstProperty.getKey().getParentKeyName()); assertEquals(VERSION_100, firstProperty.getKey().getParentKeyVersion()); assertEquals("buscontroller_feed_publishing_endpoint", firstProperty.getKey().getLocalName()); assertEquals(STRING_TEXT, firstProperty.getType().getName()); assertEquals("DMAAP Bus Controller feed endpoint", firstProperty.getDescription()); JpaToscaProperty secondProperty = propertiesIter.next(); - assertEquals(DCAE, - secondProperty.getKey().getParentKeyName()); + assertEquals(DCAE, secondProperty.getKey().getParentKeyName()); assertEquals(VERSION_100, secondProperty.getKey().getParentKeyVersion()); assertEquals("datafile.policy", secondProperty.getKey().getLocalName()); assertEquals(STRING_TEXT, secondProperty.getType().getName()); 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 ecd066a14..a5568bab8 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 @@ -243,4 +243,9 @@ public class ToscaUtilsTest { assertFalse(result.isValid()); assertTrue(result.toString().contains("parent dt1:0.0.1 of entity not found")); } + + @Test + public void testGetPredefinedDataTypes() { + assertTrue(ToscaUtils.getPredefinedDataTypes().contains(new PfConceptKey("string", PfKey.NULL_KEY_VERSION))); + } } |