diff options
Diffstat (limited to 'models-tosca/src')
16 files changed, 103 insertions, 60 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java index 6e60303a0..a65cdbe69 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java @@ -423,6 +423,7 @@ public class AuthorativeToscaProvider { */ private <T extends ToscaEntity> List<T> handlePfModelRuntimeException(final PfModelRuntimeException pfme) { if (Status.NOT_FOUND.equals(pfme.getErrorResponse().getResponseCode())) { + LOGGER.trace("request did not find any results", pfme); return Collections.emptyList(); } else { throw pfme; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java index f5335fe79..09cc6c0ca 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java @@ -93,13 +93,13 @@ public class LegacyProvider { LOGGER.debug("->createOperationalPolicy: legacyOperationalPolicy={}", legacyOperationalPolicy); - JpaToscaServiceTemplate incomingServiceTemplate = + JpaToscaServiceTemplate legacyOperationalServiceTemplate = new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy); - JpaToscaServiceTemplate outgoingingServiceTemplate = - new SimpleToscaProvider().createPolicies(dao, incomingServiceTemplate); + + new SimpleToscaProvider().createPolicies(dao, legacyOperationalServiceTemplate); LegacyOperationalPolicy createdLegacyOperationalPolicy = - new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(outgoingingServiceTemplate); + new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(legacyOperationalServiceTemplate); LOGGER.debug("<-createOperationalPolicy: createdLegacyOperationalPolicy={}", createdLegacyOperationalPolicy); return createdLegacyOperationalPolicy; @@ -223,7 +223,6 @@ public class LegacyProvider { return updatedLegacyGuardPolicyMap; } - /** * Delete legacy guard policy. * diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java index 2816df004..b500a8bc9 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java @@ -261,6 +261,11 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { PfValidationResult result = super.validate(resultIn); + if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) { + result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, + "key version is a null version")); + } + if (type == null || type.isNullKey()) { result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, "type is null or a null key")); 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 b068beaa0..423620dd7 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 @@ -203,6 +203,11 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { PfValidationResult result = super.validate(resultIn); + if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) { + result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, + "key version is a null version")); + } + if (properties != null) { result = validateProperties(result); } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java index 9c7d6d305..c537bbcb5 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java @@ -106,7 +106,7 @@ public class SimpleToscaProvider { PfValidationResult result = serviceTemplateToWrite.validate(new PfValidationResult()); if (!result.isValid()) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, result.toString()); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.toString()); } new SimpleToscaServiceTemplateProvider().write(dao, serviceTemplateToWrite); @@ -264,6 +264,9 @@ public class SimpleToscaProvider { "policy types for " + name + ":" + version + DO_NOT_EXIST); } + JpaToscaServiceTemplate dataTypeServiceTemplate = new JpaToscaServiceTemplate(serviceTemplate); + dataTypeServiceTemplate.setPolicyTypes(null); + for (JpaToscaPolicyType policyType : serviceTemplate.getPolicyTypes().getConceptMap().values()) { Collection<PfConceptKey> referencedDataTypeKeys = policyType.getReferencedDataTypes(); @@ -271,11 +274,13 @@ public class SimpleToscaProvider { JpaToscaServiceTemplate dataTypeEntityTreeServiceTemplate = getDataTypes(dao, referencedDataTypeKey.getName(), referencedDataTypeKey.getVersion()); - serviceTemplate = - ToscaServiceTemplateUtils.addFragment(serviceTemplate, dataTypeEntityTreeServiceTemplate); + dataTypeServiceTemplate = ToscaServiceTemplateUtils.addFragment(dataTypeServiceTemplate, + dataTypeEntityTreeServiceTemplate); } } + serviceTemplate = ToscaServiceTemplateUtils.addFragment(serviceTemplate, dataTypeServiceTemplate); + LOGGER.debug("<-getPolicyTypes: name={}, version={}, serviceTemplate={}", name, version, serviceTemplate); return serviceTemplate; } @@ -372,7 +377,11 @@ public class SimpleToscaProvider { throws PfModelException { LOGGER.debug("->getPolicies: name={}, version={}", name, version); - JpaToscaServiceTemplate serviceTemplate = getServiceTemplate(dao); + JpaToscaServiceTemplate dbServiceTemplate = getServiceTemplate(dao); + + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(dbServiceTemplate); + serviceTemplate.setDataTypes(new JpaToscaDataTypes()); + serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); if (!ToscaUtils.doPoliciesExist(serviceTemplate)) { throw new PfModelRuntimeException(Response.Status.NOT_FOUND, @@ -386,18 +395,20 @@ public class SimpleToscaProvider { "policies for " + name + ":" + version + DO_NOT_EXIST); } + JpaToscaServiceTemplate returnServiceTemplate = new JpaToscaServiceTemplate(serviceTemplate); + returnServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); + for (JpaToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().values()) { - if (policy.getDerivedFrom() != null) { - JpaToscaServiceTemplate referencedEntitiesServiceTemplate = - getPolicyTypes(dao, policy.getDerivedFrom().getName(), policy.getDerivedFrom().getVersion()); + JpaToscaServiceTemplate referencedEntitiesServiceTemplate = + getPolicyTypes(dao, policy.getType().getName(), policy.getType().getVersion()); - serviceTemplate = - ToscaServiceTemplateUtils.addFragment(serviceTemplate, referencedEntitiesServiceTemplate); - } + returnServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy.getKey(), policy); + returnServiceTemplate = + ToscaServiceTemplateUtils.addFragment(returnServiceTemplate, referencedEntitiesServiceTemplate); } - LOGGER.debug("<-getPolicies: name={}, version={}, serviceTemplate={}", name, version, serviceTemplate); - return serviceTemplate; + LOGGER.debug("<-getPolicies: name={}, version={}, serviceTemplate={}", name, version, returnServiceTemplate); + return returnServiceTemplate; } /** @@ -497,7 +508,7 @@ public class SimpleToscaProvider { if (policyType == null) { String errorMessage = "policy type " + policyTypeKey.getId() + " for policy " + policy.getId() + " does not exist"; - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, errorMessage); } } @@ -526,7 +537,7 @@ public class SimpleToscaProvider { // We should have one and only one returned entry if (filterdPolicyTypeList.size() != 1) { String errorMessage = "search for latest policy type " + policyTypeName + " returned more than one entry"; - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); + throw new PfModelRuntimeException(Response.Status.CONFLICT, errorMessage); } return (JpaToscaPolicyType) filterdPolicyTypeList.get(0); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java index 87b499b4c..6f21c1942 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java @@ -74,7 +74,7 @@ public class ToscaServiceTemplateUtils { compositeTemplate.setPolicyTypes( addFragmentEntitites(compositeTemplate.getPolicyTypes(), fragmentTemplate.getPolicyTypes(), result)); - if (originalTemplate.getTopologyTemplate() != null) { + if (originalTemplate.getTopologyTemplate() != null && fragmentTemplate.getTopologyTemplate() != null) { if (originalTemplate.getTopologyTemplate() .compareToWithoutEntities(fragmentTemplate.getTopologyTemplate()) == 0) { compositeTemplate.getTopologyTemplate() @@ -95,7 +95,7 @@ public class ToscaServiceTemplateUtils { if (!result.isValid()) { String message = result.toString(); - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, message); } return compositeTemplate; 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 cc0431946..b75273e5e 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 @@ -147,7 +147,7 @@ public final class ToscaUtils { final Function<JpaToscaServiceTemplate, String> checkerFunction) { String message = checkerFunction.apply(serviceTemplate); if (message != null) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message); + throw new PfModelRuntimeException(Response.Status.NOT_FOUND, message); } } @@ -263,7 +263,7 @@ public final class ToscaUtils { } if (!result.isValid()) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, result.toString()); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.toString()); } entityTypes.getConceptMap().entrySet() 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 0bf371022..858ac09fe 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 @@ -87,6 +87,7 @@ public class ToscaPolicyFilterTest { for (String policyResourceName : policyResourceNames) { String policyString = ResourceUtils.getResourceAsString(policyResourceName); if (policyResourceName.endsWith("yaml")) { + LOGGER.info("loading {}", policyResourceName); Object yamlObject = new Yaml().load(policyString); policyString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject); } @@ -150,7 +151,7 @@ public class ToscaPolicyFilterTest { assertEquals(VERSION_100, filteredList.get(7).getVersion()); assertEquals(VERSION_100, filteredList.get(12).getVersion()); - assertEquals(24, policyList.size()); + assertEquals(23, policyList.size()); assertEquals(22, filteredList.size()); policyList.get(10).setVersion("2.0.0"); @@ -172,7 +173,7 @@ public class ToscaPolicyFilterTest { public void testFilterNameVersion() { ToscaPolicyFilter filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").build(); List<ToscaPolicy> filteredList = filter.filter(policyList); - assertEquals(2, filteredList.size()); + assertEquals(1, filteredList.size()); filter = ToscaPolicyFilter.builder().name("guard.frequency.scaleout").build(); filteredList = filter.filter(policyList); @@ -184,7 +185,7 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().version(VERSION_100).build(); filteredList = filter.filter(policyList); - assertEquals(22, filteredList.size()); + assertEquals(21, filteredList.size()); filter = ToscaPolicyFilter.builder().name("OSDF_CASABLANCA.SubscriberPolicy_v1").version(VERSION_100).build(); filteredList = filter.filter(policyList); @@ -192,7 +193,7 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").version(VERSION_100).build(); filteredList = filter.filter(policyList); - assertEquals(1, filteredList.size()); + assertEquals(0, filteredList.size()); } @Test @@ -200,11 +201,11 @@ public class ToscaPolicyFilterTest { // null pattern ToscaPolicyFilter filter = ToscaPolicyFilter.builder().versionPrefix(null).build(); List<ToscaPolicy> filteredList = filter.filter(policyList); - assertEquals(24, filteredList.size()); + assertEquals(23, filteredList.size()); filter = ToscaPolicyFilter.builder().versionPrefix("1.").build(); filteredList = filter.filter(policyList); - assertEquals(22, filteredList.size()); + assertEquals(21, filteredList.size()); filter = ToscaPolicyFilter.builder().versionPrefix("100.").build(); filteredList = filter.filter(policyList); @@ -215,7 +216,11 @@ public class ToscaPolicyFilterTest { public void testFilterTypeVersion() { ToscaPolicyFilter filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").build(); List<ToscaPolicy> filteredList = filter.filter(policyList); - assertEquals(1, filteredList.size()); + assertEquals(0, filteredList.size()); + + filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.operational.common.Apex").build(); + filteredList = filter.filter(policyList); + assertEquals(0, filteredList.size()); filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.operational.common.Drools").build(); filteredList = filter.filter(policyList); @@ -231,7 +236,7 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().typeVersion(VERSION_000).build(); filteredList = filter.filter(policyList); - assertEquals(4, filteredList.size()); + assertEquals(3, filteredList.size()); filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.resource.HpaPolicy") .typeVersion(VERSION_100).build(); @@ -241,6 +246,6 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").typeVersion(VERSION_000) .build(); filteredList = filter.filter(policyList); - assertEquals(1, filteredList.size()); + assertEquals(0, filteredList.size()); } } 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 index 30696ce9d..0f038d3cd 100644 --- 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 @@ -163,7 +163,7 @@ public class ToscaPolicyTypeFilterTest { public void testFilterNameVersion() { ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().name("onap.policies.Monitoring").build(); List<ToscaPolicyType> filteredList = filter.filter(typeList); - assertEquals(2, filteredList.size()); + assertEquals(1, filteredList.size()); filter = ToscaPolicyTypeFilter.builder().name("onap.policies.monitoring.cdap.tca.hi.lo.app").build(); filteredList = filter.filter(typeList); @@ -173,9 +173,9 @@ public class ToscaPolicyTypeFilterTest { filteredList = filter.filter(typeList); assertEquals(0, filteredList.size()); - filter = ToscaPolicyTypeFilter.builder().version(VERSION_000).build(); + filter = ToscaPolicyTypeFilter.builder().version(VERSION_100).build(); filteredList = filter.filter(typeList); - assertEquals(1, filteredList.size()); + assertEquals(20, filteredList.size()); filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.Vim_fit").version(VERSION_000) .build(); 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 ae350bd90..3f0d9e2a5 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 @@ -58,11 +58,11 @@ import org.yaml.snakeyaml.Yaml; */ public class AuthorativeToscaProviderPolicyTypeTest { private static final String VERSION = "version"; - private static final String POLICY_NO_VERSION_VERSION0 = "onap.policies.NoVersion:0.0.0"; + private static final String POLICY_NO_VERSION_VERSION1 = "onap.policies.NoVersion:0.0.1"; private static final String POLICY_NO_VERSION = "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 .*on.*ull but is null$"; - private static final String VERSION_000 = "0.0.0"; + private static final String VERSION_001 = "0.0.1"; private static String yamlAsJsonString; private PfDao pfDao; private StandardCoder standardCoder; @@ -135,7 +135,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { ToscaServiceTemplate createdServiceTemplate = new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); - PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION0); + PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1); ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); @@ -150,7 +150,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); List<ToscaPolicyType> gotPolicyTypeList = - new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_000); + new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); @@ -162,14 +162,14 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(2, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); - gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, VERSION_000); + gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypeList(new DefaultPfDao(), POLICY_NO_VERSION, - VERSION_000)).hasMessageContaining("Policy Framework DAO has not been initialized"); + VERSION_001)).hasMessageContaining("Policy Framework DAO has not been initialized"); - assertTrue(new AuthorativeToscaProvider().getPolicyTypeList(pfDao, "i.dont.Exist", VERSION_000).isEmpty()); + assertTrue(new AuthorativeToscaProvider().getPolicyTypeList(pfDao, "i.dont.Exist", VERSION_001).isEmpty()); } @Test @@ -212,7 +212,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { ToscaServiceTemplate createdServiceTemplate = new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); - PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION0); + PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1); ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); @@ -234,14 +234,14 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription())); gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, - ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version(VERSION_000).build()); + ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version(VERSION_001).build()); gotPolicyType = gotServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription())); List<ToscaPolicyType> gotPolicyTypeList = - new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_000); + new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); @@ -256,7 +256,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, - ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version(VERSION_000).build()); + ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version(VERSION_001).build()); assertEquals(1, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); @@ -296,7 +296,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { ToscaServiceTemplate createdServiceTemplate = new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); - PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION0); + PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1); ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); @@ -328,7 +328,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { ToscaServiceTemplate createdServiceTemplate = new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); - PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION0); + PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1); ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); @@ -379,7 +379,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { ToscaServiceTemplate createdServiceTemplate = new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); - PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION0); + PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1); ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); @@ -395,7 +395,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertThatThrownBy(() -> { new AuthorativeToscaProvider().getPolicyTypes(pfDao, policyTypeKey.getName(), policyTypeKey.getVersion()); - }).hasMessage("policy types for onap.policies.NoVersion:0.0.0 do not exist"); + }).hasMessage("policy types for onap.policies.NoVersion:0.0.1 do not exist"); } @Test 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 0aa1da0d7..4dcfeafc9 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,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * 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 LegacyOperationalPolicyMapperTest { JpaToscaServiceTemplate policyTypeServiceTemplate = new JpaToscaServiceTemplate(); policyTypeServiceTemplate.fromAuthorative(policyTypes); - String vcpePolicyJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"); + String vcpePolicyJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.legacy.input.json"); LegacyOperationalPolicy legacyOperationalPolicy = standardCoder.decode(vcpePolicyJson, LegacyOperationalPolicy.class); 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 ec03122a6..4d0fd6fd6 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,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,8 +51,8 @@ import org.yaml.snakeyaml.Yaml; */ public class LegacyProvider4LegacyOperationalTest { 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 VCPE_OUTPUT_JSON = "policies/vCPE.policy.operational.legacy.output.json"; + private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.operational.legacy.input.json"; private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$"; private PfDao pfDao; private StandardCoder standardCoder; 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 01a52f7bd..0a8283e98 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,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -155,9 +155,9 @@ public class MonitoringPolicyTypeSerializationTest { Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next(); assertEquals(MONITORING, firstPolicyType.getKey().getName()); - assertEquals(VERSION_000, firstPolicyType.getKey().getVersion()); + assertEquals(VERSION_100, firstPolicyType.getKey().getVersion()); assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName()); - assertEquals("a base policy type for all policies that governs monitoring provisioning", + assertEquals("a base policy type for all policies that govern monitoring provisioning", firstPolicyType.getValue().getDescription()); Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next(); @@ -376,13 +376,13 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals(MONITORING, firstPolicyType.getKey().getName()); assertEquals(VERSION_100, firstPolicyType.getKey().getVersion()); assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName()); - assertEquals("a base policy type for all policies that govern monitoring provision", + assertEquals("a base policy type for all policies that govern monitoring provisioning", firstPolicyType.getValue().getDescription()); Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next(); assertEquals(DCAE, secondPolicyType.getKey().getName()); assertEquals(VERSION_100, secondPolicyType.getKey().getVersion()); - assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName()); + assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName()); assertTrue(secondPolicyType.getValue().getProperties().size() == 2); Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator(); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java index ca46de1c3..f9a0143fd 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java @@ -201,5 +201,19 @@ public class ToscaServiceTemplateUtilsTest { assertEquals(dt1, dtIterator.next()); assertEquals(pt0, compositeTemplate05.getPolicyTypes().getAll(null).iterator().next()); assertEquals(p0, compositeTemplate05.getTopologyTemplate().getPolicies().getAll(null).iterator().next()); + + JpaToscaServiceTemplate fragmentTemplate09 = new JpaToscaServiceTemplate(); + + fragmentTemplate09.setDataTypes(new JpaToscaDataTypes()); + fragmentTemplate09.getDataTypes().getConceptMap().put(dt1.getKey(), dt1); + + fragmentTemplate09.setPolicyTypes(new JpaToscaPolicyTypes()); + fragmentTemplate09.getPolicyTypes().getConceptMap().put(pt0.getKey(), pt0); + + fragmentTemplate09.setTopologyTemplate(null); + + JpaToscaServiceTemplate compositeTemplate06 = + ToscaServiceTemplateUtils.addFragment(compositeTemplate05, fragmentTemplate09); + assertEquals(compositeTemplate05.getTopologyTemplate(), compositeTemplate06.getTopologyTemplate()); } } diff --git a/models-tosca/src/test/resources/META-INF/persistence.xml b/models-tosca/src/test/resources/META-INF/persistence.xml index d6fba8f8a..de27dd9bc 100644 --- a/models-tosca/src/test/resources/META-INF/persistence.xml +++ b/models-tosca/src/test/resources/META-INF/persistence.xml @@ -34,6 +34,8 @@ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes</class> <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class> <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty</class> <properties> <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> diff --git a/models-tosca/src/test/resources/onap.policies.NoVersion.yaml b/models-tosca/src/test/resources/onap.policies.NoVersion.yaml index 5923eb22d..2dda556a6 100644 --- a/models-tosca/src/test/resources/onap.policies.NoVersion.yaml +++ b/models-tosca/src/test/resources/onap.policies.NoVersion.yaml @@ -6,6 +6,7 @@ policy_types: description: The base policy type for all policies that govern optimization onap.policies.NoVersion: derived_from: onap.policies.Optimization + version: 0.0.1 properties: applicableResources: type: list |