]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSTestRunner.java
Merge changes Ib64cf026,I238948da
[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 @Deprecated
17 public class RuntimeSTSTestRunner extends Runner {
18     
19     private final String name;
20     private final String code;
21     private final Integer priority;
22     private CommandSession session;
23
24     public RuntimeSTSTestRunner(String name, String code, Integer priority) {
25         this.name = name;
26         this.code = code;
27         this.priority = priority;
28     }
29     
30     public void setCommandSession(CommandSession session) {
31         this.session = session;
32     }
33
34     @Override
35     public Description getDescription() {
36         return Description.createTestDescription(RuntimeSTSTestRunner.class, name);
37     }
38
39     @Override
40     public void run(RunNotifier notifier) {
41         StringReader reade = new StringReader(code);
42         BufferedReader reader = new BufferedReader(reade);
43         
44         SCLContext context = SCLContext.getCurrent();
45         SCLReportingHandler printer = (SCLReportingHandler)context.get(SCLReportingHandler.REPORTING_HANDLER);
46         SCLReportingHandler handler;
47         if(printer instanceof SCLReportingHandler)
48             handler = (SCLReportingHandler)printer;
49         else
50             handler = SCLReportingHandler.DEFAULT;
51         
52         try {
53             if (session == null)
54                 session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, handler);
55             new TestScriptExecutor(session, reader, handler).execute();
56         } catch (IOException e) {
57             throw new RuntimeException(e);
58         } finally {
59             try {
60                 reader.close();
61             } catch (IOException e) {
62                 // Ignore
63             }
64         }
65     }
66
67     public String getName() {
68         return name;
69     }
70     
71     public Integer getPriority() {
72         return priority;
73     }
74
75 }