diff options
author | Jim Hahn <jrh3@att.com> | 2020-06-29 14:13:14 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-06-29 14:58:33 -0400 |
commit | 05506483dff28c491522beeaaea0f6904077e3ed (patch) | |
tree | 9146aba8b5f48b693d02ac1846b98e617931bc93 | |
parent | f92147f681bac8292021028d88c913ff977dd594 (diff) |
Fix issues in xacml-pdp for new sonar rules
Addressed issues reported due to updates to the sonar rules:
- invoke only one method in a junit lambda
- complete the assertion
- use assertThat().exists(), canRead(), etc.
Issue-ID: POLICY-2681
Change-Id: I2935f4d0295244ab3b11a57a3bc401c64b695fd1
Signed-off-by: Jim Hahn <jrh3@att.com>
11 files changed, 40 insertions, 44 deletions
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtilsTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtilsTest.java index fbfde1a4..d3aba91f 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtilsTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtilsTest.java @@ -207,12 +207,12 @@ public class XacmlPolicyUtilsTest { @Test public void testUncommonConditions() throws IOException { - File fileTemp = policyFolder.newFile(); + Path fileTemp = policyFolder.newFile().toPath(); assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> - XacmlPolicyUtils.writePolicyFile(fileTemp.toPath(), new String("not a policy")) + XacmlPolicyUtils.writePolicyFile(fileTemp, "not a policy") ); assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> - XacmlPolicyUtils.constructUniquePolicyFilename(new String("not a policy"), + XacmlPolicyUtils.constructUniquePolicyFilename("not a policy", policyFolder.getRoot().toPath()) ); } @@ -313,7 +313,7 @@ public class XacmlPolicyUtilsTest { // Copy to this folder // File copyFolder = policyFolder.newFolder("copy"); - assertThat(copyFolder.exists()).isTrue(); + assertThat(copyFolder).exists(); // // Mock up a properties object // @@ -332,10 +332,10 @@ public class XacmlPolicyUtilsTest { File propertiesFile = XacmlPolicyUtils.copyXacmlPropertiesContents( fileProperties.toAbsolutePath().toString(), mockProperties, myCreator); - assertThat(propertiesFile.canRead()).isTrue(); + assertThat(propertiesFile).canRead(); assertThat(Path.of(copyFolder.getAbsolutePath(), - rootPath.getFileName().toString()).toFile().canRead()).isTrue(); + rootPath.getFileName().toString()).toFile()).canRead(); assertThat(Path.of(copyFolder.getAbsolutePath(), - path1.getFileName().toString()).toFile().canRead()).isTrue(); + path1.getFileName().toString()).toFile()).canRead(); } } diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyTypeTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyTypeTest.java index cd28bddc..9b489a67 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyTypeTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyTypeTest.java @@ -187,10 +187,10 @@ public class MatchablePolicyTypeTest implements MatchableCallback { schema.setType("string"); property.setEntrySchema(schema); MatchablePropertyTypeMap mapValue = new MatchablePropertyTypeMap(property); - assertThat(mapValue.validate(new String("foo"))).hasSize(0); + assertThat(mapValue.validate("foo")).isEmpty(); MatchablePropertyTypeList listValue = new MatchablePropertyTypeList(property); - assertThat(listValue.validate(new String("foo"))).hasSize(0); + assertThat(listValue.validate("foo")).isEmpty(); } @Test diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java index 8e692583..b8a1d18a 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java @@ -162,7 +162,7 @@ public class StdBaseTranslatorTest { assertThat(rule.getObligationExpressions().getObligationExpression().size()).isEqualTo(1); assertThat(rule.getObligationExpressions().getObligationExpression().get(0) - .getAttributeAssignmentExpression().size()).isEqualTo(0); + .getAttributeAssignmentExpression()).isEmpty(); // // Should not throw an exception @@ -184,7 +184,7 @@ public class StdBaseTranslatorTest { assertNotNull(decision); assertThat(decision.getPolicies()).isNotNull(); - assertThat(decision.getPolicies().size()).isEqualTo(0); + assertThat(decision.getPolicies()).isEmpty(); } @Test @@ -218,7 +218,7 @@ public class StdBaseTranslatorTest { assertNotNull(decision); assertThat(decision.getPolicies()).isNotNull(); - assertThat(decision.getPolicies().size()).isEqualTo(0); + assertThat(decision.getPolicies()).isEmpty(); Obligation badObligation = TestUtilsCommon.createXacmlObligation( ToscaDictionary.ID_OBLIGATION_REST_BODY.stringValue(), diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java index 42c13d9e..9f0e0ac9 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java @@ -116,7 +116,7 @@ public class StdCombinedPolicyResultsTranslatorTest { assertNotNull(decision); assertThat(decision.getPolicies()).isNotNull(); - assertThat(decision.getPolicies().size()).isEqualTo(1); + assertThat(decision.getPolicies()).hasSize(1); } @Test diff --git a/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java b/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java index bdb8a343..fd6711d4 100644 --- a/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java +++ b/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java @@ -172,7 +172,7 @@ public class MonitoringPdpApplicationTest { LOGGER.info("Decision {}", decision); assertThat(decision.getKey()).isNotNull(); - assertThat(decision.getKey().getPolicies()).hasSize(0); + assertThat(decision.getKey().getPolicies()).isEmpty(); // // Test the branch for query params, and we have no policy anyway // @@ -181,7 +181,7 @@ public class MonitoringPdpApplicationTest { LOGGER.info("Decision {}", decision); assertThat(decision.getKey()).isNotNull(); - assertThat(decision.getKey().getPolicies()).hasSize(0); + assertThat(decision.getKey().getPolicies()).isEmpty(); // // Test the branch for query params, and we have no policy anyway // @@ -190,7 +190,7 @@ public class MonitoringPdpApplicationTest { LOGGER.info("Decision {}", decision); assertThat(decision.getKey()).isNotNull(); - assertThat(decision.getKey().getPolicies()).hasSize(0); + assertThat(decision.getKey().getPolicies()).isEmpty(); } @SuppressWarnings("unchecked") @@ -244,8 +244,7 @@ public class MonitoringPdpApplicationTest { assertThat(decision.getKey()).isNotNull(); assertThat(decision.getKey().getPolicies()).hasSize(1); jsonPolicy = (Map<String, Object>) decision.getKey().getPolicies().get("onap.scaleout.tca"); - assertThat(jsonPolicy).isNotNull(); - assertThat(jsonPolicy).doesNotContainKey("properties"); + assertThat(jsonPolicy).isNotNull().doesNotContainKey("properties"); // // Don't Ask for abbreviated results // @@ -290,7 +289,7 @@ public class MonitoringPdpApplicationTest { LOGGER.info("Decision {}", decision.getKey()); assertThat(decision.getKey()).isNotNull(); - assertThat(decision.getKey().getPolicies()).hasSize(0); + assertThat(decision.getKey().getPolicies()).isEmpty(); } } diff --git a/applications/naming/src/test/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplicationTest.java b/applications/naming/src/test/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplicationTest.java index 0077d0b9..85b182cd 100644 --- a/applications/naming/src/test/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplicationTest.java +++ b/applications/naming/src/test/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplicationTest.java @@ -176,7 +176,7 @@ public class NamingPdpApplicationTest { LOGGER.info("Decision {}", decision.getKey()); assertThat(decision.getKey()).isNotNull(); - assertThat(decision.getKey().getPolicies().size()).isEqualTo(0); + assertThat(decision.getKey().getPolicies()).isEmpty(); } @Test @@ -194,7 +194,7 @@ public class NamingPdpApplicationTest { // There is no default policy // assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(0); + assertThat(response.getPolicies()).isEmpty(); // // Ask for VNF // @@ -204,7 +204,7 @@ public class NamingPdpApplicationTest { // response = makeDecision(); assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(1); + assertThat(response.getPolicies()).hasSize(1); // // Validate it // @@ -227,7 +227,7 @@ public class NamingPdpApplicationTest { LOGGER.info("Decision Returned Policy {}", entrySet.getKey()); assertThat(entrySet.getValue()).isInstanceOf(Map.class); Map<String, Object> policyContents = (Map<String, Object>) entrySet.getValue(); - assertThat(policyContents.containsKey("properties")).isTrue(); + assertThat(policyContents).containsKey("properties"); assertThat(policyContents.get("properties")).isInstanceOf(Map.class); Map<String, Object> policyProperties = (Map<String, Object>) policyContents.get("properties"); diff --git a/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java b/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java index a11c1b14..f434e80f 100644 --- a/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java +++ b/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java @@ -220,7 +220,7 @@ public class NativePdpApplicationTest { assertThat(response).isNotNull(); Decision decision = response.getResults().iterator().next().getDecision(); assertThat(decision).isNotNull(); - assertThat(decision.toString()).isEqualTo(expected); + assertThat(decision).hasToString(expected); LOGGER.info("Xacml response we received {}", DOMResponse.toString(response)); } }
\ No newline at end of file diff --git a/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java b/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java index 8886af21..631a359c 100644 --- a/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java +++ b/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java @@ -208,7 +208,7 @@ public class OptimizationPdpApplicationTest { LOGGER.info("Decision {}", decision.getKey()); assertThat(decision.getKey()).isNotNull(); - assertThat(decision.getKey().getPolicies().size()).isEqualTo(0); + assertThat(decision.getKey().getPolicies()).isEmpty(); } /** @@ -223,15 +223,14 @@ public class OptimizationPdpApplicationTest { // List<ToscaPolicy> loadedPolicies = TestUtils.loadPolicies("src/test/resources/test-optimization-policies.yaml", service); - assertThat(loadedPolicies).isNotNull(); - assertThat(loadedPolicies).hasSize(14); + assertThat(loadedPolicies).isNotNull().hasSize(14); // // Ask for a decision for available default policies // DecisionResponse response = makeDecision(); assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(2); + assertThat(response.getPolicies()).hasSize(2); // // Validate it // @@ -255,10 +254,10 @@ public class OptimizationPdpApplicationTest { DecisionResponse response = makeDecision(); assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(1); + assertThat(response.getPolicies()).hasSize(1); response.getPolicies().forEach((key, value) -> { - assertThat(((Map<String, Object>) value).get("type")) - .isEqualTo(("onap.policies.optimization.resource.HpaPolicy")); + assertThat(((Map<String, Object>) value)).containsEntry("type", + "onap.policies.optimization.resource.HpaPolicy"); }); // // Validate it @@ -285,7 +284,7 @@ public class OptimizationPdpApplicationTest { // DecisionResponse response = makeDecision(); assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(2); + assertThat(response.getPolicies()).hasSize(2); // // Validate it // @@ -308,7 +307,7 @@ public class OptimizationPdpApplicationTest { DecisionResponse response = makeDecision(); assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(3); + assertThat(response.getPolicies()).hasSize(3); // // Validate it // @@ -331,7 +330,7 @@ public class OptimizationPdpApplicationTest { DecisionResponse response = makeDecision(); assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(6); + assertThat(response.getPolicies()).hasSize(6); // // Validate it // @@ -405,7 +404,7 @@ public class OptimizationPdpApplicationTest { DecisionResponse response = makeDecision(); assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(7); + assertThat(response.getPolicies()).hasSize(7); // // Validate it // @@ -428,7 +427,7 @@ public class OptimizationPdpApplicationTest { DecisionResponse response = makeDecision(); assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(1); + assertThat(response.getPolicies()).hasSize(1); // // Validate it // @@ -452,7 +451,7 @@ public class OptimizationPdpApplicationTest { DecisionResponse response = makeDecision(); assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(2); + assertThat(response.getPolicies()).hasSize(2); // // Validate it // @@ -516,7 +515,7 @@ public class OptimizationPdpApplicationTest { LOGGER.info("Decision Returned Policy {}", entrySet.getKey()); assertThat(entrySet.getValue()).isInstanceOf(Map.class); Map<String, Object> policyContents = (Map<String, Object>) entrySet.getValue(); - assertThat(policyContents.containsKey("properties")).isTrue(); + assertThat(policyContents).containsKey("properties"); assertThat(policyContents.get("properties")).isInstanceOf(Map.class); Map<String, Object> policyProperties = (Map<String, Object>) policyContents.get("properties"); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java index 243c9eab..2a85579c 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java @@ -95,7 +95,7 @@ public class XacmlPdpApplicationManagerTest { // We need at least 1 policies // assertThat(completedJtst).isNotNull(); - assertThat(completedJtst.getToscaTopologyTemplate().getPolicies().size()).isGreaterThan(0); + assertThat(completedJtst.getToscaTopologyTemplate().getPolicies().size()).isPositive(); // // Copy test directory over of the application directories // @@ -141,7 +141,7 @@ public class XacmlPdpApplicationManagerTest { // Test the basics from the startup // assertThat(manager).isNotNull(); - assertThat(manager.getPolicyCount()).isEqualTo(0); + assertThat(manager.getPolicyCount()).isZero(); assertThat(manager.getPolicyTypeCount()).isEqualTo(19); assertThat(manager.getToscaPolicies()).isEmpty(); assertThat(manager.getToscaPolicyIdentifiers()).isEmpty(); @@ -172,11 +172,11 @@ public class XacmlPdpApplicationManagerTest { final ToscaPolicy policyFinal = policy; assertThatCode(() -> { manager.removeUndeployedPolicy(policyFinal); - assertThat(manager.getPolicyCount()).isEqualTo(0); + assertThat(manager.getPolicyCount()).isZero(); manager.loadDeployedPolicy(policyFinal); assertThat(manager.getPolicyCount()).isEqualTo(1); manager.removeUndeployedPolicy(policyFinal); - assertThat(manager.getPolicyCount()).isEqualTo(0); + assertThat(manager.getPolicyCount()).isZero(); }).doesNotThrowAnyException(); // // try loading something unsupported diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/serialization/TestXacmlJsonMessageBodyHandler.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/serialization/TestXacmlJsonMessageBodyHandler.java index 0b77650c..1dbbff9d 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/rest/serialization/TestXacmlJsonMessageBodyHandler.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/serialization/TestXacmlJsonMessageBodyHandler.java @@ -22,7 +22,6 @@ package org.onap.policy.pdpx.main.rest.serialization; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import com.att.research.xacml.api.Request; import com.att.research.xacml.api.RequestAttributes; diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/serialization/TestXacmlXmlMessageBodyHandler.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/serialization/TestXacmlXmlMessageBodyHandler.java index ba2bd780..f2e4f4f6 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/rest/serialization/TestXacmlXmlMessageBodyHandler.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/serialization/TestXacmlXmlMessageBodyHandler.java @@ -22,7 +22,6 @@ package org.onap.policy.pdpx.main.rest.serialization; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import com.att.research.xacml.api.Request; import com.att.research.xacml.api.RequestAttributes; |