Skip to main content
summaryrefslogtreecommitdiffstats
blob: e8cfc999ded60f15a69e69a2021a4549979ade55 (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ote.core.testPoint;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp;
import org.eclipse.osee.framework.jdk.core.util.xml.XMLStreamWriterUtil;
import org.eclipse.osee.ote.core.environment.interfaces.ITestPoint;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * @author Robert A. Fisher
 */
public class CheckPoint implements ITestPoint {
   private final String testPointName;
   private String expected;
   private final String actual;
   private final boolean pass;
   private final long elpasedTime;
   private final int numTransmissions;

   /**
    * CheckPoint objects are used for describing the result of a check and can be logged directly to a the logger as a
    * testPoint or can be added to a CheckGroup if it is just a part of a larger series of checks being performed that
    * all constitute one overall check.
    * 
    * @param testPointName The item being tested. (i.e. TSD Button).
    * @param expected The expected condition for a pass point.
    * @param actual The actual condition during the check.
    * @param pass The result of the check.
    */
   public CheckPoint(String testPointName, String expected, String actual, boolean pass, long elapsedTime) {
      this(testPointName, expected, actual, pass, 0, elapsedTime);
   }

   public CheckPoint(String testPointName, String expected, String actual, boolean pass, int numTransmissions, long elapsedTime) {
      this.testPointName = testPointName;
      this.expected = expected.equals("") ? " " : this.convertNonPrintableCharacers(expected);
      this.actual = actual.equals("") ? " " : this.convertNonPrintableCharacers(actual);
      this.pass = pass;
      this.elpasedTime = elapsedTime;
      this.numTransmissions = numTransmissions;
   }

   public CheckPoint(String testPointName, Object expected, Object actual, boolean pass, long elapsedTime) {
      this(testPointName, expected.toString(), actual.toString(), pass, elapsedTime);
   }

   public CheckPoint(String testPointName, Object expected, Object actual, boolean pass) {
      this(testPointName, expected.toString(), actual.toString(), pass, 0);
   }

   public CheckPoint(String testPointName, String expected, String actual, boolean pass) {
      this(testPointName, expected, actual, pass, 0);
   }

   /**
    * @return Returns the actual.
    */
   public String getActual() {
      return actual;
   }

   /**
    * @return Returns the expected.
    */
   public String getExpected() {
      return expected;
   }

   /**
    * @return Returns the pass.
    */
   @Override
   public boolean isPass() {
      return pass;
   }

   public void setExpected(String expected) {
      this.expected = expected;
   }

   @Override
   public Element toXml(Document doc) {
      Element checkPointElement = doc.createElement("CheckPoint");

      checkPointElement.appendChild(Jaxp.createElement(doc, "TestPointName", testPointName));
      checkPointElement.appendChild(Jaxp.createElement(doc, "Expected", expected));
      checkPointElement.appendChild(Jaxp.createElement(doc, "Actual", actual));
      checkPointElement.appendChild(Jaxp.createElement(doc, "Result", pass ? "PASSED" : "FAILED"));
      checkPointElement.appendChild(Jaxp.createElement(doc, "ElapsedTime", Long.toString(this.elpasedTime)));
      checkPointElement.appendChild(Jaxp.createElement(doc, "NumberOfTransmissions",
         Integer.toString(this.numTransmissions)));

      return checkPointElement;
   }

   @Override
   public void toXml(XMLStreamWriter writer) throws XMLStreamException {
      writer.writeStartElement("CheckPoint");
      XMLStreamWriterUtil.writeElement(writer, "TestPointName", testPointName);
      XMLStreamWriterUtil.writeElement(writer, "Expected", expected);
      XMLStreamWriterUtil.writeElement(writer, "Actual", actual);
      XMLStreamWriterUtil.writeElement(writer, "Result", pass ? "PASSED" : "FAILED");
      XMLStreamWriterUtil.writeElement(writer, "ElapsedTime", Long.toString(this.elpasedTime));
      XMLStreamWriterUtil.writeElement(writer, "NumberOfTransmissions", Integer.toString(this.numTransmissions));
      writer.writeEndElement();
   }

   public String getTestPointName() {
      return testPointName;
   }

   /**
    * @return the elpasedTime
    */
   public long getElpasedTime() {
      return elpasedTime;
   }

   /**
    * @return the numTransmissions
    */
   public int getNumTransmissions() {
      return numTransmissions;
   }

   private String convertNonPrintableCharacers(String message) {
      StringBuffer buff = new StringBuffer();
      char currentChar;
      for (int i = 0; i < message.length(); i++) {
         currentChar = message.charAt(i);
         if (currentChar < 32 || currentChar > 126) {
            buff.append(" ASCII=" + (int) currentChar + " ");
         } else if (currentChar == '<') {
            buff.append(" less-than ");
         } else if (currentChar == '>') {
            buff.append(" greater-than ");
         } else if (currentChar == '&') {
            buff.append(" ampersand ");
         } else {
            buff.append(currentChar);
         }
      }

      return buff.toString();
   }
}

Back to the top