From f2b0318f53abf9f2345a5cdca74f3dd635aa9b60 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 4 Jan 2021 12:15:18 +0000 Subject: Changed identifiers to concept identifiers The policy models tosca classes ToscaPolicyIdentifier and ToscaPolicyIdentifierOptVersion can be used to identify any TOSCA concept, not just TOSCA policies so they are renamed to ToscaConceptIdentifier and ToscaCinceptIdentifierOptVersion respectively. The class ToscaPolicyTypeIdentifier is redundant and is replaced by ToscaConceptIdentifier. Issue-ID: POLICY-2900 Change-Id: Id0a37c42ea4e74f07b47e1694c4f8291c35879c9 Signed-off-by: liamfallon --- .../concepts/ToscaConceptIdentifier.java | 91 +++++++++++++++++++++ .../concepts/ToscaConceptIdentifierOptVersion.java | 78 ++++++++++++++++++ .../tosca/authorative/concepts/ToscaPolicy.java | 10 +-- .../concepts/ToscaPolicyIdentifier.java | 92 --------------------- .../concepts/ToscaPolicyIdentifierOptVersion.java | 85 -------------------- .../concepts/ToscaPolicyTypeIdentifier.java | 92 --------------------- .../simple/concepts/JpaToscaServiceTemplate.java | 10 +-- .../ToscaConceptIdentifierOptVersionTest.java | 93 ++++++++++++++++++++++ .../concepts/ToscaPolicyConceptIdentifierTest.java | 93 ++++++++++++++++++++++ .../ToscaPolicyIdentifierOptVersionTest.java | 92 --------------------- .../concepts/ToscaPolicyIdentifierTest.java | 92 --------------------- .../authorative/concepts/ToscaPolicyTest.java | 6 +- .../ToscaPolicyTypeConceptIdentifierTest.java | 93 ++++++++++++++++++++++ .../concepts/ToscaPolicyTypeIdentifierTest.java | 92 --------------------- 14 files changed, 461 insertions(+), 558 deletions(-) create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierOptVersion.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifier.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifier.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierOptVersionTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyConceptIdentifierTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeConceptIdentifierTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java (limited to 'models-tosca') diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java new file mode 100644 index 000000000..36e460e83 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020-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. + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.authorative.concepts; + +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.ValidationResult; + +/** + * Identifies a concept. Both the name and version must be non-null. + */ +@Data +@NoArgsConstructor +public class ToscaConceptIdentifier implements Comparable { + + @NonNull + private String name; + + @NonNull + private String version; + + + public ToscaConceptIdentifier(@NonNull String name, @NonNull String version) { + this.name = name; + this.version = version; + } + + public ToscaConceptIdentifier(ToscaConceptIdentifier source) { + this.name = source.name; + this.version = source.version; + } + + /** + * Validates that appropriate fields are populated for an incoming call to the PAP REST API. + * + * @return the validation result + */ + public ValidationResult validatePapRest() { + BeanValidationResult result = new BeanValidationResult("group", this); + + result.validateNotNull("name", name); + result.validateNotNull("version", version); + + return result; + } + + @Override + public int compareTo(ToscaConceptIdentifier other) { + if (this == other) { + return 0; + } + + if (other == null) { + return 1; + } + + int result = ObjectUtils.compare(getName(), other.getName()); + if (result != 0) { + return result; + } + + return ObjectUtils.compare(getVersion(), other.getVersion()); + } + + @Override + public String toString() { + return this.name + " " + this.version; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierOptVersion.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierOptVersion.java new file mode 100644 index 000000000..c23c04fe8 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierOptVersion.java @@ -0,0 +1,78 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020-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. + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.authorative.concepts; + +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.apache.commons.lang3.ObjectUtils; + +/** + * Concept identifier with an optional version; only the "name" is required. + */ +@Data +@NoArgsConstructor +public class ToscaConceptIdentifierOptVersion implements Comparable { + + @NonNull + private String name; + + private String version; + + public ToscaConceptIdentifierOptVersion(@NonNull String name, String version) { + this.name = name; + this.version = version; + } + + public ToscaConceptIdentifierOptVersion(ToscaConceptIdentifierOptVersion source) { + this.name = source.name; + this.version = source.version; + } + + public ToscaConceptIdentifierOptVersion(ToscaConceptIdentifier source) { + this.name = source.getName(); + this.version = source.getVersion(); + } + + @Override + public int compareTo(ToscaConceptIdentifierOptVersion other) { + if (this == other) { + return 0; + } + + if (other == null) { + return 1; + } + + int result = ObjectUtils.compare(getName(), other.getName()); + if (result != 0) { + return result; + } + + return ObjectUtils.compare(getVersion(), other.getVersion()); + } + + @Override + public String toString() { + return this.name + " " + this.version; + } +} 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 c98a844e5..491b478a4 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 @@ -3,7 +3,7 @@ * ONAP Policy Model * ================================================================================ * Copyright (C) 2019 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. @@ -76,8 +76,8 @@ public class ToscaPolicy extends ToscaEntity { * * @return this policy's identifier */ - public ToscaPolicyIdentifier getIdentifier() { - return new ToscaPolicyIdentifier(getName(), getVersion()); + public ToscaConceptIdentifier getIdentifier() { + return new ToscaConceptIdentifier(getName(), getVersion()); } /** @@ -85,7 +85,7 @@ public class ToscaPolicy extends ToscaEntity { * * @return this policy's type identifier */ - public ToscaPolicyTypeIdentifier getTypeIdentifier() { - return new ToscaPolicyTypeIdentifier(getType(), getTypeVersion()); + public ToscaConceptIdentifier getTypeIdentifier() { + return new ToscaConceptIdentifier(getType(), getTypeVersion()); } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifier.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifier.java deleted file mode 100644 index ba1042851..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifier.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.authorative.concepts; - -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import org.apache.commons.lang3.ObjectUtils; -import org.onap.policy.common.parameters.BeanValidationResult; -import org.onap.policy.common.parameters.ValidationResult; - -/** - * Identifies a policy. Both the name and version must be non-null. - */ -@Data -@NoArgsConstructor -public class ToscaPolicyIdentifier implements Comparable { - - @NonNull - private String name; - - @NonNull - private String version; - - - public ToscaPolicyIdentifier(@NonNull String name, @NonNull String version) { - this.name = name; - this.version = version; - } - - public ToscaPolicyIdentifier(ToscaPolicyIdentifier source) { - this.name = source.name; - this.version = source.version; - } - - /** - * Validates that appropriate fields are populated for an incoming call to the PAP - * REST API. - * - * @return the validation result - */ - public ValidationResult validatePapRest() { - BeanValidationResult result = new BeanValidationResult("group", this); - - result.validateNotNull("name", name); - result.validateNotNull("version", version); - - return result; - } - - @Override - public int compareTo(ToscaPolicyIdentifier other) { - if (this == other) { - return 0; - } - - if (other == null) { - return 1; - } - - int result = ObjectUtils.compare(getName(), other.getName()); - if (result != 0) { - return result; - } - - return ObjectUtils.compare(getVersion(), other.getVersion()); - } - - @Override - public String toString() { - return this.name + " " + this.version; - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java deleted file mode 100644 index 29bff911f..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.authorative.concepts; - -import com.google.gson.annotations.SerializedName; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import org.apache.commons.lang3.ObjectUtils; - -/** - * Policy identifier with an optional version; only the "name" is required. - */ -@Data -@NoArgsConstructor -public class ToscaPolicyIdentifierOptVersion implements Comparable { - - @NonNull - @ApiModelProperty(name = "policy-id") - @SerializedName("policy-id") - private String name; - - @ApiModelProperty(name = "policy-version") - @SerializedName("policy-version") - private String version; - - - public ToscaPolicyIdentifierOptVersion(@NonNull String name, String version) { - this.name = name; - this.version = version; - } - - public ToscaPolicyIdentifierOptVersion(ToscaPolicyIdentifierOptVersion source) { - this.name = source.name; - this.version = source.version; - } - - public ToscaPolicyIdentifierOptVersion(ToscaPolicyIdentifier source) { - this.name = source.getName(); - this.version = source.getVersion(); - } - - @Override - public int compareTo(ToscaPolicyIdentifierOptVersion other) { - if (this == other) { - return 0; - } - - if (other == null) { - return 1; - } - - int result = ObjectUtils.compare(getName(), other.getName()); - if (result != 0) { - return result; - } - - return ObjectUtils.compare(getVersion(), other.getVersion()); - } - - @Override - public String toString() { - return this.name + " " + this.version; - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifier.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifier.java deleted file mode 100644 index 32dd7cbd7..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifier.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.authorative.concepts; - -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import org.apache.commons.lang3.ObjectUtils; -import org.onap.policy.common.parameters.BeanValidationResult; -import org.onap.policy.common.parameters.ValidationResult; - -/** - * Identifies a policy type. Both the name and version must be non-null. - */ -@Data -@NoArgsConstructor -public class ToscaPolicyTypeIdentifier implements Comparable { - - @NonNull - private String name; - - @NonNull - private String version; - - - public ToscaPolicyTypeIdentifier(@NonNull String name, @NonNull String version) { - this.name = name; - this.version = version; - } - - public ToscaPolicyTypeIdentifier(ToscaPolicyTypeIdentifier source) { - this.name = source.name; - this.version = source.version; - } - - /** - * Validates that appropriate fields are populated for an incoming call to the PAP - * REST API. - * - * @return the validation result - */ - public ValidationResult validatePapRest() { - BeanValidationResult result = new BeanValidationResult("group", this); - - result.validateNotNull("name", name); - result.validateNotNull("version", version); - - return result; - } - - @Override - public int compareTo(ToscaPolicyTypeIdentifier other) { - if (this == other) { - return 0; - } - - if (other == null) { - return 1; - } - - int result = ObjectUtils.compare(getName(), other.getName()); - if (result != 0) { - return result; - } - - return ObjectUtils.compare(getVersion(), other.getVersion()); - } - - @Override - public String toString() { - return this.name + " " + this.version; - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java index c0a5cdf75..594a5c348 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java @@ -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"); @@ -269,11 +269,11 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType dataTypeKeyCollection, final BeanValidationResult result) { + private void validateReferencedDataTypesExists(final Collection dataTypeKeyCollection, + final BeanValidationResult result) { for (PfConceptKey dataTypeKey : dataTypeKeyCollection) { if (dataTypes == null || dataTypes.get(dataTypeKey) == null) { addResult(result, "data type", dataTypeKey.getId(), NOT_FOUND); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierOptVersionTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierOptVersionTest.java new file mode 100644 index 000000000..aedf5cb15 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierOptVersionTest.java @@ -0,0 +1,93 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.authorative.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Test the other constructors, as {@link PojosTest} tests the other methods. + */ +public class ToscaConceptIdentifierOptVersionTest extends ToscaIdentifierTestBase { + + public ToscaConceptIdentifierOptVersionTest() { + super(ToscaConceptIdentifierOptVersion.class, "name", "version"); + } + + @Test + public void testAllArgsConstructor_testIsNullVersion() { + assertThatThrownBy(() -> new ToscaConceptIdentifierOptVersion(null, VERSION)) + .isInstanceOf(NullPointerException.class); + + // with null version + ToscaConceptIdentifierOptVersion orig = new ToscaConceptIdentifierOptVersion(NAME, null); + assertEquals(NAME, orig.getName()); + assertEquals(null, orig.getVersion()); + + orig = new ToscaConceptIdentifierOptVersion(NAME, VERSION); + assertEquals(NAME, orig.getName()); + assertEquals(VERSION, orig.getVersion()); + } + + @Test + public void testCopyConstructor() throws Exception { + assertThatThrownBy(() -> new ToscaConceptIdentifierOptVersion((ToscaConceptIdentifierOptVersion) null)) + .isInstanceOf(NullPointerException.class); + + ToscaConceptIdentifierOptVersion orig = new ToscaConceptIdentifierOptVersion(); + + // verify with null values + assertEquals(orig.toString(), new ToscaConceptIdentifierOptVersion(orig).toString()); + + // verify with all values + orig = makeIdent(NAME, VERSION); + assertEquals(orig.toString(), new ToscaConceptIdentifierOptVersion(orig).toString()); + } + + @Test + public void testCopyToscaPolicyIdentifierConstructor() { + assertThatThrownBy(() -> new ToscaConceptIdentifierOptVersion((ToscaConceptIdentifier) null)) + .isInstanceOf(NullPointerException.class); + + ToscaConceptIdentifier orig = new ToscaConceptIdentifier(); + + // verify with null values + ToscaConceptIdentifierOptVersion newIdent = new ToscaConceptIdentifierOptVersion(orig); + assertEquals(null, newIdent.getName()); + assertEquals(null, newIdent.getVersion()); + + // verify with all values + orig.setName(NAME); + orig.setVersion(VERSION); + newIdent = new ToscaConceptIdentifierOptVersion(orig); + assertEquals(NAME, newIdent.getName()); + assertEquals(VERSION, newIdent.getVersion()); + } + + @Test + @Override + public void testCompareTo() throws Exception { + super.testCompareTo(); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyConceptIdentifierTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyConceptIdentifierTest.java new file mode 100644 index 000000000..6f49fd433 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyConceptIdentifierTest.java @@ -0,0 +1,93 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.authorative.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.policy.common.parameters.ValidationResult; + +/** + * Test methods not tested by {@link PojosTest}. + */ +public class ToscaPolicyConceptIdentifierTest extends ToscaIdentifierTestBase { + + public ToscaPolicyConceptIdentifierTest() { + super(ToscaConceptIdentifier.class, "name", "version"); + } + + @Test + public void testAllArgsConstructor() { + assertThatThrownBy(() -> new ToscaConceptIdentifier(null, VERSION)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> new ToscaConceptIdentifier(NAME, null)).isInstanceOf(NullPointerException.class); + + ToscaConceptIdentifier orig = new ToscaConceptIdentifier(NAME, VERSION); + assertEquals(NAME, orig.getName()); + assertEquals(VERSION, orig.getVersion()); + } + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new ToscaConceptIdentifier(null)).isInstanceOf(NullPointerException.class); + + ToscaConceptIdentifier orig = new ToscaConceptIdentifier(); + + // verify with null values + assertEquals(orig.toString(), new ToscaConceptIdentifier(orig).toString()); + + // verify with all values + orig = new ToscaConceptIdentifier(NAME, VERSION); + assertEquals(orig.toString(), new ToscaConceptIdentifier(orig).toString()); + } + + @Test + public void testValidatePapRest() throws Exception { + ToscaConceptIdentifier ident = new ToscaConceptIdentifier(NAME, VERSION); + ValidationResult result = ident.validatePapRest(); + assertNotNull(result); + assertTrue(result.isValid()); + assertNull(result.getResult()); + + ident = makeIdent(NAME, null); + result = ident.validatePapRest(); + assertNotNull(result); + assertFalse(result.isValid()); + assertNotNull(result.getResult()); + + ident = makeIdent(null, VERSION); + result = ident.validatePapRest(); + assertNotNull(result); + assertFalse(result.isValid()); + assertNotNull(result.getResult()); + } + + @Test + @Override + public void testCompareTo() throws Exception { + super.testCompareTo(); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java deleted file mode 100644 index 0b43173ad..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP Policy Models - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.authorative.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Test the other constructors, as {@link PojosTest} tests the other methods. - */ -public class ToscaPolicyIdentifierOptVersionTest extends ToscaIdentifierTestBase { - - public ToscaPolicyIdentifierOptVersionTest() { - super(ToscaPolicyIdentifierOptVersion.class, "policy-id", "policy-version"); - } - - @Test - public void testAllArgsConstructor_testIsNullVersion() { - assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion(null, VERSION)) - .isInstanceOf(NullPointerException.class); - - // with null version - ToscaPolicyIdentifierOptVersion orig = new ToscaPolicyIdentifierOptVersion(NAME, null); - assertEquals(NAME, orig.getName()); - assertEquals(null, orig.getVersion()); - - orig = new ToscaPolicyIdentifierOptVersion(NAME, VERSION); - assertEquals(NAME, orig.getName()); - assertEquals(VERSION, orig.getVersion()); - } - - @Test - public void testCopyConstructor() throws Exception { - assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion((ToscaPolicyIdentifierOptVersion) null)) - .isInstanceOf(NullPointerException.class); - - ToscaPolicyIdentifierOptVersion orig = new ToscaPolicyIdentifierOptVersion(); - - // verify with null values - assertEquals(orig.toString(), new ToscaPolicyIdentifierOptVersion(orig).toString()); - - // verify with all values - orig = makeIdent(NAME, VERSION); - assertEquals(orig.toString(), new ToscaPolicyIdentifierOptVersion(orig).toString()); - } - - @Test - public void testCopyToscaPolicyIdentifierConstructor() { - assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion((ToscaPolicyIdentifier) null)) - .isInstanceOf(NullPointerException.class); - - ToscaPolicyIdentifier orig = new ToscaPolicyIdentifier(); - - // verify with null values - ToscaPolicyIdentifierOptVersion newIdent = new ToscaPolicyIdentifierOptVersion(orig); - assertEquals(null, newIdent.getName()); - assertEquals(null, newIdent.getVersion()); - - // verify with all values - orig.setName(NAME); - orig.setVersion(VERSION); - newIdent = new ToscaPolicyIdentifierOptVersion(orig); - assertEquals(NAME, newIdent.getName()); - assertEquals(VERSION, newIdent.getVersion()); - } - - @Test - @Override - public void testCompareTo() throws Exception { - super.testCompareTo(); - } -} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java deleted file mode 100644 index cc40e2410..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP Policy Models - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.authorative.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.policy.common.parameters.ValidationResult; - -/** - * Test methods not tested by {@link PojosTest}. - */ -public class ToscaPolicyIdentifierTest extends ToscaIdentifierTestBase { - - public ToscaPolicyIdentifierTest() { - super(ToscaPolicyIdentifier.class, "name", "version"); - } - - @Test - public void testAllArgsConstructor() { - assertThatThrownBy(() -> new ToscaPolicyIdentifier(null, VERSION)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> new ToscaPolicyIdentifier(NAME, null)).isInstanceOf(NullPointerException.class); - - ToscaPolicyIdentifier orig = new ToscaPolicyIdentifier(NAME, VERSION); - assertEquals(NAME, orig.getName()); - assertEquals(VERSION, orig.getVersion()); - } - - @Test - public void testCopyConstructor() { - assertThatThrownBy(() -> new ToscaPolicyIdentifier(null)).isInstanceOf(NullPointerException.class); - - ToscaPolicyIdentifier orig = new ToscaPolicyIdentifier(); - - // verify with null values - assertEquals(orig.toString(), new ToscaPolicyIdentifier(orig).toString()); - - // verify with all values - orig = new ToscaPolicyIdentifier(NAME, VERSION); - assertEquals(orig.toString(), new ToscaPolicyIdentifier(orig).toString()); - } - - @Test - public void testValidatePapRest() throws Exception { - ToscaPolicyIdentifier ident = new ToscaPolicyIdentifier(NAME, VERSION); - ValidationResult result = ident.validatePapRest(); - assertNotNull(result); - assertTrue(result.isValid()); - assertNull(result.getResult()); - - ident = makeIdent(NAME, null); - result = ident.validatePapRest(); - assertNotNull(result); - assertFalse(result.isValid()); - assertNotNull(result.getResult()); - - ident = makeIdent(null, VERSION); - result = ident.validatePapRest(); - assertNotNull(result); - assertFalse(result.isValid()); - assertNotNull(result.getResult()); - } - - @Test - @Override - public void testCompareTo() throws Exception { - super.testCompareTo(); - } -} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java index 9fd559392..59f471ae8 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java @@ -3,7 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020-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. @@ -47,11 +47,11 @@ public class ToscaPolicyTest { assertEquals("ToscaEntityKey(name=my_name, version=1.2.3)", policy.getKey().toString()); - ToscaPolicyIdentifier ident = policy.getIdentifier(); + ToscaConceptIdentifier ident = policy.getIdentifier(); assertEquals("my_name", ident.getName()); assertEquals("1.2.3", ident.getVersion()); - ToscaPolicyTypeIdentifier type = policy.getTypeIdentifier(); + ToscaConceptIdentifier type = policy.getTypeIdentifier(); assertEquals("my_type", type.getName()); assertEquals("3.2.1", type.getVersion()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeConceptIdentifierTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeConceptIdentifierTest.java new file mode 100644 index 000000000..7845a1f32 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeConceptIdentifierTest.java @@ -0,0 +1,93 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.authorative.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.policy.common.parameters.ValidationResult; + +/** + * Test methods not tested by {@link PojosTest}. + */ +public class ToscaPolicyTypeConceptIdentifierTest extends ToscaIdentifierTestBase { + + public ToscaPolicyTypeConceptIdentifierTest() { + super(ToscaConceptIdentifier.class, "name", "version"); + } + + @Test + public void testAllArgsConstructor() { + assertThatThrownBy(() -> new ToscaConceptIdentifier(null, VERSION)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> new ToscaConceptIdentifier(NAME, null)).isInstanceOf(NullPointerException.class); + + ToscaConceptIdentifier orig = new ToscaConceptIdentifier(NAME, VERSION); + assertEquals(NAME, orig.getName()); + assertEquals(VERSION, orig.getVersion()); + } + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new ToscaConceptIdentifier(null)).isInstanceOf(NullPointerException.class); + + ToscaConceptIdentifier orig = new ToscaConceptIdentifier(); + + // verify with null values + assertEquals(orig.toString(), new ToscaConceptIdentifier(orig).toString()); + + // verify with all values + orig = new ToscaConceptIdentifier(NAME, VERSION); + assertEquals(orig.toString(), new ToscaConceptIdentifier(orig).toString()); + } + + @Test + public void testValidatePapRest() throws Exception { + ToscaConceptIdentifier ident = new ToscaConceptIdentifier(NAME, VERSION); + ValidationResult result = ident.validatePapRest(); + assertNotNull(result); + assertTrue(result.isValid()); + assertNull(result.getResult()); + + ident = makeIdent(NAME, null); + result = ident.validatePapRest(); + assertNotNull(result); + assertFalse(result.isValid()); + assertNotNull(result.getResult()); + + ident = makeIdent(null, VERSION); + result = ident.validatePapRest(); + assertNotNull(result); + assertFalse(result.isValid()); + assertNotNull(result.getResult()); + } + + @Test + @Override + public void testCompareTo() throws Exception { + super.testCompareTo(); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java deleted file mode 100644 index a5e0431b2..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP Policy Models - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.authorative.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.policy.common.parameters.ValidationResult; - -/** - * Test methods not tested by {@link PojosTest}. - */ -public class ToscaPolicyTypeIdentifierTest extends ToscaIdentifierTestBase { - - public ToscaPolicyTypeIdentifierTest() { - super(ToscaPolicyTypeIdentifier.class, "name", "version"); - } - - @Test - public void testAllArgsConstructor() { - assertThatThrownBy(() -> new ToscaPolicyTypeIdentifier(null, VERSION)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> new ToscaPolicyTypeIdentifier(NAME, null)).isInstanceOf(NullPointerException.class); - - ToscaPolicyTypeIdentifier orig = new ToscaPolicyTypeIdentifier(NAME, VERSION); - assertEquals(NAME, orig.getName()); - assertEquals(VERSION, orig.getVersion()); - } - - @Test - public void testCopyConstructor() { - assertThatThrownBy(() -> new ToscaPolicyTypeIdentifier(null)).isInstanceOf(NullPointerException.class); - - ToscaPolicyTypeIdentifier orig = new ToscaPolicyTypeIdentifier(); - - // verify with null values - assertEquals(orig.toString(), new ToscaPolicyTypeIdentifier(orig).toString()); - - // verify with all values - orig = new ToscaPolicyTypeIdentifier(NAME, VERSION); - assertEquals(orig.toString(), new ToscaPolicyTypeIdentifier(orig).toString()); - } - - @Test - public void testValidatePapRest() throws Exception { - ToscaPolicyTypeIdentifier ident = new ToscaPolicyTypeIdentifier(NAME, VERSION); - ValidationResult result = ident.validatePapRest(); - assertNotNull(result); - assertTrue(result.isValid()); - assertNull(result.getResult()); - - ident = makeIdent(NAME, null); - result = ident.validatePapRest(); - assertNotNull(result); - assertFalse(result.isValid()); - assertNotNull(result.getResult()); - - ident = makeIdent(null, VERSION); - result = ident.validatePapRest(); - assertNotNull(result); - assertFalse(result.isValid()); - assertNotNull(result.getResult()); - } - - @Test - @Override - public void testCompareTo() throws Exception { - super.testCompareTo(); - } -} -- cgit 1.2.3-korg