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: 5b2d8ce141460e21ad5f0ee95870aed83467780a (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
/*******************************************************************************
 * Copyright (c) 2002-2005 IBM Corporation 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
 *******************************************************************************/
package org.eclipse.wst.wsi.internal.core.report.impl;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Iterator;
import java.util.Vector;

import org.eclipse.wst.wsi.internal.core.WSIConstants;
import org.eclipse.wst.wsi.internal.core.analyzer.config.AssertionResultsOption;
import org.eclipse.wst.wsi.internal.core.analyzer.config.impl.AssertionResultsOptionImpl;
import org.eclipse.wst.wsi.internal.core.profile.TestAssertion;
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.FailureDetail;
import org.eclipse.wst.wsi.internal.core.report.PrereqFailedList;

import com.ibm.wsdl.util.xml.DOMUtils;

/**
 * Test assertion result.
 *
 * @version 1.0.1
 * @author Peter Brittenham (peterbr@us.ibm.com)
 */
public class AssertionResultImpl implements AssertionResult
{
  /**
   * Assertion result.
   */
  protected String result = null;

  /**
   * Entry.
   */
  protected Entry entry = null;

  /**
   * Profile test assertion.
   */
  protected TestAssertion testAssertion = null;

  /**
   * Failure detail messages.
   */
  protected Vector failureDetailList = null;

  /**
   * Assertion results option.
   */
  protected AssertionResultsOption assertionResultsOption =
    new AssertionResultsOptionImpl();

  /**
   * Prereq failed list.
   */
  protected PrereqFailedList prereqFailedList = null;

  /**
   * Create a new assertion result.
   */
  public AssertionResultImpl()
  {
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#getResult()
   */
  public String getResult()
  {
    return this.result;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#setResult(java.lang.String)
   */
  public void setResult(String result)
  {
    this.result = result;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#getAssertion()
   */
  public TestAssertion getAssertion()
  {
    return this.testAssertion;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#setAssertion(org.wsi.test.profile.TestAssertion)
   */
  public void setAssertion(TestAssertion testAssertion)
  {
    this.testAssertion = testAssertion;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#getEntry()
   */
  public Entry getEntry()
  {
    return this.entry;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#setEntry(org.wsi.test.report.Entry)
   */
  public void setEntry(Entry entry)
  {
    this.entry = entry;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#getFailureDetailList()
   */
  public Vector getFailureDetailList()
  {
    return this.failureDetailList;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#setFailureDetailList(java.util.Vector)
   */
  public void setFailureDetailList(Vector failureDetailList)
  {
    this.failureDetailList = failureDetailList;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#getAssertionResultsOption()
   */
  public AssertionResultsOption getAssertionResultsOption()
  {
    return this.assertionResultsOption;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#setAssertionResultsOption(org.wsi.test.analyzer.config.AssertionResultsOption)
   */
  public void setAssertionResultsOption(AssertionResultsOption assertionResultsOption)
  {
    this.assertionResultsOption = assertionResultsOption;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#getPrereqFailedList()
   */
  public PrereqFailedList getPrereqFailedList()
  {
    return this.prereqFailedList;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.report.AssertionResult#setPrereqFailedList(org.wsi.test.report.PrereqFailedList)
   */
  public void setPrereqFailedList(PrereqFailedList prereqFailedList)
  {
    this.prereqFailedList = prereqFailedList;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.document.DocumentElement#toXMLString(java.lang.String)
   */
  public String toXMLString(String namespaceName)
  {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);

    String nsName = namespaceName;
    if ((!nsName.equals("") && (!nsName.endsWith(":"))))
      nsName += ":";

    // Create element 
    pw.print("      <" + nsName + ELEM_NAME + " ");
    pw.print(WSIConstants.ATTR_ID + "=\"" + this.testAssertion.getId() + "\" ");
    pw.println(WSIConstants.ATTR_RESULT + "=\"" + this.result + "\">");

    // ADD: Add support for additional targets

    // Add prereq failed list
    if (this.prereqFailedList != null)
    {
      pw.print(prereqFailedList.toXMLString(nsName));
    }

    // ADD: Add support for multiple languages
    // If result is failed or warning, then add failure message
    if ((result.equals(RESULT_FAILED) || result.equals(RESULT_WARNING))
      && (assertionResultsOption.getShowFailureMessage()))
    {
      pw.print(
        "        <"
          + nsName
          + WSIConstants.ELEM_FAILURE_MESSAGE
          + " xml:lang=\"en\">");
      pw.print(DOMUtils.cleanString(this.testAssertion.getFailureMessage()));
      pw.println("</" + nsName + WSIConstants.ELEM_FAILURE_MESSAGE + ">");
    }

    // ADD: Add support for multiple languages
    // If any failure detail messages were specified, then add them
    if ((failureDetailList != null)
      && (assertionResultsOption.getShowFailureDetail()))
    {
      Iterator iterator = failureDetailList.iterator();
      while (iterator.hasNext())
      {
        pw.print(((FailureDetail) iterator.next()).toXMLString(nsName));
      }
    }

    // End the element
    pw.println("      </" + nsName + ELEM_NAME + ">");

    // Return string
    return sw.toString();
  }

  /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
  public String toString()
  {
    return result;
  }
}

Back to the top