Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 30ac2fe2acd3bcde3bb6f2963c8a114d1f58fbb5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*******************************************************************************
 * Copyright (c) 2002-2003 IBM Corporation, Parasoft and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   IBM      - Initial API and implementation
 *   Parasoft - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsi.internal.core.report.impl;

import java.io.StringReader;

import org.eclipse.wst.wsi.internal.core.WSIException;
import org.eclipse.wst.wsi.internal.core.analyzer.config.AnalyzerConfig;
import org.eclipse.wst.wsi.internal.core.analyzer.config.AssertionResultType;
import org.eclipse.wst.wsi.internal.core.profile.TestAssertion;
import org.eclipse.wst.wsi.internal.core.report.ArtifactReference;
import org.eclipse.wst.wsi.internal.core.report.AssertionResult;
import org.eclipse.wst.wsi.internal.core.report.Entry;
import org.eclipse.wst.wsi.internal.core.report.EntryContainer;
import org.eclipse.wst.wsi.internal.core.report.FailureDetail;
import org.eclipse.wst.wsi.internal.core.report.Report;
import org.eclipse.wst.wsi.internal.core.report.ReportArtifact;
import org.eclipse.wst.wsi.internal.core.report.ReportWriter;
import org.eclipse.wst.wsi.internal.core.report.Reporter;

/**
 * Base class for reporting errors from the analyzer.
 * Extend this class for specific types of reporting, such as reporting
 * in different formats, reporting to files, reporting to a GUI.
 *
 * @version 1.0.1
 * @author Jim Clune
 * @author Peter Brittenham
 */
public class DefaultReporter implements Reporter
{
  /**
   * Conformance report.
   */
  protected Report report;

  /**
   * Document writer.
   */
  protected ReportWriter reportWriter;

  /**
   * Analyzer config.
   */
  protected AnalyzerConfig analyzerConfig;

  /**
   * Assertoin result type.
   */
  protected AssertionResultType assertionResultType;

  /**
   * Create result reporter.
   * @param report a Report object.
   * @param reportWriter a ReportWriterObject.
   */
  public DefaultReporter(Report report, ReportWriter reportWriter)
  {
    this.report = report;
    this.reportWriter = reportWriter;

    // ADD: Verify that writer set in reportWriter

    // Get report context
    this.analyzerConfig =
      report.getReportContext().getAnalyzer().getAnalyzerConfig();
    this.assertionResultType =
      this.analyzerConfig.getAssertionResultsOption().getAssertionResultType();
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#setCurrentArtifact(org.wsi.test.report.ReportArtifact)
   */
  public void setCurrentArtifact(ReportArtifact reportArtifact)
    throws WSIException
  {
    report.setCurrentArtifact(reportArtifact);
    reportWriter.write(new StringReader(reportArtifact.getStartXMLString("")));
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#endCurrentArtifact()
   */
  public void endCurrentArtifact() throws WSIException
  {
    reportWriter.write(
      new StringReader(report.getCurrentArtifact().getEndXMLString("")));
    report.endCurrentArtifact();
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#addArtifactReference(org.wsi.test.report.ArtifactReference)
   */
  public void addArtifactReference(ArtifactReference artifactReference)
    throws WSIException
  {
    reportWriter.write(new StringReader(artifactReference.toXMLString("")));

    // Add artifact reference to report
    report.addArtifactReference(artifactReference);
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#setCurrentEntry(org.wsi.test.report.Entry)
   */
  public void setCurrentEntry(Entry entry) throws WSIException
  {
    report.setCurrentEntry(entry);
    reportWriter.write(
      new StringReader(
        entry.getStartXMLString(
          "",
          this
            .report
            .getReportContext()
            .getAnalyzer()
            .getAnalyzerConfig()
            .getAssertionResultsOption()
            .getShowMessageEntry())));
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#setCurrentEntry(org.wsi.test.report.Entry)
   */
  public void setCurrentEnvelopeEntry(Entry entry) throws WSIException
  {
    report.setCurrentEntry(entry);
    reportWriter.write(
      new StringReader(
        entry.getStartXMLString(
          "",
          this
            .report
            .getReportContext()
            .getAnalyzer()
            .getAnalyzerConfig()
            .getAssertionResultsOption()
            .getShowMessageEntry(),
		  true)));
  }
/* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#endCurrentEntry()
   */
  public void endCurrentEntry() throws WSIException
  {
    reportWriter.write(
      new StringReader(report.getCurrentEntry().getEndXMLString("")));
    report.endCurrentEntry();
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#addAssertionResult(org.wsi.test.report.AssertionResult)
   */
  public void addAssertionResult(AssertionResult assertionResult)
    throws WSIException
  {
    // Based on the config options, write out assertion result
    if ((assertionResultType.isAll())
      || ((assertionResultType.isFailedOnly())
        && (assertionResult.getResult().equals(AssertionResult.RESULT_FAILED)))
      || ((assertionResultType.isNotPassed())
        && (!assertionResult.getResult().equals(AssertionResult.RESULT_PASSED)))
	      || ((assertionResultType.isNotInfo())
	            && (!assertionResult.getAssertion().getType().equals(TestAssertion.TYPE_INFORMATIONAL))))
    {
      reportWriter.write(new StringReader(assertionResult.toXMLString("")));
    }

    // Add assertion to report
    report.addAssertionResult(assertionResult);
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#getAssertionResult(java.lang.String)
   */
  public AssertionResult getAssertionResult(String assertionId)
  {
    // Get the assertion result from the current assertion target
    return report.getAssertionResult(assertionId);
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.WriteReport#startReport()
   */
  public void startReport() throws WSIException
  {
    // Write out start of report
    reportWriter.write(new StringReader(report.getStartXMLString("")));
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.WriteReport#finishReport()
   */
  public void finishReport() throws WSIException
  {
    // End the report file
    reportWriter.write(new StringReader(report.getEndXMLString("")));
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.WriteReport#finishReportWithError(java.lang.String)
   */
  public void finishReportWithError(String errorDetail) throws WSIException
  {
    // Check if entry or artifact need to be closed
    if (this.report.getCurrentEntry() != null)
      endCurrentEntry();
    if (this.report.getCurrentArtifact() != null)
      endCurrentArtifact();

    // End the report file
    reportWriter.write(
      new StringReader(report.getErrorXMLString("", errorDetail)));
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#createAssertionResult()
   */
  public AssertionResult createAssertionResult()
  {
    return report.createAssertionResult();
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#createArtifact()
   */
  public ReportArtifact createArtifact()
  {
    return report.createArtifact();
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#createEntry()
   */
  public Entry createEntry()
  {
    return report.createEntry();
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#createEntryContainer()
   */
  public EntryContainer createEntryContainer()
  {
    return report.createEntryContainer();
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#createFailureDetail()
   */
  public FailureDetail createFailureDetail()
  {
    return report.createFailureDetail();
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.WriteReport#getReport()
   */
  public Report getReport()
  {
    return this.report;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.BuildReport#setPrereqType(java.lang.String)
   */
  public void setPrereqType(String prereqType)
  {
    this.report.setPrereqType(prereqType);
  }
}

Back to the top