Fix property validation for data type in model 42/129142/2
authorMichaelMorris <michael.morris@est.tech>
Thu, 5 May 2022 22:18:00 +0000 (23:18 +0100)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Mon, 9 May 2022 12:19:59 +0000 (12:19 +0000)
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-3990
Change-Id: I702960519cd9ef6ff7a905d837de7ca5b8f29599

catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java

index 8a00362..4268d91 100644 (file)
@@ -423,7 +423,7 @@ public abstract class BaseBusinessLogic {
     Either<Boolean, ResponseFormat> validatePropertyDefaultValue(IComplexDefaultValue property, Map<String, DataTypeDefinition> dataTypes) {
         String type;
         String innerType = null;
-        if (!propertyOperation.isPropertyTypeValid(property, null)) {
+        if (!propertyOperation.isPropertyTypeValid(property, dataTypes)) {
             log.info("Invalid type for property '{}' type '{}'", property.getName(), property.getType());
             ResponseFormat responseFormat = componentsUtils
                 .getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
index bd3e9ae..fd05760 100644 (file)
@@ -468,7 +468,7 @@ public class InputsBusinessLogicTest {
         // for BaseOperation.getAllDataTypes:
         when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
         // for BaseOperation.validatePropertyDefaultValue:
-        when(propertyOperation.isPropertyTypeValid(any(), any())).thenReturn(true);
+        when(propertyOperation.isPropertyTypeValid(any(), anyMap())).thenReturn(true);
         when(propertyOperation.isPropertyInnerTypeValid(any(),any())).thenReturn(new ImmutablePair<>(listInput.getSchemaType(), true));
         when(propertyOperation.isPropertyDefaultValueValid(any(), any())).thenReturn(true);
         // for createListInputsInGraph:
@@ -566,12 +566,12 @@ public class InputsBusinessLogicTest {
         when(propertyDeclarationOrchestrator.getPropOwnerId(componentInstInputsMap)).thenReturn(COMPONENT_INSTANCE_ID);
         when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
         // for BaseOperation.validatePropertyDefaultValue:
-        when(propertyOperation.isPropertyTypeValid(any(), any())).thenReturn(false);
+        when(propertyOperation.isPropertyTypeValid(any(), anyMap())).thenReturn(false);
 
         Either<List<InputDefinition>, ResponseFormat> result =
                 testInstance.createListInput(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, createListInputParams, true, false);
         assertThat(result.isRight()).isTrue();
-        verify(propertyOperation, times(1)).isPropertyTypeValid(any(), any());
+        verify(propertyOperation, times(1)).isPropertyTypeValid(any(), anyMap());
     }
 
     @Test
@@ -586,7 +586,7 @@ public class InputsBusinessLogicTest {
         when(propertyDeclarationOrchestrator.getPropOwnerId(componentInstInputsMap)).thenReturn(COMPONENT_INSTANCE_ID);
         when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
         // for BaseOperation.validatePropertyDefaultValue:
-        when(propertyOperation.isPropertyTypeValid(any(), any())).thenReturn(true);
+        when(propertyOperation.isPropertyTypeValid(any(), anyMap())).thenReturn(true);
         when(propertyOperation.isPropertyInnerTypeValid(any(),any())).thenReturn(new ImmutablePair<>(listInput.getSchemaType(), true));
         when(propertyOperation.isPropertyDefaultValueValid(any(), any())).thenReturn(true);
         when(toscaOperationFacadeMock.addInputsToComponent(anyMap(), eq(COMPONENT_ID))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
index 20e2114..d133e08 100644 (file)
@@ -1945,7 +1945,7 @@ public class ResourceBusinessLogicTest {
                List<PropertyDefinition> properties = new ArrayList<>();
                properties.add(property);
                basic.setProperties(properties);
-               when(propertyOperation.isPropertyTypeValid(property, null)).thenReturn(true);
+               when(propertyOperation.isPropertyTypeValid(property, (String)null)).thenReturn(true);
                when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
                Boolean validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
                assertTrue(validatePropertiesDefaultValues);
index bf8d6ae..931d599 100644 (file)
@@ -835,6 +835,13 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
         }
         return true;
     }
+    
+    public boolean isPropertyTypeValid(final IComplexDefaultValue property, final Map<String, DataTypeDefinition> dataTypes) {
+        if (property == null) {
+            return false;
+        }
+        return ToscaPropertyType.isValidType(property.getType()) != null || dataTypes.containsKey(property.getType());
+    }
 
     @Override
     public ImmutablePair<String, Boolean> isPropertyInnerTypeValid(IComplexDefaultValue property, Map<String, DataTypeDefinition> dataTypes) {
index a3c9bca..ff41d5d 100644 (file)
@@ -795,7 +795,7 @@ public class PropertyOperationTest extends ModelTestBase {
                // test 1
                testSubject = createTestSubject();
                property = null;
-               result = testSubject.isPropertyTypeValid(property, null);
+               result = testSubject.isPropertyTypeValid(property, (String)null);
                Assert.assertEquals(false, result);
        }