From 7ae3ab19d0556a0308f0d293d4dd2e58dd3d3929 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Fri, 2 Oct 2020 09:13:13 -0400 Subject: Remove duplicated code Initially, just moving the applicationName and actions as protected fields got rid of the sonar issue. I included also the supportedPolicyTypes also. But that triggered another sonar duplicate code, so I had to rename a few private fields to rid that. Seems like a very sensitive sonar detection that results in kludgy code. Issue-ID: POLICY-2681 Change-Id: Ie79a95786cdb80381cbce4b182e9e66a2776e0dd Signed-off-by: Pamela Dragosh --- .../common/std/StdXacmlApplicationServiceProvider.java | 12 +++++++++--- .../common/std/StdXacmlApplicationServiceProviderTest.java | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'applications/common/src') diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java index ba562b83..465e3f58 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -55,6 +56,11 @@ import org.slf4j.LoggerFactory; public abstract class StdXacmlApplicationServiceProvider implements XacmlApplicationServiceProvider { private static final Logger LOGGER = LoggerFactory.getLogger(StdXacmlApplicationServiceProvider.class); + + protected String applicationName = "Please Override"; + protected List actions = Collections.emptyList(); + protected List supportedPolicyTypes = new ArrayList<>(); + private Path pathForData = null; @Getter private RestServerParameters policyApiParameters; @@ -68,12 +74,12 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica @Override public String applicationName() { - return "Please Override"; + return applicationName; } @Override public List actionDecisionsSupported() { - return Collections.emptyList(); + return actions; } @Override @@ -105,7 +111,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica @Override public List supportedPolicyTypes() { - throw new UnsupportedOperationException("Please override and implement supportedPolicyTypes"); + return supportedPolicyTypes; } @Override diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java index c95d3ca5..0552ff30 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java @@ -20,6 +20,7 @@ package org.onap.policy.pdp.xacml.application.common.std; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -27,7 +28,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -181,7 +182,7 @@ public class StdXacmlApplicationServiceProviderTest { @Test public void testSupportedPolicyTypes() { - assertThatThrownBy(() -> prov.supportedPolicyTypes()).isInstanceOf(UnsupportedOperationException.class); + assertThat(prov.supportedPolicyTypes()).isEmpty(); } @Test -- cgit 1.2.3-korg