From 8e039ab3f81af2d1452f1b2db06588883529a428 Mon Sep 17 00:00:00 2001 From: Chris André Date: Mon, 4 May 2020 13:58:39 -0400 Subject: Add tests for the presence of Optional values Issue-ID: SDC-3012 Signed-off-by: Chris Andre Change-Id: I56cbf7fb5bd04ad2fbc496231d6abe72066124fe --- .../components/validation/NodeFilterValidator.java | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java index fccc034baa..021e6b49e4 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java @@ -183,23 +183,33 @@ public class NodeFilterValidator { private Either validatePropertyData(UIConstraint uiConstraint, Optional sourceSelectedProperty, Optional targetComponentInstanceProperty) { - final PropertyDefinition sourcePropDefinition = sourceSelectedProperty.get(); - final String sourceType = sourcePropDefinition.getType(); - final PropertyDefinition targetPropDefinition = targetComponentInstanceProperty.get(); - final String targetType = targetPropDefinition.getType(); - if (sourceType.equals(targetType)) { - if (schemableTypes.contains(sourceType)) { - final SchemaDefinition sourceSchemaDefinition = sourcePropDefinition.getSchema(); - final SchemaDefinition targetSchemaDefinition = targetPropDefinition.getSchema(); - if (!sourceSchemaDefinition.equals(targetSchemaDefinition)) { - return Either.right(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH, - uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString())); + if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) { + final PropertyDefinition sourcePropDefinition = sourceSelectedProperty.get(); + final String sourceType = sourcePropDefinition.getType(); + final PropertyDefinition targetPropDefinition = targetComponentInstanceProperty.get(); + final String targetType = targetPropDefinition.getType(); + if (sourceType.equals(targetType)) { + if (schemableTypes.contains(sourceType)) { + final SchemaDefinition sourceSchemaDefinition = sourcePropDefinition.getSchema(); + final SchemaDefinition targetSchemaDefinition = targetPropDefinition.getSchema(); + if (!sourceSchemaDefinition.equals(targetSchemaDefinition)) { + return Either + .right(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH, + uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString())); + } } + return Either.left(Boolean.TRUE); + } else { + return Either.right(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH, + uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString())); } - return Either.left(Boolean.TRUE); } else { - return Either.right(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH, - uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString())); + LOGGER.debug( + "Null value passed to `validatePropertyData` - sourceSelectedProperty: '{}' - targetComponentInstanceProperty: '{}'", + sourceSelectedProperty, targetComponentInstanceProperty); + return Either.right(componentsUtils + .getResponseFormat(ActionStatus.GENERAL_ERROR, uiConstraint.getServicePropertyName(), + uiConstraint.getValue().toString())); } } -- cgit 1.2.3-korg