Loading plugins/org.etsi.mts.tdl.tools.to.docx.poi/src/org/etsi/mts/tdl/tools/to/docx/poi/Generator.java +98 −0 Original line number Diff line number Diff line Loading @@ -25,12 +25,19 @@ import org.apache.poi.xwpf.usermodel.XWPFTableCell; import org.apache.poi.xwpf.usermodel.XWPFTableRow; import org.apache.xmlbeans.XmlException; import org.eclipse.core.runtime.Platform; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.etsi.mts.tdl.Annotation; import org.etsi.mts.tdl.Behaviour; import org.etsi.mts.tdl.Block; import org.etsi.mts.tdl.CompoundBehaviour; import org.etsi.mts.tdl.Package; import org.etsi.mts.tdl.SingleCombinedBehaviour; import org.etsi.mts.tdl.TestConfiguration; import org.etsi.mts.tdl.TestDescription; import org.etsi.mts.tdl.structuredobjectives.StructuredTestObjective; import org.etsi.mts.tdl.structuredobjectives.TestObjectiveVariant; import org.etsi.mts.tdl.structuredobjectives.VariantBinding; Loading Loading @@ -77,6 +84,7 @@ public class Generator { EObject p = resource.getContents().get(0); List<StructuredTestObjective> stos = EcoreUtil2.getAllContentsOfType(p, StructuredTestObjective.class); generateSTOs(document, stos); generateTPDs(document, EcoreUtil2.getAllContentsOfType(p, TestDescription.class)); } storeDocument(filename, document); Loading @@ -95,6 +103,7 @@ public class Generator { generatePackageHeading(document, prefix, i, p, hLevel); List<StructuredTestObjective> stos = getContentsOfType(p, StructuredTestObjective.class); generateSTOs(document, stos); generateTPDs(document, getContentsOfType(p, TestDescription.class)); generatePackageHeadings(document, getContentsOfType(p, Package.class), prefix+"."+i, hLevel+1); i++; } Loading @@ -110,6 +119,21 @@ public class Generator { } } private void generateTPDs(XWPFDocument document, List<TestDescription> tpds) { for (TestDescription tpd : tpds) { if (tpd.getAnnotation().stream().anyMatch(a -> a.getKey().getName().startsWith("Test Purpose"))) { //TODO: add constraints and validation, e.g. Objective present, etc. String sectionTitle = tpd.getName(); LinkedHashMap<String, String> map = getTPDReplacementMap(tpd); generateTable(document, sectionTitle, map); //TODO: variants? reuse? // LinkedHashMap<String, LinkedHashMap<String,String>> variants = getSTOVariantsMap(sto); // generateVariants(document, variants); } } } private void generatePackageHeading(XWPFDocument document, String prefix, int i, Package p, int hLevel) { System.out.println(p.getName()); XWPFParagraph par = document.createParagraph(); Loading Loading @@ -394,6 +418,80 @@ public class Generator { } private LinkedHashMap<String, String> getTPDReplacementMap(TestDescription tpd) { //map //TODO: complete, refine, restructure LinkedHashMap<String,String> map = new LinkedHashMap<>(); map.put(Placeholders.NAME, tpd.getName()); //TODO: what if 0? what if more than 1? map.put(Placeholders.DESCRIPTION, tpd.getTestObjective().get(0).getDescription().replaceAll("\"", "")); String uri = String.join("\n", tpd.getTestObjective().get(0).getObjectiveURI()).trim(); map.put(Placeholders.URI, uri.replaceAll("\"","")); TestConfiguration configuration = tpd.getTestConfiguration(); String config = ""; if (configuration != null) { if (configuration.getName()!=null) { config = configuration.getName(); } } map.put(Placeholders.CONFIGURATION, config); //TODO: how is this addressed? annotations? what about and/or? -> not supported yet String pics = "N/A"; // String pics = String.join(" ", tpd.getPicsReference() // .stream() // .map(p -> NodeModelUtils.getNode(p).getText()) // .collect(Collectors.toList())) // .trim() // ; map.put(Placeholders.PICS, pics); map.put(Placeholders.INITIAL, ""); map.put(Placeholders.EXPECTED, ""); map.put(Placeholders.FINAL, ""); Behaviour behaviour = tpd.getBehaviourDescription().getBehaviour(); if (behaviour instanceof CompoundBehaviour) { Block block = ((CompoundBehaviour) behaviour).getBlock(); for (Behaviour b : block.getBehaviour()) { if (b.getAnnotation().get(0).getKey().getName().startsWith("Initial")) { //TODO: filter extra new line String initialConditions = NodeModelUtils.getNode(b).getText(); initialConditions = initialConditions.replaceAll("\\s*Initial conditions", ""); initialConditions = filterSource(initialConditions, "\n", "\\w").trim(); map.put(Placeholders.INITIAL, initialConditions); } else if (b.getAnnotation().get(0).getKey().getName().startsWith("Expected")) { String expected = NodeModelUtils.getNode(b).getText(); expected = expected.replaceAll("\\s*Expected behaviour", ""); expected = filterSource(expected, "\n", "ensure").trim(); map.put(Placeholders.EXPECTED, expected); EList<Behaviour> expectedBehaviours = ((CompoundBehaviour) b).getBlock().getBehaviour(); if (expectedBehaviours.size() == 2) { String when = NodeModelUtils.getNode(expectedBehaviours.get(0)).getText(); String then = NodeModelUtils.getNode(expectedBehaviours.get(1)).getText(); //TODO: a bit of a hack when = filterSource(when, "\n", "\\s\\s\\s\\s\\w"); then = filterSource(then, "\n", "\\s+\\w"); map.put(Placeholders.WHEN, "when {"+when+"\n}"); map.put(Placeholders.THEN, "then {"+then+"\n}"); } } else if (b.getAnnotation().get(0).getKey().getName().startsWith("Final")) { String finalConditions = NodeModelUtils.getNode(b).getText(); finalConditions = finalConditions.replaceAll("\\s*Final conditions", ""); finalConditions = filterSource(finalConditions, "\n", "\\w").trim(); map.put(Placeholders.FINAL, finalConditions); //TODO: filter extra new line } else { //TODO: Handle other unknown blocks } } } return map; } private LinkedHashMap<String, String> getSTOReplacementMap(StructuredTestObjective sto) { //map //TODO: complete, refine, restructure Loading Loading
plugins/org.etsi.mts.tdl.tools.to.docx.poi/src/org/etsi/mts/tdl/tools/to/docx/poi/Generator.java +98 −0 Original line number Diff line number Diff line Loading @@ -25,12 +25,19 @@ import org.apache.poi.xwpf.usermodel.XWPFTableCell; import org.apache.poi.xwpf.usermodel.XWPFTableRow; import org.apache.xmlbeans.XmlException; import org.eclipse.core.runtime.Platform; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.etsi.mts.tdl.Annotation; import org.etsi.mts.tdl.Behaviour; import org.etsi.mts.tdl.Block; import org.etsi.mts.tdl.CompoundBehaviour; import org.etsi.mts.tdl.Package; import org.etsi.mts.tdl.SingleCombinedBehaviour; import org.etsi.mts.tdl.TestConfiguration; import org.etsi.mts.tdl.TestDescription; import org.etsi.mts.tdl.structuredobjectives.StructuredTestObjective; import org.etsi.mts.tdl.structuredobjectives.TestObjectiveVariant; import org.etsi.mts.tdl.structuredobjectives.VariantBinding; Loading Loading @@ -77,6 +84,7 @@ public class Generator { EObject p = resource.getContents().get(0); List<StructuredTestObjective> stos = EcoreUtil2.getAllContentsOfType(p, StructuredTestObjective.class); generateSTOs(document, stos); generateTPDs(document, EcoreUtil2.getAllContentsOfType(p, TestDescription.class)); } storeDocument(filename, document); Loading @@ -95,6 +103,7 @@ public class Generator { generatePackageHeading(document, prefix, i, p, hLevel); List<StructuredTestObjective> stos = getContentsOfType(p, StructuredTestObjective.class); generateSTOs(document, stos); generateTPDs(document, getContentsOfType(p, TestDescription.class)); generatePackageHeadings(document, getContentsOfType(p, Package.class), prefix+"."+i, hLevel+1); i++; } Loading @@ -110,6 +119,21 @@ public class Generator { } } private void generateTPDs(XWPFDocument document, List<TestDescription> tpds) { for (TestDescription tpd : tpds) { if (tpd.getAnnotation().stream().anyMatch(a -> a.getKey().getName().startsWith("Test Purpose"))) { //TODO: add constraints and validation, e.g. Objective present, etc. String sectionTitle = tpd.getName(); LinkedHashMap<String, String> map = getTPDReplacementMap(tpd); generateTable(document, sectionTitle, map); //TODO: variants? reuse? // LinkedHashMap<String, LinkedHashMap<String,String>> variants = getSTOVariantsMap(sto); // generateVariants(document, variants); } } } private void generatePackageHeading(XWPFDocument document, String prefix, int i, Package p, int hLevel) { System.out.println(p.getName()); XWPFParagraph par = document.createParagraph(); Loading Loading @@ -394,6 +418,80 @@ public class Generator { } private LinkedHashMap<String, String> getTPDReplacementMap(TestDescription tpd) { //map //TODO: complete, refine, restructure LinkedHashMap<String,String> map = new LinkedHashMap<>(); map.put(Placeholders.NAME, tpd.getName()); //TODO: what if 0? what if more than 1? map.put(Placeholders.DESCRIPTION, tpd.getTestObjective().get(0).getDescription().replaceAll("\"", "")); String uri = String.join("\n", tpd.getTestObjective().get(0).getObjectiveURI()).trim(); map.put(Placeholders.URI, uri.replaceAll("\"","")); TestConfiguration configuration = tpd.getTestConfiguration(); String config = ""; if (configuration != null) { if (configuration.getName()!=null) { config = configuration.getName(); } } map.put(Placeholders.CONFIGURATION, config); //TODO: how is this addressed? annotations? what about and/or? -> not supported yet String pics = "N/A"; // String pics = String.join(" ", tpd.getPicsReference() // .stream() // .map(p -> NodeModelUtils.getNode(p).getText()) // .collect(Collectors.toList())) // .trim() // ; map.put(Placeholders.PICS, pics); map.put(Placeholders.INITIAL, ""); map.put(Placeholders.EXPECTED, ""); map.put(Placeholders.FINAL, ""); Behaviour behaviour = tpd.getBehaviourDescription().getBehaviour(); if (behaviour instanceof CompoundBehaviour) { Block block = ((CompoundBehaviour) behaviour).getBlock(); for (Behaviour b : block.getBehaviour()) { if (b.getAnnotation().get(0).getKey().getName().startsWith("Initial")) { //TODO: filter extra new line String initialConditions = NodeModelUtils.getNode(b).getText(); initialConditions = initialConditions.replaceAll("\\s*Initial conditions", ""); initialConditions = filterSource(initialConditions, "\n", "\\w").trim(); map.put(Placeholders.INITIAL, initialConditions); } else if (b.getAnnotation().get(0).getKey().getName().startsWith("Expected")) { String expected = NodeModelUtils.getNode(b).getText(); expected = expected.replaceAll("\\s*Expected behaviour", ""); expected = filterSource(expected, "\n", "ensure").trim(); map.put(Placeholders.EXPECTED, expected); EList<Behaviour> expectedBehaviours = ((CompoundBehaviour) b).getBlock().getBehaviour(); if (expectedBehaviours.size() == 2) { String when = NodeModelUtils.getNode(expectedBehaviours.get(0)).getText(); String then = NodeModelUtils.getNode(expectedBehaviours.get(1)).getText(); //TODO: a bit of a hack when = filterSource(when, "\n", "\\s\\s\\s\\s\\w"); then = filterSource(then, "\n", "\\s+\\w"); map.put(Placeholders.WHEN, "when {"+when+"\n}"); map.put(Placeholders.THEN, "then {"+then+"\n}"); } } else if (b.getAnnotation().get(0).getKey().getName().startsWith("Final")) { String finalConditions = NodeModelUtils.getNode(b).getText(); finalConditions = finalConditions.replaceAll("\\s*Final conditions", ""); finalConditions = filterSource(finalConditions, "\n", "\\w").trim(); map.put(Placeholders.FINAL, finalConditions); //TODO: filter extra new line } else { //TODO: Handle other unknown blocks } } } return map; } private LinkedHashMap<String, String> getSTOReplacementMap(StructuredTestObjective sto) { //map //TODO: complete, refine, restructure Loading