diff options
author | Sheshukov, Natalia (ns019t) <ns019t@intl.att.com> | 2018-04-15 13:11:15 +0300 |
---|---|---|
committer | Sheshukov, Natalia (ns019t) <ns019t@intl.att.com> | 2018-04-15 18:53:14 +0300 |
commit | a1f9e908f1b29b3cc8c434bb3ca455196a0959bc (patch) | |
tree | d8bffeecaf3644d40d9cb0b76837df1308942fb4 /src/test/java/org/onap | |
parent | 4b6318aa39e841804cc0a23140c2a923bc2a06a6 (diff) |
JTosca Parser – support Annotations
Change-Id: I256e42e5f4a6e5259c17b8de56d64b44afb7f42d
Issue-ID: SDC-1223
Signed-off-by: Sheshukov, Natalia (ns019t) <ns019t@intl.att.com>
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r-- | src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java | 147 |
1 files changed, 100 insertions, 47 deletions
diff --git a/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java b/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java index 589e47c..7d0c54c 100644 --- a/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java +++ b/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java @@ -2,63 +2,116 @@ package org.onap.sdc.toscaparser.api; import org.junit.Test; import org.onap.sdc.toscaparser.api.common.JToscaException; +import org.onap.sdc.toscaparser.api.parameters.Annotation; +import org.onap.sdc.toscaparser.api.parameters.Input; import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class JToscaImportTest { - @Test - public void testNoMissingTypeValidationError() throws JToscaException { - String fileStr = JToscaImportTest.class.getClassLoader().getResource - ("csars/sdc-onboarding_csar.csar").getFile(); - File file = new File(fileStr); - new ToscaTemplate(file.getAbsolutePath(), null, true, null); - List<String> missingTypeErrors = ThreadLocalsHolder.getCollector() - .getValidationIssueReport() - .stream() - .filter(s -> s.contains("JE136")) - .collect(Collectors.toList()); - assertEquals(0, missingTypeErrors.size()); - } - - @Test - public void testNoStackOverFlowError() { - Exception jte = null; - try { - String fileStr = JToscaImportTest.class.getClassLoader().getResource - ("csars/sdc-onboarding_csar.csar").getFile(); - File file = new File(fileStr); - new ToscaTemplate(file.getAbsolutePath(), null, true, null); - } catch (Exception e){ - jte = e; - } - assertEquals(null, jte); - } - - @Test - public void testNoInvalidImports() throws JToscaException { - List<String> fileNames = new ArrayList<>(); - fileNames.add("csars/tmpCSAR_Huawei_vSPGW_fixed.csar"); - fileNames.add("csars/sdc-onboarding_csar.csar"); - fileNames.add("csars/resource-Spgw-csar-ZTE.csar"); - - for (String fileName : fileNames) { - String fileStr = JToscaImportTest.class.getClassLoader().getResource(fileName).getFile(); - File file = new File(fileStr); - new ToscaTemplate(file.getAbsolutePath(), null, true, null); - List<String> invalidImportErrors = ThreadLocalsHolder.getCollector() - .getValidationIssueReport() - .stream() - .filter(s -> s.contains("JE195")) - .collect(Collectors.toList()); - assertEquals(0, invalidImportErrors.size()); - } - } + @Test + public void testNoMissingTypeValidationError() throws JToscaException { + String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/sdc-onboarding_csar.csar") + .getFile(); + File file = new File(fileStr); + new ToscaTemplate(file.getAbsolutePath(), null, true, null); + List<String> missingTypeErrors = ThreadLocalsHolder.getCollector().getValidationIssueReport().stream() + .filter(s -> s.contains("JE136")).collect(Collectors.toList()); + assertEquals(0, missingTypeErrors.size()); + } + + @Test + public void testNoStackOverFlowError() { + Exception jte = null; + try { + String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/sdc-onboarding_csar.csar") + .getFile(); + File file = new File(fileStr); + new ToscaTemplate(file.getAbsolutePath(), null, true, null); + } catch (Exception e) { + jte = e; + } + assertEquals(null, jte); + } + + @Test + public void testNoInvalidImports() throws JToscaException { + List<String> fileNames = new ArrayList<>(); + fileNames.add("csars/tmpCSAR_Huawei_vSPGW_fixed.csar"); + fileNames.add("csars/sdc-onboarding_csar.csar"); + fileNames.add("csars/resource-Spgw-csar-ZTE.csar"); + + for (String fileName : fileNames) { + String fileStr = JToscaImportTest.class.getClassLoader().getResource(fileName).getFile(); + File file = new File(fileStr); + new ToscaTemplate(file.getAbsolutePath(), null, true, null); + List<String> invalidImportErrors = ThreadLocalsHolder.getCollector().getValidationIssueReport().stream() + .filter(s -> s.contains("JE195")).collect(Collectors.toList()); + assertEquals(0, invalidImportErrors.size()); + } + } + + @Test + public void testParseAnnotations() throws JToscaException { + + String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-AdiodVmxVpeBvService-csar.csar").getFile(); + File file = new File(fileStr); + ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null); + + List<Input> inputs = toscaTemplate.getInputs(); + assertNotNull(inputs); + assertTrue(inputs.stream().filter(i -> i.getAnnotations() != null).collect(Collectors.toList()).isEmpty()); + + inputs.forEach(Input::parseAnnotations); + assertTrue(!inputs.stream().filter(i -> i.getAnnotations() != null).collect(Collectors.toList()).isEmpty()); + } + + @Test + public void testGetInputsWithAndWithoutAnnotations() throws JToscaException { + + String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-AdiodVmxVpeBvService-csar.csar").getFile(); + File file = new File(fileStr); + ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null); + List<Input> inputs = toscaTemplate.getInputs(); + assertNotNull(inputs); + assertTrue(inputs.stream().filter(i -> i.getAnnotations() != null).collect(Collectors.toList()).isEmpty()); + + inputs = toscaTemplate.getInputs(true); + assertNotNull(inputs); + validateInputsAnnotations(inputs); + + inputs = toscaTemplate.getInputs(false); + assertNotNull(inputs); + assertTrue(inputs.stream().filter(i -> i.getAnnotations() != null).collect(Collectors.toList()).isEmpty()); + } + + private void validateInputsAnnotations(List<Input> inputs) { + List<Input> inputsWithAnnotations = inputs.stream().filter(i -> i.getAnnotations() != null) + .collect(Collectors.toList()); + assertTrue(!inputs.isEmpty()); + inputsWithAnnotations.stream().forEach(i -> validateAnnotations(i)); + } + + private void validateAnnotations(Input input) { + assertNotNull(input.getAnnotations()); + assertEquals(input.getAnnotations().size(), 1); + Annotation annotation = input.getAnnotations().get("source"); + assertEquals(annotation.getName(), "source"); + assertEquals(annotation.getType().toLowerCase(), "org.openecomp.annotations.source"); + assertNotNull(annotation.getProperties()); + Optional<Property> source_type = annotation.getProperties().stream() + .filter(p -> p.getName().equals("source_type")).findFirst(); + assertTrue(source_type.isPresent()); + assertEquals(source_type.get().getValue(), "HEAT"); + } } |