Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0aad2862811523dfc3eaa97a0fba45f68e27d2dc (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/*******************************************************************************
 * Copyright (c) 2013 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.orcs.api;

import static org.eclipse.osee.framework.core.enums.TransactionDetailsType.Baselined;
import static org.eclipse.osee.framework.core.enums.TransactionDetailsType.NonBaselined;
import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule;
import static org.eclipse.osee.orcs.api.TestBranches.CIS_Bld_1;
import static org.eclipse.osee.orcs.api.TestBranches.SAW_Bld_1;
import static org.junit.Assert.assertEquals;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import org.eclipse.osee.framework.core.data.ResultSet;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.TransactionDetailsType;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.orcs.ApplicationContext;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.data.ArtifactId;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.data.TransactionReadable;
import org.eclipse.osee.orcs.db.mock.OsgiService;
import org.eclipse.osee.orcs.search.Operator;
import org.eclipse.osee.orcs.search.QueryBuilder;
import org.eclipse.osee.orcs.search.QueryFactory;
import org.eclipse.osee.orcs.search.TransactionQuery;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.rules.TestRule;

/**
 * @author Roberto E. Escobar
 */
public class OrcsTxQueryTest {

   @Rule
   public TestRule osgi = integrationRule(this, "osee.demo.hsql");

   @Rule
   public TestName testName = new TestName();

   @OsgiService
   private OrcsApi orcsApi;

   private final static DateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
   private QueryFactory factory;

   @Before
   public void setup() {
      ApplicationContext context = null; // TODO use real application context
      factory = orcsApi.getQueryFactory(context);
   }

   @Test
   public void testGetAll() throws Exception {
      TransactionQuery query = factory.transactionQuery();

      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(24, results.size());
      assertEquals(24, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 1,  Baselined,    "2013-05-06 14:18:02.530", "System Root Branch Creation", 1, -1, 0);
      assertTx(it.next(), 2,  NonBaselined, "2013-05-06 14:18:05.205", "AddCommonBranchForClientDemo", 1, 0, 0);
      assertTx(it.next(), 3,  NonBaselined, "2013-05-06 14:18:05.393", "AddCommonBranchForClientDemo", 1, 0, 0);
      assertTx(it.next(), 4,  Baselined,    "2013-05-06 14:18:05.424", "Branch Creation for Common", 2, -1, 0);
      assertTx(it.next(), 5,  NonBaselined, "2013-05-06 14:18:05.487", "Add Types to Common Branch", 2, 0, 0);
      assertTx(it.next(), 6,  NonBaselined, "2013-05-06 14:18:06.454", "Add Common Branch", 2, 0, 0);
      assertTx(it.next(), 7,  NonBaselined, "2013-05-06 14:18:06.517", "Add Framework Access Model", 2, 0, 0);
      assertTx(it.next(), 8,  NonBaselined, "2013-05-06 14:18:06.720", "Add Dev Users", 2, 0, 0);
      assertTx(it.next(), 9,  NonBaselined, "2013-05-06 14:18:06.798", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 10, NonBaselined, "2013-05-06 14:18:06.860", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 11, NonBaselined, "2013-05-06 14:18:06.954", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 12, NonBaselined, "2013-05-06 14:18:07.032", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 13, NonBaselined, "2013-05-06 14:18:07.110", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 14, NonBaselined, "2013-05-06 14:18:07.204", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 16, NonBaselined, "2013-05-06 14:18:07.360", "AddSawBranch", 3, 0, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 18, NonBaselined, "2013-05-06 14:18:07.630", "AddCisBranch", 4, 0, 0);
      assertTx(it.next(), 19, NonBaselined, "2013-05-06 14:18:07.911", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 20, NonBaselined, "2013-05-06 14:18:08.775", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 21, NonBaselined, "2013-05-06 14:18:10.163", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 22, NonBaselined, "2013-05-06 14:18:11.564", "Populate Demo DB - Create Traceability", 3, 0, 0);
      assertTx(it.next(), 23, Baselined,    "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);
      //@formatter:on
   }

   @Test
   public void testGetByTxId() throws OseeCoreException {
      TransactionQuery query = factory.transactionQuery();
      query.andTxId(3, 23);

      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(2, results.size());
      assertEquals(2, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      assertTx(it.next(), 3, NonBaselined, "2013-05-06 14:18:05.393", "AddCommonBranchForClientDemo", 1, 0, 0);
      assertTx(it.next(), 23, Baselined, "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);

      Iterator<Integer> ids = query.getResultsAsIds().iterator();
      assertEquals(Integer.valueOf(3), ids.next());
      assertEquals(Integer.valueOf(23), ids.next());
   }

   @Test
   public void testGetByCommentEquals() throws OseeCoreException {
      TransactionQuery query = factory.transactionQuery();
      query.andCommentEquals("ClientUser");

      TransactionReadable actual = query.getResults().getExactlyOne();

      assertEquals(1, query.getCount());
      assertTx(actual, 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);
      assertEquals(Integer.valueOf(24), query.getResultsAsIds().getExactlyOne());
   }

   @Test
   public void testGetByCommentPatternEquals() throws OseeCoreException {
      TransactionQuery query = factory.transactionQuery();
      query.andCommentPattern("Branch Creation for.*");

      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(4, results.size());
      assertEquals(4, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 4,  Baselined,    "2013-05-06 14:18:05.424", "Branch Creation for Common", 2, -1, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 23, Baselined,    "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);      
      //@formatter:on

      Iterator<Integer> ids = query.getResultsAsIds().iterator();
      assertEquals(Integer.valueOf(4), ids.next());
      assertEquals(Integer.valueOf(15), ids.next());
      assertEquals(Integer.valueOf(17), ids.next());
      assertEquals(Integer.valueOf(23), ids.next());
   }

   @Test
   public void testGetByType() throws OseeCoreException {
      TransactionQuery query = factory.transactionQuery();

      query.andIs(Baselined);

      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(5, results.size());
      assertEquals(5, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 1,  Baselined,    "2013-05-06 14:18:02.530", "System Root Branch Creation", 1, -1, 0);
      assertTx(it.next(), 4,  Baselined,    "2013-05-06 14:18:05.424", "Branch Creation for Common", 2, -1, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 23, Baselined,    "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      //@formatter:on

      Iterator<Integer> ids = query.getResultsAsIds().iterator();
      assertEquals(Integer.valueOf(1), ids.next());
      assertEquals(Integer.valueOf(4), ids.next());
      assertEquals(Integer.valueOf(15), ids.next());
      assertEquals(Integer.valueOf(17), ids.next());
      assertEquals(Integer.valueOf(23), ids.next());
   }

   @Test
   public void testGetByBranchIds() throws OseeCoreException {
      TransactionQuery query = factory.transactionQuery();
      query.andBranchIds(5, 4);

      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(3, results.size());
      assertEquals(3, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 18, NonBaselined, "2013-05-06 14:18:07.630", "AddCisBranch", 4, 0, 0);
      assertTx(it.next(), 23, Baselined,    "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      //@formatter:on

      Iterator<Integer> ids = query.getResultsAsIds().iterator();
      assertEquals(Integer.valueOf(17), ids.next());
      assertEquals(Integer.valueOf(18), ids.next());
      assertEquals(Integer.valueOf(23), ids.next());
   }

   @Test
   public void testGetByBranchUuids() throws OseeCoreException {
      TransactionQuery query = factory.transactionQuery();
      query.andBranch(SAW_Bld_1, CIS_Bld_1);

      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(8, results.size());
      assertEquals(8, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 16, NonBaselined, "2013-05-06 14:18:07.360", "AddSawBranch", 3, 0, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 18, NonBaselined, "2013-05-06 14:18:07.630", "AddCisBranch", 4, 0, 0);
      assertTx(it.next(), 19, NonBaselined, "2013-05-06 14:18:07.911", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 20, NonBaselined, "2013-05-06 14:18:08.775", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 21, NonBaselined, "2013-05-06 14:18:10.163", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 22, NonBaselined, "2013-05-06 14:18:11.564", "Populate Demo DB - Create Traceability", 3, 0, 0);
      //@formatter:on

      Iterator<Integer> ids = query.getResultsAsIds().iterator();
      assertEquals(Integer.valueOf(15), ids.next());
      assertEquals(Integer.valueOf(16), ids.next());
      assertEquals(Integer.valueOf(17), ids.next());
      assertEquals(Integer.valueOf(18), ids.next());
      assertEquals(Integer.valueOf(19), ids.next());
      assertEquals(Integer.valueOf(20), ids.next());
      assertEquals(Integer.valueOf(21), ids.next());
      assertEquals(Integer.valueOf(22), ids.next());
   }

   @Test
   public void testGetLTIdOperators() throws OseeCoreException {
      TransactionQuery query = factory.transactionQuery();
      query.andTxId(Operator.LESS_THAN_EQ, 2);
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(2, results.size());
      assertEquals(2, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      assertTx(it.next(), 1, Baselined, "2013-05-06 14:18:02.530", "System Root Branch Creation", 1, -1, 0);
      assertTx(it.next(), 2, NonBaselined, "2013-05-06 14:18:05.205", "AddCommonBranchForClientDemo", 1, 0, 0);

      query = factory.transactionQuery();
      query.andTxId(Operator.LESS_THAN, 2);
      results = query.getResults();
      assertEquals(1, results.size());
      assertEquals(1, query.getCount());

      it = results.iterator();
      assertTx(it.next(), 1, Baselined, "2013-05-06 14:18:02.530", "System Root Branch Creation", 1, -1, 0);
   }

   @Test
   public void testGetGTIdOperators() throws OseeCoreException {
      TransactionQuery query = factory.transactionQuery();
      query.andTxId(Operator.GREATER_THAN_EQ, 21);
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(4, results.size());
      assertEquals(4, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      assertTx(it.next(), 21, NonBaselined, "2013-05-06 14:18:10.163",
         "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 22, NonBaselined, "2013-05-06 14:18:11.564", "Populate Demo DB - Create Traceability", 3, 0,
         0);
      assertTx(it.next(), 23, Baselined, "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);

      query = factory.transactionQuery();
      query.andTxId(Operator.GREATER_THAN, 21);
      results = query.getResults();
      assertEquals(3, results.size());
      assertEquals(3, query.getCount());

      it = results.iterator();
      assertTx(it.next(), 22, NonBaselined, "2013-05-06 14:18:11.564", "Populate Demo DB - Create Traceability", 3, 0,
         0);
      assertTx(it.next(), 23, Baselined, "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);

   }

   @Test
   public void testGetEQIdOperators() throws OseeCoreException {
      TransactionQuery query = factory.transactionQuery();
      query.andTxId(Operator.EQUAL, 21);
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(1, results.size());
      assertEquals(1, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      assertTx(it.next(), 21, NonBaselined, "2013-05-06 14:18:10.163",
         "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);

      query = factory.transactionQuery();
      query.andTxId(Operator.NOT_EQUAL, 10);
      results = query.getResults();
      assertEquals(23, results.size());
      assertEquals(23, query.getCount());

      it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 1,  Baselined,    "2013-05-06 14:18:02.530", "System Root Branch Creation", 1, -1, 0);
      assertTx(it.next(), 2,  NonBaselined, "2013-05-06 14:18:05.205", "AddCommonBranchForClientDemo", 1, 0, 0);
      assertTx(it.next(), 3,  NonBaselined, "2013-05-06 14:18:05.393", "AddCommonBranchForClientDemo", 1, 0, 0);
      assertTx(it.next(), 4,  Baselined,    "2013-05-06 14:18:05.424", "Branch Creation for Common", 2, -1, 0);
      assertTx(it.next(), 5,  NonBaselined, "2013-05-06 14:18:05.487", "Add Types to Common Branch", 2, 0, 0);
      assertTx(it.next(), 6,  NonBaselined, "2013-05-06 14:18:06.454", "Add Common Branch", 2, 0, 0);
      assertTx(it.next(), 7,  NonBaselined, "2013-05-06 14:18:06.517", "Add Framework Access Model", 2, 0, 0);
      assertTx(it.next(), 8,  NonBaselined, "2013-05-06 14:18:06.720", "Add Dev Users", 2, 0, 0);
      assertTx(it.next(), 9,  NonBaselined, "2013-05-06 14:18:06.798", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 11, NonBaselined, "2013-05-06 14:18:06.954", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 12, NonBaselined, "2013-05-06 14:18:07.032", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 13, NonBaselined, "2013-05-06 14:18:07.110", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 14, NonBaselined, "2013-05-06 14:18:07.204", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 16, NonBaselined, "2013-05-06 14:18:07.360", "AddSawBranch", 3, 0, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 18, NonBaselined, "2013-05-06 14:18:07.630", "AddCisBranch", 4, 0, 0);
      assertTx(it.next(), 19, NonBaselined, "2013-05-06 14:18:07.911", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 20, NonBaselined, "2013-05-06 14:18:08.775", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 21, NonBaselined, "2013-05-06 14:18:10.163", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 22, NonBaselined, "2013-05-06 14:18:11.564", "Populate Demo DB - Create Traceability", 3, 0, 0);
      assertTx(it.next(), 23, Baselined,    "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);
      //@formatter:on
   }

   @Test
   public void testGetTwoIdOperators() throws OseeCoreException {
      TransactionQuery query = factory.transactionQuery();
      query.andTxId(Operator.GREATER_THAN, 21, Operator.LESS_THAN, 23);
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(1, results.size());
      assertEquals(1, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      assertTx(it.next(), 22, NonBaselined, "2013-05-06 14:18:11.564", "Populate Demo DB - Create Traceability", 3, 0,
         0);

      query = factory.transactionQuery();
      query.andTxId(Operator.GREATER_THAN_EQ, 21, Operator.LESS_THAN_EQ, 23);
      results = query.getResults();
      assertEquals(3, results.size());
      assertEquals(3, query.getCount());

      it = results.iterator();
      assertTx(it.next(), 21, NonBaselined, "2013-05-06 14:18:10.163",
         "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 22, NonBaselined, "2013-05-06 14:18:11.564", "Populate Demo DB - Create Traceability", 3, 0,
         0);
      assertTx(it.next(), 23, Baselined, "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);

   }

   @Test
   public void testGetDateOperator() throws Exception {
      TransactionQuery query = factory.transactionQuery();
      Timestamp date = Timestamp.valueOf("2013-05-06 14:18:11.570");
      query.andDate(Operator.GREATER_THAN, date);
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(2, results.size());
      assertEquals(2, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      assertTx(it.next(), 23, Baselined, "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);

      query = factory.transactionQuery();
      query.andDate(Operator.LESS_THAN, date);
      results = query.getResults();
      assertEquals(22, results.size());
      assertEquals(22, query.getCount());

      it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 1,  Baselined,    "2013-05-06 14:18:02.530", "System Root Branch Creation", 1, -1, 0);
      assertTx(it.next(), 2,  NonBaselined, "2013-05-06 14:18:05.205", "AddCommonBranchForClientDemo", 1, 0, 0);
      assertTx(it.next(), 3,  NonBaselined, "2013-05-06 14:18:05.393", "AddCommonBranchForClientDemo", 1, 0, 0);
      assertTx(it.next(), 4,  Baselined,    "2013-05-06 14:18:05.424", "Branch Creation for Common", 2, -1, 0);
      assertTx(it.next(), 5,  NonBaselined, "2013-05-06 14:18:05.487", "Add Types to Common Branch", 2, 0, 0);
      assertTx(it.next(), 6,  NonBaselined, "2013-05-06 14:18:06.454", "Add Common Branch", 2, 0, 0);
      assertTx(it.next(), 7,  NonBaselined, "2013-05-06 14:18:06.517", "Add Framework Access Model", 2, 0, 0);
      assertTx(it.next(), 8,  NonBaselined, "2013-05-06 14:18:06.720", "Add Dev Users", 2, 0, 0);
      assertTx(it.next(), 9,  NonBaselined, "2013-05-06 14:18:06.798", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 10, NonBaselined, "2013-05-06 14:18:06.860", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 11, NonBaselined, "2013-05-06 14:18:06.954", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 12, NonBaselined, "2013-05-06 14:18:07.032", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 13, NonBaselined, "2013-05-06 14:18:07.110", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 14, NonBaselined, "2013-05-06 14:18:07.204", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 16, NonBaselined, "2013-05-06 14:18:07.360", "AddSawBranch", 3, 0, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 18, NonBaselined, "2013-05-06 14:18:07.630", "AddCisBranch", 4, 0, 0);
      assertTx(it.next(), 19, NonBaselined, "2013-05-06 14:18:07.911", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 20, NonBaselined, "2013-05-06 14:18:08.775", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 21, NonBaselined, "2013-05-06 14:18:10.163", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 22, NonBaselined, "2013-05-06 14:18:11.564", "Populate Demo DB - Create Traceability", 3, 0, 0);
      //@formatter:on
   }

   @Test
   public void testGetDateRange() throws Exception {
      TransactionQuery query = factory.transactionQuery();
      Timestamp date1 = Timestamp.valueOf("2013-05-06 14:18:07.110");
      Timestamp date2 = Timestamp.valueOf("2013-05-06 14:18:11.659");
      query.andDate(date1, date2);
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(11, results.size());
      assertEquals(11, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 13, NonBaselined, "2013-05-06 14:18:07.110", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 14, NonBaselined, "2013-05-06 14:18:07.204", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 16, NonBaselined, "2013-05-06 14:18:07.360", "AddSawBranch", 3, 0, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 18, NonBaselined, "2013-05-06 14:18:07.630", "AddCisBranch", 4, 0, 0);
      assertTx(it.next(), 19, NonBaselined, "2013-05-06 14:18:07.911", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 20, NonBaselined, "2013-05-06 14:18:08.775", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 21, NonBaselined, "2013-05-06 14:18:10.163", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 22, NonBaselined, "2013-05-06 14:18:11.564", "Populate Demo DB - Create Traceability", 3, 0, 0);
      assertTx(it.next(), 23, Baselined, "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      //@formatter:on
   }

   @Test
   public void testGetAuthorId() throws Exception {
      TransactionQuery query = factory.transactionQuery();
      query.andAuthorIds(-1);
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(5, results.size());
      assertEquals(5, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 1,  Baselined,    "2013-05-06 14:18:02.530", "System Root Branch Creation", 1, -1, 0);
      assertTx(it.next(), 4,  Baselined,    "2013-05-06 14:18:05.424", "Branch Creation for Common", 2, -1, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 23, Baselined,    "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      //@formatter:on

      query = factory.transactionQuery();
      query.andAuthorIds(-1, 17);
      results = query.getResults();
      assertEquals(6, results.size());
      assertEquals(6, query.getCount());

      it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 1,  Baselined,    "2013-05-06 14:18:02.530", "System Root Branch Creation", 1, -1, 0);
      assertTx(it.next(), 4,  Baselined,    "2013-05-06 14:18:05.424", "Branch Creation for Common", 2, -1, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 23, Baselined,    "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);
      //@formatter:on

      query = factory.transactionQuery();
      ArrayList<Integer> list = new ArrayList<Integer>(2);
      list.add(-1);
      list.add(17);
      query.andAuthorIds(list);
      results = query.getResults();
      assertEquals(6, results.size());
      assertEquals(6, query.getCount());

      it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 1,  Baselined,    "2013-05-06 14:18:02.530", "System Root Branch Creation", 1, -1, 0);
      assertTx(it.next(), 4,  Baselined,    "2013-05-06 14:18:05.424", "Branch Creation for Common", 2, -1, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 23, Baselined,    "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);
      //@formatter:on

   }

   @Test(expected = OseeArgumentException.class)
   public void testGetCommitId() throws Exception {
      TransactionQuery query = factory.transactionQuery();
      query.andNullCommitId();
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(24, query.getCount());
      assertEquals(24, results.size());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 1,  Baselined,    "2013-05-06 14:18:02.530", "System Root Branch Creation", 1, -1, 0);
      assertTx(it.next(), 2,  NonBaselined, "2013-05-06 14:18:05.205", "AddCommonBranchForClientDemo", 1, 0, 0);
      assertTx(it.next(), 3,  NonBaselined, "2013-05-06 14:18:05.393", "AddCommonBranchForClientDemo", 1, 0, 0);
      assertTx(it.next(), 4,  Baselined,    "2013-05-06 14:18:05.424", "Branch Creation for Common", 2, -1, 0);
      assertTx(it.next(), 5,  NonBaselined, "2013-05-06 14:18:05.487", "Add Types to Common Branch", 2, 0, 0);
      assertTx(it.next(), 6,  NonBaselined, "2013-05-06 14:18:06.454", "Add Common Branch", 2, 0, 0);
      assertTx(it.next(), 7,  NonBaselined, "2013-05-06 14:18:06.517", "Add Framework Access Model", 2, 0, 0);
      assertTx(it.next(), 8,  NonBaselined, "2013-05-06 14:18:06.720", "Add Dev Users", 2, 0, 0);
      assertTx(it.next(), 9,  NonBaselined, "2013-05-06 14:18:06.798", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 10, NonBaselined, "2013-05-06 14:18:06.860", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 11, NonBaselined, "2013-05-06 14:18:06.954", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 12, NonBaselined, "2013-05-06 14:18:07.032", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 13, NonBaselined, "2013-05-06 14:18:07.110", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 14, NonBaselined, "2013-05-06 14:18:07.204", "SimpleTemplateProviderTask", 2, 0, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 16, NonBaselined, "2013-05-06 14:18:07.360", "AddSawBranch", 3, 0, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 18, NonBaselined, "2013-05-06 14:18:07.630", "AddCisBranch", 4, 0, 0);
      assertTx(it.next(), 19, NonBaselined, "2013-05-06 14:18:07.911", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 20, NonBaselined, "2013-05-06 14:18:08.775", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 21, NonBaselined, "2013-05-06 14:18:10.163", "ArtifactImportOperationFactory: Artifact Import Wizard transaction", 3, 0, 0);
      assertTx(it.next(), 22, NonBaselined, "2013-05-06 14:18:11.564", "Populate Demo DB - Create Traceability", 3, 0, 0);
      assertTx(it.next(), 23, Baselined,    "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);
      //@formatter:on

      query = factory.transactionQuery();
      query.andCommitIds(-1, 1);
      results = query.getResults();
      assertEquals(0, results.size());
      assertEquals(0, query.getCount());

      query = factory.transactionQuery();
      ArrayList<Integer> list = new ArrayList<Integer>(2);
      list.add(1);
      list.add(2);
      query.andAuthorIds(list);
      results = query.getResults();
      assertEquals(0, results.size());
      assertEquals(0, query.getCount());

      /************************************************************
       * null not allowed in multiple argument case -- throws OseeArgumentException
       */
      query = factory.transactionQuery();
      query.andCommitIds(null, -1, 1);
      results = query.getResults();

   }

   @Test
   public void testGetHead() throws Exception {
      TransactionQuery query = factory.transactionQuery();
      query.andIsHead(1);
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(1, query.getCount());
      assertEquals(1, results.size());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
     assertTx(it.next(), 3,  NonBaselined, "2013-05-06 14:18:05.393", "AddCommonBranchForClientDemo", 1, 0, 0);
      //@formatter:on
   }

   @Test
   public void testGetHead2() throws Exception {
      TransactionQuery query = factory.transactionQuery();
      query.andIsHead(CoreBranches.COMMON);

      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(1, query.getCount());
      assertEquals(1, results.size());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);
      //@formatter:on
   }

   @Test
   public void testAuthorLocal() throws Exception {
      QueryFactory branchFactory = orcsApi.getQueryFactory(null);
      QueryBuilder branchQuery = branchFactory.fromBranch(CoreBranches.COMMON);
      /*********************************************************
       * Only valid user is 17
       */
      Integer seventeen = new Integer(17);
      branchQuery.andLocalIds(Arrays.asList(seventeen));
      ResultSet<ArtifactReadable> userIds = branchQuery.getResults();
      Iterator<ArtifactReadable> itUsers = userIds.iterator();
      ArtifactId user17 = itUsers.next();

      TransactionQuery query = factory.transactionQuery();
      query.andAuthorLocalIds(user17);
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(1, query.getCount());
      assertEquals(1, results.size());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);
      //@formatter:on

      /**********************************************************
       * Only valid user is 17. Verify the multiple entry by entering the same user twice
       */
      query = factory.transactionQuery();
      query.andAuthorLocalIds(user17, user17);
      results = query.getResults();
      assertEquals(1, query.getCount());
      assertEquals(1, results.size());

      it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 24, NonBaselined, "2013-05-06 14:18:18.542", "ClientUser", 2, 17, 0);
      //@formatter:on  
   }

   @Test
   public void testMultifield() throws Exception {
      TransactionQuery query = factory.transactionQuery();
      query.andAuthorIds(-1);
      query.andIs(Baselined);
      query.andCommentPattern("Branch Creation for.*");
      ResultSet<TransactionReadable> results = query.getResults();
      assertEquals(4, results.size());
      assertEquals(4, query.getCount());

      Iterator<TransactionReadable> it = results.iterator();
      //@formatter:off
      assertTx(it.next(), 4,  Baselined,    "2013-05-06 14:18:05.424", "Branch Creation for Common", 2, -1, 0);
      assertTx(it.next(), 15, Baselined,    "2013-05-06 14:18:07.235", "Branch Creation for SAW_Bld_1", 3, -1, 0);
      assertTx(it.next(), 17, Baselined,    "2013-05-06 14:18:07.516", "Branch Creation for CIS_Bld_1", 4, -1, 0);
      assertTx(it.next(), 23, Baselined,    "2013-05-06 14:18:11.659", "Branch Creation for SAW_Bld_2", 5, -1, 0);
      //@formatter:on
   }

   private static void assertTx(TransactionReadable actual, int localId, TransactionDetailsType type, String date, String comment, int branchId, int authorId, int commitId) {
      assertEquals(localId, actual.getLocalId());
      assertEquals(type, actual.getTxType());
      assertEquals(date, DATE_FORMATTER.format(actual.getDate()));
      assertEquals(comment, actual.getComment());

      assertEquals(authorId, actual.getAuthorId());
      assertEquals(branchId, actual.getBranchId());
      assertEquals(commitId, actual.getCommit());
   }
}

Back to the top