|
1 |
| package com.agical.rdoc.extension.junit; |
|
2 |
| |
|
3 |
| import java.io.IOException; |
|
4 |
| import java.io.InputStream; |
|
5 |
| import java.io.ObjectInputStream; |
|
6 |
| |
|
7 |
| import junit.framework.Protectable; |
|
8 |
| import junit.framework.Test; |
|
9 |
| import junit.framework.TestResult; |
|
10 |
| |
|
11 |
| import com.agical.rdoc.core.converter.ConversionException; |
|
12 |
| import com.agical.rdoc.core.converter.InputStreamConverter; |
|
13 |
| import com.agical.rdoc.core.model.test.TestNode; |
|
14 |
| import com.agical.rdoc.core.model.test.visitor.PostProcessingVisitor; |
|
15 |
| import com.agical.rdoc.core.resourcemanager.ResourceManager; |
|
16 |
| import com.agical.rmock.core.configuration.ConfiguratorImpl; |
|
17 |
| import com.agical.rmock.core.hub.Hub; |
|
18 |
| |
|
19 |
| public class RenderingTest implements Test { |
|
20 |
| private Hub hub = ConfiguratorImpl.getInstance().getHub(); |
|
21 |
| |
|
22 |
| private ResourceManager resourceManager; |
|
23 |
| |
|
24 |
1
| public int countTestCases() {
|
|
25 |
1
| return 1;
|
|
26 |
| } |
|
27 |
| |
|
28 |
0
| public void run(TestResult testResult) {
|
|
29 |
| |
|
30 |
0
| hub.beginScope();
|
|
31 |
0
| hub.connect(this);
|
|
32 |
0
| doRender(testResult);
|
|
33 |
0
| hub.endScope();
|
|
34 |
| |
|
35 |
| } |
|
36 |
| |
|
37 |
1
| void doRender(TestResult testResult) {
|
|
38 |
1
| Protectable protectable = new Protectable() {
|
|
39 |
1
| public void protect() throws Throwable {
|
|
40 |
1
| TestNode testNode = (TestNode) resourceManager.read( new InputStreamConverter() {
|
|
41 |
| |
|
42 |
0
| public Object convert(InputStream stream) throws ConversionException {
|
|
43 |
0
| try {
|
|
44 |
0
| ObjectInputStream objectInputStream = new ObjectInputStream( stream );
|
|
45 |
0
| return objectInputStream.readObject();
|
|
46 |
| } catch (IOException e) { |
|
47 |
0
| throw new ConversionException( e );
|
|
48 |
| } catch (ClassNotFoundException e) { |
|
49 |
0
| throw new ConversionException( e );
|
|
50 |
| } |
|
51 |
| } |
|
52 |
| |
|
53 |
| }, "teststructure.ser" ); |
|
54 |
1
| testNode.accept( new PostProcessingVisitor() );
|
|
55 |
| } |
|
56 |
| }; |
|
57 |
| |
|
58 |
1
| testResult.startTest(this);
|
|
59 |
1
| testResult.runProtected(this, protectable);
|
|
60 |
1
| testResult.endTest(this);
|
|
61 |
| } |
|
62 |
| |
|
63 |
3
| public void setResourceManager(ResourceManager resourceManager) {
|
|
64 |
3
| this.resourceManager = resourceManager;
|
|
65 |
| } |
|
66 |
| |
|
67 |
1
| public String toString() {
|
|
68 |
1
| return "render";
|
|
69 |
| } |
|
70 |
| } |