import lombok.EqualsAndHashCode;
import lombok.NonNull;
-import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfTimestampKey;
key.clean();
}
-
@Override
public int compareTo(@NonNull final PfConcept otherObj) {
if (this == otherObj) {
import java.util.ArrayList;
import java.util.Date;
+
import org.junit.Test;
import org.onap.policy.models.base.PfTimestampKey;
import org.onap.policy.models.base.PfValidationResult;
public void testConstructor() {
assertThatThrownBy(() -> new JpaPdpStatistics((PfTimestampKey) null)).hasMessageContaining("key");
- assertThatThrownBy(() -> new JpaPdpStatistics((JpaPdpStatistics) null))
- .hasMessageContaining("copyConcept");
+ assertThatThrownBy(() -> new JpaPdpStatistics((JpaPdpStatistics) null)).hasMessageContaining("copyConcept");
- assertThatThrownBy(() -> new JpaPdpStatistics((PdpStatistics) null))
- .hasMessageContaining("authorativeConcept");
+ assertThatThrownBy(() -> new JpaPdpStatistics((PdpStatistics) null)).hasMessageContaining("authorativeConcept");
assertNotNull(new JpaPdpStatistics());
assertNotNull(new JpaPdpStatistics(new PfTimestampKey()));
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
daoParameters.setPersistenceUnit(parameters.getPersistenceUnit());
// Decode the password using Base64
- String decodedPassword = new String(Base64.getDecoder().decode(parameters.getDatabasePassword()));
+ String decodedPassword = new String(Base64.getDecoder().decode(getValue(parameters.getDatabasePassword())));
// @formatter:off
Properties jdbcProperties = new Properties();
}
}
+ private String getValue(final String value) {
+ if (value != null && value.matches("[$][{].*[}]$")) {
+ return System.getenv(value.substring(2, value.length() - 1));
+ }
+ return value;
+ }
+
@Override
public void close() throws PfModelException {
LOGGER.debug("closing the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
throws PfModelException {
assertInitialized();
+
+ ToscaPolicyTypeIdentifier policyTypeIdentifier = new ToscaPolicyTypeIdentifier(name, version);
+ assertPolicyTypeNotSupportedInPdpGroup(policyTypeIdentifier);
+
return new AuthorativeToscaProvider().deletePolicyType(pfDao, name, version);
}
public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
throws PfModelException {
assertInitialized();
+
+ ToscaPolicyIdentifier policyIdentifier = new ToscaPolicyIdentifier(name, version);
+ assertPolicyNotDeployedInPdpGroup(policyIdentifier);
+
return new AuthorativeToscaProvider().deletePolicy(pfDao, name, version);
}
public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId,
@NonNull final String policyVersion) throws PfModelException {
assertInitialized();
+
+ assertPolicyNotDeployedInPdpGroup(
+ new ToscaPolicyIdentifier(policyId, policyVersion + LegacyProvider.LEGACY_MINOR_PATCH_SUFFIX));
+
return new LegacyProvider().deleteOperationalPolicy(pfDao, policyId, policyVersion);
}
public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId,
@NonNull final String policyVersion) throws PfModelException {
assertInitialized();
+
+ assertPolicyNotDeployedInPdpGroup(
+ new ToscaPolicyIdentifier(policyId, policyVersion + LegacyProvider.LEGACY_MINOR_PATCH_SUFFIX));
+
return new LegacyProvider().deleteGuardPolicy(pfDao, policyId, policyVersion);
}
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
}
}
+
+ /**
+ * Assert that the policy type is not supported in any PDP group.
+ *
+ * @param policyTypeIdentifier the policy type identifier
+ * @throws PfModelException if the policy type is supported in a PDP group
+ */
+ private void assertPolicyTypeNotSupportedInPdpGroup(ToscaPolicyTypeIdentifier policyTypeIdentifier)
+ throws PfModelException {
+ for (PdpGroup pdpGroup : getPdpGroups(null)) {
+ for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {
+ if (pdpSubGroup.getSupportedPolicyTypes().contains(policyTypeIdentifier)) {
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE,
+ "policy type is in use, it is referenced in PDP group " + pdpGroup.getName() + " subgroup "
+ + pdpSubGroup.getPdpType());
+ }
+ }
+ }
+ }
+
+ /**
+ * Assert that the policy is not deployed in a PDP group.
+ *
+ * @param policyIdentifier the identifier of the policy
+ * @throws PfModelException thrown if the policy is deployed in a PDP group
+ */
+ private void assertPolicyNotDeployedInPdpGroup(final ToscaPolicyIdentifier policyIdentifier)
+ throws PfModelException {
+ for (PdpGroup pdpGroup : getPdpGroups(null)) {
+ for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {
+ if (pdpSubGroup.getPolicies().contains(policyIdentifier)) {
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE,
+ "policy is in use, it is deployed in PDP group " + pdpGroup.getName() + " subgroup "
+ + pdpSubGroup.getPdpType());
+ }
+ }
+ }
+ }
}
@Override
public List<PdpStatistics> deletePdpStatistics(final String name, final Date timestamp) {
// Not implemented
- return null;
+ return new ArrayList<>();
}
/**
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
databaseProvider.close();
}
+
+ @Test
+ public void testDeletePolicyDeployedInSubgroup() throws PfModelException {
+ List<ToscaPolicyIdentifier> policies = new ArrayList<>();
+
+ policies.add(new ToscaPolicyIdentifier("p0", "0.0.1"));
+ policies.add(new ToscaPolicyIdentifier("p1", "0.0.1"));
+
+ List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
+ supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier("pt2", "0.0.1"));
+
+ PdpSubGroup subGroup = new PdpSubGroup();
+ subGroup.setPdpType("pdpType");
+ subGroup.setSupportedPolicyTypes(supportedPolicyTypes);
+ subGroup.setPolicies(policies);
+
+ List<PdpSubGroup> pdpSubgroups = new ArrayList<>();
+ pdpSubgroups.add(subGroup);
+
+ PdpGroup pdpGroup = new PdpGroup();
+ pdpGroup.setName("pdpGroup");
+ pdpGroup.setPdpGroupState(PdpState.PASSIVE);
+ pdpGroup.setPdpSubgroups(pdpSubgroups);
+
+ List<PdpGroup> pdpGroups = new ArrayList<>();
+ pdpGroups.add(pdpGroup);
+
+ PolicyModelsProvider databaseProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+ databaseProvider.createPdpGroups(pdpGroups);
+
+ assertThatThrownBy(() -> databaseProvider.deletePolicy("p0", "0.0.1"))
+ .hasMessageContaining("policy is in use, it is deployed in PDP group pdpGroup subgroup pdpType");
+
+ assertThatThrownBy(() -> databaseProvider.deletePolicy("p3", "0.0.1"))
+ .hasMessageContaining("service template not found in database");
+
+ databaseProvider.close();
+ }
+
+ @Test
+ public void testDeletePolicyTypeSupportedInSubgroup() throws PfModelException {
+ List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
+ supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier("pt1", "0.0.1"));
+ supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier("pt2", "0.0.1"));
+
+ PdpSubGroup subGroup = new PdpSubGroup();
+ subGroup.setPdpType("pdpType");
+ subGroup.setSupportedPolicyTypes(supportedPolicyTypes);
+
+ List<PdpSubGroup> pdpSubgroups = new ArrayList<>();
+ pdpSubgroups.add(subGroup);
+
+ PdpGroup pdpGroup = new PdpGroup();
+ pdpGroup.setName("pdpGroup");
+ pdpGroup.setPdpGroupState(PdpState.PASSIVE);
+ pdpGroup.setPdpSubgroups(pdpSubgroups);
+
+ List<PdpGroup> pdpGroups = new ArrayList<>();
+ pdpGroups.add(pdpGroup);
+
+ PolicyModelsProvider databaseProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+ databaseProvider.createPdpGroups(pdpGroups);
+
+ assertThatThrownBy(() -> databaseProvider.deletePolicyType("pt2", "0.0.1"))
+ .hasMessageContaining("policy type is in use, it is referenced in PDP group pdpGroup subgroup pdpType");
+
+ assertThatThrownBy(() -> databaseProvider.deletePolicyType("pt0", "0.0.1"))
+ .hasMessageContaining("service template not found in database");
+
+ databaseProvider.close();
+ }
}
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
+import java.util.Date;
import org.junit.Test;
import org.onap.policy.models.pdp.concepts.Pdp;
dummyProvider.updatePdp("name", "type", new Pdp());
dummyProvider.updatePdpStatistics(new ArrayList<>());
assertTrue(dummyProvider.getPdpStatistics("name", null).isEmpty());
+
+ assertTrue(
+ dummyProvider.getFilteredPdpStatistics("name", null, null, new Date(), new Date(), null, 0).isEmpty());
+ assertTrue(dummyProvider.createPdpStatistics(null).isEmpty());
+ assertTrue(dummyProvider.updatePdpStatistics(null).isEmpty());
+ assertTrue(dummyProvider.deletePdpStatistics(null, new Date()).isEmpty());
}
@Test
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
import org.onap.policy.models.sim.pdp.parameters.PdpStatusParameters;
-import org.onap.policy.models.sim.pdp.parameters.ToscaPolicyTypeIdentifierParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
* This class supports the handling of pdp messages.
return pdpStatus;
}
- /**
- * Method to get supported policy types from the parameters.
- *
- * @param pdpStatusParameters pdp status parameters
- * @return supportedPolicyTypes list of PolicyTypeIdent
- */
- private List<ToscaPolicyTypeIdentifier> getSupportedPolicyTypesFromParameters(
- final PdpStatusParameters pdpStatusParameters) {
- final List<ToscaPolicyTypeIdentifier> supportedPolicyTypes =
- new ArrayList<>(pdpStatusParameters.getSupportedPolicyTypes().size());
- for (final ToscaPolicyTypeIdentifierParameters policyTypeIdentParameters : pdpStatusParameters
- .getSupportedPolicyTypes()) {
- supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(policyTypeIdentParameters.getName(),
- policyTypeIdentParameters.getVersion()));
- }
- return supportedPolicyTypes;
- }
-
/**
* Method to create PdpStatus message from the context, which is to be sent by pdp simulator to pap.
*
public class LegacyProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(LegacyProvider.class);
- private static final String LEGACY_MINOR_PATCH_SUFFIX = ".0.0";
+ public static final String LEGACY_MINOR_PATCH_SUFFIX = ".0.0";
// Recurring constants
private static final String NO_POLICY_FOUND_FOR_POLICY = "no policy found for policy: ";
/*-
* ============LICENSE_START=======================================================
* 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.
import java.util.ArrayList;
import java.util.List;
+
import javax.persistence.ElementCollection;
import lombok.EqualsAndHashCode;
@Override
public void fromAuthorative(final ToscaConstraint toscaConstraint) {
+ validValues = new ArrayList<>();
if (toscaConstraint.getValidValues() != null) {
- validValues = new ArrayList<>();
validValues.addAll(toscaConstraint.getValidValues());
}
}
* 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.
import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntrySchema;
-
/**
* Class to represent the EntrySchema of list/map property in TOSCA definition.
*
private String description;
@ElementCollection
- private List<JpaToscaConstraint> constraints;
+ private List<JpaToscaConstraint> constraints = new ArrayList<>();
/**
* The full constructor creates a {@link JpaToscaEntrySchema} object with mandatory fields.
this.getClass(), ValidationResult.INVALID, "entry schema description may not be blank"));
}
-
if (constraints != null) {
for (JpaToscaConstraint constraint : constraints) {
if (constraint == null) {
@ElementCollection
@Lob
- private Map<String, String> properties;
+ private Map<String, String> properties = new LinkedHashMap<>();
@ElementCollection
private List<PfConceptKey> targets = new ArrayList<>();
* 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.
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.EmbeddedId;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
+
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+
import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
private Status status = Status.SUPPORTED;
@ElementCollection
- private List<JpaToscaConstraint> constraints;
+ private List<JpaToscaConstraint> constraints = new ArrayList<>();
@Column
private JpaToscaEntrySchema entrySchema;
@ElementCollection
- private Map<String, String> metadata;
+ private Map<String, String> metadata = new LinkedHashMap<>();
/**
* The Default Constructor creates a {@link JpaToscaProperty} object with a null key.
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.dao.PfDao;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType;
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.JpaToscaPolicyType;
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleToscaProvider.class);
// Recurring string constants
+ private static final String DATA_TYPE = "data type ";
+ private static final String POLICY_TYPE = "policy type ";
private static final String SERVICE_TEMPLATE_NOT_FOUND_IN_DATABASE = "service template not found in database";
private static final String DO_NOT_EXIST = " do not exist";
+ private static final String NOT_FOUND = " not found";
/**
* Get Service Template.
throws PfModelException {
LOGGER.debug("->deleteDataType: key={}", dataTypeKey);
- JpaToscaServiceTemplate serviceTemplate = getDataTypes(dao, dataTypeKey.getName(), dataTypeKey.getVersion());
+ JpaToscaServiceTemplate serviceTemplate = getServiceTemplate(dao);
+
+ if (!ToscaUtils.doDataTypesExist(serviceTemplate)) {
+ throw new PfModelRuntimeException(Response.Status.NOT_FOUND, "no data types found");
+ }
+
+ JpaToscaDataType dataType4Deletion = serviceTemplate.getDataTypes().get(dataTypeKey);
+ if (dataType4Deletion == null) {
+ throw new PfModelRuntimeException(Response.Status.NOT_FOUND, DATA_TYPE + dataTypeKey.getId() + NOT_FOUND);
+ }
+
+ for (JpaToscaDataType dataType : serviceTemplate.getDataTypes().getAll(null)) {
+ if (dataType.getReferencedDataTypes().contains(dataTypeKey)) {
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, DATA_TYPE + dataTypeKey.getId()
+ + " is in use, it is referenced in data type " + dataType.getId());
+ }
+ }
+
+ if (ToscaUtils.doPolicyTypesExist(serviceTemplate)) {
+ for (JpaToscaPolicyType policyType : serviceTemplate.getPolicyTypes().getAll(null)) {
+ if (policyType.getReferencedDataTypes().contains(dataTypeKey)) {
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, DATA_TYPE + dataTypeKey.getId()
+ + " is in use, it is referenced in policy type " + policyType.getId());
+ }
+ }
+ }
dao.delete(JpaToscaDataType.class, dataTypeKey);
throws PfModelException {
LOGGER.debug("->deletePolicyType: key={}", policyTypeKey);
- JpaToscaServiceTemplate serviceTemplate =
- getPolicyTypes(dao, policyTypeKey.getName(), policyTypeKey.getVersion());
+ JpaToscaServiceTemplate serviceTemplate = getServiceTemplate(dao);
+
+ if (!ToscaUtils.doPolicyTypesExist(serviceTemplate)) {
+ throw new PfModelRuntimeException(Response.Status.NOT_FOUND, "no policy types found");
+ }
+
+ JpaToscaEntityType<? extends ToscaEntity> policyType4Deletion =
+ serviceTemplate.getPolicyTypes().get(policyTypeKey);
+ if (policyType4Deletion == null) {
+ throw new PfModelRuntimeException(Response.Status.NOT_FOUND,
+ POLICY_TYPE + policyTypeKey.getId() + NOT_FOUND);
+ }
+
+ for (JpaToscaPolicyType policyType : serviceTemplate.getPolicyTypes().getAll(null)) {
+ Collection<JpaToscaEntityType<ToscaEntity>> ancestorList = ToscaUtils
+ .getEntityTypeAncestors(serviceTemplate.getPolicyTypes(), policyType, new PfValidationResult());
+
+ if (ancestorList.contains(policyType4Deletion)) {
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, POLICY_TYPE + policyTypeKey.getId()
+ + " is in use, it is referenced in policy type " + policyType.getId());
+ }
+ }
+
+ if (ToscaUtils.doPoliciesExist(serviceTemplate)) {
+ for (JpaToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getAll(null)) {
+ if (policyTypeKey.equals(policy.getType())) {
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, POLICY_TYPE
+ + policyTypeKey.getId() + " is in use, it is referenced in policy " + policy.getId());
+ }
+ }
+ }
dao.delete(JpaToscaPolicyType.class, policyTypeKey);
throws PfModelException {
LOGGER.debug("->deletePolicy: key={}", policyKey);
- JpaToscaServiceTemplate serviceTemplate = getPolicies(dao, policyKey.getName(), policyKey.getVersion());
+ JpaToscaServiceTemplate serviceTemplate = getServiceTemplate(dao);
+
+ if (!ToscaUtils.doPoliciesExist(serviceTemplate)) {
+ throw new PfModelRuntimeException(Response.Status.NOT_FOUND, "no policies found");
+ }
+
+ JpaToscaPolicy policy4Deletion = serviceTemplate.getTopologyTemplate().getPolicies().get(policyKey);
+ if (policy4Deletion == null) {
+ throw new PfModelRuntimeException(Response.Status.NOT_FOUND, "policy " + policyKey.getId() + NOT_FOUND);
+ }
dao.delete(JpaToscaPolicy.class, policyKey);
if (policyType == null) {
String errorMessage =
- "policy type " + policyTypeKey.getId() + " for policy " + policy.getId() + " does not exist";
+ POLICY_TYPE + policyTypeKey.getId() + " for policy " + policy.getId() + " does not exist";
throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, errorMessage);
}
}
}
/**
- * Find all the ancestors of an entity type.
+ * getLatestPolicyTypeVersion Find all the ancestors of an entity type.
*
* @param entityTypes the set of entity types that exist
* @param entityType the entity type for which to get the parents
return CollectionUtils.emptyCollection();
}
+ if (entityType.getKey().equals(parentEntityTypeKey)) {
+ result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class,
+ ValidationResult.INVALID, "entity cannot be an ancestor of itself"));
+ throw new PfModelRuntimeException(Response.Status.CONFLICT, result.toString());
+ }
+
@SuppressWarnings("unchecked")
Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySet = (Set<JpaToscaEntityType<ToscaEntity>>) entityTypes
.getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion());
JpaToscaPolicy policy = new JpaToscaPolicy(new PfConceptKey("PolicyName", "2.0.0"));
serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy.getKey(), policy);
+ policy.setMetadata(null);
+ assertThatThrownBy(() -> {
+ new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
+ }).hasMessageContaining("no metadata defined on TOSCA policy");
+
policy.setMetadata(new LinkedHashMap<>());
+ policy.setProperties(null);
assertThatThrownBy(() -> {
new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
}).hasMessageContaining("no properties defined on TOSCA policy");
serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().remove(policy1.getKey());
+ policy0.setProperties(null);
assertThatThrownBy(() -> {
new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
}).hasMessage("no properties defined on TOSCA policy");
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.dao.DaoParameters;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.dao.PfDaoFactory;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
import org.yaml.snakeyaml.Yaml;
assertEquals(dataType0, gotServiceTemplate.getDataTypes().get(dataType0Key));
assertEquals("Updated Description", gotServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
+ assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, new PfConceptKey("IDontExist:0.0.1")))
+ .hasMessage("data type IDontExist:0.0.1 not found");
+
JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key);
assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key));
assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
+ // Create the data type again
+ new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
+
+ updatedServiceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+ JpaToscaPolicyType pt0 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.1"));
+ updatedServiceTemplate.getPolicyTypes().getConceptMap().put(pt0.getKey(), pt0);
+ new SimpleToscaProvider().createPolicyTypes(pfDao, updatedServiceTemplate);
+
+ deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key);
+
+ assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key));
+ assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
+
assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
- .hasMessage("data types for DataType0:0.0.1 do not exist");
+ .hasMessage("no data types found");
+
+ // Create the data type again
+ new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
+
+ JpaToscaPolicyType pt0v2 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.2"));
+ JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0v2.getKey(), "prop0"));
+ prop0.setType(dataType0Key);
+ pt0v2.getProperties().put(prop0.getKey().getLocalName(), prop0);
+ updatedServiceTemplate.getPolicyTypes().getConceptMap().put(pt0v2.getKey(), pt0v2);
+ new SimpleToscaProvider().createPolicyTypes(pfDao, updatedServiceTemplate);
+
+ assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
+ .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2");
+
+ JpaToscaDataType dataType0v2 = new JpaToscaDataType(new PfConceptKey("DataType0:0.0.2"));
+ updatedServiceTemplate.getDataTypes().getConceptMap().put(dataType0v2.getKey(), dataType0v2);
+ new SimpleToscaProvider().createDataTypes(pfDao, updatedServiceTemplate);
+
+ deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0v2.getKey());
+
+ assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key));
+ assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
+
+ assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
+ .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2");
+
+ JpaToscaDataType dataType1 = new JpaToscaDataType(new PfConceptKey("DataType1:0.0.3"));
+ JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(dataType1.getKey(), "prop1"));
+ prop1.setType(dataType0v2.getKey());
+ dataType1.getProperties().put(prop1.getKey().getLocalName(), prop1);
+ updatedServiceTemplate.getDataTypes().getConceptMap().put(dataType1.getKey(), dataType1);
+ new SimpleToscaProvider().createDataTypes(pfDao, updatedServiceTemplate);
+
+ assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0v2.getKey()))
+ .hasMessage("data type DataType0:0.0.2 is in use, it is referenced in data type DataType1:0.0.3");
}
@Test
assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key));
assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().deletePolicyType(pfDao, new PfConceptKey("IDontExist:0.0.1"));
+ }).hasMessage("policy type IDontExist:0.0.1 not found");
+
+ JpaToscaPolicyType pt1 = new JpaToscaPolicyType(new PfConceptKey("pt1:0.0.2"));
+ pt1.setDerivedFrom(policyType0Key);
+ serviceTemplate.getPolicyTypes().getConceptMap().put(pt1.getKey(), pt1);
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+
+ assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
+ .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2");
+
+ serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
+ serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+
+ JpaToscaPolicy p0 = new JpaToscaPolicy(new PfConceptKey("p0:0.0.1"));
+ p0.setType(policyType0Key);
+ serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p0.getKey(), p0);
+
+ JpaToscaPolicy p1 = new JpaToscaPolicy(new PfConceptKey("p1:0.0.1"));
+ p1.setType(pt1.getKey());
+ serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p1.getKey(), p1);
+ new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
+
+ assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
+ .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2");
+
+ assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, pt1.getKey()))
+ .hasMessage("policy type pt1:0.0.2 is in use, it is referenced in policy p1:0.0.1");
+
+ new SimpleToscaProvider().deletePolicy(pfDao, p1.getKey());
+
+ new SimpleToscaProvider().deletePolicyType(pfDao, pt1.getKey());
+
+ new SimpleToscaProvider().deletePolicy(pfDao, p0.getKey());
+
JpaToscaServiceTemplate deletedServiceTemplate =
new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
- .hasMessage("policy types for PolicyType0:0.0.1 do not exist");
+ .hasMessage("no policy types found");
}
@Test
deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
- .hasMessage("policy types for PolicyType0:0.0.1 do not exist");
+ .hasMessage("no policy types found");
}
@Test
assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey),
gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
+
+ JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey);
+ assertEquals(1, deletedServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().size());
}
@Test
PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
- JpaToscaServiceTemplate deletedServiceTemplate =
- new SimpleToscaProvider().deletePolicy(pfDao, new PfConceptKey(policyKey));
+ assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, new PfConceptKey("IDontExist:0.0.1")))
+ .hasMessage("policy IDontExist:0.0.1 not found");
+
+ JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey);
assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey),
deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
- // @formatter:off
- assertThatThrownBy(
- () -> new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()))
- .hasMessage("policies for onap.restart.tca:1.0.0 do not exist");
- // @formatter:on
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
+ }).hasMessage("policies for onap.restart.tca:1.0.0 do not exist");
+
+ assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, policyKey))
+ .hasMessage("no policies found");
}
@Test
.hasMessage("list of policies specified on topology template of service template is empty");
}
+ @Test
+ public void testGetServiceTemplate() throws PfModelException {
+ assertThatThrownBy(() -> new SimpleToscaProvider().getServiceTemplate(pfDao))
+ .hasMessage("service template not found in database");
+ }
+
+ @Test
+ public void testAppendToServiceTemplate() throws PfModelException {
+ JpaToscaServiceTemplate serviceTemplateFragment = new JpaToscaServiceTemplate();
+ serviceTemplateFragment.setPolicyTypes(new JpaToscaPolicyTypes());
+ JpaToscaPolicyType badPt = new JpaToscaPolicyType();
+ serviceTemplateFragment.getPolicyTypes().getConceptMap().put(badPt.getKey(), badPt);
+
+ assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(pfDao, serviceTemplateFragment))
+ .hasMessageContaining(
+ "key on concept entry PfConceptKey(name=NULL, version=0.0.0) may not be the null key");
+ }
+
+ @Test
+ public void testGetDataTypesCornerCases() throws PfModelException {
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1");
+ }).hasMessageMatching("service template not found in database");
+
+ JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+ serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+ JpaToscaPolicyType p0 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.1"));
+ serviceTemplate.getPolicyTypes().getConceptMap().put(p0.getKey(), p0);
+
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1");
+ }).hasMessageMatching("data types for hello:0.0.1 do not exist");
+
+ serviceTemplate.setDataTypes(new JpaToscaDataTypes());
+
+ JpaToscaDataType p01 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1"));
+ serviceTemplate.getDataTypes().getConceptMap().put(p01.getKey(), p01);
+
+ new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1");
+ }).hasMessageMatching("data types for hello:0.0.1 do not exist");
+
+ JpaToscaServiceTemplate gotSt = new SimpleToscaProvider().getDataTypes(pfDao, p01.getName(), p01.getVersion());
+
+ assertEquals(p01, gotSt.getDataTypes().get(p01.getKey()));
+ assertEquals(p01, gotSt.getDataTypes().get(p01.getName()));
+ assertEquals(p01, gotSt.getDataTypes().get(p01.getName(), null));
+ assertEquals(p01, gotSt.getDataTypes().get(p01.getName(), p01.getVersion()));
+ assertEquals(1, gotSt.getDataTypes().getAll(null).size());
+ assertEquals(1, gotSt.getDataTypes().getAll(null, null).size());
+ assertEquals(1, gotSt.getDataTypes().getAll(p01.getName(), null).size());
+ assertEquals(1, gotSt.getDataTypes().getAll(p01.getName(), p01.getVersion()).size());
+
+ JpaToscaDataType p02 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.2"));
+ serviceTemplate.getDataTypes().getConceptMap().put(p02.getKey(), p02);
+
+ new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
+ gotSt = new SimpleToscaProvider().getDataTypes(pfDao, p01.getName(), p01.getVersion());
+
+ assertEquals(p01, gotSt.getDataTypes().get(p01.getKey()));
+ assertEquals(p02, gotSt.getDataTypes().get(p01.getName()));
+ assertEquals(p02, gotSt.getDataTypes().get(p01.getName(), null));
+ assertEquals(p01, gotSt.getDataTypes().get(p01.getName(), p01.getVersion()));
+ assertEquals(p02, gotSt.getDataTypes().get(p01.getName(), p02.getVersion()));
+ assertEquals(2, gotSt.getDataTypes().getAll(null).size());
+ assertEquals(2, gotSt.getDataTypes().getAll(null, null).size());
+ assertEquals(2, gotSt.getDataTypes().getAll(p01.getName(), null).size());
+ assertEquals(1, gotSt.getDataTypes().getAll(p01.getName(), p02.getVersion()).size());
+ }
+
+ @Test
+ public void testGetPolicyTypesCornerCases() throws PfModelException {
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1");
+ }).hasMessageMatching("service template not found in database");
+
+ JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+ serviceTemplate.setDataTypes(new JpaToscaDataTypes());
+ JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1"));
+ serviceTemplate.getDataTypes().getConceptMap().put(dt0.getKey(), dt0);
+
+ new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1");
+ }).hasMessageMatching("policy types for hello:0.0.1 do not exist");
+
+ serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+
+ JpaToscaPolicyType pt01 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.1"));
+ serviceTemplate.getPolicyTypes().getConceptMap().put(pt01.getKey(), pt01);
+
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1");
+ }).hasMessageMatching("policy types for hello:0.0.1 do not exist");
+
+ JpaToscaServiceTemplate gotSt =
+ new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion());
+
+ assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getKey()));
+ assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName()));
+ assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName(), null));
+ assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName(), pt01.getVersion()));
+ assertEquals(1, gotSt.getPolicyTypes().getAll(null).size());
+ assertEquals(1, gotSt.getPolicyTypes().getAll(null, null).size());
+ assertEquals(1, gotSt.getPolicyTypes().getAll(pt01.getName(), null).size());
+ assertEquals(1, gotSt.getPolicyTypes().getAll(pt01.getName(), pt01.getVersion()).size());
+
+ JpaToscaPolicyType pt02 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.2"));
+ serviceTemplate.getPolicyTypes().getConceptMap().put(pt02.getKey(), pt02);
+
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+ gotSt = new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion());
+
+ assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getKey()));
+ assertEquals(pt02, gotSt.getPolicyTypes().get(pt01.getName()));
+ assertEquals(pt02, gotSt.getPolicyTypes().get(pt01.getName(), null));
+ assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName(), pt01.getVersion()));
+ assertEquals(pt02, gotSt.getPolicyTypes().get(pt01.getName(), pt02.getVersion()));
+ assertEquals(2, gotSt.getPolicyTypes().getAll(null).size());
+ assertEquals(2, gotSt.getPolicyTypes().getAll(null, null).size());
+ assertEquals(2, gotSt.getPolicyTypes().getAll(pt01.getName(), null).size());
+ assertEquals(1, gotSt.getPolicyTypes().getAll(pt01.getName(), pt02.getVersion()).size());
+ }
+
+ @Test
+ public void testGetPoliciesCornerCases() throws PfModelException {
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1");
+ }).hasMessageMatching("service template not found in database");
+
+ JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+ serviceTemplate.setDataTypes(new JpaToscaDataTypes());
+ JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1"));
+ serviceTemplate.getDataTypes().getConceptMap().put(dt0.getKey(), dt0);
+
+ new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1");
+ }).hasMessageMatching("policies for hello:0.0.1 do not exist");
+
+ serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+
+ JpaToscaPolicyType pt01 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.1"));
+ serviceTemplate.getPolicyTypes().getConceptMap().put(pt01.getKey(), pt01);
+
+ serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
+ serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+
+ JpaToscaPolicy p01 = new JpaToscaPolicy(new PfConceptKey("p0:0.0.1"));
+ p01.setType(pt01.getKey());
+ serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p01.getKey(), p01);
+
+ new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1");
+ }).hasMessageMatching("policies for hello:0.0.1 do not exist");
+
+ JpaToscaServiceTemplate gotSt = new SimpleToscaProvider().getPolicies(pfDao, p01.getName(), p01.getVersion());
+
+ assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getKey()));
+ assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getName()));
+ assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), null));
+ assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), p01.getVersion()));
+ assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(null).size());
+ assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(null, null).size());
+ assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(p01.getName(), null).size());
+ assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(p01.getName(), p01.getVersion()).size());
+
+ JpaToscaPolicy p02 = new JpaToscaPolicy(new PfConceptKey("p0:0.0.2"));
+ p02.setType(pt01.getKey());
+ serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p02.getKey(), p02);
+
+ new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
+ gotSt = new SimpleToscaProvider().getPolicies(pfDao, p01.getName(), p01.getVersion());
+
+ assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getKey()));
+ assertEquals(p02, gotSt.getTopologyTemplate().getPolicies().get(p01.getName()));
+ assertEquals(p02, gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), null));
+ assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), p01.getVersion()));
+ assertEquals(p02, gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), p02.getVersion()));
+ assertEquals(2, gotSt.getTopologyTemplate().getPolicies().getAll(null).size());
+ assertEquals(2, gotSt.getTopologyTemplate().getPolicies().getAll(null, null).size());
+ assertEquals(2, gotSt.getTopologyTemplate().getPolicies().getAll(p01.getName(), null).size());
+ assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(p01.getName(), p02.getVersion()).size());
+ }
+
@Test
public void testNonNulls() {
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getServiceTemplate(null);
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().appendToServiceTemplate(null, null);
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().appendToServiceTemplate(null, new JpaToscaServiceTemplate());
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().appendToServiceTemplate(pfDao, null);
+ }).hasMessageMatching("^incomingServiceTemplateFragment is marked .*on.*ull but is null$");
+
assertThatThrownBy(() -> {
new SimpleToscaProvider().getDataTypes(null, null, null);
}).hasMessageMatching(DAO_IS_NULL);
assertTrue(firstDataTypeFirstProperty.getConstraints().size() == 1);
assertEquals("org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues",
firstDataTypeFirstProperty.getConstraints().iterator().next().getClass().getName());
- assertTrue(((JpaToscaConstraintValidValues) (firstDataTypeFirstProperty.getConstraints().iterator().next()))
- .getValidValues().size() == 2);
+ assertEquals(2,
+ ((JpaToscaConstraintValidValues) (firstDataTypeFirstProperty.getConstraints().iterator().next()))
+ .getValidValues().size());
JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next();
assertEquals(METRICS, firstDataTypeSecondProperty.getKey().getParentKeyName());
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 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.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
+
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
return coder.encode(auth);
}
- private void validate(String testnm, JpaToscaServiceTemplate svctmpl, String derivedFrom,
- String typeName, boolean checkResource, boolean checkService) {
+ private void validate(String testnm, JpaToscaServiceTemplate svctmpl, String derivedFrom, String typeName,
+ boolean checkResource, boolean checkService) {
JpaToscaPolicyTypes policyTypes = svctmpl.getPolicyTypes();
assertEquals(testnm + " type count", 1, policyTypes.getConceptMap().size());
String testnm = testName + " identity";
assertNotNull(testnm, prop);
- assertNull(testnm + " metadata", prop.getMetadata());
+ assertEquals(testnm + " metadata", 0, prop.getMetadata().size());
}
private void validateMatchable(String testName, Map<String, String> metadata) {
assertEquals(2, ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).size());
assertTrue(result.isValid());
+ dt0.setDerivedFrom(dt0.getKey());
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, new PfValidationResult());
+ }).hasMessageContaining("entity cannot be an ancestor of itself");
+
+ dt0.setDerivedFrom(null);
+ assertEquals(2, ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).size());
+
dt1.setDerivedFrom(new PfConceptKey("tosca.datatyps.Root", PfKey.NULL_KEY_VERSION));
assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());