result = key.validate(result);
- if (conceptMap.isEmpty()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "conceptMap may not be empty"));
- } else {
+ if (!conceptMap.isEmpty()) {
result = validateConceptMap(result);
}
/*-
* ============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");
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+
import org.junit.Test;
import org.onap.policy.models.base.testconcepts.DummyAuthorativeConcept;
import org.onap.policy.models.base.testconcepts.DummyBadPfConceptContainer;
private static final String DUMMY_VALUE = "Dummy";
private static final String VERSION0 = "0.0.1";
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void testConceptContainer() {
DummyPfConceptContainer container = new DummyPfConceptContainer();
assertThatThrownBy(() -> new DummyPfConceptContainer((PfConceptKey) null, null)).hasMessage(KEY_IS_NULL);
assertThatThrownBy(() -> new DummyPfConceptContainer(new PfConceptKey(), null))
- .hasMessage("conceptMap is marked @NonNull but is null");
+ .hasMessage("conceptMap is marked @NonNull but is null");
assertThatThrownBy(() -> new DummyPfConceptContainer(null, new TreeMap<PfConceptKey, DummyPfConcept>()))
- .hasMessage(KEY_IS_NULL);
+ .hasMessage(KEY_IS_NULL);
container.getKey().setName(DUMMY_VALUE);
DummyPfConceptContainer clonedContainer = new DummyPfConceptContainer(container);
assertEquals(DUMMY_VALUE, clonedContainer.getKey().getName());
assertThatThrownBy(() -> new DummyPfConceptContainer((DummyPfConceptContainer) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessage("copyConcept is marked @NonNull but is null");
List<PfKey> keyList = container.getKeys();
assertEquals(1, keyList.size());
assertEquals(0, container.compareTo(clonedContainer));
assertThatThrownBy(() -> new DummyPfConceptContainer((DummyPfConceptContainer) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
assertFalse(container.compareTo(null) == 0);
assertEquals(0, container.compareTo(container));
DummyPfConceptContainer validateContainer = new DummyPfConceptContainer();
assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
validateContainer.setKey(new PfConceptKey("VCKey", VERSION0));
- assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
+ assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey));
assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer();
assertThatThrownBy(() -> badContainer.fromAuthorative(authorativeList))
- .hasMessage("failed to instantiate instance of container concept class");
+ .hasMessage("failed to instantiate instance of container concept class");
authorativeList.clear();
assertThatThrownBy(() -> container.fromAuthorative(authorativeList))
- .hasMessage("An incoming list of concepts must have at least one entry");
+ .hasMessage("An incoming list of concepts must have at least one entry");
}
@Test(expected = NullPointerException.class)
/*-
* ============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");
import lombok.Data;
import lombok.EqualsAndHashCode;
+import lombok.NonNull;
import lombok.ToString;
+
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
+import org.onap.policy.models.tosca.utils.ToscaUtils;
/**
* This class is a container for TOSCA data types.
* @param authorativeConceptMapList the authorative concept to copy from
*/
public JpaToscaDataTypes(final List<Map<String, ToscaDataType>> authorativeConceptMapList) {
+ super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
this.fromAuthorative(authorativeConceptMapList);
}
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ for (JpaToscaDataType dataType : this.getConceptMap().values()) {
+ ToscaUtils.getEntityTypeAncestors(this, dataType, result);
+ }
+
+ return result;
+ }
}
/*-
* ============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");
import lombok.Data;
import lombok.EqualsAndHashCode;
+import lombok.NonNull;
import lombok.ToString;
+
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.utils.ToscaUtils;
/**
* This class is a container for TOSCA data types.
* @param authorativeConceptMapList the authorative concept to copy from
*/
public JpaToscaPolicies(final List<Map<String, ToscaPolicy>> authorativeConceptMapList) {
+ super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
this.fromAuthorative(authorativeConceptMapList);
}
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ for (JpaToscaPolicy policy : this.getConceptMap().values()) {
+ ToscaUtils.getEntityTypeAncestors(this, policy, result);
+ }
+
+ return result;
+ }
}
/*-
* ============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");
import lombok.Data;
import lombok.EqualsAndHashCode;
+import lombok.NonNull;
import lombok.ToString;
+
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.utils.ToscaUtils;
/**
* This class is a container for TOSCA policy types.
* @param authorativeConceptMapList the authorative concept to copy from
*/
public JpaToscaPolicyTypes(final List<Map<String, ToscaPolicyType>> authorativeConceptMapList) {
+ super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
this.fromAuthorative(authorativeConceptMapList);
}
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ for (JpaToscaPolicyType policyType : this.getConceptMap().values()) {
+ ToscaUtils.getEntityTypeAncestors(this, policyType, result);
+ }
+
+ return result;
+ }
}
@Override
public int compareTo(final PfConcept otherConcept) {
- if (otherConcept == null) {
- return -1;
- }
- if (this == otherConcept) {
- return 0;
- }
- if (getClass() != otherConcept.getClass()) {
- return getClass().getName().compareTo(otherConcept.getClass().getName());
- }
-
- final JpaToscaServiceTemplate other = (JpaToscaServiceTemplate) otherConcept;
- if (!super.equals(other)) {
- return super.compareTo(other);
- }
-
- int result = ObjectUtils.compare(toscaDefinitionsVersion, other.toscaDefinitionsVersion);
+ int result = compareToWithoutEntities(otherConcept);
if (result != 0) {
return result;
}
+ final JpaToscaServiceTemplate other = (JpaToscaServiceTemplate) otherConcept;
+
result = ObjectUtils.compare(dataTypes, other.dataTypes);
if (result != 0) {
return result;
return ObjectUtils.compare(topologyTemplate, other.topologyTemplate);
}
+
+ /**
+ * Compare this service template to another service template, ignoring contained entitites.
+ *
+ * @param otherConcept the other topology template
+ * @return the result of the comparison
+ */
+ public int compareToWithoutEntities(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return getClass().getName().compareTo(otherConcept.getClass().getName());
+ }
+
+ final JpaToscaServiceTemplate other = (JpaToscaServiceTemplate) otherConcept;
+ if (!super.equals(other)) {
+ return super.compareTo(other);
+ }
+
+ return ObjectUtils.compare(toscaDefinitionsVersion, other.toscaDefinitionsVersion);
+ }
}
/*-
* ============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");
package org.onap.policy.models.tosca.simple.concepts;
import java.util.List;
+
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.InheritanceType;
import javax.persistence.OneToOne;
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;
}
/**
- * The Key Constructor creates a {@link JpaToscaTopologyTemplate} object with the given concept
- * key.
+ * The Key Constructor creates a {@link JpaToscaTopologyTemplate} object with the given concept key.
*
* @param key the key
*/
@Override
public int compareTo(final PfConcept otherConcept) {
+ int result = compareToWithoutEntities(otherConcept);
+ if (result != 0) {
+ return result;
+ }
+
+ return ObjectUtils.compare(policies, ((JpaToscaTopologyTemplate) otherConcept).policies);
+ }
+
+ /**
+ * Compare this topology template to another topology template, ignoring contained entitites.
+ *
+ * @param otherConcept the other topology template
+ * @return the result of the comparison
+ */
+ public int compareToWithoutEntities(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
}
return key.compareTo(other.key);
}
- int result = ObjectUtils.compare(description, other.description);
- if (result != 0) {
- return result;
- }
-
- return ObjectUtils.compare(policies, other.policies);
+ return ObjectUtils.compare(description, other.description);
}
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.utils;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.ws.rs.core.Response;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptContainer;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
+
+/**
+ * This utility class provides methods to manage service templates.
+ */
+public class ToscaServiceTemplateUtils {
+ /**
+ * Private constructor to prevent subclassing.
+ */
+ private ToscaServiceTemplateUtils() {
+ // Private constructor to prevent subclassing
+ }
+
+ /**
+ * Add a service template fragment to a service template. All entities in the service template fragment must either
+ * a) not exist on the original service template or b) be identical to entities on the original service template.
+ *
+ * @param originalTemplate the original service template
+ * @param fragmentTemplate the fragment being added to the original service template
+ * @return
+ */
+ public static JpaToscaServiceTemplate addFragment(@NonNull final JpaToscaServiceTemplate originalTemplate,
+ @NonNull final JpaToscaServiceTemplate fragmentTemplate) {
+ PfValidationResult result = new PfValidationResult();
+
+ if (originalTemplate.compareToWithoutEntities(fragmentTemplate) != 0) {
+ result.addValidationMessage(new PfValidationMessage(originalTemplate.getKey(),
+ ToscaServiceTemplateUtils.class, ValidationResult.INVALID,
+ "service template in incoming fragment does not equal existing service template"));
+ }
+
+ JpaToscaServiceTemplate compositeTemplate = new JpaToscaServiceTemplate(originalTemplate);
+
+ compositeTemplate.setDataTypes(
+ addFragmentEntitites(compositeTemplate.getDataTypes(), fragmentTemplate.getDataTypes(), result));
+ compositeTemplate.setPolicyTypes(
+ addFragmentEntitites(compositeTemplate.getPolicyTypes(), fragmentTemplate.getPolicyTypes(), result));
+
+ if (originalTemplate.getTopologyTemplate() != null) {
+ if (originalTemplate.getTopologyTemplate()
+ .compareToWithoutEntities(fragmentTemplate.getTopologyTemplate()) == 0) {
+ compositeTemplate.getTopologyTemplate()
+ .setPolicies(addFragmentEntitites(compositeTemplate.getTopologyTemplate().getPolicies(),
+ fragmentTemplate.getTopologyTemplate().getPolicies(), result));
+ } else {
+ result.addValidationMessage(new PfValidationMessage(originalTemplate.getTopologyTemplate().getKey(),
+ ToscaServiceTemplateUtils.class, ValidationResult.INVALID,
+ "topology template in incoming fragment does not equal existing topology template"));
+ }
+ } else if (fragmentTemplate.getTopologyTemplate() != null) {
+ compositeTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate(fragmentTemplate.getTopologyTemplate()));
+ }
+
+ if (result.isValid()) {
+ result = compositeTemplate.validate(result);
+ }
+
+ if (!result.isValid()) {
+ String message = result.toString();
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message);
+ }
+
+ return compositeTemplate;
+ }
+
+ /**
+ * Check entities from a fragment container can be added to an original container.
+ *
+ * @param <S> The type of container
+ *
+ * @param compositeContainer the original container
+ * @param fragmentContainer the fragment being added to the original container
+ * @return the composite container with the result
+ */
+ @SuppressWarnings("unchecked")
+ // @formatter:off
+ private static
+ <S extends PfConceptContainer<? extends JpaToscaEntityType<? extends ToscaEntity>, ? extends ToscaEntity>>
+ S addFragmentEntitites(final S compositeContainer, final S fragmentContainer,
+ final PfValidationResult result) {
+
+ if (compositeContainer == null) {
+ return fragmentContainer;
+ }
+
+ if (fragmentContainer == null) {
+ return compositeContainer;
+ }
+
+ for (Entry<PfConceptKey, ? extends JpaToscaEntityType<? extends ToscaEntity>> fragmentEntry : fragmentContainer
+ .getConceptMap().entrySet()) {
+ JpaToscaEntityType<? extends ToscaEntity> containerEntry =
+ compositeContainer.getConceptMap().get(fragmentEntry.getKey());
+ if (containerEntry != null && !containerEntry.equals(fragmentEntry.getValue())) {
+ result.addValidationMessage(new PfValidationMessage(fragmentEntry.getKey(),
+ ToscaServiceTemplateUtils.class,
+ ValidationResult.INVALID, "entity in incoming fragment does not equal existing entity"));
+ }
+ }
+
+ // This use of a generic map is required to get around typing errors in directly adding the fragment map to the
+ // original map
+ @SuppressWarnings("rawtypes")
+ Map originalContainerMap = compositeContainer.getConceptMap();
+ originalContainerMap.putAll(fragmentContainer.getConceptMap());
+
+ return compositeContainer;
+ }
+ // @formatter:on
+}
package org.onap.policy.models.tosca.utils;
+import java.util.Collection;
+import java.util.Set;
import java.util.function.Function;
import javax.ws.rs.core.Response;
+import lombok.NonNull;
+
+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.PfModelRuntimeException;
+import org.onap.policy.models.base.PfNameVersion;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class ToscaUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(ToscaUtils.class);
+ private static final String ROOT_KEY_NAME_SUFFIX = ".Root";
+
/**
* Private constructor to prevent subclassing.
*/
return null;
}
+
+ /**
+ * 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
+ * @param result the result of the ancestor search with any warnings or errors
+ * @return
+ */
+ public static Collection<? extends JpaToscaEntityType<?>> getEntityTypeAncestors(
+ @NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
+ @NonNull JpaToscaEntityType<?> entityType, @NonNull final PfValidationResult result) {
+
+ PfConceptKey parentEntityTypeKey = entityType.getDerivedFrom();
+ if (parentEntityTypeKey == null || parentEntityTypeKey.getName().endsWith(ROOT_KEY_NAME_SUFFIX)) {
+ return CollectionUtils.emptyCollection();
+ }
+
+ @SuppressWarnings("unchecked")
+ Set<JpaToscaEntityType<?>> ancestorEntitySet = (Set<JpaToscaEntityType<?>>) entityTypes
+ .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion());
+
+ if (ancestorEntitySet.isEmpty()) {
+ result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class,
+ ValidationResult.INVALID, "parent " + parentEntityTypeKey.getId() + " of entity not found"));
+ } else {
+ for (JpaToscaEntityType<?> filteredEntityType : ancestorEntitySet) {
+ ancestorEntitySet.addAll(getEntityTypeAncestors(entityTypes, filteredEntityType, result));
+ }
+ }
+ return ancestorEntitySet;
+ }
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import static org.junit.Assert.assertTrue;
import com.google.gson.GsonBuilder;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
assertThatThrownBy(() -> {
filter.filter(null);
- }).hasMessage("originalList is marked @NonNull but is null");
+ }).hasMessageMatching("originalList is marked .*on.*ull but is null");
}
@Test
assertEquals(2, filteredList.size());
filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").typeVersion(VERSION_000)
- .build();
+ .build();
filteredList = filter.filter(policyList);
assertEquals(1, filteredList.size());
}
* ONAP Policy Models
* ================================================================================
* 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.
public void testGetIdentifier_testGetTypeIdentifier() {
assertThatThrownBy(() -> {
new ToscaPolicy(null);
- }).hasMessage("copyObject is marked @NonNull but is null");
-
+ }).hasMessageMatching("copyObject is marked .*on.*ull but is null");
ToscaPolicy policy = new ToscaPolicy();
/*-
* ============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");
import static org.junit.Assert.assertTrue;
import com.google.gson.GsonBuilder;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
assertThatThrownBy(() -> {
filter.filter(null);
- }).hasMessage("originalList is marked @NonNull but is null");
+ }).hasMessageMatching("originalList is marked .*on.*ull but is null");
}
@Test
/*-
* ============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.
public void testToscaPolicyType() {
assertThatThrownBy(() -> {
new ToscaPolicyType(null);
- }).hasMessage("copyObject is marked @NonNull but is null");
+ }).hasMessageMatching("copyObject is marked .*on.*ull but is null");
ToscaPolicyType tpt = new ToscaPolicyType();
tpt.setName("AType");
/*-
* ============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");
import java.util.ArrayList;
import java.util.List;
+
import org.junit.Test;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT));
assertThatThrownBy(() -> new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null))
- .hasMessage("operation is marked @NonNull but is null");
+ .hasMessageMatching("operation is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello"))
- .hasMessage("operation is marked @NonNull but is null");
+ .hasMessageMatching("operation is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null))
- .hasMessage("compareTo is marked @NonNull but is null");
+ .hasMessageMatching("compareTo is marked .*on.*ull but is null");
assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT));
/*-
* ============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");
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
/**
* DAO test for ToscaDatatype.
assertThatThrownBy(() -> {
new JpaToscaDataType((PfConceptKey) null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching("key is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaDataType((JpaToscaDataType) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfConceptKey dtKey = new PfConceptKey("tdt", VERSION_001);
JpaToscaDataType tdt = new JpaToscaDataType(dtKey);
Map<String, JpaToscaProperty> properties = new LinkedHashMap<>();
JpaToscaProperty tp =
- new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", VERSION_001));
+ new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", VERSION_001));
properties.put(tp.getKey().getLocalName(), tp);
tdt.setProperties(properties);
assertEquals(properties, tdt.getProperties());
assertThatThrownBy(() -> {
tdt.validate(null);
- }).hasMessage("resultIn is marked @NonNull but is null");
+ }).hasMessageMatching("resultIn is marked .*on.*ull but is null");
ToscaDataType dat = new ToscaDataType();
dat.setName("name");
/*-
* ============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");
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
public class JpaToscaDataTypesTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
@Test
public void testDataTypes() {
assertNotNull(new JpaToscaDataTypes(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaDataType>()));
assertNotNull(new JpaToscaDataTypes(new JpaToscaDataTypes()));
- assertThatThrownBy(() -> new JpaToscaDataTypes((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaDataTypes((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaDataTypes((JpaToscaDataTypes) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
- assertThatThrownBy(() -> new JpaToscaDataTypes(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaDataTypes(null, null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaDataTypes(new PfConceptKey(), null))
- .hasMessage("conceptMap is marked @NonNull but is null");
+ .hasMessageMatching("conceptMap is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaDataTypes(null, new TreeMap<PfConceptKey, JpaToscaDataType>()))
- .hasMessage(KEY_IS_NULL);
+ .hasMessageMatching(KEY_IS_NULL);
List<Map<String, ToscaDataType>> dtMapList = new ArrayList<>();
dtMapList.add(new LinkedHashMap<>());
- dtMapList.get(0).put("policyType", new ToscaDataType());
+
+ ToscaDataType dt0 = new ToscaDataType();
+ dt0.setName("dt0");
+ dt0.setVersion("0.0.1");
+ dt0.setDescription("dt0 description");
+
+ dtMapList.get(0).put("dt0", dt0);
assertNotNull(new JpaToscaDataTypes(dtMapList));
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+ assertThatThrownBy(() -> new JpaToscaDataTypes(dtMapList).validate(null))
+ .hasMessageMatching("resultIn is marked .*on.*ull but is null");
+
+ dt0.setDerivedFrom(null);
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+
+ dt0.setDerivedFrom("tosca.datatypes.Root");
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+
+ dt0.setDerivedFrom("some.other.Thing");
+ PfValidationResult result = new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent some.other.Thing:0.0.0 of entity not found");
+
+ dt0.setDerivedFrom(null);
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+
+ ToscaDataType dt1 = new ToscaDataType();
+ dt1.setName("dt1");
+ dt1.setVersion("0.0.1");
+ dt1.setDescription("dt1 description");
+
+ dtMapList.get(0).put("dt1", dt1);
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+
+ dt1.setDerivedFrom("dt0");
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+
+ dt1.setDerivedFrom("dt2");
+ result = new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent dt2:0.0.0 of entity not found");
+
+ dt1.setDerivedFrom("dt0");
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
}
}
/*-
* ============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");
import java.util.ArrayList;
import java.util.List;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfValidationResult;
assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema(new PfConceptKey())));
assertThatThrownBy(() -> new JpaToscaEntrySchema((PfConceptKey) null))
- .hasMessage("type is marked @NonNull but is null");
+ .hasMessageMatching("type is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaEntrySchema((JpaToscaEntrySchema) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
otherEs.setConstraints(constraints);
assertEquals(0, tes.compareTo(otherEs));
- assertThatThrownBy(() -> tes.copyTo(null)).hasMessage("target is marked @NonNull but is null");
+ assertThatThrownBy(() -> tes.copyTo(null)).hasMessageMatching("target is marked .*on.*ull but is null");
assertEquals(1, tes.getKeys().size());
assertEquals(1, new JpaToscaEntrySchema(typeKey).getKeys().size());
tes.setType(typeKey);
assertTrue(tes.validate(new PfValidationResult()).isValid());
- tes.setDescription("");;
+ tes.setDescription("");
+
assertFalse(tes.validate(new PfValidationResult()).isValid());
tes.setDescription(A_DESCRIPTION);
assertTrue(tes.validate(new PfValidationResult()).isValid());
tes.getConstraints().remove(null);
assertTrue(tes.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tes.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
}
}
/*-
* ============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");
*/
public class JpaToscaEventFilterTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
private static final String A_REQUREMENT = "A Requrement";
private static final String A_CAPABILITY = "A Capability";
private static final String VERSION_001 = "0.0.1";
assertNotNull(new JpaToscaEventFilter(new PfReferenceKey(), new PfConceptKey()));
assertNotNull(new JpaToscaEventFilter(new JpaToscaEventFilter()));
- assertThatThrownBy(() -> new JpaToscaEventFilter((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaEventFilter((PfReferenceKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaEventFilter(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaEventFilter(null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaEventFilter(null, new PfConceptKey())).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaEventFilter(null, new PfConceptKey())).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaEventFilter(new PfReferenceKey(), null))
- .hasMessage("node is marked @NonNull but is null");
+ .hasMessageMatching("node is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaEventFilter((JpaToscaEventFilter) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfConceptKey efParentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey efKey = new PfReferenceKey(efParentKey, "trigger0");
tef.setNode(nodeKey);
assertTrue(tef.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tef.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tef.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
}
}
/*-
* ============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");
import java.util.Map;
import java.util.TreeMap;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelService;
*/
public class JpaToscaModelTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
private static final String VERSION_001 = "0.0.1";
@Test
assertNotNull(new JpaToscaModel(new PfConceptKey(), new JpaToscaServiceTemplates()));
assertNotNull(new JpaToscaModel(new JpaToscaModel()));
- assertThatThrownBy(() -> new JpaToscaModel((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaModel((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaModel(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaModel(null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaModel(null, new JpaToscaServiceTemplates())).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaModel(null, new JpaToscaServiceTemplates()))
+ .hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaModel(new PfConceptKey(), null))
- .hasMessage("serviceTemplates is marked @NonNull but is null");
+ .hasMessageMatching("serviceTemplates is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaModel((JpaToscaModel) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
PfConceptKey tstsKey = new PfConceptKey("tsts", VERSION_001);
Map<PfConceptKey, JpaToscaServiceTemplate> tstMap = new TreeMap<>();
otherDt.setServiceTemplates(tsts);
assertEquals(0, tm.compareTo(otherDt));
- assertThatThrownBy(() -> new JpaToscaModel((JpaToscaModel) null))
- .isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new JpaToscaModel((JpaToscaModel) null)).isInstanceOf(NullPointerException.class);
assertEquals(2, tm.getKeys().size());
assertEquals(2, new JpaToscaModel().getKeys().size());
assertEquals(tttClone0, tm);
assertFalse(new JpaToscaModel().validate(new PfValidationResult()).isValid());
- assertFalse(tm.validate(new PfValidationResult()).isValid());
+ assertTrue(tm.validate(new PfValidationResult()).isValid());
tm.register();
assertTrue(PfModelService.existsModel(tm.getServiceTemplates().getId()));
PfModelService.deregisterModel(tm.getServiceTemplates().getId());
- assertThatThrownBy(() -> tm.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tm.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
}
}
/*-
* ============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");
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
public class JpaToscaPoliciesTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
@Test
public void testPolicies() {
assertNotNull(new JpaToscaPolicies(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaPolicy>()));
assertNotNull(new JpaToscaPolicies(new JpaToscaPolicies()));
- assertThatThrownBy(() -> new JpaToscaPolicies((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaPolicies((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaPolicies((JpaToscaPolicies) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
- assertThatThrownBy(() -> new JpaToscaPolicies(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaPolicies(null, null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaPolicies(new PfConceptKey(), null))
- .hasMessage("conceptMap is marked @NonNull but is null");
+ .hasMessageMatching("conceptMap is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaPolicies(null, new TreeMap<PfConceptKey, JpaToscaPolicy>()))
- .hasMessage(KEY_IS_NULL);
+ .hasMessageMatching(KEY_IS_NULL);
List<Map<String, ToscaPolicy>> polMapList = new ArrayList<>();
polMapList.add(new LinkedHashMap<>());
- polMapList.get(0).put("policyType", new ToscaPolicy());
+
+ ToscaPolicy pol0 = new ToscaPolicy();
+ pol0.setName("pol0");
+ pol0.setVersion("0.0.1");
+ pol0.setDescription("pol0 description");
+ pol0.setType("pt0");
+ pol0.setTypeVersion("0.0.1");
+
+ polMapList.get(0).put("pol0", pol0);
assertNotNull(new JpaToscaPolicies(polMapList));
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+ assertThatThrownBy(() -> new JpaToscaPolicies(polMapList).validate(null))
+ .hasMessageMatching("resultIn is marked .*on.*ull but is null");
+
+ pol0.setDerivedFrom(null);
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+
+ pol0.setDerivedFrom("tosca.Policies.Root");
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+
+ pol0.setDerivedFrom("some.other.Thing");
+ PfValidationResult result = new JpaToscaPolicies(polMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent some.other.Thing:0.0.0 of entity not found");
+
+ pol0.setDerivedFrom(null);
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+
+ ToscaPolicy pol1 = new ToscaPolicy();
+ pol1.setName("pol1");
+ pol1.setVersion("0.0.1");
+ pol1.setDescription("pol1 description");
+ pol1.setType("pt0");
+ pol1.setTypeVersion("0.0.1");
+
+ polMapList.get(0).put("pol1", pol1);
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+
+ pol1.setDerivedFrom("pol0");
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+
+ pol1.setDerivedFrom("pol2");
+ result = new JpaToscaPolicies(polMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent pol2:0.0.0 of entity not found");
+
+ pol1.setDerivedFrom("pol0");
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
}
}
/*-
* ============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");
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
/**
* DAO test for ToscaPolicy.
*/
public class JpaToscaPolicyTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
private static final String VERSION_001 = "0.0.1";
@Test
assertThatThrownBy(() -> {
new JpaToscaPolicy((PfConceptKey) null);
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaPolicy(null, null);
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaPolicy(new PfConceptKey(), null);
- }).hasMessage("type is marked @NonNull but is null");
+ }).hasMessageMatching("type is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
new JpaToscaPolicy(null, new PfConceptKey());
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaPolicy((JpaToscaPolicy) null))
- .isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new JpaToscaPolicy((JpaToscaPolicy) null)).isInstanceOf(NullPointerException.class);
PfConceptKey tpKey = new PfConceptKey("tdt", VERSION_001);
PfConceptKey ptKey = new PfConceptKey("policyType", VERSION_001);
assertThatThrownBy(() -> {
tp.validate(null);
- }).hasMessage("resultIn is marked @NonNull but is null");
+ }).hasMessageMatching("resultIn is marked .*on.*ull but is null");
assertNotNull(tp.toAuthorative());
tp.getType().setVersion(PfKey.NULL_KEY_VERSION);
assertThatThrownBy(() -> {
tp.fromAuthorative(null);
- }).hasMessage("toscaPolicy is marked @NonNull but is null");
+ }).hasMessageMatching("toscaPolicy is marked .*on.*ull but is null");
pol = new ToscaPolicy();
pol.setName("policy");
/*-
* ============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");
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
assertNotNull(new JpaToscaPolicyType(new JpaToscaPolicyType()));
assertThatThrownBy(() -> new JpaToscaPolicyType((PfConceptKey) null))
- .hasMessage("key is marked @NonNull but is null");
+ .hasMessageMatching("key is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaPolicyType((JpaToscaPolicyType) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfConceptKey ptKey = new PfConceptKey("tdt", VERSION_001);
JpaToscaPolicyType tpt = new JpaToscaPolicyType(ptKey);
tpt.getMetadata().remove("nullKey");
assertTrue(tpt.validate(new PfValidationResult()).isValid());
- tpt.setDescription("");;
+ tpt.setDescription("");
+
assertFalse(tpt.validate(new PfValidationResult()).isValid());
tpt.setDescription(A_DESCRIPTION);
assertTrue(tpt.validate(new PfValidationResult()).isValid());
tpt.setDerivedFrom(derivedFromKey);
assertTrue(tpt.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tpt.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tpt.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaEntityType<ToscaPolicy>((PfConceptKey) null))
- .hasMessage("key is marked @NonNull but is null");
+ .hasMessageMatching("key is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaEntityType<ToscaPolicy>((JpaToscaEntityType<ToscaPolicy>) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
JpaToscaEntityType<ToscaPolicy> tet = new JpaToscaEntityType<>(tpt.getKey());
assertEquals(-1, tet.compareTo(null));
/*-
* ============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");
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
public class JpaToscaPolicyTypesTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
@Test
public void testPolicyTypes() {
assertNotNull(new JpaToscaPolicyTypes(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaPolicyType>()));
assertNotNull(new JpaToscaPolicyTypes(new JpaToscaPolicyTypes()));
- assertThatThrownBy(() -> new JpaToscaPolicyTypes((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaPolicyTypes((JpaToscaPolicyTypes) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
- assertThatThrownBy(() -> new JpaToscaPolicyTypes(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes(null, null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaPolicyTypes(new PfConceptKey(), null))
- .hasMessage("conceptMap is marked @NonNull but is null");
+ .hasMessageMatching("conceptMap is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaPolicyTypes(null, new TreeMap<PfConceptKey, JpaToscaPolicyType>()))
- .hasMessage(KEY_IS_NULL);
+ .hasMessageMatching(KEY_IS_NULL);
List<Map<String, ToscaPolicyType>> ptMapList = new ArrayList<>();
ptMapList.add(new LinkedHashMap<>());
- ptMapList.get(0).put("policyType", new ToscaPolicyType());
+
+ ToscaPolicyType pt0 = new ToscaPolicyType();
+ pt0.setName("pt0");
+ pt0.setVersion("0.0.1");
+ pt0.setDescription("pt0 description");
+
+ ptMapList.get(0).put("pt0", pt0);
assertNotNull(new JpaToscaPolicyTypes(ptMapList));
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes(ptMapList).validate(null))
+ .hasMessageMatching("resultIn is marked .*on.*ull but is null");
+
+ pt0.setDerivedFrom(null);
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+
+ pt0.setDerivedFrom("tosca.PolicyTypes.Root");
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+
+ pt0.setDerivedFrom("some.other.Thing");
+ PfValidationResult result = new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent some.other.Thing:0.0.0 of entity not found");
+
+ pt0.setDerivedFrom(null);
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+
+ ToscaPolicyType pt1 = new ToscaPolicyType();
+ pt1.setName("pt1");
+ pt1.setVersion("0.0.1");
+ pt1.setDescription("pt1 description");
+
+ ptMapList.get(0).put("pt1", pt1);
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+
+ pt1.setDerivedFrom("pt0");
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+
+ pt1.setDerivedFrom("pt2");
+ result = new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent pt2:0.0.0 of entity not found");
+
+ pt1.setDerivedFrom("pt0");
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
}
}
/*-
* ============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");
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
*/
public class JpaToscaPropertyTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
private static final String DEFAULT_KEY = "defaultKey";
private static final String A_DESCRIPTION = "A Description";
private static final String VERSION_001 = "0.0.1";
assertNotNull(new JpaToscaProperty(new PfReferenceKey(), new PfConceptKey()));
assertNotNull(new JpaToscaProperty(new JpaToscaProperty()));
- assertThatThrownBy(() -> new JpaToscaProperty((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaProperty((PfReferenceKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaProperty(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaProperty(null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaProperty(null, new PfConceptKey())).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaProperty(null, new PfConceptKey())).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaProperty(new PfReferenceKey(), null))
- .hasMessage("type is marked @NonNull but is null");
+ .hasMessageMatching("type is marked .*on.*ull but is null");
PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0");
JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
tp.setEntrySchema(tes);
- TreeMap<String,String> metadata = new TreeMap<>();
+ TreeMap<String, String> metadata = new TreeMap<>();
metadata.put("metaA", "dataA");
metadata.put("metaB", "dataB");
tp.setMetadata(metadata);
assertEquals(0, tp.compareTo(otherDt));
assertThatThrownBy(() -> new JpaToscaProperty((JpaToscaProperty) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
assertEquals(3, tp.getKeys().size());
assertEquals(2, new JpaToscaProperty().getKeys().size());
tp.setMetadata(null);
assertTrue(tp.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tp.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tp.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
}
@Test
JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
tp.setEntrySchema(tes);
- TreeMap<String,String> metadata = new TreeMap<>();
+ TreeMap<String, String> metadata = new TreeMap<>();
metadata.put("metaA", "dataA");
metadata.put("metaB", "dataB");
tp.setMetadata(metadata);
/*-
* ============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");
import java.util.Map;
import java.util.TreeMap;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
*/
public class JpaToscaServiceTemplateTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
private static final String VERSION_001 = "0.0.1";
@Test
assertNotNull(new JpaToscaServiceTemplate(new PfConceptKey(), ""));
assertNotNull(new JpaToscaServiceTemplate(new JpaToscaServiceTemplate()));
- assertThatThrownBy(() -> new JpaToscaServiceTemplate((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaServiceTemplate(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate(null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaServiceTemplate(null, "")).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate(null, "")).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaServiceTemplate(new PfConceptKey(), null))
- .hasMessage("toscaDefinitionsVersion is marked @NonNull but is null");
+ .hasMessageMatching("toscaDefinitionsVersion is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfConceptKey tstKey = new PfConceptKey("tst", VERSION_001);
JpaToscaServiceTemplate tst = new JpaToscaServiceTemplate(tstKey, "Tosca Version");
tst.setDescription("A Description");
assertTrue(tst.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tst.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tst.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
}
}
/*-
* ============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");
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplates;
public class JpaToscaServiceTemplatesTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
@Test
public void testServiceTemplates() {
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates((PfConceptKey) null);
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates((JpaToscaServiceTemplates) null);
- }).hasMessage("copyConcept is marked @NonNull but is null");
+ }).hasMessageMatching("copyConcept is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates(null, null);
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates(new PfConceptKey(), null);
- }).hasMessage("conceptMap is marked @NonNull but is null");
+ }).hasMessageMatching("conceptMap is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates(null, new TreeMap<PfConceptKey, JpaToscaServiceTemplate>());
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
List<Map<String, ToscaServiceTemplate>> tsMapList = new ArrayList<>();
tsMapList.add(new LinkedHashMap<>());
/*-
* ============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");
import static org.junit.Assert.assertTrue;
import java.util.Date;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
*/
public class JpaToscaTimeIntervalTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
@Test
public void testTimeIntervalPojo() {
assertNotNull(new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), new Date()));
assertNotNull(new JpaToscaTimeInterval(new JpaToscaTimeInterval()));
- assertThatThrownBy(() -> new JpaToscaTimeInterval((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTimeInterval((PfReferenceKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, new Date())).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, new Date())).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), new Date())).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), new Date()))
+ .hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), null, null))
- .hasMessage("startTime is marked @NonNull but is null");
+ .hasMessageMatching("startTime is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), null, new Date()))
- .hasMessage("startTime is marked @NonNull but is null");
+ .hasMessageMatching("startTime is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), null))
- .hasMessage("endTime is marked @NonNull but is null");
+ .hasMessageMatching("endTime is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfConceptKey ttiParentKey = new PfConceptKey("tParentKey", "0.0.1");
PfReferenceKey ttiKey = new PfReferenceKey(ttiParentKey, "trigger0");
tti.setEndTime(endTime);
assertTrue(tti.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tti.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tti.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
}
}
/*-
* ============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");
import java.util.Map;
import java.util.TreeMap;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
assertNotNull(new JpaToscaTopologyTemplate(new ToscaTopologyTemplate()));
assertThatThrownBy(() -> new JpaToscaTopologyTemplate((PfReferenceKey) null))
- .hasMessage("key is marked @NonNull but is null");
+ .hasMessageMatching("key is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfReferenceKey tttKey = new PfReferenceKey("tst", VERSION_001, "ttt");
JpaToscaTopologyTemplate ttt = new JpaToscaTopologyTemplate(tttKey);
assertEquals(0, ttt.compareTo(otherDt));
assertThatThrownBy(() -> new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
assertEquals(4, ttt.getKeys().size());
assertEquals(1, new JpaToscaTopologyTemplate().getKeys().size());
ttt.setDescription(A_DESCRIPTION);
assertTrue(ttt.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> ttt.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> ttt.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
}
}
/*-
* ============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");
import java.time.Duration;
import java.util.Date;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
*/
public class JpaToscaTriggerTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
private static final String EVENT_TYPE = "EventType";
private static final String ACTION = "Action";
private static final String A_METHOD = "A Method";
assertNotNull(new JpaToscaTrigger(new PfReferenceKey(), EVENT_TYPE, ACTION));
assertNotNull(new JpaToscaTrigger(new JpaToscaTrigger()));
- assertThatThrownBy(() -> new JpaToscaTrigger((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTrigger((PfReferenceKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTrigger(null, null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTrigger(null, EVENT_TYPE, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, EVENT_TYPE, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTrigger(null, EVENT_TYPE, ACTION)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, EVENT_TYPE, ACTION)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTrigger(null, null, ACTION)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, null, ACTION)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaTrigger(new PfReferenceKey(), null, null))
- .hasMessage("eventType is marked @NonNull but is null");
+ .hasMessageMatching("eventType is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTrigger(new PfReferenceKey(), EVENT_TYPE, null))
- .hasMessage("action is marked @NonNull but is null");
+ .hasMessageMatching("action is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTrigger(new PfReferenceKey(), null, ACTION))
- .hasMessage("eventType is marked @NonNull but is null");
+ .hasMessageMatching("eventType is marked .*on.*ull but is null");
- assertThatThrownBy(() -> new JpaToscaTrigger((JpaToscaTrigger) null))
- .isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new JpaToscaTrigger((JpaToscaTrigger) null)).isInstanceOf(NullPointerException.class);
PfConceptKey tparentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey tkey = new PfReferenceKey(tparentKey, "trigger0");
tdt.setMethod(A_METHOD);
assertTrue(tdt.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tdt.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tdt.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
}
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.utils;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Iterator;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+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.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
+
+/**
+ * Import the {@link ToscaServiceTemplateUtilsTest} class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaServiceTemplateUtilsTest {
+ @Test
+ public void testAddFragmentNulls() {
+ assertThatThrownBy(() -> {
+ ToscaServiceTemplateUtils.addFragment(null, null);
+ }).hasMessageMatching("originalTemplate is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaServiceTemplateUtils.addFragment(null, new JpaToscaServiceTemplate());
+ }).hasMessageMatching("originalTemplate is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaServiceTemplateUtils.addFragment(new JpaToscaServiceTemplate(), null);
+ }).hasMessageMatching("fragmentTemplate is marked .*on.*ull but is null");
+
+ assertEquals(new JpaToscaServiceTemplate(),
+ ToscaServiceTemplateUtils.addFragment(new JpaToscaServiceTemplate(), new JpaToscaServiceTemplate()));
+ }
+
+ @Test
+ public void testAddFragment() {
+ JpaToscaServiceTemplate originalTemplate = new JpaToscaServiceTemplate();
+ JpaToscaServiceTemplate fragmentTemplate00 = new JpaToscaServiceTemplate();
+
+ assertEquals(originalTemplate, ToscaServiceTemplateUtils.addFragment(originalTemplate, originalTemplate));
+ assertEquals(originalTemplate, ToscaServiceTemplateUtils.addFragment(originalTemplate, fragmentTemplate00));
+ assertEquals(originalTemplate, ToscaServiceTemplateUtils.addFragment(fragmentTemplate00, originalTemplate));
+ assertEquals(originalTemplate, ToscaServiceTemplateUtils.addFragment(fragmentTemplate00, fragmentTemplate00));
+ assertEquals(fragmentTemplate00, ToscaServiceTemplateUtils.addFragment(originalTemplate, originalTemplate));
+ assertEquals(fragmentTemplate00, ToscaServiceTemplateUtils.addFragment(originalTemplate, fragmentTemplate00));
+ assertEquals(fragmentTemplate00, ToscaServiceTemplateUtils.addFragment(fragmentTemplate00, originalTemplate));
+ assertEquals(fragmentTemplate00, ToscaServiceTemplateUtils.addFragment(fragmentTemplate00, fragmentTemplate00));
+
+ fragmentTemplate00.setDataTypes(new JpaToscaDataTypes());
+ fragmentTemplate00.setPolicyTypes(new JpaToscaPolicyTypes());
+
+ JpaToscaServiceTemplate compositeTemplate00 =
+ ToscaServiceTemplateUtils.addFragment(originalTemplate, fragmentTemplate00);
+ assertEquals(compositeTemplate00,
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate00, fragmentTemplate00));
+ assertEquals(compositeTemplate00,
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate00, new JpaToscaServiceTemplate()));
+ assertEquals(compositeTemplate00,
+ ToscaServiceTemplateUtils.addFragment(new JpaToscaServiceTemplate(), compositeTemplate00));
+
+ JpaToscaDataType dt0 = new JpaToscaDataType();
+ dt0.setKey(new PfConceptKey("dt0", "0.0.1"));
+ dt0.setDescription("dt0 description");
+ JpaToscaServiceTemplate fragmentTemplate01 = new JpaToscaServiceTemplate();
+ fragmentTemplate01.setDataTypes(new JpaToscaDataTypes());
+ fragmentTemplate01.getDataTypes().getConceptMap().put(dt0.getKey(), dt0);
+
+ JpaToscaServiceTemplate compositeTemplate01 =
+ ToscaServiceTemplateUtils.addFragment(originalTemplate, fragmentTemplate01);
+ assertEquals(compositeTemplate01,
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate01, fragmentTemplate01));
+ assertEquals(compositeTemplate01,
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate01, new JpaToscaServiceTemplate()));
+ assertEquals(compositeTemplate01,
+ ToscaServiceTemplateUtils.addFragment(new JpaToscaServiceTemplate(), compositeTemplate01));
+
+ JpaToscaServiceTemplate compositeTemplate02 =
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate00, fragmentTemplate01);
+ assertEquals(compositeTemplate02,
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate02, fragmentTemplate01));
+ assertEquals(compositeTemplate02,
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate02, new JpaToscaServiceTemplate()));
+ assertEquals(compositeTemplate02,
+ ToscaServiceTemplateUtils.addFragment(new JpaToscaServiceTemplate(), compositeTemplate02));
+
+ JpaToscaDataType otherDt0 = new JpaToscaDataType();
+ otherDt0.setKey(new PfConceptKey("dt0", "0.0.1"));
+ otherDt0.setDescription("dt0 description");
+ JpaToscaServiceTemplate fragmentTemplate02 = new JpaToscaServiceTemplate();
+ fragmentTemplate02.setDataTypes(new JpaToscaDataTypes());
+ fragmentTemplate02.getDataTypes().getConceptMap().put(otherDt0.getKey(), otherDt0);
+
+ compositeTemplate00 = ToscaServiceTemplateUtils.addFragment(compositeTemplate00, fragmentTemplate02);
+ assertEquals(compositeTemplate00,
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate00, fragmentTemplate02));
+
+ JpaToscaDataType badOtherDt0 = new JpaToscaDataType();
+ badOtherDt0.setKey(new PfConceptKey("dt0", "0.0.1"));
+ badOtherDt0.setDescription("dt0 bad description");
+ JpaToscaServiceTemplate fragmentTemplate03 = new JpaToscaServiceTemplate();
+ fragmentTemplate03.setDataTypes(new JpaToscaDataTypes());
+ fragmentTemplate03.getDataTypes().getConceptMap().put(otherDt0.getKey(), otherDt0);
+ fragmentTemplate03.getDataTypes().getConceptMap().put(badOtherDt0.getKey(), badOtherDt0);
+
+ final JpaToscaServiceTemplate compositeTestTemplate = new JpaToscaServiceTemplate(compositeTemplate00);
+ assertThatThrownBy(() -> {
+ ToscaServiceTemplateUtils.addFragment(compositeTestTemplate, fragmentTemplate03);
+ }).hasMessageContaining("entity in incoming fragment does not equal existing entity");
+
+ JpaToscaServiceTemplate fragmentTemplate04 = new JpaToscaServiceTemplate();
+ fragmentTemplate04.setDescription("Another service template");
+ assertThatThrownBy(() -> {
+ ToscaServiceTemplateUtils.addFragment(compositeTestTemplate, fragmentTemplate04);
+ }).hasMessageContaining("service template in incoming fragment does not equal existing service template");
+
+ JpaToscaServiceTemplate fragmentTemplate05 = new JpaToscaServiceTemplate();
+ fragmentTemplate05.setTopologyTemplate(new JpaToscaTopologyTemplate());
+ fragmentTemplate05.getTopologyTemplate().setDescription("topology template description");
+ JpaToscaServiceTemplate compositeTemplate03 =
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate02, fragmentTemplate05);
+ assertEquals(fragmentTemplate05.getTopologyTemplate(), compositeTemplate03.getTopologyTemplate());
+
+ JpaToscaServiceTemplate fragmentTemplate06 = new JpaToscaServiceTemplate();
+ fragmentTemplate06.setTopologyTemplate(new JpaToscaTopologyTemplate());
+ fragmentTemplate06.getTopologyTemplate().setDescription("topology template description");
+ JpaToscaServiceTemplate compositeTemplate04 =
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate03, fragmentTemplate06);
+ assertEquals(fragmentTemplate06.getTopologyTemplate(), compositeTemplate04.getTopologyTemplate());
+
+ JpaToscaServiceTemplate fragmentTemplate07 = new JpaToscaServiceTemplate();
+ fragmentTemplate07.setTopologyTemplate(new JpaToscaTopologyTemplate());
+ fragmentTemplate07.getTopologyTemplate().setDescription("topology template other description");
+ assertThatThrownBy(() -> {
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate04, fragmentTemplate07);
+ }).hasMessageContaining("topology template in incoming fragment does not equal existing topology template");
+
+ JpaToscaDataType dt1 = new JpaToscaDataType();
+ dt1.setKey(new PfConceptKey("dt1", "0.0.1"));
+ dt1.setDescription("dt1 description");
+
+ JpaToscaPolicyType pt0 = new JpaToscaPolicyType();
+ pt0.setKey(new PfConceptKey("pt0", "0.0.1"));
+ pt0.setDescription("pt0 description");
+
+ JpaToscaPolicy p0 = new JpaToscaPolicy();
+ p0.setKey(new PfConceptKey("p0", "0.0.1"));
+ p0.setDescription("pt0 description");
+
+ JpaToscaServiceTemplate fragmentTemplate08 = new JpaToscaServiceTemplate();
+
+ fragmentTemplate08.setDataTypes(new JpaToscaDataTypes());
+ fragmentTemplate08.getDataTypes().getConceptMap().put(dt1.getKey(), dt1);
+
+ fragmentTemplate08.setPolicyTypes(new JpaToscaPolicyTypes());
+ fragmentTemplate08.getPolicyTypes().getConceptMap().put(pt0.getKey(), pt0);
+
+ fragmentTemplate08.setTopologyTemplate(new JpaToscaTopologyTemplate());
+ fragmentTemplate08.getTopologyTemplate().setDescription("topology template description");
+
+ fragmentTemplate08.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+ fragmentTemplate08.getTopologyTemplate().getPolicies().getConceptMap().put(p0.getKey(), p0);
+
+ assertThatThrownBy(() -> {
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate04, fragmentTemplate08);
+ }).hasMessageContaining("JpaToscaPolicy:INVALID:type is null or a null key");
+
+ p0.setType(pt0.getKey());
+
+ JpaToscaServiceTemplate compositeTemplate05 =
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate04, fragmentTemplate08);
+ Iterator<JpaToscaDataType> dtIterator = compositeTemplate05.getDataTypes().getAll(null).iterator();
+ assertEquals(dt0, dtIterator.next());
+ assertEquals(dt1, dtIterator.next());
+ assertEquals(pt0, compositeTemplate05.getPolicyTypes().getAll(null).iterator().next());
+ assertEquals(p0, compositeTemplate05.getTopologyTemplate().getPolicies().getAll(null).iterator().next());
+ }
+}
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfValidationResult;
+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.JpaToscaPolicyTypes;
ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
}).doesNotThrowAnyException();
}
+
+ @Test
+ public void testGetentityTypeAncestors() {
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(null, null, null);
+ }).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(null, null, new PfValidationResult());
+ }).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(null, new JpaToscaDataType(), null);
+ }).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(null, new JpaToscaDataType(), new PfValidationResult());
+ }).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(new JpaToscaDataTypes(), null, null);
+ }).hasMessageMatching("entityType is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(new JpaToscaDataTypes(), null, new PfValidationResult());
+ }).hasMessageMatching("entityType is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(new JpaToscaDataTypes(), new JpaToscaDataType(), null);
+ }).hasMessageMatching("result is marked .*on.*ull but is null");
+
+ JpaToscaDataTypes dataTypes = new JpaToscaDataTypes();
+ JpaToscaDataType dt0 = new JpaToscaDataType();
+ dt0.setKey(new PfConceptKey("dt0", "0.0.1"));
+ dt0.setDescription("dt0 description");
+ PfValidationResult result = new PfValidationResult();
+
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+
+ dataTypes.getConceptMap().put(dt0.getKey(), dt0);
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertTrue(result.isValid());
+
+ dt0.setDerivedFrom(null);
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertTrue(result.isValid());
+
+ dt0.setDerivedFrom(new PfConceptKey("tosca.datatyps.Root", PfKey.NULL_KEY_VERSION));
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertTrue(result.isValid());
+
+ dt0.setDerivedFrom(new PfConceptKey("some.thing.Else", PfKey.NULL_KEY_VERSION));
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertFalse(result.isValid());
+ assertTrue(result.toString().contains("parent some.thing.Else:0.0.0 of entity not found"));
+
+ result = new PfValidationResult();
+ dt0.setDerivedFrom(new PfConceptKey("tosca.datatyps.Root", PfKey.NULL_KEY_VERSION));
+
+ JpaToscaDataType dt1 = new JpaToscaDataType();
+ dt1.setKey(new PfConceptKey("dt1", "0.0.1"));
+ dt1.setDescription("dt1 description");
+ dataTypes.getConceptMap().put(dt1.getKey(), dt1);
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
+ assertTrue(result.isValid());
+
+ dt1.setDerivedFrom(dt0.getKey());
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
+ assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
+ assertTrue(result.isValid());
+
+ JpaToscaDataType dt2 = new JpaToscaDataType();
+ dt2.setKey(new PfConceptKey("dt2", "0.0.1"));
+ dt2.setDescription("dt2 description");
+ dataTypes.getConceptMap().put(dt2.getKey(), dt2);
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
+ assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
+ assertTrue(result.isValid());
+
+ dt2.setDerivedFrom(dt1.getKey());
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).isEmpty());
+ assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
+ assertEquals(2, ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).size());
+ assertTrue(result.isValid());
+
+ 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());
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).isEmpty());
+ assertEquals(0, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
+ assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).size());
+ assertTrue(result.isValid());
+
+ dataTypes.getConceptMap().remove(dt1.getKey());
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).isEmpty());
+ assertFalse(result.isValid());
+ assertTrue(result.toString().contains("parent dt1:0.0.1 of entity not found"));
+ }
}