summaryrefslogtreecommitdiffstats
path: root/models-tosca
diff options
context:
space:
mode:
Diffstat (limited to 'models-tosca')
-rw-r--r--models-tosca/pom.xml5
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java5
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java5
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java1
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java11
-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
13 files changed, 243 insertions, 34 deletions
diff --git a/models-tosca/pom.xml b/models-tosca/pom.xml
index 9fbda40d8..3397316ab 100644
--- a/models-tosca/pom.xml
+++ b/models-tosca/pom.xml
@@ -81,5 +81,10 @@
<artifactId>openpojo</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java
index d6f3a6815..a5a800587 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@
package org.onap.policy.models.tosca.authorative.concepts;
import java.util.List;
-import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Data;
import lombok.NonNull;
@@ -52,7 +51,7 @@ public class ToscaEntityFilter<T extends ToscaEntity> implements PfObjectFilter<
.filter(p -> filterString(p.getName(), name))
.filter(p -> LATEST_VERSION.equals(version)
|| filterString(p.getVersion(), version))
- .collect(Collectors.toList());
+ .toList();
// @formatter:off
if (LATEST_VERSION.equals(version)) {
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java
index 749873a23..0bb72e549 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@
package org.onap.policy.models.tosca.authorative.concepts;
import java.util.List;
-import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Data;
import lombok.NonNull;
@@ -63,7 +62,7 @@ public class ToscaTypedEntityFilter<T extends ToscaEntity> implements PfObjectFi
.filter(filterPrefixPred(versionPrefix, T::getVersion))
.filter(filterStringPred(type, T::getType))
.filter(filterStringPred(typeVersion, T::getTypeVersion))
- .collect(Collectors.toList());
+ .toList();
// @formatter:off
if (LATEST_VERSION.equals(version)) {
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
index 35971563f..f047658fb 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
@@ -55,7 +55,6 @@ import org.slf4j.LoggerFactory;
public class AuthorativeToscaProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(AuthorativeToscaProvider.class);
- // TODO: In next release this locking mechanism should be removed and replaced with proper session handling
private static final Object providerLockObject = "providerLockObject";
/**
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java
index 14502c64c..593d18bbb 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java
@@ -3,7 +3,7 @@
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -110,19 +110,10 @@ public class JpaToscaPolicyType extends JpaToscaWithToscaProperties<ToscaPolicyT
super.setToscaEntity(toscaPolicyType);
super.toAuthorative();
- // TODO need to copy targets & triggers?
-
return toscaPolicyType;
}
@Override
- public void fromAuthorative(final ToscaPolicyType toscaPolicyType) {
- super.fromAuthorative(toscaPolicyType);
-
- // TODO need to copy targets & triggers?
- }
-
- @Override
public List<PfKey> getKeys() {
final List<PfKey> keyList = super.getKeys();
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());