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.RvTestException;
35 import com.reuters.msgtest.config.RvTestConfiguration;
36 import com.tibco.tibrv.TibrvMsg;
37 import java.util.Collection;
38 import java.util.Iterator;
39 import java.util.LinkedList;
40 import java.util.List;
41
42
43 /***
44 * @author Michael Ward
45 */
46 public class Responses {
47 private List responses;
48 private RvTestConfiguration rvTestConfiguration;
49
50 public Responses(RvTestConfiguration rvTestConfiguration) {
51 this.rvTestConfiguration = rvTestConfiguration;
52 responses = new LinkedList();
53 }
54
55 /***
56 * Add a <code>Respnse</code> to the collection. Will create from a URI if
57 * applicable
58 *
59 * @param response
60 * a <code>Response</code> value
61 */
62 public void addResponse(Response response) {
63
64
65 if (response.getUri() != null) {
66 try {
67 List list = (List) rvTestConfiguration.create(response.getUri());
68
69 response.setTibrvMsg((TibrvMsg) list.get(0));
70 response.getTibrvMsg().setSendSubject(response.getSubject());
71
72
73 } catch (Exception e) {
74 throw new RuntimeException("Unable to create Messages", e);
75 }
76 }
77
78 responses.add(response);
79 }
80
81 /***
82 * Return a <code>Response</code> from the collection.
83 *
84 * @param i
85 * an <code>int</code> value
86 * @return a <code>Response</code> value
87 */
88 public Response getResponse(int i) {
89 return (Response) responses.get(i);
90 }
91
92 /***
93 * Return a <code>Response</code> from the collection with a given name.
94 * It return the first match if successful and null if no match was found.
95 *
96 * @param name
97 * The name of a Response to retrieve.
98 * @throws RvTestException
99 * If the response is not found
100 */
101 public Response getResponse(String name) throws RvTestException {
102 Iterator iterator = responses.iterator();
103
104 while (iterator.hasNext()) {
105 Response response = (Response) iterator.next();
106
107 if (name.equalsIgnoreCase(response.getName())) {
108 return response;
109 }
110 }
111
112 throw new RvTestException("Unknown response: " + name);
113 }
114
115 public Iterator iterator() {
116 return responses.iterator();
117 }
118
119 public int size() {
120 return responses.size();
121 }
122
123 public void addAll(Collection c) {
124 responses.addAll(c);
125 }
126 }