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 /models-decisions | |
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>
Diffstat (limited to 'models-decisions')
5 files changed, 206 insertions, 0 deletions
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); + } +} |