aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java3
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java69
5 files changed, 50 insertions, 54 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java
index 8f580382d2..cbf14da3fd 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java
@@ -60,6 +60,7 @@ import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -67,7 +68,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@Path("/v1/catalog/{componentType}/{componentId}/componentInstance/{componentInstanceId}/interfaceOperation")
-@Tags({@Tag(name = "SDCE-2 APIs")})
+@Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Controller
@@ -104,11 +105,14 @@ public class ComponentInterfaceOperationServlet extends AbstractValidationsServl
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response updateComponentInstanceInterfaceOperation(
@Parameter(description = "valid values: resources / services", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("componentType") final String componentType,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("componentType") String componentType,
@Parameter(description = "Component Id") @PathParam("componentId") String componentId,
@Parameter(description = "Component Instance Id") @PathParam("componentInstanceId") String componentInstanceId,
@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
LOGGER.debug(START_HANDLE_REQUEST_OF, request.getMethod(), request.getRequestURI());
+ userId = ValidationUtils.sanitizeInputString(userId);
+ componentType = ValidationUtils.sanitizeInputString(componentType);
+ componentInstanceId = ValidationUtils.sanitizeInputString(componentInstanceId);
LOGGER.debug(MODIFIER_ID_IS, userId);
final User userModifier = componentInterfaceOperationBusinessLogic.validateUser(userId);
final ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
@@ -118,7 +122,7 @@ public class ComponentInterfaceOperationServlet extends AbstractValidationsServl
}
final byte[] bytes = IOUtils.toByteArray(request.getInputStream());
if (bytes == null || bytes.length == 0) {
- LOGGER.error(INTERFACE_OPERATION_CONTENT_INVALID);
+ LOGGER.error(INTERFACE_OPERATION_CONTENT_INVALID, "content is empty");
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
}
final String data = new String(bytes);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java
index 919a5bca00..64e61699ed 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java
@@ -155,9 +155,9 @@ public class InterfacesOperationsConverter {
return false;
}
- private static String getInputValue(String inputValue) {
- String toscaInputValue = inputValue;
- if (Objects.nonNull(inputValue) && inputValue.contains(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName())) {
+ private static String getInputValue(final OperationInputDefinition input) {
+ String inputValue = input.getValue() == null ? input.getToscaDefaultValue(): input.getValue();
+ if (inputValue != null && inputValue.contains(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName())) {
Gson gson = new Gson();
Map<String, List<String>> consumptionValue = gson.fromJson(inputValue, Map.class);
List<String> mappedOutputValue = consumptionValue.get(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName());
@@ -166,9 +166,9 @@ public class InterfacesOperationsConverter {
String interfaceName = interfaceType.substring(interfaceType.lastIndexOf('.') + 1);
mappedOutputValue.remove(1);
mappedOutputValue.add(1, interfaceName);
- toscaInputValue = gson.toJson(consumptionValue);
+ inputValue = gson.toJson(consumptionValue);
}
- return toscaInputValue;
+ return inputValue;
}
private static String getInterfaceType(Component component, String interfaceType) {
@@ -384,12 +384,7 @@ public class InterfacesOperationsConverter {
toscaInput.setDescription(input.getDescription());
toscaInput.setType(input.getType());
toscaInput.setRequired(input.isRequired());
- if (isServiceProxyInterface) {
- String inputValue = Objects.nonNull(input.getValue()) ? getInputValue(input.getValue()) : getInputValue(input.getToscaDefaultValue());
- toscaInput.setDefaultp(propertyConvertor.convertToToscaObject(input, inputValue, dataTypes, false));
- } else {
- toscaInput.setDefaultp(propertyConvertor.convertToToscaObject(input, getInputValue(input.getToscaDefaultValue()), dataTypes, false));
- }
+ toscaInput.setDefaultp(propertyConvertor.convertToToscaObject(input, getInputValue(input), dataTypes, false));
toscaInputs.put(input.getName(), toscaInput);
}
toscaOperation.setInputs(toscaInputs);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
index 89ff754933..5d3fe1bf77 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
@@ -53,7 +53,6 @@ import org.springframework.stereotype.Service;
public class PropertyConvertor {
private static final Logger log = Logger.getLogger(PropertyConvertor.class);
- private JsonParser jsonParser = new JsonParser();
public Either<ToscaNodeType, ToscaError> convertProperties(Component component, ToscaNodeType toscaNodeType,
Map<String, DataTypeDefinition> dataTypes) {
@@ -145,7 +144,7 @@ public class PropertyConvertor {
StringReader reader = new StringReader(value);
JsonReader jsonReader = new JsonReader(reader);
jsonReader.setLenient(true);
- jsonElement = jsonParser.parse(jsonReader);
+ jsonElement = JsonParser.parseReader(jsonReader);
if (value.equals("")) {
return value;
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
index d20f1c0600..e55a92dd0b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
@@ -206,8 +206,7 @@ class InterfacesOperationsConverterTest {
ToscaNodeType nodeType = new ToscaNodeType();
interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
- ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
- interfacesOperationsConverter, null);
+ ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null, null, null);
ToscaTemplate template = new ToscaTemplate("testService");
Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
nodeTypes.put(NODE_TYPE_NAME, nodeType);
@@ -493,7 +492,7 @@ class InterfacesOperationsConverterTest {
private ListDataDefinition<OperationInputDefinition> createInputs(Component component, int numOfInputs) {
ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
for (int i = 0; i < numOfInputs; i++) {
- String mappedPropertyName = java.util.UUID.randomUUID().toString() + "." + MAPPED_PROPERTY_NAME + i;
+ String mappedPropertyName = java.util.UUID.randomUUID() + "." + MAPPED_PROPERTY_NAME + i;
operationInputDefinitionList.add(createMockOperationInputDefinition(
INPUT_NAME_PREFIX + inputTypes[i] + "_" + i, mappedPropertyName, i));
addMappedPropertyAsComponentInput(component, mappedPropertyName);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java
index 05ff278fc0..36c9eb8288 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java
@@ -20,25 +20,21 @@
package org.openecomp.sdc.be.tosca;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import fj.data.Either;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.model.DataTypeDefinition;
@@ -48,16 +44,17 @@ import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
-@RunWith(MockitoJUnitRunner.class)
-public class PropertyConvertorTest {
+class PropertyConvertorTest {
+
private PropertyDefinition property;
private Map<String, DataTypeDefinition> dataTypes;
@InjectMocks
private PropertyConvertor propertyConvertor;
- @Before
+ @BeforeEach
public void setUp(){
+ MockitoAnnotations.openMocks(this);
property = new PropertyDefinition();
property.setName("myProperty");
property.setType(ToscaPropertyType.INTEGER.getType());
@@ -66,7 +63,7 @@ public class PropertyConvertorTest {
}
@Test
- public void testConvertProperty() {
+ void testConvertProperty() {
SchemaDefinition schema = new SchemaDefinition();
schema.setProperty(property);
@@ -76,14 +73,14 @@ public class PropertyConvertorTest {
}
@Test
- public void convertPropertyWhenValueAndDefaultNull() {
+ void convertPropertyWhenValueAndDefaultNull() {
ToscaProperty prop = propertyConvertor.convertProperty(dataTypes, property, PropertyConvertor.PropertyType.PROPERTY);
assertNotNull(prop);
assertNull(prop.getDefaultp());
}
@Test
- public void convertPropertyWhenValueNullAndDefaultNotEmpty() {
+ void convertPropertyWhenValueNullAndDefaultNotEmpty() {
final String def = "1";
property.setDefaultValue(def);
ToscaProperty result = propertyConvertor.convertProperty(dataTypes, property, PropertyConvertor.PropertyType.PROPERTY);
@@ -92,7 +89,7 @@ public class PropertyConvertorTest {
}
@Test
- public void convertPropertyWithMetadata() {
+ void convertPropertyWithMetadata() {
Map<String, String> metadata = new HashMap<>();
metadata.put("key1", "value");
property.setMetadata(metadata);
@@ -102,7 +99,7 @@ public class PropertyConvertorTest {
}
@Test
- public void convertPropertiesWhenValueAndDefaultNullInOne() {
+ void convertPropertiesWhenValueAndDefaultNullInOne() {
PropertyDefinition property1 = new PropertyDefinition();
property1.setName("otherProperty");
property1.setType(ToscaPropertyType.INTEGER.getType());
@@ -126,7 +123,7 @@ public class PropertyConvertorTest {
}
@Test
- public void convertPropertiesWhenValueAndDefaultExist() {
+ void convertPropertiesWhenValueAndDefaultExist() {
PropertyDefinition property1 = new PropertyDefinition();
property1.setName("otherProperty");
property1.setType(ToscaPropertyType.INTEGER.getType());
@@ -147,7 +144,7 @@ public class PropertyConvertorTest {
}
@Test
- public void convertPropertiesWhenValueAndDefaultNullInAll() {
+ void convertPropertiesWhenValueAndDefaultNullInAll() {
PropertyDefinition property1 = new PropertyDefinition();
property1.setName("otherProperty");
property1.setType(ToscaPropertyType.INTEGER.getType());
@@ -166,23 +163,25 @@ public class PropertyConvertorTest {
}
@Test
- public void convertPropertyWhichStartsWithSemiColon() throws Exception {
- PropertyDefinition property1 = new PropertyDataDefinitionBuilder()
- .setDefaultValue("::")
- .setType(ToscaPropertyType.STRING.getType())
- .build();
- ToscaProperty toscaProperty = propertyConvertor.convertProperty(Collections.emptyMap(), property1, PropertyConvertor.PropertyType.PROPERTY);
- assertThat(toscaProperty.getDefaultp()).isEqualTo("::");
+ void convertPropertyWhichStartsWithSemiColon() {
+ final PropertyDefinition property = new PropertyDataDefinitionBuilder()
+ .setDefaultValue("::")
+ .setType(ToscaPropertyType.STRING.getType())
+ .build();
+ final ToscaProperty toscaProperty =
+ propertyConvertor.convertProperty(Collections.emptyMap(), property, PropertyConvertor.PropertyType.PROPERTY);
+ assertEquals("::", toscaProperty.getDefaultp());
}
@Test
- public void convertPropertyWhichStartsWithSlash() throws Exception {
- PropertyDefinition property1 = new PropertyDataDefinitionBuilder()
- .setDefaultValue("/")
- .setType(ToscaPropertyType.STRING.getType())
- .build();
- ToscaProperty toscaProperty = propertyConvertor.convertProperty(Collections.emptyMap(), property1, PropertyConvertor.PropertyType.PROPERTY);
- assertThat(toscaProperty.getDefaultp()).isEqualTo("/");
+ void convertPropertyWhichStartsWithSlash() {
+ final PropertyDefinition property = new PropertyDataDefinitionBuilder()
+ .setDefaultValue("/")
+ .setType(ToscaPropertyType.STRING.getType())
+ .build();
+ final ToscaProperty toscaProperty =
+ propertyConvertor.convertProperty(Collections.emptyMap(), property, PropertyConvertor.PropertyType.PROPERTY);
+ assertEquals("/", toscaProperty.getDefaultp());
}
}