diff options
author | waynedunican <wayne.dunican@est.tech> | 2024-07-23 09:23:51 +0100 |
---|---|---|
committer | waynedunican <wayne.dunican@est.tech> | 2024-08-13 08:49:10 +0100 |
commit | b7804abcf865dc58a01bed3f2be4756e731d9288 (patch) | |
tree | 7f6fc3b50622578bb8612de9fe5e5c6adddfaf28 | |
parent | a029ccab07f2dd71286804da620c513da9fdfc0e (diff) |
Improve code coverage and sonar fixes
Increased code coverage to 90%
SONAR - Removed TODO comments
SONAR - Added NOSONAR where appropriate
SONAR - Replaced stream.Collect() with stream.toList() where applicable
SONAR - Made variables serializable or transient to comply with sonar rules
Issue-ID: POLICY-5069
Change-Id: Ife256eaf4e6f427fe40b138bacc6f112dc5bcea4
Signed-off-by: waynedunican <wayne.dunican@est.tech>
110 files changed, 1500 insertions, 213 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java index df6141b9b..f97d7b48a 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2020, 2024 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -54,7 +54,7 @@ public class PfConceptFilter implements PfObjectFilter<PfConcept> { .filter(filterStringPred(name, PfConcept::getName)) .filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), PfConcept::getVersion)) .filter(filterPrefixPred(versionPrefix, PfConcept::getVersion)) - .collect(Collectors.toList()); + .collect(Collectors.toList()); //NOSONAR // @formatter:off if (LATEST_VERSION.equals(version)) { diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java index 1caa6329e..0beeb01d9 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2023 Nordix Foundation. + * Copyright (C) 2019, 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ @@ -123,10 +123,10 @@ public abstract class PfModel extends PfConcept { for (final PfKey pfKey : this.getKeys()) { // Check for the two type of keys we have - if (pfKey instanceof PfConceptKey) { - validateArtifactKeyInModel((PfConceptKey) pfKey, artifactKeySet, result); - } else if (pfKey instanceof PfReferenceKey) { - validateReferenceKeyInModel((PfReferenceKey) pfKey, referenceKeySet, result); + if (pfKey instanceof PfConceptKey pfConceptKey) { + validateArtifactKeyInModel(pfConceptKey, artifactKeySet, result); + } else if (pfKey instanceof PfReferenceKey pfReferenceKey) { + validateReferenceKeyInModel(pfReferenceKey, referenceKeySet, result); } else { // It must be a PfKeyUse, nothing else is legal usedKeySet.add((PfKeyUse) pfKey); diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java index 51054ee77..f7e6b5aa6 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021, 2023 Nordix Foundation. + * Copyright (C) 2019-2021, 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -114,7 +114,7 @@ public final class PfUtils { return defaultValue; } - return source.stream().map(mapFunc).collect(Collectors.toList()); + return source.stream().map(mapFunc).collect(Collectors.toList()); //NOSONAR } /** diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java b/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java index c2eb2b649..e9c8591b6 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023-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. @@ -67,8 +67,8 @@ public class PfValidator extends BeanValidator { */ @Override public boolean verCascade(BeanValidationResult result, String fieldName, Object value) { - if (value instanceof Validated) { - ValidationResult result2 = ((Validated) value).validate(fieldName); + if (value instanceof Validated validated) { + ValidationResult result2 = validated.validate(fieldName); if (result2 == null) { return true; } @@ -129,6 +129,6 @@ public class PfValidator extends BeanValidator { @Override public Object xlate(Object value) { - return (value instanceof PfKey ? ((PfKey) value).getId() : value); + return (value instanceof PfKey pfKey ? pfKey.getId() : value); } } diff --git a/models-base/src/main/java/org/onap/policy/models/base/Validated.java b/models-base/src/main/java/org/onap/policy/models/base/Validated.java index 711dd7be6..0c4f36034 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/Validated.java +++ b/models-base/src/main/java/org/onap/policy/models/base/Validated.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. + * Modifications 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. @@ -119,6 +120,6 @@ public class Validated { * @return the value's ID, if it's a key, the original value otherwise */ private static Object getKeyId(Object value) { - return (value instanceof PfKey ? ((PfKey) value).getId() : value); + return (value instanceof PfKey pfKey ? pfKey.getId() : value); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java index d605645ad..35535e789 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java @@ -130,7 +130,7 @@ class PfReferenceKeyTest { assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, "NPLN", "LN"))); assertEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, NPKLN, "NLN"))); - assertNotEquals(testReferenceKey, null); + assertNotNull(testReferenceKey); assertThatThrownBy(() -> new PfReferenceKey((PfReferenceKey) null)).isInstanceOf(NullPointerException.class); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java index 2fea439b6..9d142bf96 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java @@ -48,7 +48,7 @@ class PfUtilsTest { assertEquals(0, PfUtils.compareObjects(null, null)); assertEquals(-1, PfUtils.compareObjects(HELLO, null)); assertEquals(1, PfUtils.compareObjects(null, HELLO)); - assertNotEquals(PfUtils.compareObjects(HELLO, "goodbye"), 0); + assertNotEquals(0, PfUtils.compareObjects(HELLO, "goodbye")); assertEquals(0, PfUtils.compareObjects(HELLO, HELLO)); } diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java index 594528be8..4b3d9e89a 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java @@ -102,7 +102,6 @@ public class DummyPfKey extends PfKey { @Override public boolean isNewerThan(@NonNull PfKey otherKey) { - // TODO Auto-generated method stub return false; } diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java index 489262865..3f0199ac5 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java @@ -33,7 +33,6 @@ import org.onap.policy.models.base.PfObjectFilter; public class DummyPfObjectFilter implements PfObjectFilter<DummyPfObject> { @Override public List<DummyPfObject> filter(List<DummyPfObject> originalList) { - // TODO Auto-generated method stub return null; } } diff --git a/models-dao/pom.xml b/models-dao/pom.xml index 1a3371530..da32f2509 100644 --- a/models-dao/pom.xml +++ b/models-dao/pom.xml @@ -54,5 +54,14 @@ <groupId>org.hibernate.orm</groupId> <artifactId>hibernate-core</artifactId> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-junit-jupiter</artifactId> + </dependency> </dependencies> </project> diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java index c6faf21ec..6b1409acf 100644 --- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java +++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java @@ -455,7 +455,7 @@ public class DefaultPfDao implements PfDao { * The invoking code only passes well-known classes into this method, thus * disabling the sonar about SQL injection. */ - size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class) // NOSONAR + size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class) .getSingleResult(); } return size; diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/ProxyDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/ProxyDao.java index ec0c357e6..e48fe16c4 100644 --- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/ProxyDao.java +++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/ProxyDao.java @@ -367,7 +367,7 @@ public class ProxyDao implements PfDao { * The invoking code only passes well-known classes into this method, thus * disabling the sonar about SQL injection. */ - size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class) // NOSONAR + size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class) .getSingleResult(); return size; } diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/PfFilterParametersTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/PfFilterParametersTest.java new file mode 100644 index 000000000..ec864a5a3 --- /dev/null +++ b/models-dao/src/test/java/org/onap/policy/models/dao/PfFilterParametersTest.java @@ -0,0 +1,91 @@ +/*- + * ============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.dao; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.Map; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class PfFilterParametersTest { + + @Mock + private Map<String, Object> mockFilterMap; + + private PfFilterParameters pfFilterParametersUnderTest; + + @BeforeEach + void setUp() { + pfFilterParametersUnderTest = new PfFilterParameters("name", "version", + LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC), + LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC), mockFilterMap, 0, "sortOrder"); + } + + @Test + void testGetName() { + assertThat(pfFilterParametersUnderTest.getName()).isEqualTo("name"); + } + + @Test + void testGetVersion() { + assertThat(pfFilterParametersUnderTest.getVersion()).isEqualTo("version"); + } + + @Test + void testGetStartTime() { + assertThat(pfFilterParametersUnderTest.getStartTime()) + .isEqualTo(LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC)); + } + + @Test + void testGetEndTime() { + assertThat(pfFilterParametersUnderTest.getEndTime()) + .isEqualTo(LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC)); + } + + @Test + void testGetFilterMap() { + assertThat(pfFilterParametersUnderTest.getFilterMap()).isEqualTo(mockFilterMap); + } + + @Test + void testGetRecordNum() { + assertThat(pfFilterParametersUnderTest.getRecordNum()).isZero(); + } + + @Test + void testGetSortOrder() { + assertThat(pfFilterParametersUnderTest.getSortOrder()).isEqualTo("sortOrder"); + } + + @Test + void testBuilder() { + assertThatCode(PfFilterParameters::builder).doesNotThrowAnyException(); + } +} diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/impl/PfNonTimestampKeyFilterTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/impl/PfNonTimestampKeyFilterTest.java new file mode 100644 index 000000000..faab76bb7 --- /dev/null +++ b/models-dao/src/test/java/org/onap/policy/models/dao/impl/PfNonTimestampKeyFilterTest.java @@ -0,0 +1,36 @@ +/*- + * ============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.dao.impl; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.Test; + +class PfNonTimestampKeyFilterTest { + + static PfNonTimestampKeyFilter filter; + + @Test + void testPfNonTimestampKeyFilter() { + filter = new PfNonTimestampKeyFilter(); + assertNotNull(filter); + } +} diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/impl/ProxyDaoTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/impl/ProxyDaoTest.java new file mode 100644 index 000000000..e2fe1d91c --- /dev/null +++ b/models-dao/src/test/java/org/onap/policy/models/dao/impl/ProxyDaoTest.java @@ -0,0 +1,548 @@ +/*- + * ============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.dao.impl; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.TypedQuery; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.base.PfReferenceTimestampKey; +import org.onap.policy.models.base.PfTimestampKey; +import org.onap.policy.models.dao.DaoParameters; +import org.onap.policy.models.dao.PfFilterParameters; + +@ExtendWith(MockitoExtension.class) +class ProxyDaoTest { + + @Mock + private EntityManager mockMg; + + @Mock + private TypedQuery mockQuery; + + private ProxyDao proxyDaoUnderTest; + + @BeforeEach + void setUp() { + proxyDaoUnderTest = new ProxyDao(mockMg); + } + + @Test + void testInit() { + assertThatCode(() -> proxyDaoUnderTest.init(new DaoParameters())).doesNotThrowAnyException(); + } + + @Test + void testClose() { + assertThatCode((() -> proxyDaoUnderTest.close())).doesNotThrowAnyException(); + } + + @Test + void testCreate_Null() { + final PfConcept obj = null; + + proxyDaoUnderTest.create(obj); + + verify(mockMg, never()).merge(null); + verify(mockMg, never()).flush(); + } + + @Test + void testCreate() { + final PfConceptKey obj = new PfConceptKey("name", "1.0.0"); + + proxyDaoUnderTest.create(obj); + + verify(mockMg).merge(obj); + verify(mockMg).flush(); + } + + @Test + void testDelete1_Null() { + final PfConcept obj = null; + + proxyDaoUnderTest.delete(obj); + + verify(mockMg, never()).remove(null); + } + + @Test + void testDelete1() { + final PfConceptKey obj = new PfConceptKey("name", "1.0.0"); + + when(mockMg.contains(obj)).thenReturn(false); + when(mockMg.merge(obj)).thenReturn(obj); + + proxyDaoUnderTest.delete(obj); + + verify(mockMg).remove(obj); + } + + @Test + void testDelete2WithNullKey() { + proxyDaoUnderTest.delete(PfConceptKey.class, (PfConceptKey) null); + // Verify that no interactions with mg are made when key is null + verify(mockMg, never()).createQuery(anyString(), any()); + } + + @Test + void testDelete2WithValidKey() { + PfConceptKey key = new PfConceptKey("name", "1.0.0"); + + when(mockMg.createQuery(anyString(), eq(PfConceptKey.class))).thenReturn(mockQuery); + when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery); + + proxyDaoUnderTest.delete(PfConceptKey.class, key); + + ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class); + verify(mockMg).createQuery(queryCaptor.capture(), eq(PfConceptKey.class)); + verify(mockQuery).setParameter("name", key.getName()); + verify(mockQuery).setParameter("version", key.getVersion()); + verify(mockQuery).executeUpdate(); + + assertEquals("DELETE FROM PfConceptKey c WHERE c.key.name = :name " + + "AND c.key.version = :version", queryCaptor.getValue()); + } + + @Test + void testDelete3WithNullKey() { + proxyDaoUnderTest.delete(PfReferenceKey.class, (PfReferenceKey) null); + // Verify that no interactions with mg are made when key is null + verify(mockMg, never()).createQuery(anyString(), any()); + } + + @Test + void testDelete3WithValidKey() { + PfReferenceKey key = new PfReferenceKey("name", "1.0.0", "localName"); + + when(mockMg.createQuery(anyString(), eq(PfReferenceKey.class))).thenReturn(mockQuery); + when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery); + + proxyDaoUnderTest.delete(PfReferenceKey.class, key); + + ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class); + verify(mockMg).createQuery(queryCaptor.capture(), eq(PfReferenceKey.class)); + verify(mockQuery).setParameter("parentname", key.getParentKeyName()); + verify(mockQuery).setParameter("parentversion", key.getParentKeyVersion()); + verify(mockQuery).setParameter("localname", key.getLocalName()); + verify(mockQuery).executeUpdate(); + + assertEquals("DELETE FROM PfReferenceKey c WHERE c.key.parentKeyName = :parentname" + + " AND c.key.parentKeyVersion = :parentversion" + + " AND c.key.localName = :localname", queryCaptor.getValue()); + } + + @Test + void testDelete4WithNullKey() { + proxyDaoUnderTest.delete(PfTimestampKey.class, (PfTimestampKey) null); + // Verify that no interactions with mg are made when key is null + verify(mockMg, never()).createQuery(anyString(), any()); + } + + @Test + void testDelete4WithValidKey() { + final PfTimestampKey key = new PfTimestampKey("name", "1.0.0", LocalDateTime.of(2020, + 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC)); + + when(mockMg.createQuery(anyString(), eq(PfTimestampKey.class))).thenReturn(mockQuery); + when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery); + + proxyDaoUnderTest.delete(PfTimestampKey.class, key); + + ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class); + verify(mockMg).createQuery(queryCaptor.capture(), eq(PfTimestampKey.class)); + verify(mockQuery).setParameter("name", key.getName()); + verify(mockQuery).setParameter("version", key.getVersion()); + verify(mockQuery).setParameter("timeStamp", key.getTimeStamp()); + verify(mockQuery).executeUpdate(); + + assertEquals("DELETE FROM PfTimestampKey c WHERE c.key.name = :name AND c.key.version = :version " + + "AND c.key.timeStamp = :timeStamp", queryCaptor.getValue()); + } + + @Test + void testCreateCollectionWithNull() { + proxyDaoUnderTest.createCollection(null); + + verify(mockMg, never()).merge(null); + } + + @Test + void testCreateCollection() { + List<PfConceptKey> list = List.of(new PfConceptKey("name", "1.0.0"), + new PfConceptKey("name2", "1.0.1")); + + proxyDaoUnderTest.createCollection(list); + + for (final Object ck : list) { + verify(mockMg).merge(ck); + } + } + + @Test + void testCreateCollectionWithIsEmpty() { + proxyDaoUnderTest.createCollection(List.of()); + + verify(mockMg, never()).merge(null); + } + + @Test + void testDeleteCollection() { + final Collection<PfConceptKey> list = List.of( + new PfConceptKey("name", "1.0.0"), + new PfConceptKey("name2", "1.0.1")); + for (final Object o : list) { + lenient().when(mockMg.contains(o)).thenReturn(true); + } + + proxyDaoUnderTest.deleteCollection(list); + + for (final Object o : list) { + verify(mockMg).remove(o); + } + } + + @Test + void testDeleteCollection_EntityManagerContainsReturnsFalse() { + final Collection<PfConceptKey> list = List.of( + new PfConceptKey("name", "1.0.0"), + new PfConceptKey("name2", "1.0.1")); + for (final Object o : list) { + lenient().when(mockMg.contains(o)).thenReturn(false); + lenient().when(mockMg.merge(o)).thenReturn(o); + } + + proxyDaoUnderTest.deleteCollection(list); + + for (final Object o : list) { + verify(mockMg).remove(o); + } + } + + @Test + void testDeleteByConceptKey() { + final Collection<PfConceptKey> keys = List.of(new PfConceptKey("name", "1.0.0")); + when(mockMg.createQuery(anyString(), eq(PfConceptKey.class))).thenReturn(mockQuery); + when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery); + when(mockQuery.executeUpdate()).thenReturn(1); + + final int result = proxyDaoUnderTest.deleteByConceptKey(PfConceptKey.class, keys); + + assertThat(result).isEqualTo(1); + } + + @Test + void testDeleteByConceptKeyWithNull() { + final int result = proxyDaoUnderTest.deleteByConceptKey(PfConceptKey.class, null); + assertThat(result).isZero(); + } + + @Test + void testDeleteByConceptKeyWithEmpty() { + final int result = proxyDaoUnderTest.deleteByConceptKey(PfConceptKey.class, List.of()); + assertThat(result).isZero(); + } + + @Test + void testDeleteByReferenceKey() { + // Setup + final Collection<PfReferenceKey> keys = List.of( + new PfReferenceKey("parentkeyname", "1.0.0", "parentlocalname")); + when(mockMg.createQuery(anyString(), eq(PfReferenceKey.class))).thenReturn(mockQuery); + when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery); + when(mockQuery.executeUpdate()).thenReturn(1); + + final int result = proxyDaoUnderTest.deleteByReferenceKey(PfReferenceKey.class, keys); + + assertThat(result).isEqualTo(1); + } + + @Test + void testDeleteByReferenceKeyWithNull() { + final int result = proxyDaoUnderTest.deleteByReferenceKey(PfReferenceKey.class, null); + assertThat(result).isZero(); + } + + @Test + void testDeleteByReferenceKeyWithIsEmpty() { + final int result = proxyDaoUnderTest.deleteByReferenceKey(PfReferenceKey.class, List.of()); + assertThat(result).isZero(); + } + + @Test + void testDeleteAll() { + when(mockMg.createQuery(anyString(), eq(PfConceptKey.class))).thenReturn(mockQuery); + proxyDaoUnderTest.deleteAll(PfConceptKey.class); + verify(mockQuery).executeUpdate(); + } + + @Test + void testGetFiltered1() { + final List<PfConcept> expectedResult = List.of(new PfConceptKey()); + lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery); + for (final PfConcept ck : expectedResult) { + lenient().when(mockMg.find(eq( + PfConcept.class), any(Object.class))).thenReturn(ck); + } + + final List<PfConcept> result = proxyDaoUnderTest.getFiltered(PfConcept.class, "name", "1.0.0"); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGenericGetNull() { + assertEquals(null, proxyDaoUnderTest.get(null, new PfConceptKey( + "name", "1.0.0"))); + } + + @Test + void testGetAllNull() { + assertEquals(Collections.emptyList(), proxyDaoUnderTest.getAll(null)); + assertEquals(Collections.emptyList(), proxyDaoUnderTest.getAll(null, + new PfConceptKey("name", "1.0.0"))); + assertEquals(Collections.emptyList(), proxyDaoUnderTest.getAll(null, + "name", 1)); + + } + + @Test + void testGetAllVersionsByParentNull() { + assertEquals(Collections.emptyList(), proxyDaoUnderTest + .getAllVersionsByParent(null, "name")); + assertEquals(Collections.emptyList(), proxyDaoUnderTest + .getAllVersionsByParent(PfConcept.class, null)); + } + + @Test + void testGetAllVersionsNull() { + assertEquals(Collections.emptyList(), proxyDaoUnderTest + .getAllVersions(null, "conceptName")); + assertEquals(Collections.emptyList(), proxyDaoUnderTest + .getAllVersions(PfConcept.class, null)); + } + + @Test + void testGetConceptNull() { + assertNull(proxyDaoUnderTest.getConcept(null, + new PfConceptKey("name", "1.0.0"))); + assertNull(proxyDaoUnderTest.getConcept(PfConcept.class, (PfConceptKey) null)); + assertNull(proxyDaoUnderTest.getConcept(null, + new PfReferenceKey("name", "1.0.0", "localName"))); + assertNull(proxyDaoUnderTest.getConcept(PfConcept.class, (PfReferenceKey) null)); + + } + + @Test + void testGetFiltered2() { + List<PfConceptKey> list = List.of(new PfConceptKey("name", "1.0.0"), + new PfConceptKey("name2", "1.0.1")); + + proxyDaoUnderTest.createCollection(list); + + final PfFilterParameters filterParams = PfFilterParameters.builder() + .name("name") + .version("1.0.0") + .build(); + final List<PfConcept> expectedResult = List.of(new PfConceptKey("name", "1.0.0")); + + when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery); + when(mockQuery.getResultList()).thenReturn(expectedResult); + + final List<PfConcept> result = proxyDaoUnderTest.getFiltered(PfConcept.class, filterParams); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGet1() { + final PfConceptKey key = new PfConceptKey("name", "1.0.0"); + final PfConcept expectedResult = new PfConceptKey(key); + when(mockMg.find(eq(PfConcept.class), any(Object.class))).thenReturn(key); + + final PfConcept result = proxyDaoUnderTest.get(PfConcept.class, key); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGet2() { + final PfReferenceKey key = + new PfReferenceKey("parentKeyName", "1.0.0", "parentLocalName", "localName"); + final PfConcept expectedResult = new PfReferenceKey(key); + when(mockMg.find(eq(PfConcept.class), any(Object.class))).thenReturn(key); + + final PfConcept result = proxyDaoUnderTest.get(PfConcept.class, key); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGet3() { + final PfTimestampKey key = + new PfTimestampKey("name", "1.0.0", LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC)); + final PfConcept expectedResult = new PfTimestampKey(key); + when(mockMg.find(eq(PfConcept.class), any(Object.class))).thenReturn(key); + + final PfConcept result = proxyDaoUnderTest.get(PfConcept.class, key); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGet4() { + final PfReferenceTimestampKey key = + new PfReferenceTimestampKey("parentKeyName", "1.0.0", "parentLocalName", "localName", + LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC)); + final PfConcept expectedResult = new PfReferenceTimestampKey(key); + when(mockMg.find(eq(PfConcept.class), any(Object.class))).thenReturn(key); + + final PfConcept result = proxyDaoUnderTest.get(PfConcept.class, key); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGetAll1() { + final List<PfConcept> expectedResult = List.of(new PfConceptKey("name", "1.0.0")); + + lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery); + lenient().when(mockQuery.getResultList()).thenReturn(expectedResult); + final List<PfConcept> result = proxyDaoUnderTest.getAll(PfConcept.class); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGetAll2() { + final PfConceptKey parentKey = new PfConceptKey("name", "1.0.0"); + final List<PfConcept> expectedResult = List.of(parentKey); + + lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery); + lenient().when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery); + lenient().when(mockQuery.getResultList()).thenReturn(expectedResult); + + final List<PfConcept> result = proxyDaoUnderTest.getAll(PfConcept.class, parentKey); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGetAll3() { + final List<PfConcept> expectedResult = List.of(new PfConceptKey("name", "1.0.0")); + lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery); + lenient().when(mockQuery.setMaxResults(1)).thenReturn(mockQuery); + lenient().when(mockQuery.getResultList()) + .thenReturn(List.of(new PfConceptKey("name", "1.0.0"))); + + final List<PfConcept> result = proxyDaoUnderTest.getAll(PfConcept.class, "name", 1); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGetAllVersionsByParent() { + final List<PfConcept> expectedResult = List.of(new PfConceptKey("name", "1.0.0")); + lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery); + lenient().when(mockQuery.setParameter(anyString(), anyString())).thenReturn(mockQuery); + lenient().when(mockQuery.getResultList()) + .thenReturn(List.of(new PfConceptKey("name", "1.0.0"))); + + final List<PfConcept> result = proxyDaoUnderTest.getAllVersionsByParent(PfConcept.class, "name"); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGetAllVersions() { + final List<PfConcept> expectedResult = List.of(new PfConceptKey("name", "1.0.0")); + lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery); + lenient().when(mockQuery.setParameter(anyString(), anyString())).thenReturn(mockQuery); + lenient().when(mockQuery.getResultList()) + .thenReturn(List.of(new PfConceptKey("name", "1.0.0"))); + + final List<PfConcept> result = proxyDaoUnderTest.getAllVersions(PfConcept.class, "name"); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGetConcept1() { + final PfConceptKey key = new PfConceptKey("name", "1.0.0"); + final PfConcept expectedResult = key; + lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery); + lenient().when(mockQuery.setParameter(anyString(), anyString())).thenReturn(mockQuery); + lenient().when(mockQuery.getResultList()).thenReturn(List.of(key)); + + final PfConcept result = proxyDaoUnderTest.getConcept(PfConcept.class, key); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testGetConcept2() { + final PfReferenceKey key = new PfReferenceKey(); + final PfConcept expectedResult = key; + lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery); + lenient().when(mockQuery.setParameter(anyString(), anyString())).thenReturn(mockQuery); + lenient().when(mockQuery.getResultList()).thenReturn(List.of(key)); + + final PfConcept result = proxyDaoUnderTest.getConcept(PfConcept.class, key); + + assertThat(result).isEqualTo(expectedResult); + } + + @Test + void testUpdate() { + final PfConcept obj = null; + final PfConcept expectedResult = null; + when(mockMg.merge(null)).thenReturn(null); + + final PfConcept result = proxyDaoUnderTest.update(obj); + + assertThat(result).isEqualTo(expectedResult); + verify(mockMg).flush(); + } +} diff --git a/models-decisions/pom.xml b/models-decisions/pom.xml index 7c71d2fd3..a69e0d4ea 100644 --- a/models-decisions/pom.xml +++ b/models-decisions/pom.xml @@ -55,5 +55,9 @@ <artifactId>openpojo</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> </dependencies> </project> diff --git a/models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionException.java b/models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionException.java new file mode 100644 index 000000000..5123f713b --- /dev/null +++ b/models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionException.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Decision Models + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.decisions.concepts; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.Test; + +class TestDecisionException { + + @Test + void testException() { + Response.Status status = Response.Status.NOT_ACCEPTABLE; + String message = "Test exception thrown"; + + DecisionException exception = new DecisionException(status, message); + + assertNotNull(exception); + assertEquals(status, exception.getErrorResponse().getResponseCode()); + assertEquals(message, exception.getMessage()); + + assertThrows(DecisionException.class, () -> { + throw exception; + }); + } +} diff --git a/models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionRequest.java b/models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionRequest.java new file mode 100644 index 000000000..2d4acfb2a --- /dev/null +++ b/models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionRequest.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Decision Models + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.decisions.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + + +class TestDecisionRequest { + + private DecisionRequest request1; + + @BeforeEach + void setUp() { + request1 = new DecisionRequest(); + } + + @Test + void testConstructor() { + DecisionRequest request2 = new DecisionRequest(request1); + assertEquals(request1, request2); + } + + @Test + void testConstructorContextNotNull() { + Map testMap = new HashMap<String, Object>(); + testMap.put("entry1", "test"); + request1.setContext(testMap); + DecisionRequest request2 = new DecisionRequest(request1); + assertThat(request2.toString()).contains("context={entry1=test}"); + } + + @Test + void testConstructorResourceNotNull() { + Map testMap = new HashMap<String, Object>(); + testMap.put("resourceEntry1", "test"); + request1.setResource(testMap); + DecisionRequest request2 = new DecisionRequest(request1); + assertThat(request2.toString()).contains("resource={resourceEntry1=test}"); + } +} diff --git a/models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionRequestMessageBodyHandler.java b/models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionRequestMessageBodyHandler.java new file mode 100644 index 000000000..3bd416810 --- /dev/null +++ b/models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionRequestMessageBodyHandler.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Decision Models + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.decisions.serialization; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import com.google.gson.GsonBuilder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class TestDecisionRequestMessageBodyHandler { + + DecisionRequestMessageBodyHandler handler; + + @BeforeEach + void setUp() { + handler = new DecisionRequestMessageBodyHandler(); + } + + @Test + void testDecisionRequestMessageBodyHandlerConstructor() { + GsonBuilder builder = new GsonBuilder(); + DecisionRequestMessageBodyHandler handler2 = + new DecisionRequestMessageBodyHandler(builder); + assertNotNull(handler); + assertNotNull(handler2); + } +} diff --git a/models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionResponseMessageBodyHandler.java b/models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionResponseMessageBodyHandler.java new file mode 100644 index 000000000..93e39df4a --- /dev/null +++ b/models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionResponseMessageBodyHandler.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Decision Models + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.decisions.serialization; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import com.google.gson.GsonBuilder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class TestDecisionResponseMessageBodyHandler { + + DecisionResponseMessageBodyHandler handler; + + @BeforeEach + void setUp() { + handler = new DecisionResponseMessageBodyHandler(); + } + + @Test + void testDecisionResponseMessageBodyHandler() { + GsonBuilder builder = new GsonBuilder(); + DecisionResponseMessageBodyHandler handler2 = new DecisionResponseMessageBodyHandler(builder); + assertNotNull(handler); + assertNotNull(handler2); + } +} diff --git a/models-interactions/model-actors/actor.a1p/src/test/java/org/onap/policy/controlloop/actor/a1p/A1pOperationTest.java b/models-interactions/model-actors/actor.a1p/src/test/java/org/onap/policy/controlloop/actor/a1p/A1pOperationTest.java index 930888da2..7ab5d475d 100644 --- a/models-interactions/model-actors/actor.a1p/src/test/java/org/onap/policy/controlloop/actor/a1p/A1pOperationTest.java +++ b/models-interactions/model-actors/actor.a1p/src/test/java/org/onap/policy/controlloop/actor/a1p/A1pOperationTest.java @@ -59,7 +59,7 @@ import org.onap.policy.sdnr.util.StatusCodeEnum; */ @BeforeEach @Override - void setUp() throws Exception { + void setUp() { super.setUp(); operation = new A1pOperation(params, config); diff --git a/models-interactions/model-actors/actor.a1p/src/test/java/org/onap/policy/controlloop/actor/a1p/BasicA1pOperation.java b/models-interactions/model-actors/actor.a1p/src/test/java/org/onap/policy/controlloop/actor/a1p/BasicA1pOperation.java index 3620b0cef..6a254a4f1 100644 --- a/models-interactions/model-actors/actor.a1p/src/test/java/org/onap/policy/controlloop/actor/a1p/BasicA1pOperation.java +++ b/models-interactions/model-actors/actor.a1p/src/test/java/org/onap/policy/controlloop/actor/a1p/BasicA1pOperation.java @@ -69,7 +69,7 @@ public abstract class BasicA1pOperation extends BasicBidirectionalTopicOperation /** * Initializes mocks and sets up. */ - void setUp() throws Exception { + void setUp() { super.setUpBasic(); response = new PciMessage(); diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java index 8768aec7b..7a101cb8d 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023, 2024 Nordix Foundation. + * Modifications Copyright (C) 2023-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. @@ -82,7 +82,7 @@ class AaiCustomQueryOperationTest extends BasicAaiOperation { * Sets up. */ @BeforeEach - void setUp() throws Exception { + void setUp() { super.setUpBasic(); oper = new AaiCustomQueryOperation(params, config); @@ -166,7 +166,7 @@ class AaiCustomQueryOperationTest extends BasicAaiOperation { } @Test - void testGetVserverLink() throws Exception { + void testGetVserverLink() { oper.setProperty(OperationProperties.AAI_VSERVER_LINK, MY_LINK); assertEquals(MY_LINK, oper.getVserverLink()); } @@ -194,7 +194,7 @@ class AaiCustomQueryOperationTest extends BasicAaiOperation { private OperationResult getResult(CompletableFuture<OperationOutcome> future2) - throws InterruptedException, ExecutionException, TimeoutException { + throws InterruptedException, ExecutionException { executor.runAll(100); assertTrue(future2.isDone()); diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java index e9890b748..831edcc70 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023, 2024 Nordix Foundation. + * Modifications Copyright (C) 2023-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. @@ -66,7 +66,7 @@ class AaiGetOperationTest extends BasicAaiOperation { * Sets up. */ @BeforeEach - void setUp() throws Exception { + void setUp() { super.setUpBasic(); oper = new AaiGetOperation(params, config); } diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java index cf2bb1b62..bed847a10 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023, 2024 Nordix Foundation. + * Modifications Copyright (C) 2023-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. @@ -75,7 +75,7 @@ class AaiGetPnfOperationTest extends BasicAaiOperation { * Sets up. */ @BeforeEach - void setUp() throws Exception { + void setUp() { super.setUpBasic(); oper = new AaiGetPnfOperation(params, config); oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, TARGET_ENTITY); @@ -174,7 +174,7 @@ class AaiGetPnfOperationTest extends BasicAaiOperation { * Tests startOperationAsync() when a property is missing. */ @Test - void testStartOperationAsyncMissingProperty() throws Exception { + void testStartOperationAsyncMissingProperty() { oper = new AaiGetPnfOperation(params, config); oper.generateSubRequestId(1); diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java index 65d3fe831..e3beb52ac 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java @@ -75,7 +75,7 @@ class AaiGetTenantOperationTest extends BasicAaiOperation { * Sets up. */ @BeforeEach - void setUp() throws Exception { + void setUp() { super.setUpBasic(); oper = new AaiGetTenantOperation(params, config); oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, TARGET_ENTITY); @@ -174,7 +174,7 @@ class AaiGetTenantOperationTest extends BasicAaiOperation { * Tests startOperationAsync() when a property is missing. */ @Test - void testStartOperationAsyncMissingProperty() throws Exception { + void testStartOperationAsyncMissingProperty() { oper = new AaiGetTenantOperation(params, config); oper.generateSubRequestId(1); diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java index caa190f71..94efe0af3 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java @@ -66,7 +66,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp */ @BeforeEach @Override - void setUp() throws Exception { + void setUp() { super.setUp(); oper = new MyOper(params, config); diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java index b934d8659..45d64db34 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java @@ -86,7 +86,7 @@ public abstract class BasicAppcOperation extends BasicBidirectionalTopicOperatio /** * Initializes mocks and sets up. */ - void setUp() throws Exception { + void setUp() { super.setUpBasic(); response = new Response(); diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java index fad504434..2e0926e12 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java @@ -62,7 +62,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.Bidirectional @BeforeEach @Override - void setUp() throws Exception { + void setUp() { super.setUp(); oper = new ModifyConfigOperation(params, config); @@ -90,8 +90,6 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.Bidirectional oper.setProperty(OperationProperties.AAI_RESOURCE_VNF, genvnf); outcome = oper.start().get(); - // assertEquals(OperationResult.SUCCESS, outcome.getResult()); - // assertTrue(outcome.getResponse() instanceof Response); assertNotNull(outcome); } diff --git a/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java b/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java index 8fa165f6f..53677c766 100644 --- a/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java +++ b/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java @@ -126,8 +126,6 @@ import org.onap.policy.simulators.TopicServer; oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, TARGET_ENTITY); outcome = oper.start().get(); - // assertEquals(OperationResult.SUCCESS, outcome.getResult()); - // assertTrue(outcome.getResponse() instanceof AppcLcmMessageWrapper); assertNotNull(outcome); } @@ -167,7 +165,7 @@ import org.onap.policy.simulators.TopicServer; * Tests makeRequest() when a property is missing. */ @Test - void testMakeRequestMissingProperty() throws Exception { + void testMakeRequestMissingProperty() { oper = new AppcLcmOperation(params, config); oper.generateSubRequestId(1); diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcActorServiceManagerTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcActorServiceManagerTest.java index dc7fcf447..e3ad6bea4 100644 --- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcActorServiceManagerTest.java +++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcActorServiceManagerTest.java @@ -51,7 +51,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationResult; * Sets up the fields. */ @BeforeEach - void setUp() throws Exception { + void setUp() { future = new CompletableFuture<>(); manager = new CdsActorServiceManager(new OperationOutcome(), future); } @@ -68,7 +68,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationResult; } @Test - void testOnMessageProcessing() throws InterruptedException, ExecutionException, TimeoutException { + void testOnMessageProcessing() { Status status = Status.newBuilder().setEventType(EventType.EVENT_COMPONENT_PROCESSING).build(); output = ExecutionServiceOutput.newBuilder().setStatus(status).build(); @@ -89,7 +89,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationResult; } @Test - void testOnError() throws InterruptedException, ExecutionException, TimeoutException { + void testOnError() { Exception exception = new Exception("something failed"); manager.onError(exception); diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java index 3510c4a67..09ca68434 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java @@ -129,7 +129,7 @@ class BandwidthOnDemandOperationTest extends BasicSdncOperation { */ @Test - void testMakeRequestMissingBandwidth() throws Exception { + void testMakeRequestMissingBandwidth() { oper = new BandwidthOnDemandOperation(params, config); oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE); oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME); @@ -143,7 +143,7 @@ class BandwidthOnDemandOperationTest extends BasicSdncOperation { } @Test - void testMakeRequestMissingBandwidthChangeTime() throws Exception { + void testMakeRequestMissingBandwidthChangeTime() { oper = new BandwidthOnDemandOperation(params, config); oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE); oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH); @@ -157,7 +157,7 @@ class BandwidthOnDemandOperationTest extends BasicSdncOperation { } @Test - void testMakeRequestMissingVnfId() throws Exception { + void testMakeRequestMissingVnfId() { oper = new BandwidthOnDemandOperation(params, config); oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE); oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH); diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java index cfdec987d..5dee02fcb 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java @@ -112,7 +112,7 @@ abstract class BasicSdncOperation extends BasicHttpOperation { * @return the request that was posted */ protected SdncRequest verifyOperation(SdncOperation operation) - throws InterruptedException, ExecutionException, TimeoutException, CoderException { + throws InterruptedException, ExecutionException, CoderException { CompletableFuture<OperationOutcome> future2 = operation.start(); executor.runAll(100); diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java index ee9a3a1f2..bd67f7fec 100644 --- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java +++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java @@ -70,7 +70,7 @@ abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperation<PciMe /** * Initializes mocks and sets up. */ - void setUp() throws Exception { + void setUp() { super.setUpBasic(); response = new PciMessage(); @@ -102,7 +102,7 @@ abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperation<PciMe * @param operation operation to run */ protected void verifyOperation(SdnrOperation operation) - throws InterruptedException, ExecutionException, TimeoutException { + throws InterruptedException, ExecutionException { CompletableFuture<OperationOutcome> future2 = operation.start(); executor.runAll(100); diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java index e16ad1177..f7dd9b935 100644 --- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java +++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java @@ -66,7 +66,7 @@ import org.onap.policy.sdnr.util.StatusCodeEnum; */ @BeforeEach @Override - void setUp() throws Exception { + void setUp() { super.setUp(); operation = new SdnrOperation(params, config); @@ -148,8 +148,6 @@ import org.onap.policy.sdnr.util.StatusCodeEnum; operation.setProperty(OperationProperties.EVENT_PAYLOAD, "my payload"); outcome = operation.start().get(); - // assertEquals(OperationResult.SUCCESS, outcome.getResult()); - // assertTrue(outcome.getResponse() instanceof PciMessage); assertNotNull(outcome); } diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/RestManagerResponse.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/RestManagerResponse.java index 129305d99..57c3f7ee2 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/RestManagerResponse.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/RestManagerResponse.java @@ -46,7 +46,6 @@ import org.onap.policy.common.utils.coder.CoderException; */ @AllArgsConstructor public class RestManagerResponse extends Response { - // TODO move to actorServices @Getter private final int status; diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java index 8076fbcb9..4ef0a7ba9 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Wipro Limited. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023-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. @@ -121,7 +121,6 @@ public class VfModuleDelete extends SoOperation { */ protected CompletableFuture<Response> delete(String uri, Map<String, Object> headers, String contentType, String request, InvocationCallback<Response> callback) { - // TODO move to HttpOperation final String url = getClient().getBaseUrl() + uri; @@ -163,7 +162,6 @@ public class VfModuleDelete extends SoOperation { * @return the builder */ protected Builder addAuthHeader(Builder builder) { - // TODO move to HttpOperation final HttpClient client = getClient(); String username = client.getUserName(); if (StringUtils.isBlank(username)) { @@ -229,11 +227,6 @@ public class VfModuleDelete extends SoOperation { // requestInfo details.setRequestInfo(constructRequestInfo()); - /* - * TODO the legacy SO code always passes null for the last argument, though it - * should be passing the vfModuleInstanceId - */ - // compute the path String svcId = getRequiredText("service instance ID", vnfServiceItem.getServiceInstanceId()); String path = PATH_PREFIX + svcId + "/vnfs/" + vnfItem.getVnfId() + "/vfModules/null"; diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java index ff1a93b85..0edc7d374 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java @@ -110,7 +110,7 @@ class ModifyCllTest extends BasicSoOperation { * Tests makeRequest() when a property is missing. */ @Test - void testMakeRequestMissingProperty() throws Exception { + void testMakeRequestMissingProperty() { oper = new ModifyCll(params, config); assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest()) diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java index c5c183275..4db3ca308 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java @@ -110,7 +110,7 @@ class ModifyNssiTest extends BasicSoOperation { * Tests makeRequest() when a property is missing. */ @Test - void testMakeRequestMissingProperty() throws Exception { + void testMakeRequestMissingProperty() { oper = new ModifyNssi(params, config); assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest()) diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java index fe88a2371..f04708210 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java @@ -212,7 +212,7 @@ import org.onap.policy.so.SoResponse; } @Test - void testConstructCloudConfiguration() throws Exception { + void testConstructCloudConfiguration() { Tenant tenantItem = new Tenant(); tenantItem.setTenantId("my-tenant-id"); @@ -235,7 +235,7 @@ import org.onap.policy.so.SoResponse; } @Test - void testGetRequiredText() throws Exception { + void testGetRequiredText() { assertThatCode(() -> oper.getRequiredText("some value", "my value")).doesNotThrowAnyException(); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java index 721cb6a6d..d1b2c0747 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java @@ -221,7 +221,7 @@ class VfModuleCreateTest extends BasicSoOperation { * Tests makeRequest() when a property is missing. */ @Test - void testMakeRequestMissingProperty() throws Exception { + void testMakeRequestMissingProperty() { loadProperties(); ServiceInstance instance = new ServiceInstance(); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java index 5ece1968d..208db3f57 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java @@ -277,7 +277,7 @@ class VfModuleDeleteTest extends BasicSoOperation { */ @Test @SuppressWarnings("unchecked") - void testDeleteException() throws Exception { + void testDeleteException() { Throwable thrown = new IllegalStateException(EXPECTED_EXCEPTION); // need a new future, with an exception @@ -360,7 +360,7 @@ class VfModuleDeleteTest extends BasicSoOperation { * Tests makeRequest() when a property is missing. */ @Test - void testMakeRequestMissingProperty() throws Exception { + void testMakeRequestMissingProperty() { loadProperties(); ServiceInstance instance = new ServiceInstance(); @@ -381,7 +381,7 @@ class VfModuleDeleteTest extends BasicSoOperation { } @SuppressWarnings("unchecked") - private void configureResponse(String responseText) throws CoderException { + private void configureResponse(String responseText) { // indicate that the response was completed lenient().when(javaResp.statusCode()).thenReturn(200); lenient().when(javaResp.body()).thenReturn(responseText); diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java index 48ee9dcfc..4727de010 100644 --- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java +++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java @@ -24,6 +24,7 @@ package org.onap.policy.controlloop.actor.test; import static org.junit.jupiter.api.Assertions.assertEquals; import jakarta.ws.rs.core.Response; +import java.util.Collections; import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -122,7 +123,7 @@ public class BasicOperation { * @return payload data */ protected Map<String, Object> makePayload() { - return null; + return Collections.emptyMap(); } /** diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java index c795f9cc5..0d04e5894 100644 --- a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java @@ -37,7 +37,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.onap.policy.common.endpoints.event.comm.TopicSink; @@ -71,7 +70,7 @@ class BasicBidirectionalTopicOperationTest { * Sets up. */ @BeforeEach - void setUp() throws Exception { + void setUp() { oper.setUpBasic(); } diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicHttpOperationTest.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicHttpOperationTest.java index 58392b96e..907802963 100644 --- a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicHttpOperationTest.java +++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicHttpOperationTest.java @@ -43,7 +43,7 @@ class BasicHttpOperationTest { @BeforeEach - void setUp() throws Exception { + void setUp() { oper = new BasicHttpOperation(ACTOR, OPERATION); oper.setUpBasic(); } @@ -62,7 +62,7 @@ class BasicHttpOperationTest { } @Test - void testSetUp() throws Exception { + void testSetUp() { assertNotNull(oper.client); assertSame(oper.client, oper.factory.get(BasicHttpOperation.MY_CLIENT)); assertEquals(200, oper.rawResponse.getStatus()); @@ -73,7 +73,7 @@ class BasicHttpOperationTest { } @Test - void testInitOperator() throws Exception { + void testInitOperator() { oper.initConfig(); assertSame(oper.client, oper.config.getClient()); diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicOperationTest.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicOperationTest.java index b2afce2c3..cf61e191b 100644 --- a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicOperationTest.java +++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicOperationTest.java @@ -23,9 +23,9 @@ package org.onap.policy.controlloop.actor.test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; +import java.util.Collections; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -44,7 +44,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Util; @BeforeEach - void setUp() throws Exception { + void setUp() { oper = new BasicHttpOperation(ACTOR, OPERATION); oper.setUpBasic(); } @@ -63,7 +63,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Util; } @Test - void testSetUp() throws Exception { + void testSetUp() { assertNotNull(oper.future); assertNotNull(oper.outcome); assertNotNull(oper.executor); @@ -82,7 +82,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Util; @Test void testMakePayload() { - assertNull(oper.makePayload()); + assertEquals(Collections.emptyMap(), oper.makePayload()); } @Test diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java index 920e79984..e0fd18b08 100644 --- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java +++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java @@ -76,7 +76,6 @@ import org.onap.policy.vfc.VfcResponseDescriptor; VfcResponseDescriptor mockDescriptor = Mockito.mock(VfcResponseDescriptor.class); Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(mockDescriptor); - // TODO use actual request state value Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE"); assertNotNull(oper.getRequestState(mockResponse)); } diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperationTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperationTest.java index ee9d28c57..fa81836f3 100644 --- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperationTest.java +++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperationTest.java @@ -94,7 +94,7 @@ import org.onap.policy.simulators.XacmlSimulatorJaxRs; * Sets up. */ @BeforeEach - void setUp() throws Exception { + void setUp() { super.setUpBasic(); guardConfig = mock(DecisionConfig.class); diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/GuardOperationTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/GuardOperationTest.java index a4187b523..f8b53e8f8 100644 --- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/GuardOperationTest.java +++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/GuardOperationTest.java @@ -28,7 +28,6 @@ import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import java.util.Map; import java.util.TreeMap; @@ -86,7 +85,7 @@ import org.onap.policy.simulators.XacmlSimulatorJaxRs; * Sets up. */ @BeforeEach - void setUp() throws Exception { + void setUp() { super.setUpBasic(); guardConfig = mock(DecisionConfig.class); diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorTest.java index 3f0e52860..81c946419 100644 --- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorTest.java +++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorTest.java @@ -23,7 +23,6 @@ package org.onap.policy.controlloop.actor.xacml; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.stream.Collectors; diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java index 5765f35ba..8f2199f05 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java @@ -95,7 +95,6 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial */ @Override protected long getTimeoutMs(Integer timeoutSec) { - // TODO move this method to the superclass return (timeoutSec == null || timeoutSec == 0 ? getTimeoutMs() : super.getTimeoutMs(timeoutSec)); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java index 5ecebd668..7e4543eca 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java @@ -98,7 +98,7 @@ class BidirectionalTopicActorTest { } @Test - void testDoStart() throws BidirectionalTopicClientException { + void testDoStart() { // allocate some handlers actor.getTopicHandler(MY_SINK, MY_SOURCE1); actor.getTopicHandler(MY_SINK, MY_SOURCE2); @@ -117,7 +117,7 @@ class BidirectionalTopicActorTest { } @Test - void testDoStop() throws BidirectionalTopicClientException { + void testDoStop() { // allocate some handlers actor.getTopicHandler(MY_SINK, MY_SOURCE1); actor.getTopicHandler(MY_SINK, MY_SOURCE2); @@ -136,7 +136,7 @@ class BidirectionalTopicActorTest { } @Test - void testDoShutdown() throws BidirectionalTopicClientException { + void testDoShutdown() { // allocate some handlers actor.getTopicHandler(MY_SINK, MY_SOURCE1); @@ -187,7 +187,7 @@ class BidirectionalTopicActorTest { } @Test - void testGetTopicHandler() throws BidirectionalTopicClientException { + void testGetTopicHandler() { assertSame(handler1, actor.getTopicHandler(MY_SINK, MY_SOURCE1)); assertSame(handler2, actor.getTopicHandler(MY_SINK, MY_SOURCE2)); @@ -195,7 +195,7 @@ class BidirectionalTopicActorTest { } @Test - void testMakeTopicHandler() throws BidirectionalTopicClientException { + void testMakeTopicHandler() { // use a real actor actor = new BidirectionalTopicActor<>(ACTOR, BidirectionalTopicActorParams.class); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java index 1fc8cc18e..67283f5d4 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java @@ -174,7 +174,7 @@ class BidirectionalTopicOperationTest { * Tests startOperationAsync() when processResponse() throws an exception. */ @Test - void testStartOperationAsyncProcException() throws Exception { + void testStartOperationAsyncProcException() { oper = new MyOperation(params, config) { @Override protected OperationOutcome processResponse(OperationOutcome outcome, String rawResponse, @@ -202,7 +202,7 @@ class BidirectionalTopicOperationTest { * Tests startOperationAsync() when the publisher throws an exception. */ @Test - void testStartOperationAsyncPubException() throws Exception { + void testStartOperationAsyncPubException() { // indicate that nothing was published when(handler.send(any())).thenReturn(false); @@ -302,7 +302,7 @@ class BidirectionalTopicOperationTest { * Tests processResponse() when the decoder succeeds. */ @Test - void testProcessResponseDecodeOk() throws CoderException { + void testProcessResponseDecodeOk() { assertSame(outcome, oper.processResponse(outcome, responseText, stdResponse)); assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertEquals(response, outcome.getResponse()); @@ -312,7 +312,7 @@ class BidirectionalTopicOperationTest { * Tests processResponse() when the decoder throws an exception. */ @Test - void testProcessResponseDecodeExcept() throws CoderException { + void testProcessResponseDecodeExcept() { assertThatIllegalArgumentException().isThrownBy( () -> oper.processResponse(outcome, "{invalid json", stdResponse)); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java index 9813d1b7a..8e1a8783a 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java @@ -260,7 +260,7 @@ class HttpOperationTest { * Tests handleResponse() when it fails. */ @Test - void testHandleResponseFailed() throws Exception { + void testHandleResponseFailed() { CompletableFuture<OperationOutcome> future2 = oper.handleResponse(outcome, PATH, cb -> { callback.set(cb); return future; @@ -322,7 +322,7 @@ class HttpOperationTest { * Tests processResponse() when the decoder throws an exception. */ @Test - void testProcessResponseDecodeExcept() throws CoderException { + void testProcessResponseDecodeExcept() { MyGetOperation<Integer> oper2 = new MyGetOperation<>(Integer.class); assertThatIllegalArgumentException().isThrownBy(() -> oper2.processResponse(outcome, PATH, response)); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java index 0850bb358..78f465ea8 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java @@ -89,7 +89,7 @@ class HttpPollingOperationTest { * Sets up. */ @BeforeEach - void setUp() throws Exception { + void setUp() { Mockito.lenient().when(client.getBaseUrl()).thenReturn(BASE_URI); Mockito.lenient().when(config.getClient()).thenReturn(client); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java index ca81e2eb3..13a16bfc2 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java @@ -29,7 +29,6 @@ import static org.mockito.Mockito.when; import java.util.Collections; import java.util.Map; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java index 27b841a91..d2ca7dbc6 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java @@ -137,7 +137,7 @@ class OperationPartialTest { * Attaches the appender to the logger. */ @BeforeAll - static void setUpBeforeClass() throws Exception { + static void setUpBeforeClass() { /* * Attach appender to the logger. */ @@ -565,7 +565,7 @@ class OperationPartialTest { */ @Test @SuppressWarnings("unchecked") - void testAnyOfEdge() throws Exception { + void testAnyOfEdge() { List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); // zero items: check both using a list and using an array @@ -651,7 +651,7 @@ class OperationPartialTest { */ @Test @SuppressWarnings("unchecked") - void testAllOfEdge() throws Exception { + void testAllOfEdge() { List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); // zero items: check both using a list and using an array @@ -667,7 +667,7 @@ class OperationPartialTest { } @Test - void testAttachFutures() throws Exception { + void testAttachFutures() { List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); // third task throws an exception during construction @@ -770,7 +770,7 @@ class OperationPartialTest { */ @Test @SuppressWarnings("unchecked") - void testSequenceEdge() throws Exception { + void testSequenceEdge() { List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); // zero items: check both using a list and using an array diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java index c0d3a0df8..2c8275986 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java @@ -157,7 +157,7 @@ class PipelineControllerFutureTest { * Tests completeAsync(executor) when canceled before execution. */ @Test - void testCompleteAsyncSupplierOfQextendsTExecutorCanceled() throws Exception { + void testCompleteAsyncSupplierOfQextendsTExecutorCanceled() { CompletableFuture<String> future = controller.completeAsync(() -> TEXT, executor); assertTrue(future.cancel(false)); @@ -181,7 +181,7 @@ class PipelineControllerFutureTest { * Tests completeAsync() when canceled. */ @Test - void testCompleteAsyncSupplierOfQextendsTCanceled() throws Exception { + void testCompleteAsyncSupplierOfQextendsTCanceled() { CountDownLatch canceled = new CountDownLatch(1); // run async, but await until canceled @@ -210,7 +210,7 @@ class PipelineControllerFutureTest { @Test void testCompleteOnTimeoutTLongTimeUnit() throws Exception { CountDownLatch stopped = new CountDownLatch(1); - controller.add(() -> stopped.countDown()); + controller.add(stopped::countDown); CompletableFuture<String> future = controller.completeOnTimeout(TEXT, 1, TimeUnit.MILLISECONDS); @@ -288,7 +288,7 @@ class PipelineControllerFutureTest { * Tests delayedComplete() when an exception is generated. */ @Test - void testDelayedCompleteWithException() throws Exception { + void testDelayedCompleteWithException() { controller.add(runnable1); BiConsumer<String, Throwable> stopper = controller.delayedComplete(); @@ -314,7 +314,7 @@ class PipelineControllerFutureTest { } @Test - void testDelayedRemoveFutureOfF() throws Exception { + void testDelayedRemoveFutureOfF() { BiConsumer<String, Throwable> remover = controller.delayedRemove(future1); remover.accept(TEXT, EXPECTED_EXCEPTION); @@ -331,7 +331,7 @@ class PipelineControllerFutureTest { } @Test - void testDelayedRemoveRunnable() throws Exception { + void testDelayedRemoveRunnable() { BiConsumer<String, Throwable> remover = controller.delayedRemove(runnable1); remover.accept(TEXT, EXPECTED_EXCEPTION); @@ -380,7 +380,7 @@ class PipelineControllerFutureTest { * Tests wrap(), when the controller is not running. */ @Test - void testWrapNotRunning() throws Exception { + void testWrapNotRunning() { controller.cancel(false); controller = spy(controller); @@ -395,7 +395,7 @@ class PipelineControllerFutureTest { * Tests wrap(), when the future throws an exception. */ @Test - void testWrapException() throws Exception { + void testWrapException() { controller = spy(controller); CompletableFuture<String> future = controller.wrap(compFuture); @@ -428,7 +428,7 @@ class PipelineControllerFutureTest { * Tests wrap(Function) when the controller is canceled after the future is added. */ @Test - void testWrapFunctionCancel() throws Exception { + void testWrapFunctionCancel() { Function<String, CompletableFuture<String>> func = controller.wrap(input -> compFuture); CompletableFuture<String> future = func.apply(TEXT); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java index e050416f5..f27eb6ae5 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java @@ -31,7 +31,6 @@ import static org.mockito.Mockito.verify; import java.util.Arrays; import java.util.Map; import java.util.function.BiConsumer; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java index 7a6eb6859..ed77525be 100644 --- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java @@ -3,7 +3,7 @@ * * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023-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. @@ -42,7 +42,6 @@ import org.onap.aai.domain.yang.Vserver; public class AaiCqResponse implements Serializable { private static final long serialVersionUID = 1L; - public static final String CONTEXT_KEY = AaiConstants.CONTEXT_PREFIX + "AaiCqResponse"; public static final String OPERATION = "CustomQuery"; private static final String GENERIC_VNF = "generic-vnf"; private static final String VF_MODULE = "vf-module"; @@ -50,7 +49,7 @@ public class AaiCqResponse implements Serializable { @SerializedName("results") private List<Serializable> inventoryResponseItems = new LinkedList<>(); - private final Gson gson; + private final transient Gson gson; /** * Constructor creates a custom query response from a valid json string. diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java index a6a671815..26a39875f 100644 --- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java @@ -3,7 +3,7 @@ * aai * ================================================================================ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation. * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,6 +25,7 @@ package org.onap.policy.aai; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -48,8 +49,6 @@ import org.slf4j.LoggerFactory; @AllArgsConstructor public final class AaiManager { - // TODO remove this class - /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(AaiManager.class); @@ -246,12 +245,12 @@ public final class AaiManager { pnfName = URLEncoder.encode(pnfName, StandardCharsets.UTF_8.toString()) + AAI_DEPTH_SUFFIX; } catch (UnsupportedEncodingException e) { logger.error("Failed to encode the pnfName: {} using UTF-8", pnfName, e); - return null; + return Collections.emptyMap(); } var responseGet = getStringQuery(urlGet, username, password, requestId, pnfName); if (responseGet == null) { logger.error("Null response from AAI for the url: {}.", urlGet); - return null; + return Collections.emptyMap(); } try { @SuppressWarnings("unchecked") @@ -261,7 +260,7 @@ public final class AaiManager { .collect(Collectors.toMap(e -> "pnf." + e.getKey(), Map.Entry::getValue)); } catch (CoderException e) { logger.error("Failed to fetch PNF from AAI", e); - return null; + return Collections.emptyMap(); } } } diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java index 72a78147b..0a47fcb05 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java @@ -87,7 +87,7 @@ class CommonHeaderTest { assertEquals(commonHeader, (Object) commonHeader); assertEquals(commonHeader, copiedCommonHeader); - assertNotEquals(commonHeader, null); + assertNotNull(commonHeader); assertNotEquals(commonHeader, (Object) "Hello"); CommonHeader clonedCommonHeader = new CommonHeader(commonHeader); diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java index 7ab4ae746..67b3d85d4 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java @@ -76,7 +76,7 @@ class RequestTest { assertEquals(request, (Object) request); assertEquals(request, copiedRequest); - assertNotEquals(request, null); + assertNotNull(request); assertNotEquals(request, (Object) "Hello"); checkField(commonHeader, Request::setCommonHeader); diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java index a13e08f64..f095df909 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java @@ -58,7 +58,7 @@ class ResponseStatusTest { assertEquals(status, (Object) status); assertEquals(status, copiedStatus); - assertNotEquals(status, null); + assertNotNull(status); assertNotEquals(status, (Object) "Hello"); status.setCode(-1); diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java index ee0ff371b..dffb9588c 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java @@ -70,7 +70,7 @@ class ResponseTest { assertEquals(response, (Object) response); assertEquals(response, copiedResponse); - assertNotEquals(response, null); + assertNotNull(response); assertNotEquals(response, (Object) "Hello"); response.setCommonHeader(null); diff --git a/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java b/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java index 1a35064ca..b0a605b8c 100644 --- a/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java +++ b/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java @@ -152,9 +152,7 @@ class CdsProcessorGrpcClientTest { @Test void testCdsProcessorGrpcClientConstructorFailure() { props.setHost(null); - assertThrows(IllegalStateException.class, () -> { - new CdsProcessorGrpcClient(listener, props).close(); - }); + assertThrows(IllegalStateException.class, () -> new CdsProcessorGrpcClient(listener, props)); } @Test diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java index 4f0dbf730..8ac1c3f49 100644 --- a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java @@ -3,7 +3,7 @@ * controlloop * ================================================================================ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019, 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. @@ -47,7 +47,7 @@ public abstract class ControlLoopEvent implements Serializable { protected String policyName; protected String policyVersion; protected ControlLoopEventStatus closedLoopEventStatus; - protected Map<String, String> additionalEventParams; + private Map<String, String> additionalEventParams; /** * Construct an instance from an existing instance. diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java index b7622bde2..12900a2b4 100644 --- a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java @@ -3,7 +3,7 @@ * controlloop * ================================================================================ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019, 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. @@ -39,7 +39,7 @@ public class VirtualControlLoopEvent extends ControlLoopEvent { private static final long serialVersionUID = -5752405682246066226L; @SerializedName("AAI") - protected Map<String, String> aai = new HashMap<>(); + private Map<String, String> aai = new HashMap<>(); protected String payload; protected Instant closedLoopAlarmStart; protected Instant closedLoopAlarmEnd; diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java index 4770000c8..b14df21ef 100644 --- a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java @@ -37,7 +37,7 @@ class ControlLoopOperationTest { assertEquals(operation, (Object) operation); assertNotEquals(operation, (Object) ""); - assertNotEquals(operation, null); + assertNotNull(operation); assertNotEquals(0, operation.hashCode()); assertTrue(operation.toString().startsWith("ControlLoopOperation")); diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java index 23c9cea3b..5f21633e3 100644 --- a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java +++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java @@ -33,6 +33,6 @@ class HttpDeleteWithBodyTest { void testGetMethod() { HttpDeleteWithBody deleteWithBody = new HttpDeleteWithBody(NO_URI); assertEquals("DELETE", deleteWithBody.getMethod()); - assertEquals(deleteWithBody.getURI().toString(), NO_URI); + assertEquals(NO_URI, deleteWithBody.getURI().toString()); } }
\ No newline at end of file diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java index 28136e667..7a2177136 100644 --- a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java +++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java @@ -107,7 +107,7 @@ public class RestTest { * @throws Exception if there is a problem */ @AfterAll - public static void tearDown() throws Exception { + public static void tearDown() { HttpServletServerFactoryInstance.getServerFactory().destroy(); } diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java index 1885ed124..d852e8bda 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java @@ -80,7 +80,7 @@ class PciCommonHeaderTest { assertEquals(commonHeader, (Object) commonHeader); assertEquals(commonHeader, copiedPciCommonHeader); - assertNotEquals(commonHeader, null); + assertNotNull(commonHeader); assertNotEquals(commonHeader, (Object) "Hello"); PciCommonHeader clonedPciCommonHeader = new PciCommonHeader(commonHeader); diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java index 1334fcc42..00eb694e8 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java @@ -61,7 +61,7 @@ class PciRequestTest { assertEquals(request, (Object) request); assertEquals(request, copiedPciRequest); - assertNotEquals(request, null); + assertNotNull(request); assertNotEquals(request, (Object) "Hello"); request.setCommonHeader(null); diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java index 722c081d4..a4a3e45b0 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java @@ -54,7 +54,7 @@ class PciRequestWrapperTest { assertEquals(requestWrapper, (Object) requestWrapper); assertEquals(requestWrapper, copiedPciRequestWrapper); - assertNotEquals(requestWrapper, null); + assertNotNull(requestWrapper); assertNotEquals(requestWrapper, (Object) "Hello"); requestWrapper.setBody(null); diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java index 70480b1f7..d2e28fd68 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java @@ -67,8 +67,7 @@ class PciResponseTest { @Test void testEqualsObject() { PciResponse response = new PciResponse(); - assertEquals(response, response); - assertNotEquals(response, null); + assertNotNull(response); assertNotEquals(response, new Object()); PciResponse response2 = new PciResponse(); diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java index 1b0247336..a34d65c9d 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java @@ -50,17 +50,13 @@ class PciResponseWrapperTest { copiedPciResponseWrapper.setBody(responseWrapper.getBody()); assertEquals(responseWrapper, (Object) responseWrapper); - //assertEquals(responseWrapper, copiedPciResponseWrapper); - assertNotEquals(responseWrapper, null); + assertNotNull(responseWrapper); assertNotEquals(responseWrapper, (Object) "Hello"); responseWrapper.setBody(null); assertNotEquals(responseWrapper, copiedPciResponseWrapper); copiedPciResponseWrapper.setBody(null); - //assertEquals(responseWrapper, copiedPciResponseWrapper); responseWrapper.setBody(response); - //assertNotEquals(responseWrapper, copiedPciResponseWrapper); copiedPciResponseWrapper.setBody(response); - //assertEquals(responseWrapper, copiedPciResponseWrapper); } } diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java index e8f779edb..495fc133f 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java @@ -52,7 +52,7 @@ class PciStatusTest { assertEquals(status, (Object) status); assertEquals(status, copiedStatus); - assertNotEquals(status, null); + assertNotNull(status); assertNotEquals(status, (Object) "Hello"); status.setCode(-1); diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java index 8e915c3e9..3c11c0966 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java @@ -71,7 +71,7 @@ class PciWrapperTest { assertEquals(wrapper, (Object) wrapper); assertEquals(wrapper, copiedPciWrapper); - assertNotEquals(wrapper, null); + assertNotNull(wrapper); assertNotEquals(wrapper, (Object) "Hello"); checkField(VERSION_19, PciWrapper::setVersion); diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java index 98a828979..64fc4ac60 100644 --- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java @@ -115,7 +115,7 @@ class SoRequestDetailsTest { assertEquals(details, (Object) details); assertEquals(details, copiedDetails); - assertNotEquals(details, null); + assertNotNull(details); assertNotEquals(details, (Object) "Hello"); checkField(cloudConfiguration, SoRequestDetails::setCloudConfiguration); diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java index f33bfd72f..32298816e 100644 --- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java @@ -74,7 +74,7 @@ class SoResponseWrapperTest { assertEquals(responseWrapper, (Object) responseWrapper); assertEquals(responseWrapper, identicalResponseWrapper); - assertNotEquals(responseWrapper, null); + assertNotNull(responseWrapper); assertNotEquals(responseWrapper, (Object) "AString"); assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null)); diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/CdsSimulatorTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/CdsSimulatorTest.java index f3d5b3b96..d7cfd18bd 100644 --- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/CdsSimulatorTest.java +++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/CdsSimulatorTest.java @@ -127,7 +127,7 @@ class CdsSimulatorTest { } @Test - void testGetResponse() throws IOException, CoderException, ParseException { + void testGetResponse() throws IOException, CoderException { CdsSimulator cdsSimulator = new CdsSimulator(Util.LOCALHOST, sim.getPort()); String reqstr = ResourceUtils.getResourceAsString( "org/onap/policy/simulators/cds/cds.request.json"); diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java index 6ab41ddf8..583c371e3 100644 --- a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java +++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java @@ -3,7 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 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. @@ -22,7 +22,6 @@ package org.onap.policy.models.pap.concepts; import java.util.List; -import java.util.stream.Collectors; import lombok.ToString; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; @@ -41,7 +40,7 @@ public class PdpDeployPolicies { */ public List<ToscaConceptIdentifierOptVersion> getPolicies() { return policies == null ? null - : policies.stream().map(PapPolicyIdentifier::getGenericIdentifier).collect(Collectors.toList()); + : policies.stream().map(PapPolicyIdentifier::getGenericIdentifier).toList(); } /** @@ -51,6 +50,6 @@ public class PdpDeployPolicies { */ public void setPolicies(final List<ToscaConceptIdentifierOptVersion> policies) { this.policies = - policies == null ? null : policies.stream().map(PapPolicyIdentifier::new).collect(Collectors.toList()); + policies == null ? null : policies.stream().map(PapPolicyIdentifier::new).toList(); } } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java index 5373ace1d..d838a1bbc 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2021, 2024 Nordix Foundation. * Modifications Copyright (C) 2019-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.pdp.concepts; import java.util.List; -import java.util.stream.Collectors; import lombok.Builder; import lombok.Data; import lombok.NonNull; @@ -76,7 +75,7 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> { .filter(p -> filterOnPolicyTypeList(p, policyTypeList, matchPolicyTypesExactly)) .filter(p -> filterOnPolicyList(p, policyList, matchPoliciesExactly)) .filter(p -> filterOnPdpState(p, pdpState)) - .collect(Collectors.toList()); + .toList(); // @formatter:on } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java index 6729d7e88..6be00bc0f 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.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, 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. @@ -26,7 +26,6 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import lombok.Getter; import lombok.Setter; import lombok.ToString; @@ -88,7 +87,7 @@ public class PdpGroups { if (null == groups) { result.setResult(ValidationStatus.INVALID, "is null"); } else { - List<String> names = groups.stream().map(PdpGroup::getName).collect(Collectors.toList()); + List<String> names = groups.stream().map(PdpGroup::getName).toList(); if (groups.size() != new HashSet<>(names).size()) { result = new ObjectValidationResult(GROUPS_FIELD, names, ValidationStatus.INVALID, "duplicate group names"); diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java index b962e2b32..fed2bbb28 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 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. @@ -24,7 +24,6 @@ package org.onap.policy.models.pdp.concepts; import java.util.LinkedList; import java.util.List; -import java.util.stream.Collectors; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -88,8 +87,8 @@ public class PdpUpdate extends PdpMessage { this.description = source.description; this.pdpHeartbeatIntervalMs = source.pdpHeartbeatIntervalMs; this.policiesToBeDeployed = (source.policiesToBeDeployed == null ? null - : source.policiesToBeDeployed.stream().map(ToscaPolicy::new).collect(Collectors.toList())); + : source.policiesToBeDeployed.stream().map(ToscaPolicy::new).toList()); this.policiesToBeUndeployed = (source.policiesToBeUndeployed == null ? null - : source.policiesToBeUndeployed.stream().map(ToscaConceptIdentifier::new).collect(Collectors.toList())); + : source.policiesToBeUndeployed.stream().map(ToscaConceptIdentifier::new).toList()); } } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParameters.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParameters.java index 991e8231b..777149254 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParameters.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParameters.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications 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. @@ -21,6 +22,7 @@ package org.onap.policy.models.pdp.persistence.provider; import java.time.Instant; +import java.util.Collections; import java.util.Map; import lombok.Builder; import lombok.Getter; @@ -53,7 +55,7 @@ public class PdpFilterParameters implements PfFilterParametersIntfc { return filterMap; } else if (group == null) { - return null; + return Collections.emptyMap(); } else if (subGroup == null) { filterMap = Map.of("pdpGroupName", group); diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java index fe4632893..291248b45 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java @@ -33,7 +33,6 @@ import lombok.NonNull; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.dao.PfDao; @@ -293,7 +292,8 @@ public class PdpProvider { return Collections.emptyList(); } - List<JpaPdpPolicyStatus> jpas = objs.stream().map(JpaPdpPolicyStatus::new).collect(Collectors.toList()); + List<JpaPdpPolicyStatus> jpas = objs.stream().map(JpaPdpPolicyStatus::new) + .collect(Collectors.toList()); // validate the objects var result = new BeanValidationResult(fieldName, jpas); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParametersTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParametersTest.java index 998ccf6af..acf1f6053 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParametersTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParametersTest.java @@ -33,9 +33,9 @@ class PdpFilterParametersTest { @Test void testGetFilterMap() { - assertThat(PdpFilterParameters.builder().build().getFilterMap()).isNull(); + assertThat(PdpFilterParameters.builder().build().getFilterMap()).isEmpty(); - assertThat(PdpFilterParameters.builder().subGroup(SUBGROUP).build().getFilterMap()).isNull(); + assertThat(PdpFilterParameters.builder().subGroup(SUBGROUP).build().getFilterMap()).isEmpty(); PdpFilterParameters params = PdpFilterParameters.builder().group(GROUP).build(); Map<String, Object> map = params.getFilterMap(); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java index 85d68ae80..15ea29d94 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java @@ -38,7 +38,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.base.Validated; import org.onap.policy.models.dao.DaoParameters; @@ -66,7 +65,6 @@ import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider; */ class PdpProviderTest { private static final String PDP_GROUPS0_JSON = "testdata/PdpGroups0.json"; - private static final String PDP_TYPE_IS_NULL = "pdpType is marked .*ull but is null"; private static final String SUBGROUP_IS_NULL = "pdpSubGroup is marked .*ull but is null"; private static final String GROUP_IS_NULL = "pdpGroupName is marked .*ull but is null"; private static final String DAO_IS_NULL = "dao is marked .*ull but is null"; @@ -594,7 +592,7 @@ class PdpProviderTest { List<PdpPolicyStatus> records = prov.getGroupPolicyStatus(pfDao, GROUP_A); assertThat(records).hasSize(2); - Collections.sort(records, (rec1, rec2) -> rec1.getPdpId().compareTo(rec2.getPdpId())); + records.sort((rec1, rec2) -> rec1.getPdpId().compareTo(rec2.getPdpId())); assertThat(records.get(0)).isEqualTo(idx); assertThat(records.get(1)).isEqualTo(idy); diff --git a/models-provider/pom.xml b/models-provider/pom.xml index cc692aabb..35e201476 100644 --- a/models-provider/pom.xml +++ b/models-provider/pom.xml @@ -91,5 +91,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-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java index 5fa6e809c..6d7a7075f 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java @@ -23,8 +23,13 @@ package org.onap.policy.models.provider; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import jakarta.persistence.EntityManager; +import lombok.Getter; +import lombok.Setter; import lombok.ToString; import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.onap.policy.models.dao.impl.ProxyDao; /** * Test the {@link PolicyModelsProviderFactory} class. @@ -34,6 +39,11 @@ import org.junit.jupiter.api.Test; @ToString class PolicyModelsProviderFactoryTest { + @Getter + @Setter + @Mock + private EntityManager mgr; + @Test void testFactory() { PolicyModelsProviderFactory factory = new PolicyModelsProviderFactory(); @@ -70,5 +80,26 @@ class PolicyModelsProviderFactoryTest { }).hasMessage("could not create an instance of PolicyModelsProvider " + "\"org.onap.policy.models.provider.impl.DummyBadProviderImpl\""); // @formatter:on + + assertThatThrownBy(() -> { + PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters(); + ProxyDao dao = new ProxyDao(mgr); + factory.createPolicyModelsProvider(dao, pars); + }).hasMessageContaining("could not create an instance of PolicyModelsProvider"); + + assertThatThrownBy(() -> { + PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters(); + pars.setImplementation(null); + ProxyDao dao = new ProxyDao(mgr); + factory.createPolicyModelsProvider(dao, pars); + }).hasMessage("could not find implementation of the \"PolicyModelsProvider\" interface \"null\""); + + assertThatThrownBy(() -> { + PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters(); + pars.setImplementation("java.lang.String"); + ProxyDao dao = new ProxyDao(mgr); + factory.createPolicyModelsProvider(dao, pars); + }).hasMessage( + "the class \"java.lang.String\" is not an implementation of the \"PolicyModelsProvider\" interface"); } } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/AbstractModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/AbstractModelsProviderTest.java new file mode 100644 index 000000000..d6aefdab0 --- /dev/null +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/AbstractModelsProviderTest.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Provider Models + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.provider.impl; + +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; + +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.PfModelException; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; + +class AbstractModelsProviderTest { + + @Mock + private PolicyModelsProviderParameters mockParameters; + + private AbstractModelsProvider abstractModelsProviderUnderTest; + + private AutoCloseable mockitoCloseable; + + @BeforeEach + void setUp() { + mockitoCloseable = openMocks(this); + abstractModelsProviderUnderTest = new AbstractModelsProvider(mockParameters) {}; + } + + @AfterEach + void tearDown() throws Exception { + mockitoCloseable.close(); + } + + @Test + void testInitError() { + when(mockParameters.getDatabaseUrl()).thenReturn("invalidParameter"); + when(mockParameters.getDatabaseDriver()).thenReturn("invalidParameter"); + when(mockParameters.getDatabaseUser()).thenReturn("invalidParameter"); + when(mockParameters.getDatabasePassword()).thenReturn("invalidParameter"); + when(mockParameters.getPersistenceUnit()).thenReturn("invalidParameter"); + + assertThrows(PfModelException.class, () -> abstractModelsProviderUnderTest.init()); + } + + @Test + void testClose() { + when(mockParameters.getDatabaseUrl()).thenReturn("result"); + when(mockParameters.getPersistenceUnit()).thenReturn("result"); + + assertThatCode(abstractModelsProviderUnderTest::close).doesNotThrowAnyException(); + } +} diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java index 16d4ee4ac..0db2e0d3d 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java @@ -22,6 +22,7 @@ package org.onap.policy.models.provider.impl; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -44,6 +45,7 @@ import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; @@ -488,6 +490,53 @@ class DatabasePolicyModelsProviderTest { databaseProvider.deleteToscaNodeTemplate("invalidName", "1.0.1"); }).hasMessage("node template invalidName:1.0.1 not found"); + assertThatCode(() -> databaseProvider.getServiceTemplateList(NAME, VERSION_100)) + .doesNotThrowAnyException(); + + assertThatCode(() -> databaseProvider.getFilteredServiceTemplateList(ToscaEntityFilter + .<ToscaServiceTemplate>builder().build())) + .doesNotThrowAnyException(); + + + } + + @Test + void testToscaTemplateMethods() throws PfModelException { + databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); + + assertThatThrownBy(() -> databaseProvider.createServiceTemplate(new ToscaServiceTemplate())) + .hasMessageContaining("\"service template\" INVALID"); + + assertThatThrownBy(() -> databaseProvider.updateServiceTemplate(new ToscaServiceTemplate())) + .hasMessageContaining("\"service template\" INVALID"); + + assertThatThrownBy(() -> databaseProvider.deleteServiceTemplate(NAME, VERSION_100)) + .hasMessageContaining("service template not found in database"); + + assertThatThrownBy(() -> databaseProvider.getToscaNodeTemplate(NAME, VERSION_100)) + .hasMessageContaining("service template not found in database"); + + assertNotNull(databaseProvider.getAllPolicyStatus()); + + assertNotNull(databaseProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion())); + + assertNotNull(databaseProvider.getGroupPolicyStatus("testGroup")); + + ToscaServiceTemplate serviceTemplate = makeNodeTemplate(); + databaseProvider.createToscaNodeTemplates(serviceTemplate); + + assertThatCode(() -> databaseProvider.createServiceTemplate(new ToscaServiceTemplate())) + .doesNotThrowAnyException(); + assertThatCode(() -> databaseProvider.getToscaNodeTemplate(serviceTemplate.getName(), + serviceTemplate.getVersion())).doesNotThrowAnyException(); + + assertThatCode(() -> databaseProvider.updateServiceTemplate(new ToscaServiceTemplate())) + .doesNotThrowAnyException(); + assertThatCode(() -> databaseProvider.deleteServiceTemplate(serviceTemplate.getName(), + serviceTemplate.getVersion())).doesNotThrowAnyException(); + + + databaseProvider.close(); } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DbPolicyModelsProviderImplTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DbPolicyModelsProviderImplTest.java new file mode 100644 index 000000000..d14ed8f2e --- /dev/null +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DbPolicyModelsProviderImplTest.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Provider Models + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.provider.impl; + +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.mockito.MockitoAnnotations.openMocks; + +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.dao.impl.ProxyDao; + +class DbPolicyModelsProviderImplTest { + + @Mock + private ProxyDao mockPfDao; + + private DbPolicyModelsProviderImpl dbPolicyModelsProviderImplUnderTest; + + private AutoCloseable mockitoCloseable; + + @BeforeEach + void setUp() { + mockitoCloseable = openMocks(this); + dbPolicyModelsProviderImplUnderTest = new DbPolicyModelsProviderImpl(mockPfDao); + } + + @AfterEach + void tearDown() throws Exception { + mockitoCloseable.close(); + } + + @Test + void testInit() { + assertThatCode(() -> dbPolicyModelsProviderImplUnderTest.init()) + .doesNotThrowAnyException(); + } + + @Test + void testClose() { + assertThatCode(() -> dbPolicyModelsProviderImplUnderTest.close()) + .doesNotThrowAnyException(); + } +} diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java index 227f1866f..e9aedad99 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java @@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThatCode; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import java.net.URISyntaxException; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorConstants.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorConstants.java index ca6562368..bd301740a 100644 --- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorConstants.java +++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorConstants.java @@ -34,7 +34,7 @@ import org.junit.jupiter.api.Test; */ class TestPdpSimulatorConstants { @Test - void test() throws Exception { + void test() { // verify that constructor does not throw an exception assertThatCode(() -> { Constructor<PdpSimulatorConstants> c = PdpSimulatorConstants.class.getDeclaredConstructor(); diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java index ce32fd407..dd82c84b2 100644 --- a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java +++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java @@ -52,6 +52,8 @@ public class Main extends ServiceManagerContainer { private static final String CANNOT_CONNECT = "cannot connect to port "; + private static final String FALSE_STRING = "false"; + @Getter(AccessLevel.PROTECTED) private static Main instance; @@ -185,9 +187,9 @@ public class Main extends ServiceManagerContainer { Boolean.toString(params.isHttps())); props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX, params.getProviderClass()); - props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "false"); - props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX, "false"); - props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SNI_HOST_CHECK_SUFFIX, "false"); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, FALSE_STRING); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX, FALSE_STRING); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SNI_HOST_CHECK_SUFFIX, FALSE_STRING); props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER, String.join(",", 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()); |