aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2021-03-04 16:13:36 +0000
committerGerrit Code Review <gerrit@onap.org>2021-03-04 16:13:36 +0000
commit4301496b538fcb10df92d53984ed2a05dade3d08 (patch)
treeb70d63c746b6e2a84736c5eac6a500440b5cde56 /models-tosca/src
parent8d77651dfb0ade7d5b9059260788ec583340c590 (diff)
parented11e882d9128616156a2be08744e5a9bdb01111 (diff)
Merge "Refactor models for common type handling"
Diffstat (limited to 'models-tosca/src')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaCapabilityAssignment.java26
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaNodeTemplate.java7
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java33
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaRequirement.java27
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithTypeAndObjectProperties.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithObjectProperties.java)36
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java4
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java26
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java58
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java4
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithTypeAndStringProperties.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringProperties.java)88
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java28
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithTypeAndObjectPropertiesTest.java (renamed from models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithObjectPropertiesTest.java)13
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java28
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java5
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java28
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java16
16 files changed, 247 insertions, 180 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaCapabilityAssignment.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaCapabilityAssignment.java
index 2d9cf9a39..11ffc044b 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaCapabilityAssignment.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaCapabilityAssignment.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,16 +21,38 @@
package org.onap.policy.models.tosca.authorative.concepts;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
+import lombok.NonNull;
+import lombok.ToString;
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
-public class ToscaCapabilityAssignment extends ToscaWithObjectProperties {
+@ToString(callSuper = true)
+public class ToscaCapabilityAssignment extends ToscaWithTypeAndObjectProperties {
private Map<String, Object> attributes;
private List<Object> occurrences;
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyObject object to copy
+ */
+ public ToscaCapabilityAssignment(@NonNull ToscaCapabilityAssignment copyObject) {
+ super(copyObject);
+
+ if (copyObject.attributes != null) {
+ attributes = new LinkedHashMap<>(copyObject.attributes);
+ }
+
+ if (copyObject.occurrences != null) {
+ occurrences = new ArrayList<>(copyObject.occurrences);
+ }
+ }
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaNodeTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaNodeTemplate.java
index c4bc84cd8..c95836de6 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaNodeTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaNodeTemplate.java
@@ -31,12 +31,13 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
+import lombok.ToString;
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
-public class ToscaNodeTemplate extends ToscaWithObjectProperties {
- private String type;
+@ToString(callSuper = true)
+public class ToscaNodeTemplate extends ToscaWithTypeAndObjectProperties {
private List<Map<String, ToscaRequirement>> requirements;
private Map<String, ToscaCapabilityAssignment> capabilities;
@@ -48,8 +49,6 @@ public class ToscaNodeTemplate extends ToscaWithObjectProperties {
public ToscaNodeTemplate(@NonNull ToscaNodeTemplate copyObject) {
super(copyObject);
- this.type = copyObject.type;
-
this.requirements = (copyObject.requirements != null ? new ArrayList<>(copyObject.requirements) : null);
this.capabilities = (copyObject.capabilities != null ? new LinkedHashMap<>(copyObject.capabilities) : null);
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java
index b3a38050a..00d783d2d 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java
@@ -23,8 +23,6 @@
package org.onap.policy.models.tosca.authorative.concepts;
-import com.google.gson.annotations.SerializedName;
-import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@@ -40,40 +38,13 @@ import lombok.ToString;
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@ToString(callSuper = true)
-public class ToscaPolicy extends ToscaWithObjectProperties {
- private String type;
-
- @ApiModelProperty(name = "type_version")
- @SerializedName("type_version")
- private String typeVersion;
-
+public class ToscaPolicy extends ToscaWithTypeAndObjectProperties {
/**
* Copy constructor.
*
- * @param copyObject the obejct to copy from.
+ * @param copyObject object to copy
*/
public ToscaPolicy(@NonNull ToscaPolicy copyObject) {
super(copyObject);
-
- this.type = copyObject.type;
- this.typeVersion = copyObject.typeVersion;
- }
-
- /**
- * Gets the identifier for this policy.
- *
- * @return this policy's identifier
- */
- public ToscaConceptIdentifier getIdentifier() {
- return new ToscaConceptIdentifier(getName(), getVersion());
- }
-
- /**
- * Gets the type identifier for this policy.
- *
- * @return this policy's type identifier
- */
- public ToscaConceptIdentifier getTypeIdentifier() {
- return new ToscaConceptIdentifier(getType(), getTypeVersion());
}
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaRequirement.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaRequirement.java
index 166b81174..d2c3b83a3 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaRequirement.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaRequirement.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,15 +21,38 @@
package org.onap.policy.models.tosca.authorative.concepts;
+import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
+import lombok.ToString;
@Data
@EqualsAndHashCode(callSuper = true)
-public class ToscaRequirement extends ToscaWithObjectProperties {
+@NoArgsConstructor
+@ToString(callSuper = true)
+public class ToscaRequirement extends ToscaWithTypeAndObjectProperties {
private String capability;
private String node;
private String relationship;
private List<Object> occurrences;
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyObject object to copy
+ */
+ public ToscaRequirement(@NonNull ToscaRequirement copyObject) {
+ super(copyObject);
+
+ this.capability = copyObject.capability;
+ this.node = copyObject.node;
+ this.relationship = copyObject.relationship;
+
+ if (copyObject.occurrences != null) {
+ occurrences = new ArrayList<>(copyObject.occurrences);
+ }
+ }
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithObjectProperties.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithTypeAndObjectProperties.java
index f6cf24f61..0bcb1cf54 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithObjectProperties.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithTypeAndObjectProperties.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +21,8 @@
package org.onap.policy.models.tosca.authorative.concepts;
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModelProperty;
import java.util.LinkedHashMap;
import java.util.Map;
import lombok.Data;
@@ -36,19 +39,46 @@ import lombok.ToString;
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@ToString
-public class ToscaWithObjectProperties extends ToscaEntity {
+public class ToscaWithTypeAndObjectProperties extends ToscaEntity {
+ private String type;
+
+ @ApiModelProperty(name = "type_version")
+ @SerializedName("type_version")
+ private String typeVersion;
+
private Map<String, Object> properties;
/**
- * Cop[y constructor.
+ * Copy constructor.
*
* @param copyObject object to copy
*/
- public ToscaWithObjectProperties(@NonNull ToscaWithObjectProperties copyObject) {
+ public ToscaWithTypeAndObjectProperties(@NonNull ToscaWithTypeAndObjectProperties copyObject) {
super(copyObject);
+ this.type = copyObject.type;
+ this.typeVersion = copyObject.typeVersion;
+
if (copyObject.properties != null) {
properties = new LinkedHashMap<>(copyObject.properties);
}
}
+
+ /**
+ * Gets the identifier for this policy.
+ *
+ * @return this policy's identifier
+ */
+ public ToscaConceptIdentifier getIdentifier() {
+ return new ToscaConceptIdentifier(getName(), getVersion());
+ }
+
+ /**
+ * Gets the type identifier for this policy.
+ *
+ * @return this policy's type identifier
+ */
+ public ToscaConceptIdentifier getTypeIdentifier() {
+ return new ToscaConceptIdentifier(getType(), getTypeVersion());
+ }
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java
index bb5cf5a73..76508dabe 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -50,7 +50,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignme
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
-public class JpaToscaCapabilityAssignment extends JpaToscaWithStringProperties<ToscaCapabilityAssignment> {
+public class JpaToscaCapabilityAssignment extends JpaToscaWithTypeAndStringProperties<ToscaCapabilityAssignment> {
private static final long serialVersionUID = 1675770231921107988L;
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java
index 9507a9d2f..f6cfc1258 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +26,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.CascadeType;
-import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
@@ -39,8 +38,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.parameters.annotations.NotBlank;
-import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -59,16 +56,11 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
-public class JpaToscaNodeTemplate extends JpaToscaWithStringProperties<ToscaNodeTemplate> {
+public class JpaToscaNodeTemplate extends JpaToscaWithTypeAndStringProperties<ToscaNodeTemplate> {
private static final long serialVersionUID = 1675770231921107988L;
private static final StandardCoder STANDARD_CODER = new StandardCoder();
- @Column
- @NotNull
- @NotBlank
- private String type;
-
// formatter:off
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "requirementsName", referencedColumnName = "name")
@@ -106,7 +98,7 @@ public class JpaToscaNodeTemplate extends JpaToscaWithStringProperties<ToscaNode
*/
public JpaToscaNodeTemplate(final JpaToscaNodeTemplate copyConcept) {
super(copyConcept);
- this.type = copyConcept.type;
+
this.requirements =
(copyConcept.requirements != null ? new JpaToscaRequirements(copyConcept.requirements) : null);
this.capabilities =
@@ -121,7 +113,6 @@ public class JpaToscaNodeTemplate extends JpaToscaWithStringProperties<ToscaNode
*/
public JpaToscaNodeTemplate(@NonNull final PfConceptKey key, final String type) {
super(key);
- this.type = type;
}
/**
@@ -139,8 +130,6 @@ public class JpaToscaNodeTemplate extends JpaToscaWithStringProperties<ToscaNode
super.setToscaEntity(toscaNodeTemplate);
super.toAuthorative();
- toscaNodeTemplate.setType(type);
-
if (requirements != null) {
toscaNodeTemplate.setRequirements(requirements.toAuthorative());
}
@@ -160,8 +149,6 @@ public class JpaToscaNodeTemplate extends JpaToscaWithStringProperties<ToscaNode
public void fromAuthorative(ToscaNodeTemplate toscaNodeTemplate) {
super.fromAuthorative(toscaNodeTemplate);
- type = toscaNodeTemplate.getType();
-
if (toscaNodeTemplate.getRequirements() != null) {
requirements = new JpaToscaRequirements();
requirements.fromAuthorative(toscaNodeTemplate.getRequirements());
@@ -212,8 +199,6 @@ public class JpaToscaNodeTemplate extends JpaToscaWithStringProperties<ToscaNode
public void clean() {
super.clean();
- type = type.trim();
-
if (requirements != null) {
requirements.clean();
}
@@ -236,11 +221,6 @@ public class JpaToscaNodeTemplate extends JpaToscaWithStringProperties<ToscaNode
final JpaToscaNodeTemplate other = (JpaToscaNodeTemplate) otherConcept;
- result = type.compareTo(other.type);
- if (result != 0) {
- return result;
- }
-
result = ObjectUtils.compare(requirements, other.requirements);
if (result != 0) {
return result;
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
index dae3527ee..b33205c43 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
@@ -3,7 +3,7 @@
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,6 @@ package org.onap.policy.models.tosca.simple.concepts;
import java.util.LinkedHashMap;
import java.util.List;
-import javax.persistence.AttributeOverride;
-import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
@@ -46,7 +44,6 @@ import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.validation.annotations.VerifyKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
/**
@@ -60,7 +57,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = true)
-public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
+public class JpaToscaPolicy extends JpaToscaWithTypeAndStringProperties<ToscaPolicy> {
private static final long serialVersionUID = 3265174757061982805L;
// Tags for metadata
@@ -69,23 +66,14 @@ public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
private static final StandardCoder STANDARD_CODER = new StandardCoder();
- // @formatter:off
- @Column
- @AttributeOverride(name = "name", column = @Column(name = "type_name"))
- @AttributeOverride(name = "version", column = @Column(name = "type_version"))
- @VerifyKey
- @NotNull
- private PfConceptKey type;
-
@ElementCollection
private List<@NotNull @Valid PfConceptKey> targets;
- // @formatter:on
/**
* The Default Constructor creates a {@link JpaToscaPolicy} object with a null key.
*/
public JpaToscaPolicy() {
- this(new PfConceptKey());
+ super();
}
/**
@@ -94,7 +82,7 @@ public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
* @param key the key
*/
public JpaToscaPolicy(@NonNull final PfConceptKey key) {
- this(key, new PfConceptKey());
+ super(key, new PfConceptKey());
}
/**
@@ -104,8 +92,7 @@ public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
* @param type the type of the policy
*/
public JpaToscaPolicy(@NonNull final PfConceptKey key, @NonNull final PfConceptKey type) {
- super(key);
- this.type = type;
+ super(key, type);
}
/**
@@ -115,7 +102,6 @@ public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
*/
public JpaToscaPolicy(@NonNull final JpaToscaPolicy copyConcept) {
super(copyConcept);
- this.type = new PfConceptKey(copyConcept.type);
this.targets = PfUtils.mapList(copyConcept.targets, PfConceptKey::new);
}
@@ -126,7 +112,6 @@ public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
*/
public JpaToscaPolicy(final ToscaPolicy authorativeConcept) {
super(new PfConceptKey());
- type = new PfConceptKey();
this.fromAuthorative(authorativeConcept);
}
@@ -136,14 +121,6 @@ public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
super.setToscaEntity(toscaPolicy);
super.toAuthorative();
- toscaPolicy.setType(type.getName());
-
- if (!PfKey.NULL_KEY_VERSION.equals(type.getVersion())) {
- toscaPolicy.setTypeVersion(type.getVersion());
- } else {
- toscaPolicy.setTypeVersion(null);
- }
-
return toscaPolicy;
}
@@ -151,22 +128,6 @@ public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
public void fromAuthorative(@NonNull final ToscaPolicy toscaPolicy) {
super.fromAuthorative(toscaPolicy);
- if (toscaPolicy.getType() != null) {
- type.setName(toscaPolicy.getType());
- } else {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
- "PolicyType type not specified, the type of the PolicyType for this policy must be specified in "
- + "the type field");
- }
-
- if (toscaPolicy.getTypeVersion() != null) {
- type.setVersion(toscaPolicy.getTypeVersion());
- } else {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
- "PolicyType version not specified, the version of the PolicyType for this policy must be specified"
- + " in the type_version field");
- }
-
// Add the property metadata if it doesn't exist already
if (toscaPolicy.getMetadata() == null) {
setMetadata(new LinkedHashMap<>());
@@ -201,8 +162,6 @@ public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
public List<PfKey> getKeys() {
final List<PfKey> keyList = super.getKeys();
- keyList.addAll(type.getKeys());
-
if (targets != null) {
keyList.addAll(targets);
}
@@ -214,8 +173,6 @@ public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
public void clean() {
super.clean();
- type.clean();
-
if (targets != null) {
for (PfConceptKey target : targets) {
target.clean();
@@ -245,11 +202,6 @@ public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
final JpaToscaPolicy other = (JpaToscaPolicy) otherConcept;
- result = type.compareTo(other.type);
- if (result != 0) {
- return result;
- }
-
return PfUtils.compareCollections(targets, other.targets);
}
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java
index eeae03dd7..20b6aff96 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java
@@ -3,7 +3,7 @@
* ONAP Requirement Model
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaRequirement;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = true)
-public class JpaToscaRequirement extends JpaToscaWithStringProperties<ToscaRequirement> {
+public class JpaToscaRequirement extends JpaToscaWithTypeAndStringProperties<ToscaRequirement> {
private static final long serialVersionUID = 2785481541573683089L;
private static final String AUTHORATIVE_UNBOUNDED_LITERAL = "UNBOUNDED";
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringProperties.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithTypeAndStringProperties.java
index afe4a84d1..1ba63cad5 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringProperties.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithTypeAndStringProperties.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,10 +22,14 @@
package org.onap.policy.models.tosca.simple.concepts;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
+import javax.persistence.AttributeOverride;
+import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Lob;
import javax.persistence.MappedSuperclass;
+import javax.ws.rs.core.Response;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
@@ -33,8 +38,11 @@ import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaWithObjectProperties;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaWithTypeAndObjectProperties;
/**
* Class to represent JPA TOSCA classes containing property maps whose values are Strings.
@@ -42,31 +50,47 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaWithObjectProperti
@MappedSuperclass
@Data
@EqualsAndHashCode(callSuper = true)
-public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProperties> extends JpaToscaEntityType<T>
- implements PfAuthorative<T> {
+public abstract class JpaToscaWithTypeAndStringProperties<T extends ToscaWithTypeAndObjectProperties>
+ extends JpaToscaEntityType<T> implements PfAuthorative<T> {
private static final long serialVersionUID = 2785481541573683089L;
+ @Column
+ @AttributeOverride(name = "name", column = @Column(name = "type_name"))
+ @AttributeOverride(name = "version", column = @Column(name = "type_version"))
+ @VerifyKey
+ @NotNull
+ private PfConceptKey type;
+
@ElementCollection
@Lob
private Map<@NotNull String, @NotNull String> properties;
/**
- * The Default Constructor creates a {@link JpaToscaWithStringProperties} object with
- * a null key.
+ * The Default Constructor creates a {@link JpaToscaWithTypeAndStringProperties} object with a null key.
*/
- protected JpaToscaWithStringProperties() {
+ protected JpaToscaWithTypeAndStringProperties() {
this(new PfConceptKey());
}
/**
- * The Key Constructor creates a {@link JpaToscaWithStringProperties} object with the
- * given concept key.
+ * The Key Constructor creates a {@link JpaToscaWithTypeAndStringProperties} object with the given concept key.
+ *
+ * @param key the key
+ */
+ protected JpaToscaWithTypeAndStringProperties(@NonNull final PfConceptKey key) {
+ this(key, new PfConceptKey());
+ }
+
+ /**
+ * The full Constructor creates a {@link JpaToscaWithTypeAndStringProperties} object with all mandatory fields.
*
* @param key the key
+ * @param type the type of the policy
*/
- protected JpaToscaWithStringProperties(@NonNull final PfConceptKey key) {
+ protected JpaToscaWithTypeAndStringProperties(@NonNull final PfConceptKey key, @NonNull final PfConceptKey type) {
super(key);
+ this.type = type;
}
/**
@@ -74,8 +98,9 @@ public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProp
*
* @param copyConcept the concept to copy from
*/
- protected JpaToscaWithStringProperties(@NonNull final JpaToscaWithStringProperties<T> copyConcept) {
+ protected JpaToscaWithTypeAndStringProperties(@NonNull final JpaToscaWithTypeAndStringProperties<T> copyConcept) {
super(copyConcept);
+ this.type = new PfConceptKey(copyConcept.type);
this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
}
@@ -84,8 +109,9 @@ public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProp
*
* @param authorativeConcept the authorative concept to copy from
*/
- protected JpaToscaWithStringProperties(final T authorativeConcept) {
+ protected JpaToscaWithTypeAndStringProperties(final T authorativeConcept) {
super(new PfConceptKey());
+ type = new PfConceptKey();
this.fromAuthorative(authorativeConcept);
}
@@ -93,6 +119,14 @@ public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProp
public T toAuthorative() {
T tosca = super.toAuthorative();
+ tosca.setType(type.getName());
+
+ if (!PfKey.NULL_KEY_VERSION.equals(type.getVersion())) {
+ tosca.setTypeVersion(type.getVersion());
+ } else {
+ tosca.setTypeVersion(null);
+ }
+
tosca.setProperties(PfUtils.mapMap(properties, this::deserializePropertyValue));
return tosca;
@@ -102,6 +136,21 @@ public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProp
public void fromAuthorative(@NonNull final T authorativeConcept) {
super.fromAuthorative(authorativeConcept);
+ if (authorativeConcept.getType() != null) {
+ type.setName(authorativeConcept.getType());
+ } else {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ "Type not specified, the type of this TOSCA entity must be specified in the type field");
+ }
+
+ if (authorativeConcept.getTypeVersion() != null) {
+ type.setVersion(authorativeConcept.getTypeVersion());
+ } else {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ "Version not specified, the version of this TOSCA entity must be specified"
+ + " in the type_version field");
+ }
+
properties = PfUtils.mapMap(authorativeConcept.getProperties(), this::serializePropertyValue);
}
@@ -121,11 +170,21 @@ public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProp
*/
protected abstract String serializePropertyValue(Object propValue);
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = super.getKeys();
+
+ keyList.addAll(type.getKeys());
+
+ return keyList;
+ }
@Override
public void clean() {
super.clean();
+ type.clean();
+
properties = PfUtils.mapMap(properties, String::trim);
}
@@ -155,7 +214,12 @@ public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProp
}
@SuppressWarnings("unchecked")
- final JpaToscaWithStringProperties<T> other = (JpaToscaWithStringProperties<T>) otherConcept;
+ final JpaToscaWithTypeAndStringProperties<T> other = (JpaToscaWithTypeAndStringProperties<T>) otherConcept;
+
+ result = type.compareTo(other.type);
+ if (result != 0) {
+ return result;
+ }
return PfUtils.compareMaps(properties, other.properties);
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java
index b806e4152..5dda6ecfc 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -145,7 +145,7 @@ public final class ToscaUtils {
* @param serviceTemplate the service template containing policy types to be checked
*/
public static void assertExist(final JpaToscaServiceTemplate serviceTemplate,
- final Function<JpaToscaServiceTemplate, String> checkerFunction) {
+ final Function<JpaToscaServiceTemplate, String> checkerFunction) {
String message = checkerFunction.apply(serviceTemplate);
if (message != null) {
throw new PfModelRuntimeException(Response.Status.NOT_FOUND, message);
@@ -158,7 +158,7 @@ public final class ToscaUtils {
* @param serviceTemplate the service template containing policy types to be checked
*/
public static boolean doExist(final JpaToscaServiceTemplate serviceTemplate,
- final Function<JpaToscaServiceTemplate, String> checkerFunction) {
+ final Function<JpaToscaServiceTemplate, String> checkerFunction) {
return checkerFunction.apply(serviceTemplate) == null;
}
@@ -220,8 +220,8 @@ public final class ToscaUtils {
* @return the entity set containing the ancestors of the incoming entity
*/
public static Collection<JpaToscaEntityType<ToscaEntity>> getEntityTypeAncestors(
- @NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
- @NonNull JpaToscaEntityType<?> entityType, @NonNull final BeanValidationResult result) {
+ @NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
+ @NonNull JpaToscaEntityType<?> entityType, @NonNull final BeanValidationResult result) {
PfConceptKey parentEntityTypeKey = entityType.getDerivedFrom();
if (parentEntityTypeKey == null || parentEntityTypeKey.getName().endsWith(ROOT_KEY_NAME_SUFFIX)) {
@@ -230,17 +230,17 @@ public final class ToscaUtils {
if (entityType.getKey().equals(parentEntityTypeKey)) {
result.addResult(new ObjectValidationResult("entity type", entityType.getKey().getId(),
- ValidationStatus.INVALID, "ancestor of itself"));
+ ValidationStatus.INVALID, "ancestor of itself"));
throw new PfModelRuntimeException(Response.Status.CONFLICT, result.getResult());
}
@SuppressWarnings("unchecked")
Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySet = (Set<JpaToscaEntityType<ToscaEntity>>) entityTypes
- .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion());
+ .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion());
Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySetToReturn = new HashSet<>(ancestorEntitySet);
if (ancestorEntitySet.isEmpty()) {
- result.addResult(new ObjectValidationResult("parent", parentEntityTypeKey.getId(),
- ValidationStatus.INVALID, Validated.NOT_FOUND));
+ result.addResult(new ObjectValidationResult("parent", parentEntityTypeKey.getId(), ValidationStatus.INVALID,
+ Validated.NOT_FOUND));
} else {
for (JpaToscaEntityType<?> filteredEntityType : ancestorEntitySet) {
ancestorEntitySetToReturn.addAll(getEntityTypeAncestors(entityTypes, filteredEntityType, result));
@@ -257,18 +257,18 @@ public final class ToscaUtils {
* @param entityVersion the version of the entity
*/
public static void getEntityTree(
- @NonNull final PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
- final String entityName, final String entityVersion) {
+ @NonNull final PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
+ final String entityName, final String entityVersion) {
BeanValidationResult result = new BeanValidationResult("entity", entityName);
@SuppressWarnings("unchecked")
Set<JpaToscaEntityType<?>> filteredEntitySet =
- (Set<JpaToscaEntityType<?>>) entityTypes.getAllNamesAndVersions(entityName, entityVersion);
+ (Set<JpaToscaEntityType<?>>) entityTypes.getAllNamesAndVersions(entityName, entityVersion);
Set<JpaToscaEntityType<?>> filteredEntitySetToReturn = new HashSet<>(filteredEntitySet);
for (JpaToscaEntityType<?> filteredEntityType : filteredEntitySet) {
filteredEntitySetToReturn
- .addAll(ToscaUtils.getEntityTypeAncestors(entityTypes, filteredEntityType, result));
+ .addAll(ToscaUtils.getEntityTypeAncestors(entityTypes, filteredEntityType, result));
}
if (!result.isValid()) {
@@ -276,6 +276,6 @@ public final class ToscaUtils {
}
entityTypes.getConceptMap().entrySet()
- .removeIf(entityEntry -> !filteredEntitySetToReturn.contains(entityEntry.getValue()));
+ .removeIf(entityEntry -> !filteredEntitySetToReturn.contains(entityEntry.getValue()));
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithObjectPropertiesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithTypeAndObjectPropertiesTest.java
index 7186a3ff0..79fb26540 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithObjectPropertiesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithTypeAndObjectPropertiesTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,19 +28,19 @@ import static org.junit.Assert.assertNotEquals;
import java.util.Map;
import org.junit.Test;
-public class ToscaWithObjectPropertiesTest {
+public class ToscaWithTypeAndObjectPropertiesTest {
@Test
public void testCopyConstructor() {
- ToscaWithObjectProperties tosca = new ToscaWithObjectProperties();
- assertEquals(tosca, new ToscaWithObjectProperties(tosca));
+ ToscaWithTypeAndObjectProperties tosca = new ToscaWithTypeAndObjectProperties();
+ assertEquals(tosca, new ToscaWithTypeAndObjectProperties(tosca));
tosca.setProperties(Map.of("abc", 10, "def", "world"));
- assertEquals(tosca, new ToscaWithObjectProperties(tosca));
+ assertEquals(tosca, new ToscaWithTypeAndObjectProperties(tosca));
- assertNotEquals(tosca, new ToscaWithObjectProperties());
+ assertNotEquals(tosca, new ToscaWithTypeAndObjectProperties());
- assertThatThrownBy(() -> new ToscaWithObjectProperties(null)).hasMessageContaining("copyObject")
+ assertThatThrownBy(() -> new ToscaWithTypeAndObjectProperties(null)).hasMessageContaining("copyObject")
.hasMessageContaining("is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java
index 9637d4252..4fcdd8c0d 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -44,10 +44,16 @@ public class JpaToscaCapabilityAssignmentTest {
@Test
public void testPropertyPojo() {
+ ToscaCapabilityAssignment tca = new ToscaCapabilityAssignment();
+ tca.setName("world");
+ tca.setVersion("1.2.3");
+ tca.setType("planet");
+ tca.setTypeVersion("4.5.6");
+
assertNotNull(new JpaToscaCapabilityAssignment());
assertNotNull(new JpaToscaCapabilityAssignment(new PfConceptKey()));
assertNotNull(new JpaToscaCapabilityAssignment(new JpaToscaCapabilityAssignment()));
- assertNotNull(new JpaToscaCapabilityAssignment(new ToscaCapabilityAssignment()));
+ assertNotNull(new JpaToscaCapabilityAssignment(tca));
assertThatThrownBy(() -> new JpaToscaCapabilityAssignment((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaCapabilityAssignment((JpaToscaCapabilityAssignment) null))
@@ -149,11 +155,19 @@ public class JpaToscaCapabilityAssignmentTest {
@Test
public void testAuthorative() {
- ToscaCapabilityAssignment tca =
- new JpaToscaCapabilityAssignment(new ToscaCapabilityAssignment()).toAuthorative();
+ ToscaCapabilityAssignment tca = new ToscaCapabilityAssignment();
+ tca.setName("world");
+ tca.setVersion("1.2.3");
+ tca.setType("planet");
+ tca.setTypeVersion("4.5.6");
+
+ ToscaCapabilityAssignment tcaConsTo =
+ new JpaToscaCapabilityAssignment(tca).toAuthorative();
+
+ assertEquals(tca, tcaConsTo);
- JpaToscaCapabilityAssignment jtca = new JpaToscaCapabilityAssignment(tca);
- ToscaCapabilityAssignment tca2 = jtca.toAuthorative();
- assertEquals(tca, tca2);
+ JpaToscaCapabilityAssignment jtca = new JpaToscaCapabilityAssignment(tcaConsTo);
+ ToscaCapabilityAssignment tcaFromTo = jtca.toAuthorative();
+ assertEquals(tca, tcaFromTo);
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
index 48bcb0bee..b9adce195 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -61,8 +61,7 @@ public class JpaToscaPolicyTest {
assertThatThrownBy(() -> {
new JpaToscaPolicy(pol);
}).hasMessage(
- "PolicyType version not specified, the version of the PolicyType for this policy must be specified in"
- + " the type_version field");
+ "Version not specified, the version of this TOSCA entity must be specified in the type_version field");
assertThatThrownBy(() -> {
new JpaToscaPolicy((PfConceptKey) null);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java
index 7cd6facf0..f232fcb7b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +33,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaWithObjectProperties;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaWithTypeAndObjectProperties;
public class JpaToscaWithStringPropertiesTest {
private static final String SOME_DESCRIPTION = "some description";
@@ -53,13 +54,14 @@ public class JpaToscaWithStringPropertiesTest {
@Test
public void testGetKeys() {
PfConceptKey key = new PfConceptKey("bye", "9.8.7");
+ PfConceptKey typeKey = new PfConceptKey("type", "6.5.4");
- jpa = new MyJpa(key);
+ jpa = new MyJpa(key, typeKey);
jpa.setDescription(SOME_DESCRIPTION);
jpa.setProperties(Map.of(KEY1, STRING1, KEY2, STRING2));
// properties should be ignored
- assertThat(jpa.getKeys()).isEqualTo(List.of(key));
+ assertThat(jpa.getKeys()).isEqualTo(List.of(key, typeKey));
}
@Test
@@ -85,6 +87,8 @@ public class JpaToscaWithStringPropertiesTest {
@Test
public void testFromAuthorative() {
MyTosca tosca = new MyTosca();
+ tosca.setType("type");
+ tosca.setTypeVersion("1.2.3");
tosca.setDescription(SOME_DESCRIPTION);
jpa.fromAuthorative(tosca);
@@ -144,6 +148,8 @@ public class JpaToscaWithStringPropertiesTest {
MyTosca tosca = new MyTosca();
tosca.setName("world");
tosca.setVersion("3.2.1");
+ tosca.setType("planet");
+ tosca.setTypeVersion("6.5.4");
tosca.setDescription(SOME_DESCRIPTION);
tosca.setProperties(Map.of(KEY1, INT1, KEY2, INT2));
@@ -151,6 +157,7 @@ public class JpaToscaWithStringPropertiesTest {
assertEquals(SOME_DESCRIPTION, jpa.getDescription());
assertThat(jpa.getProperties()).isEqualTo(Map.of(KEY1, STRING1, KEY2, STRING2));
assertEquals(new PfConceptKey("world", "3.2.1"), jpa.getKey());
+ assertEquals(new PfConceptKey("planet", "6.5.4"), jpa.getType());
}
@Test
@@ -159,8 +166,12 @@ public class JpaToscaWithStringPropertiesTest {
jpa.setText("some text");
assertThat(jpa.validateWithKey("fieldA").isValid()).isFalse();
- // valid
+ // not valid, type is not set
jpa.setKey(new PfConceptKey("xyz", "2.3.4"));
+ assertThat(jpa.validateWithKey("fieldB").isValid()).isFalse();
+
+ // valid, type is set
+ jpa.setType(new PfConceptKey("uvw", "5.6.7"));
assertThat(jpa.validateWithKey("fieldB").isValid()).isTrue();
// null text - bean validator should fail
@@ -168,12 +179,11 @@ public class JpaToscaWithStringPropertiesTest {
assertThat(jpa.validateWithKey("fieldA").isValid()).isFalse();
}
- private static class MyTosca extends ToscaWithObjectProperties {
-
+ private static class MyTosca extends ToscaWithTypeAndObjectProperties {
}
@NoArgsConstructor
- protected static class MyJpa extends JpaToscaWithStringProperties<MyTosca> {
+ protected static class MyJpa extends JpaToscaWithTypeAndStringProperties<MyTosca> {
private static final long serialVersionUID = 1L;
@NotNull
@@ -189,6 +199,10 @@ public class JpaToscaWithStringPropertiesTest {
super(key);
}
+ public MyJpa(PfConceptKey key, PfConceptKey type) {
+ super(key, type);
+ }
+
public MyJpa(MyTosca tosca) {
super(tosca);
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
index a926ca149..07624aeee 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -400,13 +400,12 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
- }).hasMessage("PolicyType type not specified, the type of the PolicyType for this policy must be "
- + "specified in the type field");
+ }).hasMessage("Type not specified, the type of this TOSCA entity must be specified in the type field");
toscaPolicy.setType("IDontExist");
assertThatThrownBy(() -> {
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
- }).hasMessage("PolicyType version not specified, the version of the PolicyType for this policy must be "
+ }).hasMessage("Version not specified, the version of this TOSCA entity must be "
+ "specified in the type_version field");
toscaPolicy.setTypeVersion("hello");
@@ -420,7 +419,7 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
}).hasMessageContaining("policy type").hasMessageContaining("IDontExist:99.100.101")
- .hasMessageContaining(Validated.NOT_FOUND);
+ .hasMessageContaining(Validated.NOT_FOUND);
toscaPolicy.setType("IDontExist");
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
@@ -429,8 +428,7 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
- }).hasMessage("PolicyType type not specified, the type of the PolicyType for this policy must be "
- + "specified in the type field");
+ }).hasMessage("Type not specified, the type of this TOSCA entity must be specified in the type field");
toscaPolicy.setType(originalPolicyType);
toscaPolicy.setTypeVersion(originalPolicyTypeVersion);
@@ -525,8 +523,8 @@ public class SimpleToscaProviderTest {
serviceTemplateFragment.getPolicyTypes().getConceptMap().put(badPt.getKey(), badPt);
assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(pfDao, serviceTemplateFragment))
- .hasMessageContaining("key on concept entry").hasMessageContaining("NULL:0.0.0")
- .hasMessageContaining(Validated.IS_A_NULL_KEY);
+ .hasMessageContaining("key on concept entry").hasMessageContaining("NULL:0.0.0")
+ .hasMessageContaining(Validated.IS_A_NULL_KEY);
}
@Test