]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSTestRunner.java
Merge "(refs #7216) Removed OldTransferableGraph1 and all referring code"
[simantics/platform.git] / bundles / org.simantics.tests.modelled / src / org / simantics / tests / modelled / junit / RuntimeSTSTestRunner.java
1 package org.simantics.tests.modelled.junit;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.StringReader;
6
7 import org.junit.runner.Description;
8 import org.junit.runner.Runner;
9 import org.junit.runner.notification.RunNotifier;
10 import org.simantics.scl.compiler.commands.CommandSession;
11 import org.simantics.scl.compiler.commands.TestScriptExecutor;
12 import org.simantics.scl.osgi.SCLOsgi;
13 import org.simantics.scl.runtime.SCLContext;
14 import org.simantics.scl.runtime.reporting.SCLReportingHandler;
15
16 public class RuntimeSTSTestRunner extends Runner {
17     
18     private final String name;
19     private final String code;
20     private final Integer priority;
21     private CommandSession session;
22
23     public RuntimeSTSTestRunner(String name, String code, Integer priority) {
24         this.name = name;
25         this.code = code;
26         this.priority = priority;
27     }
28     
29     public void setCommandSession(CommandSession session) {
30         this.session = session;
31     }
32
33     @Override
34     public Description getDescription() {
35         return Description.createTestDescription(RuntimeSTSTestRunner.class, name);
36     }
37
38     @Override
39     public void run(RunNotifier notifier) {
40         StringReader reade = new StringReader(code);
41         BufferedReader reader = new BufferedReader(reade);
42         
43         SCLContext context = SCLContext.getCurrent();
44         SCLReportingHandler printer = (SCLReportingHandler)context.get(SCLReportingHandler.REPORTING_HANDLER);
45         SCLReportingHandler handler;
46         if(printer instanceof SCLReportingHandler)
47             handler = (SCLReportingHandler)printer;
48         else
49             handler = SCLReportingHandler.DEFAULT;
50         
51         try {
52             if (session == null)
53                 session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, handler);
54             new TestScriptExecutor(session, reader, handler).execute();
55         } catch (IOException e) {
56             throw new RuntimeException(e);
57         } finally {
58             try {
59                 reader.close();
60             } catch (IOException e) {
61                 // Ignore
62             }
63         }
64     }
65
66     public String getName() {
67         return name;
68     }
69     
70     public Integer getPriority() {
71         return priority;
72     }
73
74 }