Search in sources :

Example 1 with GetInput

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);
}
Also used : Input(org.onap.sdc.toscaparser.api.parameters.Input) GetInput(org.onap.sdc.toscaparser.api.functions.GetInput) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) Property(org.onap.sdc.toscaparser.api.Property) Test(org.junit.Test)

Example 2 with GetInput

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;
}
Also used : Pattern(java.util.regex.Pattern) Input(org.onap.sdc.toscaparser.api.parameters.Input) GetInput(org.onap.sdc.toscaparser.api.functions.GetInput) Optional(java.util.Optional) Matcher(java.util.regex.Matcher) GetInput(org.onap.sdc.toscaparser.api.functions.GetInput) Collection(java.util.Collection) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

GetInput (org.onap.sdc.toscaparser.api.functions.GetInput)2 Input (org.onap.sdc.toscaparser.api.parameters.Input)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Test (org.junit.Test)1 Property (org.onap.sdc.toscaparser.api.Property)1 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)1