1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.loadtest.log;
14
15 import java.io.IOException;
16 import java.io.PrintWriter;
17 import java.util.Date;
18
19 import javax.swing.ImageIcon;
20
21 import com.eviware.soapui.model.testsuite.TestStepResult;
22 import com.eviware.soapui.support.action.swing.ActionList;
23
24 /***
25 * An error entry in the LoadTest Log
26 *
27 * @author Ole.Matzura
28 */
29
30 public class LoadTestLogErrorEntry implements LoadTestLogEntry
31 {
32 private final String error;
33 private TestStepResult result;
34 private String type;
35 private ImageIcon icon;
36 private long timestamp;
37 private boolean discarded;
38 private String targetStepName;
39 private final int threadIndex;
40
41 public LoadTestLogErrorEntry( String type, String error, TestStepResult result, ImageIcon icon, int threadIndex )
42 {
43 this.icon = icon;
44 this.type = type;
45 this.error = error;
46 this.result = result;
47 this.threadIndex = threadIndex;
48 this.targetStepName = result.getTestStep().getName();
49
50 timestamp = result == null ? System.currentTimeMillis() : result.getTimeStamp();
51 }
52
53 public LoadTestLogErrorEntry(String type, String message, ImageIcon icon, int threadIndex )
54 {
55 this.type = type;
56 this.error = message;
57 this.icon = icon;
58 this.threadIndex = threadIndex;
59
60 targetStepName = "- Total -";
61
62 timestamp = System.currentTimeMillis();
63 }
64
65 public String getMessage()
66 {
67 if( discarded )
68 return error + " [discarded]";
69 else
70 return error + " [threadIndex=" + threadIndex + "]";
71 }
72
73 public TestStepResult getTestStepResult()
74 {
75 return result;
76 }
77
78 public long getTimeStamp()
79 {
80 return timestamp;
81 }
82
83 public String getTargetStepName()
84 {
85 return targetStepName;
86 }
87
88 public ImageIcon getIcon()
89 {
90 return icon;
91 }
92
93 public String getType()
94 {
95 return type;
96 }
97
98 public boolean isError()
99 {
100 return true;
101 }
102
103 public ActionList getActions()
104 {
105 return result == null ? null : result.getActions();
106 }
107
108 public void exportToFile(String fileName) throws IOException
109 {
110 PrintWriter writer = new PrintWriter(fileName );
111
112 writer.write( new Date( timestamp ).toString() );
113 writer.write( ":" );
114 writer.write( targetStepName );
115 writer.write( ":" );
116 writer.write( error );
117 writer.write( ":" );
118 writer.print( threadIndex );
119 writer.println();
120 if( result != null )
121 {
122 writer.println( "----------------------------------------------------" );
123 result.writeTo( writer );
124 }
125 else if( discarded )
126 {
127 writer.println( "-> Discarded" );
128 }
129
130 writer.close();
131 }
132
133 public void discard()
134 {
135 result = null;
136 discarded = true;
137 }
138
139 public boolean isDiscarded()
140 {
141 return discarded;
142 }
143 }