|
1 |
| package com.agical.rdoc.core.render; |
|
2 |
| |
|
3 |
| import java.io.BufferedReader; |
|
4 |
| import java.io.ByteArrayInputStream; |
|
5 |
| import java.io.IOException; |
|
6 |
| import java.io.InputStream; |
|
7 |
| import java.io.InputStreamReader; |
|
8 |
| import java.io.ObjectInputStream; |
|
9 |
| import java.io.UnsupportedEncodingException; |
|
10 |
| import java.util.StringTokenizer; |
|
11 |
| |
|
12 |
| import com.agical.rdoc.core.converter.ConversionException; |
|
13 |
| import com.agical.rdoc.core.converter.InputStreamConverter; |
|
14 |
| import com.agical.rdoc.core.model.TextFormatter; |
|
15 |
| import com.agical.rdoc.core.model.test.TestNode; |
|
16 |
| import com.agical.rdoc.core.model.test.visitor.PostProcessingVisitor; |
|
17 |
| import com.agical.rdoc.core.resourcemanager.ResourceManager; |
|
18 |
| import com.agical.rdoc.util.Read; |
|
19 |
| import com.agical.rdoc.velocity.render.VelocityTestStructureRenderer; |
|
20 |
| import com.agical.rmock.core.configuration.ConfiguratorImpl; |
|
21 |
| import com.agical.rmock.core.hub.Hub; |
|
22 |
| |
|
23 |
| public class TDDocRenderer { |
|
24 |
| private Hub hub = ConfiguratorImpl.getInstance().getHub(); |
|
25 |
| private ResourceManager resourceManager; |
|
26 |
| |
|
27 |
0
| public void doRender() {
|
|
28 |
0
| hub.beginScope();
|
|
29 |
0
| hub.connect(this);
|
|
30 |
0
| TestNode testNode = (TestNode) resourceManager.read( new InputStreamConverter() {
|
|
31 |
| |
|
32 |
0
| public Object convert(InputStream stream) throws ConversionException {
|
|
33 |
0
| try {
|
|
34 |
0
| ObjectInputStream objectInputStream = new ObjectInputStream( stream );
|
|
35 |
0
| return objectInputStream.readObject();
|
|
36 |
| } catch (IOException e) { |
|
37 |
0
| throw new ConversionException( e );
|
|
38 |
| } catch (ClassNotFoundException e) { |
|
39 |
0
| throw new ConversionException( e );
|
|
40 |
| } |
|
41 |
| } |
|
42 |
| |
|
43 |
| }, "teststructure.ser" ); |
|
44 |
0
| testNode.accept( getTestNodeVisitor() );
|
|
45 |
0
| hub.endScope();
|
|
46 |
| |
|
47 |
| } |
|
48 |
| |
|
49 |
0
| private PostProcessingVisitor getTestNodeVisitor() {
|
|
50 |
0
| InputStream inputStream = null;
|
|
51 |
0
| try {
|
|
52 |
0
| inputStream = (InputStream) resourceManager.read(new InputStreamConverter() {
|
|
53 |
0
| public Object convert(InputStream stream) throws ConversionException {
|
|
54 |
0
| try {
|
|
55 |
0
| String string = Read.readInputStream("UTF-8", stream);
|
|
56 |
0
| return new ByteArrayInputStream( string.getBytes("UTF-8") );
|
|
57 |
| } catch (UnsupportedEncodingException e) { |
|
58 |
0
| throw new ConversionException( "Bad encoding", e);
|
|
59 |
| } catch (IOException e) { |
|
60 |
0
| throw new ConversionException( "IOException", e);
|
|
61 |
| } |
|
62 |
| } |
|
63 |
| |
|
64 |
| }, "tmp/renderInfo.txt"); |
|
65 |
0
| BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( inputStream ) );
|
|
66 |
| |
|
67 |
0
| PostProcessingVisitor postProcessingVisitor = new PostProcessingVisitor();
|
|
68 |
0
| String tmp = null;
|
|
69 |
| |
|
70 |
0
| while( (tmp = bufferedReader.readLine()) != null ) {
|
|
71 |
0
| StringTokenizer stringTokenizer = new StringTokenizer( tmp, "\t", false );
|
|
72 |
0
| String formatter = stringTokenizer.nextToken();
|
|
73 |
0
| String template = stringTokenizer.nextToken();
|
|
74 |
0
| String target = stringTokenizer.nextToken();
|
|
75 |
0
| Class formatterClass = this.getClass().forName(formatter);
|
|
76 |
0
| TextFormatter textFormatter = (TextFormatter) formatterClass.newInstance();
|
|
77 |
0
| postProcessingVisitor.addPostProcessor( new VelocityTestStructureRenderer( template, target, textFormatter ));
|
|
78 |
| } |
|
79 |
| |
|
80 |
0
| return postProcessingVisitor;
|
|
81 |
| } catch (Exception e) { |
|
82 |
0
| e.printStackTrace();
|
|
83 |
0
| throw new RuntimeException( e.getMessage() );
|
|
84 |
| } finally { |
|
85 |
0
| try {
|
|
86 |
0
| inputStream.close();
|
|
87 |
| } catch (IOException e) { |
|
88 |
0
| e.printStackTrace();
|
|
89 |
0
| throw new RuntimeException( e.getMessage() );
|
|
90 |
| } |
|
91 |
| } |
|
92 |
| } |
|
93 |
| |
|
94 |
0
| public void setResourceManager(ResourceManager resourceManager) {
|
|
95 |
0
| this.resourceManager = resourceManager;
|
|
96 |
| } |
|
97 |
| |
|
98 |
0
| public String toString() {
|
|
99 |
0
| return "render";
|
|
100 |
| } |
|
101 |
| |
|
102 |
0
| public static void main(String[] args) {
|
|
103 |
0
| new TDDocRenderer().doRender();
|
|
104 |
| } |
|
105 |
| } |