Commits (3)
......@@ -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;
......@@ -74,15 +81,10 @@ public class Generator {
generatePackageHeadings(resource, document, prefix, hLevel);
} else {
//flat generation
List<StructuredTestObjective> stos = EcoreUtil2.getAllContentsOfType(resource.getContents().get(0), StructuredTestObjective.class);
for (StructuredTestObjective sto : stos) {
String sectionTitle = sto.getName();
LinkedHashMap<String, String> map = getReplacementMap(sto);
generateTable(document, sectionTitle, map);
LinkedHashMap<String, LinkedHashMap<String,String>> variants = getVariantsMap(sto);
generateVariants(document, variants);
}
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);
......@@ -100,18 +102,38 @@ public class Generator {
for (Package p : packages) {
generatePackageHeading(document, prefix, i, p, hLevel);
List<StructuredTestObjective> stos = getContentsOfType(p, StructuredTestObjective.class);
for (StructuredTestObjective sto : stos) {
String sectionTitle = sto.getName();
LinkedHashMap<String, String> map = getReplacementMap(sto);
generateTable(document, sectionTitle, map);
LinkedHashMap<String, LinkedHashMap<String,String>> variants = getVariantsMap(sto);
generateVariants(document, variants);
}
generateSTOs(document, stos);
generateTPDs(document, getContentsOfType(p, TestDescription.class));
generatePackageHeadings(document, getContentsOfType(p, Package.class), prefix+"."+i, hLevel+1);
i++;
}
}
private void generateSTOs(XWPFDocument document, List<StructuredTestObjective> stos) {
for (StructuredTestObjective sto : stos) {
String sectionTitle = sto.getName();
LinkedHashMap<String, String> map = getSTOReplacementMap(sto);
generateTable(document, sectionTitle, map);
LinkedHashMap<String, LinkedHashMap<String,String>> variants = getSTOVariantsMap(sto);
generateVariants(document, variants);
}
}
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();
......@@ -365,7 +387,7 @@ public class Generator {
}
}
private LinkedHashMap<String, LinkedHashMap<String, String>> getVariantsMap(StructuredTestObjective sto) {
private LinkedHashMap<String, LinkedHashMap<String, String>> getSTOVariantsMap(StructuredTestObjective sto) {
LinkedHashMap<String, LinkedHashMap<String, String>> variants = new LinkedHashMap<>();
if (sto.getVariants() != null) {
for (TestObjectiveVariant v : sto.getVariants().getVariants()) {
......@@ -396,7 +418,81 @@ public class Generator {
}
private LinkedHashMap<String, String> getReplacementMap(StructuredTestObjective sto) {
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
//TODO: transfer to variants as well
......