/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
/**
* Validates that appropriate fields are populated for an incoming call to the PAP REST API.
*
+ * @param updateGroupFlow if the operation is pdp group update
* @return the validation result
*/
- public ValidationResult validatePapRest() {
+ public ValidationResult validatePapRest(boolean updateGroupFlow) {
BeanValidationResult result = new BeanValidationResult("group", this);
/*
*/
result.validateNotNull("name", name);
- result.validateNotNullList(SUBGROUP_FIELD, pdpSubgroups, PdpSubGroup::validatePapRest);
+ result.validateNotNullList(SUBGROUP_FIELD, pdpSubgroups,
+ (PdpSubGroup pdpSubGroup) -> pdpSubGroup.validatePapRest(updateGroupFlow));
if (pdpSubgroups != null && pdpSubgroups.isEmpty()) {
result.addResult(new ObjectValidationResult(SUBGROUP_FIELD, pdpSubgroups, ValidationStatus.INVALID,
* ONAP Policy Models
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 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.
* @return the validation result
*/
public ValidationResult validatePapRest() {
- BeanValidationResult result = new BeanValidationResult(GROUPS_FIELD, this);
-
- result.validateNotNullList(GROUPS_FIELD, groups, PdpGroup::validatePapRest);
+ ValidationResult result = new BeanValidationResult(GROUPS_FIELD, this);
+ ((BeanValidationResult) result).validateNotNullList(GROUPS_FIELD, groups,
+ (PdpGroup pdpGroup) -> pdpGroup.validatePapRest(false));
if (!result.isValid()) {
return result;
}
// verify that the same group doesn't appear more than once
+ return checkForDuplicateGroups(result);
+ }
+
+ /**
+ * Validates that there are no duplicate PdpGroups with the same name.
+ *
+ * @param result the validation result
+ * @return the validation result
+ */
+ public ValidationResult checkForDuplicateGroups(ValidationResult result) {
List<String> names = groups.stream().map(PdpGroup::getName).collect(Collectors.toList());
- if (groups.size() == new HashSet<>(names).size()) {
- return result;
+ if (groups.size() != new HashSet<>(names).size()) {
+ result = new ObjectValidationResult(GROUPS_FIELD, names, ValidationStatus.INVALID, "duplicate group names");
}
-
- // different sizes implies duplicates
- return new ObjectValidationResult(GROUPS_FIELD, names, ValidationStatus.INVALID, "duplicate group names");
+ return result;
}
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* Validates that appropriate fields are populated for an incoming call to the PAP
* REST API.
*
+ * @param updateGroupFlow if the operation is pdp group update
* @return the validation result
*/
- public ValidationResult validatePapRest() {
+ public ValidationResult validatePapRest(boolean updateGroupFlow) {
BeanValidationResult result = new BeanValidationResult("group", this);
result.validateNotNull("pdpType", pdpType);
- result.validateNotNullList("supportedPolicyTypes", supportedPolicyTypes,
- ToscaPolicyTypeIdentifier::validatePapRest);
- result.validateNotNullList("policies", policies, ToscaPolicyIdentifier::validatePapRest);
+ // When doing PdpGroup Update operation, supported policy types and policies doesn't have to be validated.
+ if (!updateGroupFlow) {
+ result.validateNotNullList("policies", policies, ToscaPolicyIdentifier::validatePapRest);
+ result.validateNotNullList("supportedPolicyTypes", supportedPolicyTypes,
+ ToscaPolicyTypeIdentifier::validatePapRest);
- if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) {
- result.addResult(new ObjectValidationResult("supportedPolicyTypes", supportedPolicyTypes,
- ValidationStatus.INVALID, "empty list"));
+ if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) {
+ result.addResult(new ObjectValidationResult("supportedPolicyTypes", supportedPolicyTypes,
+ ValidationStatus.INVALID, "empty list"));
+ }
}
if (desiredInstanceCount <= 0) {
* 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.
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();
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());
}
private void assertInvalid(PdpGroup group) {
- ValidationResult result = group.validatePapRest();
+ ValidationResult result = group.validatePapRest(false);
assertNotNull(result);
assertFalse(result.isValid());
assertNotNull(result.getResult());
* 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.
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();
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());
}
private void assertInvalid(PdpSubGroup sub2) {
- ValidationResult result = sub2.validatePapRest();
+ ValidationResult result = sub2.validatePapRest(false);
assertNotNull(result);
assertFalse(result.isValid());
assertNotNull(result.getResult());