aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'models-tosca/src/test')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilterTest.java10
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java2
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java2
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentsTest.java79
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypeTest.java74
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java76
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java4
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java3
8 files changed, 233 insertions, 17 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilterTest.java
index b9ae31bb5..c1c3f4aeb 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilterTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilterTest.java
@@ -146,16 +146,6 @@ class ToscaEntityFilterTest {
typeList.get(12).setVersion("2.0.0");
filteredList = filter.filter(typeList);
assertEquals(19, filteredList.size());
- //
- // This seems to change around as to where this policy type
- // got changed - perhaps we change this test to find a specific name
- // to test for vs an index which never remains consistent?
- //
- // assertEquals("2.0.0", filteredList.get(18).getVersion());
- //
- // And now this index changes again??
- //
- // assertEquals(VERSION_100, filteredList.get(17).getVersion());
typeList.get(12).setVersion(VERSION_100);
filteredList = filter.filter(typeList);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java
index 78058d99c..d12e741c1 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java
@@ -169,7 +169,7 @@ class AuthorativeToscaProviderGenericTest {
}
@Test
- void testNullParameters() throws Exception {
+ void testNullParameters() {
assertThatThrownBy(() -> new AuthorativeToscaProvider().getServiceTemplateList(null, null, null))
.hasMessageMatching("^dao is marked .*on.*ull but is null$");
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
index b07535e59..a993b303b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
@@ -423,7 +423,7 @@ class AuthorativeToscaProviderPolicyTypeTest {
}
@Test
- void testNullParameters() throws Exception {
+ void testNullParameters() {
assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypeList(null, null, null))
.hasMessageMatching("^dao is marked .*on.*ull but is null$");
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentsTest.java
new file mode 100644
index 000000000..7d546632b
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentsTest.java
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.MockitoAnnotations.openMocks;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.models.base.PfConceptKey;
+
+class JpaToscaCapabilityAssignmentsTest {
+
+ @Mock
+ private PfConceptKey mockKey;
+
+ private JpaToscaCapabilityAssignments jpaToscaCapabilityAssignmentsUnderTest;
+
+ @BeforeEach
+ void setUp() {
+ openMocks(this);
+ jpaToscaCapabilityAssignmentsUnderTest = new JpaToscaCapabilityAssignments(mockKey, Map.ofEntries(
+ Map.entry(new PfConceptKey("name", "1.0.0"),
+ new JpaToscaCapabilityAssignment(new PfConceptKey("name", "1.0.0")))));
+ }
+
+ @Test
+ void testConstructors() {
+ JpaToscaCapabilityAssignments assignment = new JpaToscaCapabilityAssignments();
+ assertNotNull(assignment);
+
+ PfConceptKey key = new PfConceptKey();
+ assignment = new JpaToscaCapabilityAssignments(key);
+ assertNotNull(assignment);
+
+ assignment = new JpaToscaCapabilityAssignments(key, new HashMap<>());
+ assertNotNull(assignment);
+
+ JpaToscaCapabilityAssignments assignmentCopy = new JpaToscaCapabilityAssignments(assignment);
+ assertNotNull(assignmentCopy);
+
+ assertThatThrownBy(() -> new JpaToscaCapabilityAssignments(List.of(new HashMap<>())))
+ .hasMessageContaining("An incoming list of concepts must have at least one entry");
+ }
+
+ @Test
+ void testValidate() {
+ BeanValidationResult result = jpaToscaCapabilityAssignmentsUnderTest.validate("fieldName");
+ assertThat(result.getResult()).contains("item has status INVALID");
+
+ assertThatThrownBy(() -> jpaToscaCapabilityAssignmentsUnderTest.validate(null))
+ .hasMessageContaining("fieldName is marked non-null but is null");
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypeTest.java
new file mode 100644
index 000000000..4f2b40102
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypeTest.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.openMocks;
+
+import java.util.Map;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
+
+class JpaToscaCapabilityTypeTest {
+
+ @Mock
+ private PfConceptKey mockKey;
+
+ private JpaToscaCapabilityType jpaToscaCapabilityTypeUnderTest;
+
+ private AutoCloseable mockitoCloseable;
+
+ @BeforeEach
+ void setUp() {
+ mockitoCloseable = openMocks(this);
+ jpaToscaCapabilityTypeUnderTest = new JpaToscaCapabilityType(mockKey);
+ }
+
+ @AfterEach
+ void tearDown() throws Exception {
+ mockitoCloseable.close();
+ }
+
+ @Test
+ void testToAuthorative() {
+ final ToscaCapabilityType expectedResult = new ToscaCapabilityType();
+ expectedResult.setName("name");
+ expectedResult.setVersion("version");
+ expectedResult.setDerivedFrom("name");
+ expectedResult.setMetadata(Map.ofEntries(Map.entry("value", "value")));
+ expectedResult.setDescription("description");
+ final ToscaProperty toscaProperty = new ToscaProperty();
+ expectedResult.setProperties(Map.ofEntries(Map.entry("value", toscaProperty)));
+
+ when(mockKey.getName()).thenReturn("name");
+ when(mockKey.getVersion()).thenReturn("version");
+
+ final ToscaCapabilityType result = jpaToscaCapabilityTypeUnderTest.toAuthorative();
+
+ assertThat(result.toString()).contains(expectedResult.toString());
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java
new file mode 100644
index 000000000..228a4f822
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.MockitoAnnotations.openMocks;
+
+import java.util.List;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.models.base.PfConceptKey;
+
+class JpaToscaRequirementTest {
+
+ @Mock
+ private PfConceptKey mockKey;
+ @Mock
+ private List<Integer> mockOccurrences;
+
+ private JpaToscaRequirement jpaToscaRequirementUnderTest;
+
+ private AutoCloseable mockitoCloseable;
+
+ @BeforeEach
+ void setUp() {
+ mockitoCloseable = openMocks(this);
+ jpaToscaRequirementUnderTest = new JpaToscaRequirement(mockKey);
+ jpaToscaRequirementUnderTest.setOccurrences(mockOccurrences);
+ }
+
+ @AfterEach
+ void tearDown() throws Exception {
+ mockitoCloseable.close();
+ }
+
+ @Test
+ void testCapabilityGetterAndSetter() {
+ final String capability = "capability";
+ jpaToscaRequirementUnderTest.setCapability(capability);
+ assertThat(jpaToscaRequirementUnderTest.getCapability()).isEqualTo(capability);
+
+ final String node = "node";
+ jpaToscaRequirementUnderTest.setNode(node);
+ assertThat(jpaToscaRequirementUnderTest.getNode()).isEqualTo(node);
+
+ final String relationship = "relationship";
+ jpaToscaRequirementUnderTest.setRelationship(relationship);
+ assertThat(jpaToscaRequirementUnderTest.getRelationship()).isEqualTo(relationship);
+
+ assertThat(jpaToscaRequirementUnderTest.getOccurrences()).isEqualTo(mockOccurrences);
+
+ assertThat(jpaToscaRequirementUnderTest.toString())
+ .hasToString("JpaToscaRequirement(capability=capability, node=node, relationship=relationship, "
+ + "occurrences=mockOccurrences)");
+ }
+}
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 a789cd57b..b26b3976f 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
@@ -531,13 +531,13 @@ class SimpleToscaProviderTest {
}
@Test
- void testGetServiceTemplate() throws PfModelException {
+ void testGetServiceTemplate() {
assertThatThrownBy(() -> new SimpleToscaProvider().getServiceTemplate(pfDao))
.hasMessage("service template not found in database");
}
@Test
- void testAppendToServiceTemplate() throws PfModelException {
+ void testAppendToServiceTemplate() {
JpaToscaServiceTemplate serviceTemplateFragment = new JpaToscaServiceTemplate();
serviceTemplateFragment.setPolicyTypes(new JpaToscaPolicyTypes());
JpaToscaPolicyType badPt = new JpaToscaPolicyType();
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java
index 4ddae1c5c..7ee015d59 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java
@@ -173,9 +173,6 @@ class OptimizationPolicyTypeSerializationTest {
assertNotNull(prop, testnm);
- // this line results in a stack overflow
- // assertEquals(testnm + " name", "geography", prop.getName());
-
assertEquals("One or more geographic regions", prop.getDescription(), testnm + " description");
assertEquals("list", prop.getType().getName(), testnm + " description");
validateMatchable(testnm, prop.getMetadata());