From 2a7cbf33a8b53bb83d43bf1adca7e6a8658cb262 Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Tue, 21 Jan 2020 17:07:50 +0000 Subject: Handling supported policy type during PdpGroup Update Change-Id: I469125c232af9d78a55c3dfa71cb701cb3864015 Issue-ID: POLICY-2023 Signed-off-by: a.sreekumar --- .../policy/models/pdp/concepts/PdpGroupTest.java | 42 ++++++++++++++++++++-- .../models/pdp/concepts/PdpSubGroupTest.java | 39 ++++++++++++++++++-- 2 files changed, 75 insertions(+), 6 deletions(-) (limited to 'models-pdp/src/test/java/org/onap') diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java index a282b7dba..4f11079c2 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java @@ -3,7 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -120,6 +120,42 @@ public class PdpGroupTest { assertEquals(1, mapList.get(0).size()); } + @Test + public void testValidatePapRest_GroupUpdateFlow() { + PdpGroup group = new PdpGroup(); + group.setName(NAME); + // with supported policy type and policies + PdpSubGroup subgroup1 = new PdpSubGroup(); + subgroup1.setDesiredInstanceCount(1); + subgroup1.setPdpType(PDP_TYPE1); + subgroup1.setSupportedPolicyTypes(Arrays.asList(new ToscaPolicyTypeIdentifier("a-type-name", "3.2.1"))); + subgroup1.setPolicies(Collections.emptyList()); + group.setPdpSubgroups(Arrays.asList(subgroup1)); + + ValidationResult result = group.validatePapRest(true); + assertNotNull(result); + assertTrue(result.isValid()); + assertNull(result.getResult()); + + // without supported policy type and policies + PdpSubGroup subgroup2 = new PdpSubGroup(); + subgroup2.setDesiredInstanceCount(1); + subgroup2.setPdpType(PDP_TYPE1); + group.setPdpSubgroups(Arrays.asList(subgroup2)); + + // valid + result = group.validatePapRest(true); + assertNotNull(result); + assertTrue(result.isValid()); + assertNull(result.getResult()); + + // invalid + result = group.validatePapRest(false); + assertNotNull(result); + assertFalse(result.isValid()); + assertNotNull(result.getResult()); + } + @Test public void testValidatePapRest() { PdpGroup group = new PdpGroup(); @@ -140,7 +176,7 @@ public class PdpGroupTest { group.setPdpSubgroups(Arrays.asList(subgroup1, subgroup2, subgroup3)); // valid - ValidationResult result = group.validatePapRest(); + ValidationResult result = group.validatePapRest(false); assertNotNull(result); assertTrue(result.isValid()); assertNull(result.getResult()); @@ -179,7 +215,7 @@ public class PdpGroupTest { } private void assertInvalid(PdpGroup group) { - ValidationResult result = group.validatePapRest(); + ValidationResult result = group.validatePapRest(false); assertNotNull(result); assertFalse(result.isValid()); assertNotNull(result.getResult()); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java index e24e8e2d6..ba55426c7 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java @@ -3,7 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,6 +90,39 @@ public class PdpSubGroupTest { assertEquals(orig.toString(), new PdpSubGroup(orig).toString()); } + @Test + public void testValidatePapRest_GroupUpdateFlow() throws Exception { + PdpSubGroup subgrp = new PdpSubGroup(); + // with supported policy type and policies + subgrp.setDesiredInstanceCount(1); + subgrp.setPdpType("pdp-type"); + subgrp.setSupportedPolicyTypes( + Arrays.asList(makeIdent("type-X", VERSION_300, ToscaPolicyTypeIdentifier.class))); + subgrp.setPolicies(Arrays.asList(makeIdent("policy-X", "4.0.0", ToscaPolicyIdentifier.class))); + + ValidationResult result = subgrp.validatePapRest(false); + assertNotNull(result); + assertTrue(result.isValid()); + assertNull(result.getResult()); + + // without supported policy type and policies + PdpSubGroup subgrp2 = new PdpSubGroup(); + subgrp2.setDesiredInstanceCount(1); + subgrp2.setPdpType("pdp-type"); + + // valid + result = subgrp2.validatePapRest(true); + assertNotNull(result); + assertTrue(result.isValid()); + assertNull(result.getResult()); + + // invalid + result = subgrp2.validatePapRest(false); + assertNotNull(result); + assertFalse(result.isValid()); + assertNotNull(result.getResult()); + } + @Test public void testValidatePapRest() throws Exception { PdpSubGroup subgrp = new PdpSubGroup(); @@ -101,7 +134,7 @@ public class PdpSubGroupTest { subgrp.setPolicies(Arrays.asList(makeIdent("policy-X", "4.0.0", ToscaPolicyIdentifier.class))); // valid - ValidationResult result = subgrp.validatePapRest(); + ValidationResult result = subgrp.validatePapRest(false); assertNotNull(result); assertTrue(result.isValid()); assertNull(result.getResult()); @@ -158,7 +191,7 @@ public class PdpSubGroupTest { } private void assertInvalid(PdpSubGroup sub2) { - ValidationResult result = sub2.validatePapRest(); + ValidationResult result = sub2.validatePapRest(false); assertNotNull(result); assertFalse(result.isValid()); assertNotNull(result.getResult()); -- cgit