From fb35c3e3c80bd17308abfd34964e854ad9975342 Mon Sep 17 00:00:00 2001 From: sebdet Date: Tue, 9 Apr 2019 13:09:37 +0200 Subject: Fix guard payload Fix guard payload nullpointerException when guard list is empty or null Issue-ID: CLAMP-303 Change-Id: I6f714a877036cbc531dd35505202dde227cc224a Signed-off-by: sebdet --- .../microservice/OperationalPolicyPayloadTest.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java index 739708ca..76e29c31 100644 --- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java +++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java @@ -47,18 +47,29 @@ public class OperationalPolicyPayloadTest { .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml")); } + @Test + public void testGuardPolicyEmptyPayloadConstruction() throws IOException { + JsonObject jsonConfig = new GsonBuilder().create().fromJson( + ResourceFileUtil.getResourceAsString("tosca/operational-policy-no-guard-properties.json"), + JsonObject.class); + OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig); + Map guardsMap = policy.createGuardPolicyPayloads(); + assertThat(guardsMap).isEmpty(); + assertThat(guardsMap.entrySet()).isEmpty(); + } + @Test public void testGuardPolicyPayloadConstruction() throws IOException { JsonObject jsonConfig = new GsonBuilder().create().fromJson( ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class); OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig); - Map guardsList = policy.createGuardPolicyPayloads(); + Map guardsMap = policy.createGuardPolicyPayloads(); JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/guard1-policy-payload.json"), - guardsList.get("guard1"), false); + guardsMap.get("guard1"), false); JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/guard2-policy-payload.json"), - guardsList.get("guard2"), false); + guardsMap.get("guard2"), false); } } -- cgit 1.2.3-korg