use of org.onap.sdc.toscaparser.api.functions.GetInput in project so by onap.
the class ToscaResourceInputTest method getListResourceInput.
@Test
public void getListResourceInput() {
ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
LinkedHashMap<String, Property> hashMap = new LinkedHashMap<>();
hashMap.put("key1", property);
Map<String, Object> map = new HashMap<>();
map.put("customizationUUID", "69df3303-d2b3-47a1-9d04-41604d3a95fd");
Metadata metadata = new Metadata(map);
when(entityDetails.getProperties()).thenReturn(hashMap);
when(property.getValue()).thenReturn(getInput);
when(getInput.getInputName()).thenReturn("nameKey");
when(input.getName()).thenReturn("nameKey");
when(input.getDefault()).thenReturn("defaultValue");
when(getInput.toString()).thenReturn("getinput:[sites,INDEX,role]");
when(entityDetails.getMetadata()).thenReturn(metadata);
List<Input> inputs = new ArrayList<>();
inputs.add(input);
String resourceInput = toscaResourceInstaller.getVnfcResourceInput(entityDetails, inputs);
assertEquals("{\\\"key1\\\":\\\"[sites,INDEX,role]|defaultValue\\\"}", resourceInput);
}
use of org.onap.sdc.toscaparser.api.functions.GetInput in project so by onap.
the class ToscaResourceInstaller method getValue.
// this of temporary solution
private static String getValue(Object value, List<Input> inputs) {
String outInput;
String defaultValue = null;
if (value instanceof Map) {
Collection values = ((LinkedHashMap) value).values();
outInput = (values.size() > 0) ? values.toArray()[0].toString() : "";
} else if (value instanceof GetInput) {
String inputName = ((GetInput) value).getInputName();
Optional<Input> inputOptional = inputs.stream().filter(input -> input.getName().equals(inputName)).findFirst();
if (inputOptional.isPresent()) {
Input input = inputOptional.get();
defaultValue = input.getDefault() != null ? input.getDefault().toString() : "";
}
// Gets a value between [ and ]
String regex = "\\[.*?\\]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(value.toString());
String valueStr = matcher.find() ? matcher.group() : inputName;
outInput = valueStr + "|" + defaultValue;
} else {
outInput = value != null ? value.toString() : "";
}
return outInput;
}
Aggregations