1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.tests
.request
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
20 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequest
;
21 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequest
;
22 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequestStub
;
25 * <b><u>TmfEventRequestTest</u></b>
27 * Test suite for the TmfEventRequest class.
29 @SuppressWarnings("nls")
30 public class TmfEventRequestTest
extends TestCase
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 private static TmfTimeRange range1
= new TmfTimeRange(TmfTimeRange
.Eternity
);
37 private static TmfTimeRange range2
= new TmfTimeRange(new TmfTimestamp(), TmfTimestamp
.BigCrunch
);
39 private static TmfEventRequest
<TmfEvent
> fRequest1
;
40 private static TmfEventRequest
<TmfEvent
> fRequest1b
;
41 private static TmfEventRequest
<TmfEvent
> fRequest1c
;
42 private static TmfEventRequest
<TmfEvent
> fRequest2
;
43 private static TmfEventRequest
<TmfEvent
> fRequest3
;
44 private static TmfEventRequest
<TmfEvent
> fRequest4
;
46 private static int fRequestCount
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 public TmfEventRequestTest(String name
) {
57 protected void setUp() throws Exception
{
59 TmfDataRequest
.reset();
60 fRequest1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
61 fRequest2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range2
, 100, 200);
62 fRequest3
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range2
, 200, 200);
63 fRequest4
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range2
, 200, 300);
64 fRequest1b
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
65 fRequest1c
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
66 fRequestCount
= fRequest1c
.getRequestId() + 1;
70 protected void tearDown() throws Exception
{
74 private TmfEventRequest
<TmfEvent
> setupTestRequest(final boolean[] flags
) {
76 TmfEventRequest
<TmfEvent
> request
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, new TmfTimeRange(TmfTimeRange
.Eternity
), 100, 200) {
78 public void handleCompleted() {
79 super.handleCompleted();
83 public void handleSuccess() {
84 super.handleSuccess();
88 public void handleFailure() {
89 super.handleFailure();
93 public void handleCancel() {
101 // ------------------------------------------------------------------------
103 // ------------------------------------------------------------------------
105 public void testTmfEventRequest() {
106 TmfEventRequest
<TmfEvent
> request
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class);
108 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
109 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
111 assertEquals("StartTime", TmfTimestamp
.BigBang
, request
.getRange().getStartTime());
112 assertEquals("EndTime", TmfTimestamp
.BigCrunch
, request
.getRange().getEndTime());
114 assertEquals("getIndex", 0, request
.getIndex());
115 assertEquals("getNbRequestedEvents", TmfDataRequest
.ALL_DATA
, request
.getNbRequested());
117 assertFalse("isCompleted", request
.isCompleted());
118 assertFalse("isFailed", request
.isFailed());
119 assertFalse("isCancelled", request
.isCancelled());
121 assertEquals("getNbRead", 0, request
.getNbRead());
124 public void testTmfEventRequestTimeRange() {
125 TmfTimeRange range
= new TmfTimeRange(new TmfTimestamp(), TmfTimestamp
.BigCrunch
);
126 TmfEventRequest
<TmfEvent
> request
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range
);
128 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
129 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
131 assertEquals("StartTime", new TmfTimestamp(), request
.getRange().getStartTime());
132 assertEquals("EndTime", TmfTimestamp
.BigCrunch
, request
.getRange().getEndTime());
134 assertEquals("getIndex", 0, request
.getIndex());
135 assertEquals("getNbRequestedEvents", TmfDataRequest
.ALL_DATA
, request
.getNbRequested());
137 assertFalse("isCompleted", request
.isCompleted());
138 assertFalse("isFailed", request
.isFailed());
139 assertFalse("isCancelled", request
.isCancelled());
141 assertEquals("getNbRead", 0, request
.getNbRead());
144 public void testTmfEventRequestTimeRangeNbRequested() {
145 TmfTimeRange range
= new TmfTimeRange(new TmfTimestamp(), TmfTimestamp
.BigCrunch
);
146 TmfEventRequest
<TmfEvent
> request
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range
, 100);
148 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
149 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
151 assertEquals("StartTime", new TmfTimestamp(), request
.getRange().getStartTime());
152 assertEquals("EndTime", TmfTimestamp
.BigCrunch
, request
.getRange().getEndTime());
154 assertEquals("getIndex", 0, request
.getIndex());
155 assertEquals("getNbRequestedEvents", 100, request
.getNbRequested());
157 assertFalse("isCompleted", request
.isCompleted());
158 assertFalse("isFailed", request
.isFailed());
159 assertFalse("isCancelled", request
.isCancelled());
161 assertEquals("getNbRead", 0, request
.getNbRead());
164 public void testTmfEventRequestTimeRangeNbRequestedBlocksize() {
165 TmfTimeRange range
= new TmfTimeRange(new TmfTimestamp(), TmfTimestamp
.BigCrunch
);
166 TmfEventRequest
<TmfEvent
> request
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range
, 100, 200);
168 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
169 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
171 assertEquals("StartTime", new TmfTimestamp(), request
.getRange().getStartTime());
172 assertEquals("EndTime", TmfTimestamp
.BigCrunch
, request
.getRange().getEndTime());
174 assertEquals("getIndex", 0, request
.getIndex());
175 assertEquals("getNbRequestedEvents", 100, request
.getNbRequested());
177 assertFalse("isCompleted", request
.isCompleted());
178 assertFalse("isFailed", request
.isFailed());
179 assertFalse("isCancelled", request
.isCancelled());
181 assertEquals("getNbRead", 0, request
.getNbRead());
184 // ------------------------------------------------------------------------
186 // ------------------------------------------------------------------------
188 public void testEqualsReflexivity() throws Exception
{
189 assertTrue("equals", fRequest1
.equals(fRequest1
));
190 assertTrue("equals", fRequest2
.equals(fRequest2
));
192 assertFalse("equals", fRequest1
.equals(fRequest2
));
193 assertFalse("equals", fRequest2
.equals(fRequest1
));
196 public void testEqualsSymmetry() throws Exception
{
197 assertTrue("equals", fRequest1
.equals(fRequest1b
));
198 assertTrue("equals", fRequest1b
.equals(fRequest1
));
200 assertFalse("equals", fRequest1
.equals(fRequest3
));
201 assertFalse("equals", fRequest2
.equals(fRequest3
));
202 assertFalse("equals", fRequest3
.equals(fRequest1
));
203 assertFalse("equals", fRequest3
.equals(fRequest2
));
206 public void testEqualsTransivity() throws Exception
{
207 assertTrue("equals", fRequest1
.equals(fRequest1b
));
208 assertTrue("equals", fRequest1b
.equals(fRequest1c
));
209 assertTrue("equals", fRequest1
.equals(fRequest1c
));
212 public void testEqualsNull() throws Exception
{
213 assertFalse("equals", fRequest1
.equals(null));
214 assertFalse("equals", fRequest2
.equals(null));
217 // ------------------------------------------------------------------------
219 // ------------------------------------------------------------------------
221 public void testHashCode() throws Exception
{
222 assertTrue("hashCode", fRequest1
.hashCode() == fRequest1
.hashCode());
223 assertTrue("hashCode", fRequest2
.hashCode() == fRequest2
.hashCode());
224 assertTrue("hashCode", fRequest1
.hashCode() != fRequest2
.hashCode());
227 // ------------------------------------------------------------------------
229 // ------------------------------------------------------------------------
231 public void testToString() {
232 String expected1
= "[TmfEventRequest(0,TmfEvent," + range1
+ ",100)]";
233 String expected2
= "[TmfEventRequest(1,TmfEvent," + range2
+ ",100)]";
234 String expected3
= "[TmfEventRequest(2,TmfEvent," + range2
+ ",200)]";
235 String expected4
= "[TmfEventRequest(3,TmfEvent," + range2
+ ",200)]";
237 assertEquals("toString", expected1
, fRequest1
.toString());
238 assertEquals("toString", expected2
, fRequest2
.toString());
239 assertEquals("toString", expected3
, fRequest3
.toString());
240 assertEquals("toString", expected4
, fRequest4
.toString());
243 // ------------------------------------------------------------------------
245 // ------------------------------------------------------------------------
247 public void testDone() {
249 final boolean[] flags
= new boolean[4];
250 TmfEventRequest
<TmfEvent
> request
= setupTestRequest(flags
);
253 assertTrue ("isCompleted", request
.isCompleted());
254 assertFalse("isFailed", request
.isFailed());
255 assertFalse("isCancelled", request
.isCancelled());
257 assertTrue ("handleCompleted", flags
[0]);
258 assertTrue ("handleSuccess", flags
[1]);
259 assertFalse("handleFailure", flags
[2]);
260 assertFalse("handleCancel", flags
[3]);
263 // ------------------------------------------------------------------------
265 // ------------------------------------------------------------------------
267 public void testFail() {
269 final boolean[] flags
= new boolean[4];
270 TmfEventRequest
<TmfEvent
> request
= setupTestRequest(flags
);
273 assertTrue ("isCompleted", request
.isCompleted());
274 assertTrue ("isFailed", request
.isFailed());
275 assertFalse("isCancelled", request
.isCancelled());
277 assertTrue ("handleCompleted", flags
[0]);
278 assertFalse("handleSuccess", flags
[1]);
279 assertTrue ("handleFailure", flags
[2]);
280 assertFalse("handleCancel", flags
[3]);
283 // ------------------------------------------------------------------------
285 // ------------------------------------------------------------------------
287 public void testCancel() {
289 final boolean[] flags
= new boolean[4];
290 TmfEventRequest
<TmfEvent
> request
= setupTestRequest(flags
);
293 assertTrue ("isCompleted", request
.isCompleted());
294 assertFalse("isFailed", request
.isFailed());
295 assertTrue ("isCancelled", request
.isCancelled());
297 assertTrue ("handleCompleted", flags
[0]);
298 assertFalse("handleSuccess", flags
[1]);
299 assertFalse("handleFailure", flags
[2]);
300 assertTrue ("handleCancel", flags
[3]);
303 // ------------------------------------------------------------------------
305 // ------------------------------------------------------------------------
This page took 0.038155 seconds and 6 git commands to generate.