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
40 public LoadTestLogErrorEntry( String type, String error, TestStepResult result, ImageIcon icon)
41 {
42 this.icon = icon;
43 this.type = type;
44 this.error = error;
45 this.result = result;
46 this.targetStepName = result.getTestStep().getName();
47
48 timestamp = result == null ? System.currentTimeMillis() : result.getTimeStamp();
49 }
50
51 public LoadTestLogErrorEntry(String type, String message, ImageIcon icon)
52 {
53 this.type = type;
54 this.error = message;
55 this.icon = icon;
56
57 targetStepName = "- Total -";
58
59 timestamp = System.currentTimeMillis();
60 }
61
62 public String getMessage()
63 {
64 if( discarded )
65 return error + " [discarded]";
66 else
67 return error;
68 }
69
70 public TestStepResult getTestStepResult()
71 {
72 return result;
73 }
74
75 public long getTimeStamp()
76 {
77 return timestamp;
78 }
79
80 public String getTargetStepName()
81 {
82 return targetStepName;
83 }
84
85 public ImageIcon getIcon()
86 {
87 return icon;
88 }
89
90 public String getType()
91 {
92 return type;
93 }
94
95 public boolean isError()
96 {
97 return true;
98 }
99
100 public ActionList getActions()
101 {
102 return result == null ? null : result.getActions();
103 }
104
105 public void exportToFile(String fileName) throws IOException
106 {
107 PrintWriter writer = new PrintWriter(fileName );
108
109 writer.write( new Date( timestamp ).toString() );
110 writer.write( ":" );
111 writer.write( targetStepName );
112 writer.write( ":" );
113 writer.write( error );
114 writer.println();
115 if( result != null )
116 {
117 writer.println( "----------------------------------------------------" );
118 result.writeTo( writer );
119 }
120 else if( discarded )
121 {
122 writer.println( "-> Discarded" );
123 }
124
125 writer.close();
126 }
127
128 public void discard()
129 {
130 result = null;
131 discarded = true;
132 }
133
134 public boolean isDiscarded()
135 {
136 return discarded;
137 }
138 }