summaryrefslogtreecommitdiffstats
path: root/applications/common
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2020-10-02 09:13:13 -0400
committerPamela Dragosh <pdragosh@research.att.com>2020-10-02 09:13:18 -0400
commit7ae3ab19d0556a0308f0d293d4dd2e58dd3d3929 (patch)
tree16e26e30d7a6e734ec34108d24727eb8afc0c9dc /applications/common
parent57e705469481f446aeada858c8eb411c5cccebc8 (diff)
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 <pdragosh@research.att.com>
Diffstat (limited to 'applications/common')
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java12
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java5
2 files changed, 12 insertions, 5 deletions
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<String> actions = Collections.emptyList();
+ protected List<ToscaPolicyTypeIdentifier> 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<String> actionDecisionsSupported() {
- return Collections.emptyList();
+ return actions;
}
@Override
@@ -105,7 +111,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
@Override
public List<ToscaPolicyTypeIdentifier> 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