From fe80c60ca766af048d7eb6f9bc073d40ee033046 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Wed, 21 Jul 2021 10:58:13 -0400 Subject: Add attribute return example into Tutorial Used the tutorial to demonstrate returning of attributes back into the Decision response. Needed to update the docker compose for both tutorials to ensure they are using the master branch versions of api and pap. Issue-ID: POLICY-2865 Change-Id: Ia568dfae27d659d940217ddf8d9295dd8409f0e3 Signed-off-by: Pamela Dragosh --- .../tutorial/tutorial/TutorialApplicationTest.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'tutorials/tutorial-xacml-application/src/test') diff --git a/tutorials/tutorial-xacml-application/src/test/java/org/onap/policy/tutorial/tutorial/TutorialApplicationTest.java b/tutorials/tutorial-xacml-application/src/test/java/org/onap/policy/tutorial/tutorial/TutorialApplicationTest.java index 4fda0983..66001260 100644 --- a/tutorials/tutorial-xacml-application/src/test/java/org/onap/policy/tutorial/tutorial/TutorialApplicationTest.java +++ b/tutorials/tutorial-xacml-application/src/test/java/org/onap/policy/tutorial/tutorial/TutorialApplicationTest.java @@ -18,9 +18,11 @@ package org.onap.policy.tutorial.tutorial; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.XACML3; import java.io.File; import java.io.IOException; import java.util.Properties; @@ -101,19 +103,31 @@ public class TutorialApplicationTest { TextFileUtils .getTextFileAsString("src/test/resources/tutorial-decision-request.json"), DecisionRequest.class); + LOGGER.info("{}", gson.encode(decisionRequest, true)); // // Test a decision - should start with a permit // Pair decision = service.makeDecision(decisionRequest, null); - LOGGER.info(decision.getLeft().toString()); + LOGGER.info("{}", gson.encode(decision.getLeft(), true)); assertEquals("Permit", decision.getLeft().getStatus()); // + // Check that there are attributes + // + assertThat(decision.getLeft().getAttributes()).isNotNull().hasSize(1) + .containsKey(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE.stringValue()); + // // This should be a deny // decisionRequest.getResource().put("user", "audit"); + LOGGER.info("{}", gson.encode(decisionRequest, true)); decision = service.makeDecision(decisionRequest, null); - LOGGER.info(decision.getLeft().toString()); + LOGGER.info("{}", gson.encode(decision.getLeft(), true)); assertEquals("Deny", decision.getLeft().getStatus()); + // + // Check that there are attributes + // + assertThat(decision.getLeft().getAttributes()).isNotNull().hasSize(1) + .containsKey(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE.stringValue()); } } -- cgit