From 70736cfbf6ad1a068f8ee53adddd4faa3b6fa8a8 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Fri, 12 Apr 2019 11:03:44 -0400 Subject: Add statistics and sonar cleanup and blacklist * Adding in the statistics for decisions and errors. * Cleaned up sonar issues and added code coverage. * Sped up JUnit tests * Fix JUnit issues with not finding application path * Fix TestDecision not finding persistence.xml * Fix for lingering statistics from previous runs. That needs to be addressed at a later time. * Changed persistence to use properties for configuration of database rather than hard coding the persistence.xml * Fix for Josh's comment to use else-if * Changed to use apache Pair * Added blacklist guard policy Issue-ID: POLICY-1440 Change-Id: I56af8c3dcc82463f7381f1eaea7f1440b76200bd Signed-off-by: Pamela Dragosh --- .../monitoring/MonitoringPdpApplicationTest.java | 79 +++++----------------- 1 file changed, 16 insertions(+), 63 deletions(-) (limited to 'applications/monitoring/src/test/java') 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 9b26df16..04c9d20b 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 @@ -24,6 +24,8 @@ package org.onap.policy.xacml.pdp.application.monitoring; import static org.assertj.core.api.Assertions.assertThat; +import com.att.research.xacml.api.Response; + import java.io.File; import java.io.IOException; import java.util.Iterator; @@ -31,6 +33,7 @@ import java.util.List; import java.util.Properties; import java.util.ServiceLoader; +import org.apache.commons.lang3.tuple.Pair; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.FixMethodOrder; @@ -146,11 +149,11 @@ public class MonitoringPdpApplicationTest { // // Ask for a decision // - DecisionResponse response = service.makeDecision(requestSinglePolicy); - LOGGER.info("Decision {}", response); + Pair decision = service.makeDecision(requestSinglePolicy); + LOGGER.info("Decision {}", decision); - assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(0); + assertThat(decision.getKey()).isNotNull(); + assertThat(decision.getKey().getPolicies().size()).isEqualTo(0); } @Test @@ -168,15 +171,15 @@ public class MonitoringPdpApplicationTest { // // Ask for a decision // - DecisionResponse response = service.makeDecision(requestSinglePolicy); - LOGGER.info("Decision {}", response); + Pair decision = service.makeDecision(requestSinglePolicy); + LOGGER.info("Decision {}", decision); - assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(1); + assertThat(decision.getKey()).isNotNull(); + assertThat(decision.getKey().getPolicies().size()).isEqualTo(1); // // Dump it out as Json // - LOGGER.info(gson.encode(response)); + LOGGER.info(gson.encode(decision.getKey())); LOGGER.info("Now testing unloading of policy"); // // Now unload it @@ -187,61 +190,11 @@ public class MonitoringPdpApplicationTest { // // Ask for a decision // - response = service.makeDecision(requestSinglePolicy); - LOGGER.info("Decision {}", response); - - assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(0); - } - - @Test - public void test4BadPolicies() { - /* - * - * THESE TEST SHOULD BE MOVED INTO THE API PROJECT - * - // - // No need for service, just test some of the methods - // for bad policies - // - MonitoringPdpApplication onapPdpEngine = new MonitoringPdpApplication(); - - assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> { - try (InputStream is = - new FileInputStream("src/test/resources/test.monitoring.policy.missingmetadata.yaml")) { - onapPdpEngine.convertPolicies(is); - } - }).withMessageContaining("missing metadata section"); - - assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> { - try (InputStream is = - new FileInputStream("src/test/resources/test.monitoring.policy.missingtype.yaml")) { - onapPdpEngine.convertPolicies(is); - } - }).withMessageContaining("missing type value"); - - assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> { - try (InputStream is = - new FileInputStream("src/test/resources/test.monitoring.policy.missingversion.yaml")) { - onapPdpEngine.convertPolicies(is); - } - }).withMessageContaining("missing version value"); - - assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> { - try (InputStream is = - new FileInputStream("src/test/resources/test.monitoring.policy.badmetadata.1.yaml")) { - onapPdpEngine.convertPolicies(is); - } - }).withMessageContaining("missing metadata policy-version"); - - assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> { - try (InputStream is = - new FileInputStream("src/test/resources/test.monitoring.policy.badmetadata.2.yaml")) { - onapPdpEngine.convertPolicies(is); - } - }).withMessageContaining("missing metadata policy-id"); + decision = service.makeDecision(requestSinglePolicy); + LOGGER.info("Decision {}", decision.getKey()); - */ + assertThat(decision.getKey()).isNotNull(); + assertThat(decision.getKey().getPolicies().size()).isEqualTo(0); } } -- cgit 1.2.3-korg