diff --git a/plugins/org.etsi.mts.tdl.standalone/src/org/etsi/mts/tdl/standalone/Standalone.java b/plugins/org.etsi.mts.tdl.standalone/src/org/etsi/mts/tdl/standalone/Standalone.java index a040139cf05eb479090c0ca6e2e4d445bf118f63..275e9f72c1b4f672746a396fa1b23e6bf15f11a6 100644 --- a/plugins/org.etsi.mts.tdl.standalone/src/org/etsi/mts/tdl/standalone/Standalone.java +++ b/plugins/org.etsi.mts.tdl.standalone/src/org/etsi/mts/tdl/standalone/Standalone.java @@ -33,8 +33,17 @@ import org.etsi.mts.tdl.ComponentInstanceRole; import org.etsi.mts.tdl.Extension; import org.etsi.mts.tdl.GateType; import org.etsi.mts.tdl.Package; +import org.etsi.mts.tdl.Behaviour; +import org.etsi.mts.tdl.CompoundBehaviour; +import org.etsi.mts.tdl.BoundedLoopBehaviour; +import org.etsi.mts.tdl.AlternativeBehaviour; +import org.etsi.mts.tdl.ConditionalBehaviour; +import org.etsi.mts.tdl.ProcedureCall; +import org.etsi.mts.tdl.Interaction; +import org.etsi.mts.tdl.Message; import org.etsi.mts.tdl.StructuredDataType; import org.etsi.mts.tdl.TestConfiguration; +import org.etsi.mts.tdl.TestDescription; import org.etsi.mts.tdl.tdlPackage; import org.etsi.mts.tdl.asn2tdl.ASN2TDLTranslator; import org.etsi.mts.tdl.constraints.evl.Validator; @@ -377,7 +386,33 @@ public class Standalone { Resource resource = TDLHelper.load(path); //export to external generator EObject model = resource.getContents().get(0); - List<TestConfiguration> testConfigurations = EcoreUtil2.getAllContentsOfType(model, TestConfiguration.class); + generateConfiguration(path, model); + System.out.println(); + generateBehaviour(path, model); + + /* + * @startuml + component Tester { + portout p1c + portout p2c + portout p3c + } + + component SUT { + portin p1d + portin p2d + portin p3d + } + p1c <--> p1d + p2c <--> p2d + p3c <--> p3d + @enduml + + */ + } + + private void generateConfiguration(String path, EObject model) { + List<TestConfiguration> testConfigurations = EcoreUtil2.getAllContentsOfType(model, TestConfiguration.class); String d = "@startuml\n"; for (TestConfiguration tc : testConfigurations) { d += "rectangle \"Test Configuration\\n"+tc.getName()+"\" {\n"; @@ -416,27 +451,93 @@ public class Standalone { // TODO Auto-generated catch block e.printStackTrace(); } + } - /* - * @startuml - component Tester { - portout p1c - portout p2c - portout p3c + private void generateBehaviour(String path, EObject model) { + List<TestDescription> testDescriptions = EcoreUtil2.getAllContentsOfType(model, TestDescription.class); + + + for (TestDescription td : testDescriptions) { + String d = "@startuml\n"; + d+="hide footbox\n"; + d+="title Foot Box removed\n"; + TestConfiguration tc = td.getTestConfiguration(); + for (var i : tc.getComponentInstance()) { + if (i.getRole() == ComponentInstanceRole.TESTER) { + d+="participant "+tc.getName()+"_"+i.getName()+" [\n == " + +i.getRole().toString() + +"\n ----\n \"\"" + +i.getName() + +" : " + +i.getType().getName() + +"\"\"\n]\n\n"; + } + } + for (var i : tc.getComponentInstance()) { + if (i.getRole() == ComponentInstanceRole.SUT) { + d+="participant "+tc.getName()+"_"+i.getName()+" [\n == " + +i.getRole().toString() + +"\n ----\n \"\"" + +i.getName() + +" : " + +i.getType().getName() + +"\"\"\n]\n\n"; + } + } + + if (td.getBehaviourDescription()!= null) { + var b = td.getBehaviourDescription().getBehaviour(); + try { + d += processBehaviour(castObject(b.getClass(), b)); + } catch (Exception e) { + System.out.println("Error: "+e.getMessage()); + } } - component SUT { - portin p1d - portin p2d - portin p3d + d += "@enduml"; + //TODO: need to split behaviours.. + System.out.println(d); + try { + //TODO: make configurable + Files.writeString(Path.of(path+"-"+td.getName()+"-behaviour.md"), d); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - p1c <--> p1d - p2c <--> p2d - p3c <--> p3d - @enduml + } + } + + private <T> T castObject(Class<T> clazz, Object object) { + return (T) object; + } + + private String processBehaviour(Behaviour b) { + String d = "' Not supported yet: "+b.getClass().getName(); + System.out.println(d); + return d+"\n"; + } + + private String processBehaviour(CompoundBehaviour b) { + String d = ""; + for (var nested : b.getBlock().getBehaviour()) { + d+=processBehaviour(castObject(nested.getClass(), nested)); + } + //TODO: handle prefixes and indentation? + return d; + } + + private String processBehaviour(Message b) { + var sc = b.getSourceGate().getComponent(); + var c = sc.container().getName()+"_"+sc.getName(); + var tc = b.getTarget().get(0).getTargetGate().getComponent(); + var t = tc.container().getName()+"_"+tc.getName(); + var a = b.getArgument(); + String d = ""; + //TODO: use node model untils to get text (needs processing) + d += c+" -> "+t+" : "+b.toString()+"\n"; + return d; + } - */ - } private String processComponentInstance(ComponentInstance i) { String c = "component \"<<"+i.getRole().getName()+">>\\n"+i.getName()+":"+i.getType().getName()+"\" { \n";