Add tests for the presence of Optional values 61/107061/2
authorChris André <chris.andre@yoppworks.com>
Mon, 4 May 2020 17:58:39 +0000 (13:58 -0400)
committerOjas Dubey <Ojas.Dubey@amdocs.com>
Tue, 5 May 2020 12:13:48 +0000 (12:13 +0000)
Issue-ID: SDC-3012
Signed-off-by: Chris Andre <chris.andre@yoppworks.com>
Change-Id: I56cbf7fb5bd04ad2fbc496231d6abe72066124fe

catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java

index fccc034..021e6b4 100644 (file)
@@ -183,23 +183,33 @@ public class NodeFilterValidator {
     private Either<Boolean, ResponseFormat> validatePropertyData(UIConstraint uiConstraint,
             Optional<? extends PropertyDefinition> sourceSelectedProperty,
             Optional<? extends PropertyDefinition> 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()));
         }
     }