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 package com.reuters.msgtest.fixture;
33
34 import com.reuters.msgtest.SubjectSubstitution;
35 import com.reuters.msgtest.digester.RvMessage;
36 import com.tibco.tibrv.TibrvMsg;
37 import java.util.HashSet;
38 import java.util.Iterator;
39 import java.util.LinkedList;
40 import java.util.List;
41 import java.util.Set;
42
43
44 /***
45 * @author Michael Ward
46 */
47 public class Response {
48 public final static int EQUALS = 0;
49 public final static int EQUALSIGNORE = 1;
50 public final static int NONE = 2;
51 private List ignoredFields;
52 private String name;
53 private String uri;
54 private String subject;
55 private int minexpected;
56 private int maxexpected;
57 private int comparisonMethod = -1;
58 private TibrvMsg tibrvMsg;
59 private SubjectSubstitution subjectSubstitution;
60
61 public Response(SubjectSubstitution subjectSubstitution) {
62 ignoredFields = new LinkedList();
63 this.subjectSubstitution = subjectSubstitution;
64 }
65
66 public void addIgnoredField(String field) {
67 ignoredFields.add(field);
68 }
69
70 /***
71 * Get the value of IgnoredFields. These are the tibrvfields that will be
72 * ignored when performing an equalsignore comparison operation.
73 * @return value of IgnoredFields.
74 */
75 public Set getIgnoredFields() {
76 return new HashSet(ignoredFields);
77 }
78
79 /***
80 * Set the value of IgnoredFields.
81 * @param ignoredFields The vector of field names in the message to ignore
82 * when performing comparison operations.
83 */
84 public void setIgnoredFields(Set ignoredFields) {
85 for (Iterator iter = ignoredFields.iterator(); iter.hasNext();) {
86 this.ignoredFields.add(iter.next());
87 }
88 }
89
90 public String getUri() {
91 return uri;
92 }
93
94 public void setUri(String uri) {
95 this.uri = uri;
96 }
97
98 public String getSubject() {
99 return subject;
100 }
101
102 public void setSubject(String subject) {
103 this.subject = subjectSubstitution.process(subject);
104 }
105
106 /***
107 * Get the name of this response message.
108 *
109 * @return a <code>String</code> value
110 */
111 public String getName() {
112 return name;
113 }
114
115 public void setName(String name) {
116 this.name = name;
117 }
118
119 /***
120 * Get the minimum number of messages expected on this subject.
121 * @return value of MinExpected.
122 */
123 public int getMinexpected() {
124 return minexpected;
125 }
126
127 /***
128 * Set the minimum number of messages expected on this subject.
129 * @param minexpected Value to assign to MinExpected.
130 */
131 public void setMinexpected(int minexpected) {
132 this.minexpected = minexpected;
133 }
134
135 /***
136 * Get the maximum number of messages expected on this subject.
137 * @return value of MaxExpected.
138 */
139 public int getMaxexpected() {
140 return maxexpected;
141 }
142
143 /***
144 * Set the maximum number of messages expected on this subject.
145 * @param maxexpected Value to assign to MaxExpected.
146 */
147 public void setMaxexpected(int maxexpected) {
148 this.maxexpected = maxexpected;
149 }
150
151 /***
152 * Get the value of comparisonMethod that will be used to
153 * compare message contents. This is either
154 * EQUALS, all tibrvfields must match, EQUALSIGNORE ignore certain tibrvfields,
155 * or NONE, meaning ingore all field values, just ensure a message
156 * was received on the subject.
157 * @return value of comparisonMethod.
158 */
159 public int getComparisonMethod() {
160 return comparisonMethod;
161 }
162
163 /***
164 * Set the value of comparisonMethod.
165 * @param comparisonMethod Value to assign to comparisonMethod.
166 */
167 public void setComparisonMethod(int comparisonMethod) {
168 this.comparisonMethod = comparisonMethod;
169 }
170
171 /***
172 * Get the expected TibrvMsg response message.
173 *
174 * @return The expected TibrvMsg.
175 */
176 public TibrvMsg getTibrvMsg() {
177 return tibrvMsg;
178 }
179
180 /***
181 * Set the expected TibrvMsg response message.
182 *
183 * @param tibrvMsg The expected TibrvMsg.
184 */
185 public void setTibrvMsg(TibrvMsg tibrvMsg) {
186 this.tibrvMsg = tibrvMsg;
187 }
188
189 /***
190 * todo should this be pulled to an interface? (m2ward)
191 *
192 * @see Stimulus
193 */
194 public void processRvMessage(RvMessage rvMessage) {
195 setTibrvMsg(rvMessage.convert());
196 }
197 }