View Javadoc

1   /*
2    * Copyright (c) 2004, RV Test Team
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10   *
11   * Redistributions in binary form must reproduce the above copyright notice,
12   * this list of conditions and the following disclaimer in the documentation
13   * and/or other materials provided with the distribution.
14   *
15   * Neither the name of the "RV Test Team" nor the names of its contributors may
16   * be used to endorse or promote products derived from this software without
17   * specific prior written permission.
18   *
19   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29   * THE POSSIBILITY OF SUCH DAMAGE.
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 }