Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8df8f8d4e199f7ba5edfdd295f8365e822ba7997 (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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
/*******************************************************************************
 * Copyright (c) 2012 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.CoreArtifactTypes.Component;
import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.GeneralDocument;
import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import static org.eclipse.osee.framework.core.enums.CoreRelationTypes.Default_Hierarchical__Child;
import static org.eclipse.osee.framework.core.enums.CoreRelationTypes.Default_Hierarchical__Parent;
import static org.eclipse.osee.framework.core.enums.CoreRelationTypes.Dependency__Artifact;
import static org.eclipse.osee.framework.core.enums.CoreRelationTypes.Dependency__Dependency;
import static org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC;
import static org.eclipse.osee.framework.core.enums.SystemUser.OseeSystem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import java.util.Arrays;
import java.util.Iterator;
import java.util.concurrent.Callable;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.TokenFactory;
import org.eclipse.osee.framework.core.data.TransactionId;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.enums.DeletionFlag;
import org.eclipse.osee.framework.core.enums.SystemUser;
import org.eclipse.osee.framework.core.enums.TransactionDetailsType;
import org.eclipse.osee.framework.core.util.OsgiUtil;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.OrcsBranch;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.data.AttributeReadable;
import org.eclipse.osee.orcs.data.BranchReadable;
import org.eclipse.osee.orcs.data.TransactionReadable;
import org.eclipse.osee.orcs.db.mock.OrcsIntegrationByClassRule;
import org.eclipse.osee.orcs.db.mock.TestDatabase;
import org.eclipse.osee.orcs.search.QueryBuilder;
import org.eclipse.osee.orcs.search.QueryFactory;
import org.eclipse.osee.orcs.search.TransactionQuery;
import org.eclipse.osee.orcs.transaction.TransactionBuilder;
import org.eclipse.osee.orcs.transaction.TransactionFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestName;

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

   @Rule
   public ExpectedException thrown = ExpectedException.none();

   @Rule
   public final TestName testName = new TestName();

   private static TestDatabase db;
   private static TransactionFactory txFactory;
   private static final ArtifactId userArtifact = OseeSystem;
   private static OrcsBranch orcsBranch;
   private static QueryFactory query;

   private static ArtifactId artifact1;
   private static ArtifactId artifact2;
   private static TransactionId[] transactions;

   @BeforeClass
   public static void setUp() throws Exception {
      db = new TestDatabase(OrcsTransactionTest.class.getName(), "for whole class", "orcs.jdbc.service");
      db.initialize();
      OrcsApi orcsApi = OsgiUtil.getService(OrcsTransactionTest.class, OrcsApi.class);
      txFactory = orcsApi.getTransactionFactory();
      orcsBranch = orcsApi.getBranchOps();
      query = orcsApi.getQueryFactory();
      setupHistory();
   }

   @AfterClass
   public static void cleanup() throws Exception {
      db.cleanup();
   }

   @Test
   public void testWritingUriAttribute() throws OseeCoreException {
      final String requirementText = "The engine torque shall be directly controllable through the engine control unit";

      TransactionBuilder tx = createTx();

      ArtifactId torqueRequirement =
         tx.createArtifact(CoreArtifactTypes.SoftwareRequirementPlainText, "Engine Torque Control");
      tx.createAttribute(torqueRequirement, CoreAttributeTypes.PlainTextContent, requirementText);

      tx.commit();

      ResultSet<ArtifactReadable> results =
         query.fromBranch(COMMON).andIsOfType(CoreArtifactTypes.SoftwareRequirementPlainText).getResults();

      Optional<ArtifactReadable> item = Iterables.tryFind(results, new Predicate<ArtifactReadable>() {
         @Override
         public boolean apply(ArtifactReadable artifact) {
            String data = "";
            try {
               data = artifact.getSoleAttributeAsString(CoreAttributeTypes.PlainTextContent, "");
            } catch (OseeCoreException ex) {
               fail(Lib.exceptionToString(ex));
            }
            return requirementText.equals(data);
         }
      });

      assertTrue(item.isPresent());
      assertEquals(torqueRequirement.getGuid(), item.get().getGuid());
   }

   @Test
   public void testCreateArtifact() throws OseeCoreException {
      String comment = "Test Artifact Write";
      String expectedName = "Create A Folder";
      String expectedAnnotation = "Annotate It";

      query.branchQuery();

      TransactionQuery transactionQuery = query.transactionQuery();
      TransactionReadable previousTx = transactionQuery.andIsHead(COMMON).getResults().getExactlyOne();

      TransactionBuilder tx = txFactory.createTransaction(COMMON, userArtifact, comment);

      ArtifactId artifactId = tx.createArtifact(CoreArtifactTypes.Folder, expectedName);

      tx.setAttributesFromStrings(artifactId, CoreAttributeTypes.Annotation, expectedAnnotation);
      assertEquals(expectedName, artifactId.getName());

      TransactionReadable newTx = tx.commit();
      assertFalse(tx.isCommitInProgress());

      TransactionReadable newHeadTx = transactionQuery.andIsHead(COMMON).getResults().getExactlyOne();

      assertEquals(newTx, newHeadTx);

      TransactionReadable newTxReadable = transactionQuery.andTxId(newTx).getResults().getExactlyOne();
      checkTransaction(previousTx, newTxReadable, COMMON, comment, userArtifact);

      ResultSet<ArtifactReadable> result = query.fromBranch(COMMON).andIds(artifactId).getResults();

      ArtifactReadable artifact = result.getExactlyOne();

      assertEquals(expectedAnnotation, artifact.getAttributeValues(CoreAttributeTypes.Annotation).iterator().next());
      assertEquals(expectedName, artifact.getName());
      assertEquals(expectedAnnotation, artifact.getAttributeValues(CoreAttributeTypes.Annotation).iterator().next());
      assertEquals(artifactId.getGuid(), artifact.getGuid());
   }

   @Test
   public void testCreateArtifactWithoutTagger() throws OseeCoreException {
      String comment = "Test Artifact with untagged attribute";
      String expectedName = "Create An Artifact";
      String expectedAnnotation = "Annotate It";
      String expectedQualifaction = "Test";

      query.branchQuery();

      TransactionQuery transactionQuery = query.transactionQuery();
      transactionQuery.andIsHead(COMMON).getResults().getExactlyOne();

      TransactionBuilder tx = txFactory.createTransaction(COMMON, userArtifact, comment);

      ArtifactId artifactId = tx.createArtifact(CoreArtifactTypes.SubsystemRequirementHTML, expectedName);

      tx.setAttributesFromStrings(artifactId, CoreAttributeTypes.Annotation, expectedAnnotation);
      tx.setAttributesFromStrings(artifactId, CoreAttributeTypes.QualificationMethod, expectedQualifaction);
      assertEquals(expectedName, artifactId.getName());

      tx.commit();

      ArtifactReadable artifactReadable = query.fromBranch(COMMON).andIds(artifactId).getResults().getExactlyOne();
      assertEquals(expectedName, artifactReadable.getName());
      assertEquals(expectedQualifaction,
         artifactReadable.getSoleAttributeAsString(CoreAttributeTypes.QualificationMethod));

   }

   @Test
   public void testCopyArtifact() throws Exception {
      ArtifactReadable user = query.fromBranch(COMMON).andIds(SystemUser.Anonymous).getResults().getExactlyOne();

      // duplicate on same branch
      TransactionBuilder transaction1 = createTx();
      ArtifactId duplicate = transaction1.copyArtifact(user);
      transaction1.commit();
      ArtifactReadable userDup = query.fromBranch(COMMON).andIds(duplicate).getResults().getExactlyOne();

      assertNotSame(SystemUser.Anonymous.getGuid(), userDup.getGuid());
      assertEquals(SystemUser.Anonymous.getName(), userDup.getName());

      // duplicate on different branch
      IOseeBranch branchToken = TokenFactory.createBranch("DuplicateArtifact tests");
      Callable<BranchReadable> callableBranch = orcsBranch.createTopLevelBranch(branchToken, userArtifact);

      BranchReadable topLevelBranch = callableBranch.call();

      TransactionBuilder transaction2 =
         txFactory.createTransaction(topLevelBranch, userArtifact, testName.getMethodName());
      duplicate = transaction2.copyArtifact(user);
      transaction2.commit();
      userDup = query.fromBranch(topLevelBranch).andIds(duplicate).getResults().getExactlyOne();

      assertNotSame(SystemUser.Anonymous.getGuid(), userDup.getGuid());
      assertEquals(SystemUser.Anonymous.getName(), userDup.getName());
   }

   @Test
   public void testIntroduceArtifact() throws Exception {
      ArtifactReadable user = query.fromBranch(COMMON).andIds(SystemUser.Anonymous).getResults().getExactlyOne();

      IOseeBranch branchToken = TokenFactory.createBranch("IntroduceArtifact tests");
      BranchReadable topLevelBranch = orcsBranch.createTopLevelBranch(branchToken, userArtifact).call();

      TransactionBuilder transaction =
         txFactory.createTransaction(topLevelBranch, userArtifact, testName.getMethodName());
      transaction.introduceArtifact(COMMON, user);
      transaction.commit();

      ArtifactReadable introduced =
         query.fromBranch(topLevelBranch).andIds(SystemUser.Anonymous).getResults().getExactlyOne();
      assertEquals(user.getLocalId(), introduced.getLocalId());
   }

   @Test
   public void testIntroduceOnSameBranch() throws OseeCoreException {
      ArtifactReadable user = query.fromBranch(COMMON).andIds(SystemUser.Anonymous).getResults().getExactlyOne();

      TransactionBuilder tx = createTx();

      thrown.expect(OseeArgumentException.class);
      tx.introduceArtifact(COMMON, user);
   }

   @Test
   public void testReadAfterWrite() throws OseeCoreException {
      QueryBuilder queryBuilder = query.fromBranch(COMMON).andIds(OseeSystem);

      ArtifactReadable oseeSystem = queryBuilder.getResults().getExactlyOne();

      TransactionBuilder tx = createTx();
      tx.setSoleAttributeFromString(oseeSystem, CoreAttributeTypes.Name, "Test");
      tx.commit();

      ArtifactReadable newGuest = queryBuilder.getResults().getExactlyOne();

      assertEquals(OseeSystem.getName(), oseeSystem.getName());
      assertEquals("Test", newGuest.getName());
   }

   @Test
   public void testDeleteArtifact() throws OseeCoreException {
      TransactionBuilder tx = createTx();
      ArtifactId artifact = tx.createArtifact(CoreArtifactTypes.AccessControlModel, "deleteMe");
      tx.commit();

      ArtifactReadable toDelete = query.fromBranch(COMMON).andIds(artifact).getResults().getExactlyOne();

      tx = txFactory.createTransaction(COMMON, userArtifact, testName.getMethodName());
      tx.deleteArtifact(toDelete);
      tx.commit();

      toDelete = query.fromBranch(COMMON).andIds(artifact).includeDeletedArtifacts().getResults().getOneOrNull();
      assertNotNull(toDelete);
      assertTrue(toDelete.isHardDeleted());
   }

   @Test
   public void testDeleteAttribute() throws OseeCoreException {
      TransactionBuilder tx = createTx();
      ArtifactId artifact = tx.createArtifact(CoreArtifactTypes.AccessControlModel, "deleteThis");
      tx.createAttribute(artifact, CoreAttributeTypes.GeneralStringData, "deleted Name");
      tx.createAttribute(artifact, CoreAttributeTypes.PublishInline, true);
      tx.commit();

      tx = createTx();
      tx.deleteAttributes(artifact, CoreAttributeTypes.GeneralStringData);
      tx.commit();

      QueryBuilder builder = query.fromBranch(COMMON);
      builder.andExists(CoreAttributeTypes.GeneralStringData);
      builder.andIds(artifact);
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      assertEquals(0, artifacts.size());
      builder = query.fromBranch(COMMON);
      builder.andExists(CoreAttributeTypes.GeneralStringData);
      builder.andIds(artifact);
      builder.includeDeletedAttributes();
      artifacts = builder.getResults();
      assertEquals(1, artifacts.size());
      builder = query.fromBranch(COMMON);
      builder.andExists(CoreAttributeTypes.Annotation);
      builder.andIds(artifact);
      builder.includeDeletedAttributes();
      artifacts = builder.getResults();
      assertEquals(0, artifacts.size());

      ArtifactReadable toDelete = query.fromBranch(COMMON).andIds(artifact).getResults().getExactlyOne();

      tx = createTx();
      tx.deleteArtifact(toDelete);
      tx.commit();

      toDelete = query.fromBranch(COMMON).andIds(artifact).includeDeletedArtifacts().getResults().getOneOrNull();
      assertNotNull(toDelete);
      assertTrue(toDelete.isHardDeleted());

   }

   private static void setupHistory() {
      TransactionBuilder tx = txFactory.createTransaction(COMMON, userArtifact, "create art 1 and 2");
      artifact1 = tx.createArtifact(CoreArtifactTypes.AccessControlModel, "deleteThis");
      tx.createAttribute(artifact1, CoreAttributeTypes.GeneralStringData, "deleted Name");
      tx.createAttribute(artifact1, CoreAttributeTypes.PublishInline, true);
      artifact2 = tx.createArtifact(CoreArtifactTypes.Folder, "deleteThisFolder");
      tx.createAttribute(artifact2, CoreAttributeTypes.Annotation, "annotation");
      tx.relate(artifact2, Default_Hierarchical__Parent, artifact1);
      TransactionId tx1 = tx.commit();

      tx = txFactory.createTransaction(COMMON, userArtifact, "delete art 1 attribute");
      tx.deleteAttributes(artifact1, CoreAttributeTypes.GeneralStringData);
      TransactionId tx2 = tx.commit();

      ArtifactReadable toDelete = query.fromBranch(COMMON).andIds(artifact1).getResults().getExactlyOne();

      tx = txFactory.createTransaction(COMMON, userArtifact, "delete art 1");
      tx.deleteArtifact(toDelete);
      tx.deleteAttributes(artifact2, CoreAttributeTypes.Annotation);
      tx.unrelate(artifact2, Default_Hierarchical__Parent, artifact1);
      TransactionId tx3 = tx.commit();

      toDelete = query.fromBranch(COMMON).andIds(artifact2).getResults().getExactlyOne();

      tx = txFactory.createTransaction(COMMON, userArtifact, "delete art 2");
      tx.deleteArtifact(toDelete);
      TransactionId tx4 = tx.commit();

      toDelete = query.fromBranch(COMMON).andIds(artifact1).includeDeletedArtifacts().getResults().getOneOrNull();
      assertNotNull(toDelete);
      assertTrue(toDelete.isHardDeleted());
      transactions = new TransactionId[] {tx1, tx2, tx3, tx4};
   }

   @Test
   public void testHistoricalArtifactsCreated() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[0]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact1, artifact2);
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, artifact1, artifact2);
   }

   @Test
   public void testHistoricalOneArtifactDeleted() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[2]);
      builder.andIds(artifact1, artifact2);
      verifyHistoricalArtifacts(builder.getResults(), null, artifact2);
   }

   @Test
   public void testHistoricalDeletedAttribute() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[1]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact1, artifact2);
      // test the historical count query
      int count = builder.getCount();
      assertEquals(1, count);
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, null, artifact2);
   }

   @Test
   public void testHistoricalOneArtifactDeletedAttribute() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[1]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact1);
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, null, null);
   }

   @Test
   public void testHistoricalIncludeDeletedAttribute() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[1]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact1);
      builder.includeDeletedAttributes();
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, artifact1, null);
   }

   @Test
   public void testHistoricalTwoArtifactsIncludeDeletedAttribute() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[1]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact2, artifact1);
      builder.includeDeletedAttributes();
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, artifact1, artifact2);
   }

   @Test
   public void testHistoricalAllowDeletedArtifactsDeletedAttributes() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[2]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact1, artifact2);
      builder.includeDeletedArtifacts();
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, null, null);
   }

   @Test
   public void testHistoricalAllowDeletedArtifactsNondeletedAttribute() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[2]);
      builder.andExists(CoreAttributeTypes.PublishInline, CoreAttributeTypes.Annotation);
      builder.andIds(artifact1, artifact2);
      builder.includeDeletedArtifacts();
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, artifact1, null);
   }

   @Test
   public void testHistoricalRelation() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[1]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact2, artifact1);
      builder.includeDeletedAttributes();
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, artifact1, artifact2);
      Iterator<ArtifactReadable> iter = artifacts.iterator();
      ArtifactReadable artifact1Actual = iter.next();
      if (!artifact1Actual.equals(artifact2)) {
         artifact1Actual = iter.next();
      }
      builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[1]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact1, artifact2);
      builder.includeDeletedArtifacts();
      builder.includeDeletedAttributes();
      builder.andRelatedTo(Default_Hierarchical__Parent, artifact1Actual);
      artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, artifact1, null);
   }

   @Test
   public void testHistoricalDeletedRelation() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[1]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact2, artifact1);
      builder.includeDeletedAttributes();
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, artifact1, artifact2);
      Iterator<ArtifactReadable> iter = artifacts.iterator();
      ArtifactReadable artifact1Actual = iter.next();
      if (!artifact1Actual.equals(artifact2)) {
         artifact1Actual = iter.next();
      }
      builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[2]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact1, artifact2);
      builder.includeDeletedArtifacts();
      builder.includeDeletedAttributes();
      builder.andRelatedTo(Default_Hierarchical__Parent, artifact1Actual);
      artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, null, null);
   }

   @Test
   public void testHistoricalAllowDeletedRelation() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[1]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact2, artifact1);
      builder.includeDeletedAttributes();
      ResultSet<ArtifactReadable> artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, artifact1, artifact2);
      Iterator<ArtifactReadable> iter = artifacts.iterator();
      ArtifactReadable artifact1Actual = iter.next();
      if (!artifact1Actual.equals(artifact2)) {
         artifact1Actual = iter.next();
      }
      builder = query.fromBranch(COMMON);
      builder.fromTransaction(transactions[2]);
      builder.andExists(CoreAttributeTypes.GeneralStringData, CoreAttributeTypes.Annotation);
      builder.andIds(artifact1, artifact2);
      builder.includeDeletedArtifacts();
      builder.includeDeletedAttributes();
      builder.includeDeletedRelations();
      builder.andRelatedTo(Default_Hierarchical__Parent, artifact1Actual);
      artifacts = builder.getResults();
      verifyHistoricalArtifacts(artifacts, artifact1, null);
   }

   public void verifyHistoricalArtifacts(ResultSet<ArtifactReadable> artifacts, ArtifactId artifact, ArtifactId artifact1) throws OseeCoreException {
      int size = artifacts.size();
      int expectedSize = 0;
      if (artifact != null) {
         expectedSize++;
      }
      if (artifact1 != null) {
         expectedSize++;
      }
      assertEquals(expectedSize, size);
      if (size > 0) {
         for (ArtifactReadable art : artifacts) {
            if (artifact != null && art.matches(artifact)) {
               assertEquals(1,
                  art.getAttributeCount(CoreAttributeTypes.GeneralStringData, DeletionFlag.INCLUDE_DELETED));
               assertEquals(1, art.getAttributeCount(CoreAttributeTypes.PublishInline, DeletionFlag.INCLUDE_DELETED));
            } else if (artifact1 != null && art.matches(artifact1)) {
               assertEquals(1, art.getAttributeCount(CoreAttributeTypes.Annotation, DeletionFlag.INCLUDE_DELETED));
            } else {
               assertTrue("Unexpected artifact", false);
            }
         }
      }
   }

   @Test
   public void testArtifactGetTransaction() throws OseeCoreException {
      TransactionBuilder tx = createTx();

      ArtifactId artId = tx.createArtifact(CoreArtifactTypes.Component, "A component");
      TransactionId startingTx = tx.commit();

      ArtifactReadable artifact = query.fromBranch(COMMON).andId(artId).getResults().getExactlyOne();
      assertEquals(startingTx, artifact.getTransaction());

      TransactionBuilder tx2 = createTx();
      tx2.setName(artifact, "Modified - component");
      TransactionId lastTx = tx2.commit();

      assertFalse(startingTx.equals(lastTx));

      ArtifactReadable currentArtifact = query.fromBranch(COMMON).andId(artId).getResults().getExactlyOne();
      assertEquals(lastTx, currentArtifact.getTransaction());
   }

   @Test
   public void testRelate() throws OseeCoreException {
      TransactionBuilder tx1 = createTx();
      ArtifactId art1 = tx1.createArtifact(CoreArtifactTypes.Component, "A component");
      ArtifactId art2 = tx1.createArtifact(CoreArtifactTypes.User, "User Artifact");
      tx1.relate(art1, CoreRelationTypes.Users_User, art2);
      tx1.commit();

      ArtifactReadable artifact = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      assertEquals("A component", artifact.getName());

      ResultSet<ArtifactReadable> related = artifact.getRelated(CoreRelationTypes.Users_User);
      assertEquals(1, related.size());
      assertEquals("User Artifact", related.getExactlyOne().getName());
   }

   @Test
   public void testRelateTypeCheckException() throws OseeCoreException {
      TransactionBuilder tx1 = createTx();
      ArtifactId art1 = tx1.createArtifact(CoreArtifactTypes.Component, "A component");
      ArtifactId art2 = tx1.createArtifact(CoreArtifactTypes.User, "User Artifact");

      thrown.expect(OseeArgumentException.class);
      thrown.expectMessage("Relation validity error for [artifact type[Component]");
      thrown.expectMessage("only items of type [User] are allowed");
      tx1.relate(art2, CoreRelationTypes.Users_User, art1);
   }

   @Test
   public void testRelateWithSortType() throws OseeCoreException {
      TransactionBuilder tx1 = createTx();
      ArtifactId art1 = tx1.createArtifact(CoreArtifactTypes.Component, "A component");
      ArtifactId art2 = tx1.createArtifact(CoreArtifactTypes.Component, "B component");
      ArtifactId art3 = tx1.createArtifact(CoreArtifactTypes.Component, "C component");
      tx1.addChildren(art1, art2, art3);
      TransactionId tx1Id = tx1.commit();

      QueryBuilder art1Query = query.fromBranch(COMMON).andIds(art1);

      ArtifactReadable artifact = art1Query.getResults().getExactlyOne();
      assertEquals("A component", artifact.getName());
      assertEquals(tx1Id, artifact.getTransaction());

      ResultSet<ArtifactReadable> children = artifact.getChildren();
      assertEquals(2, children.size());

      Iterator<ArtifactReadable> iterator = children.iterator();
      assertEquals("B component", iterator.next().getName());
      assertEquals("C component", iterator.next().getName());

      TransactionBuilder tx2 = createTx();
      ArtifactId art4 = tx2.createArtifact(Component, "D component");
      tx2.relate(art1, Default_Hierarchical__Child, art4, LEXICOGRAPHICAL_DESC);
      TransactionId tx2Id = tx2.commit();

      ArtifactReadable artifact21 = art1Query.getResults().getExactlyOne();
      assertEquals("A component", artifact21.getName());
      assertEquals(tx2Id, artifact21.getTransaction());

      ResultSet<ArtifactReadable> children2 = artifact21.getChildren();
      assertEquals(3, children2.size());

      Iterator<ArtifactReadable> iterator2 = children2.iterator();
      assertEquals("D component", iterator2.next().getName());
      assertEquals("C component", iterator2.next().getName());
      assertEquals("B component", iterator2.next().getName());
   }

   @Test
   public void testSetRelations() throws OseeCoreException {
      TransactionBuilder tx1 = createTx();
      ArtifactId art1 = tx1.createArtifact(Component, "A component");
      ArtifactId art2 = tx1.createArtifact(Component, "B component");
      ArtifactId art3 = tx1.createArtifact(Component, "C component");
      ArtifactId art4 = tx1.createArtifact(Component, "D component");
      tx1.addChildren(art1, art2);
      tx1.commit();

      ArtifactReadable artifact1 = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      assertEquals("A component", artifact1.getName());

      ResultSet<ArtifactReadable> children = artifact1.getChildren();
      assertEquals(1, children.size());

      Iterator<ArtifactReadable> iterator = children.iterator();
      ArtifactReadable artifact2 = children.iterator().next();

      assertEquals("B component", artifact2.getName());
      assertEquals(artifact1, artifact2.getParent());
      assertEquals(art2, artifact2);

      TransactionBuilder tx2 = createTx();
      tx2.setRelations(art1, Default_Hierarchical__Child, Arrays.asList(art3, art4));
      tx2.commit();

      artifact1 = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      assertEquals("A component", artifact1.getName());

      children = artifact1.getChildren();
      assertEquals(2, children.size());

      iterator = children.iterator();
      ArtifactReadable artifact3 = iterator.next();
      ArtifactReadable artifact4 = iterator.next();

      assertEquals("C component", artifact3.getName());
      assertEquals("D component", artifact4.getName());

      assertEquals(artifact1, artifact3.getParent());
      assertEquals(artifact1, artifact4.getParent());

      assertEquals(art3, artifact3);
      assertEquals(art4, artifact4);

      artifact2 = query.fromBranch(COMMON).andIds(art2).getResults().getExactlyOne();
      assertEquals("B component", artifact2.getName());
      assertNull(artifact2.getParent());
      assertEquals(art2, artifact2);
   }

   @Test
   public void testAddChildren() throws OseeCoreException {
      TransactionBuilder tx1 = createTx();
      ArtifactId art1 = tx1.createArtifact(Component, "A component");
      ArtifactId art2 = tx1.createArtifact(Component, "C component");
      ArtifactId art3 = tx1.createArtifact(Component, "B component");
      tx1.commit();

      TransactionBuilder tx2 = createTx();
      tx2.addChildren(art1, art2, art3);
      tx2.commit();

      ArtifactReadable artifact1 = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      assertEquals("A component", artifact1.getName());

      ResultSet<ArtifactReadable> children = artifact1.getChildren();
      assertEquals(2, children.size());

      Iterator<ArtifactReadable> iterator = children.iterator();
      ArtifactReadable artifact3 = iterator.next();
      ArtifactReadable artifact2 = iterator.next();

      assertEquals(art3, artifact3);
      assertEquals(art2, artifact2);

      assertEquals("B component", artifact3.getName());
      assertEquals("C component", artifact2.getName());

      assertEquals(artifact1, artifact2.getParent());
      assertEquals(artifact1, artifact3.getParent());
   }

   @Test
   public void testSetRationale() throws OseeCoreException {
      String rationale = "This is my rationale";

      TransactionBuilder tx1 = createTx();
      ArtifactId art1 = tx1.createArtifact(Component, "A component");
      ArtifactId art2 = tx1.createArtifact(Component, "B component");

      tx1.relate(art1, Default_Hierarchical__Child, art2);
      tx1.setRationale(art1, Default_Hierarchical__Child, art2, rationale);

      tx1.commit();

      ArtifactReadable artifact = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      assertEquals("A component", artifact.getName());

      ResultSet<ArtifactReadable> children = artifact.getChildren();
      assertEquals(1, children.size());

      ArtifactReadable otherArtifact = children.getExactlyOne();
      assertEquals("B component", otherArtifact.getName());

      String actual1 = artifact.getRationale(Default_Hierarchical__Child, otherArtifact);
      assertEquals(rationale, actual1);

      String actual2 = otherArtifact.getRationale(Default_Hierarchical__Parent, artifact);
      assertEquals(rationale, actual2);
   }

   @Test
   public void testUnrelate() throws OseeCoreException {
      TransactionBuilder tx1 = createTx();
      ArtifactId art1 = tx1.createArtifact(Component, "A component");
      ArtifactId art2 = tx1.createArtifact(Component, "C component");
      ArtifactId art3 = tx1.createArtifact(Component, "B component");
      tx1.addChildren(art1, art2, art3);
      ArtifactId art4 = tx1.createArtifact(GeneralDocument, "Document");
      tx1.relate(art1, Dependency__Dependency, art4);
      tx1.commit();

      ArtifactReadable artifact4 = query.fromBranch(COMMON).andIds(art4).getResults().getExactlyOne();
      assertEquals(art4, artifact4);

      ArtifactReadable artifact1 = artifact4.getRelated(CoreRelationTypes.Dependency__Artifact).getExactlyOne();
      assertEquals(art1, artifact1);

      Iterator<ArtifactReadable> iterator = artifact1.getChildren().iterator();
      assertEquals(art3, iterator.next());
      assertEquals(art2, iterator.next());

      // Un-relate a child
      TransactionBuilder tx2 = createTx();
      tx2.unrelate(art1, Default_Hierarchical__Child, art2);
      tx2.commit();

      artifact4 = query.fromBranch(COMMON).andIds(art4).getResults().getExactlyOne();
      assertEquals(art4, artifact4);

      artifact1 = artifact4.getRelated(CoreRelationTypes.Dependency__Artifact).getExactlyOne();
      assertEquals(art1, artifact1);

      assertEquals(art3, artifact1.getChildren().getExactlyOne());
   }

   @Test
   public void testUnrelateFromAllByType() throws OseeCoreException {
      TransactionBuilder tx1 = createTx();
      ArtifactId art1 = tx1.createArtifact(Component, "A component");
      ArtifactId art2 = tx1.createArtifact(Component, "C component");
      ArtifactId art3 = tx1.createArtifact(Component, "B component");
      tx1.addChildren(art1, art2, art3);

      ArtifactId art4 = tx1.createArtifact(GeneralDocument, "Document");
      tx1.relate(art1, Dependency__Dependency, art4);
      tx1.commit();

      ArtifactReadable artifact4 = query.fromBranch(COMMON).andIds(art4).getResults().getExactlyOne();
      assertEquals(art4, artifact4);

      ArtifactReadable artifact1 = artifact4.getRelated(Dependency__Artifact).getExactlyOne();
      assertEquals(art1, artifact1);

      Iterator<ArtifactReadable> iterator = artifact1.getChildren().iterator();
      assertEquals(art3, iterator.next());
      assertEquals(art2, iterator.next());

      // Unrelate All children
      TransactionBuilder tx2 = createTx();
      tx2.unrelateFromAll(Default_Hierarchical__Parent, art1);
      tx2.commit();

      artifact4 = query.fromBranch(COMMON).andIds(art4).getResults().getExactlyOne();
      assertEquals(art4, artifact4);

      artifact1 = artifact4.getRelated(Dependency__Artifact).getExactlyOne();
      assertEquals(art1, artifact1);

      assertEquals(true, artifact1.getChildren().isEmpty());
   }

   @Test
   public void testAttributeCommitOnlyAffectNewStripe() throws OseeCoreException {
      // create artifact and check exists and name set
      TransactionBuilder tx1 = createTx();
      ArtifactId art1 = tx1.createArtifact(Component, "orig name");
      TransactionId rec1 = tx1.commit();
      assertNotNull(rec1);
      art1 = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      assertEquals("orig name", art1.getName());

      // change name
      ArtifactId art2 = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      TransactionBuilder tx2 = createTx();
      tx2.setName(art2, "new name");
      TransactionId rec2 = tx2.commit();
      assertNotNull(rec2);

      // verify that change only exists on new stripe?
      ArtifactId art3 = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      assertEquals("orig name", art1.getName());
      // this should be same name cause we didn't re-query it and the tx didn't change the model?
      assertEquals("orig name", art2.getName());
      // since art3 is a re-query, it should show the same name
      assertEquals("new name", art3.getName());
   }

   @Test
   public void testUnrelateFromAll() throws OseeCoreException {
      ArtifactReadable artifact1 = null;
      ArtifactReadable artifact2 = null;
      ArtifactReadable artifact3 = null;
      ArtifactReadable artifact4 = null;

      TransactionBuilder tx1 = createTx();
      ArtifactId art1 = tx1.createArtifact(Component, "A component");
      ArtifactId art2 = tx1.createArtifact(Component, "B component");
      ArtifactId art3 = tx1.createArtifact(Component, "C component");
      tx1.addChildren(art1, art2, art3);

      ArtifactId art4 = tx1.createArtifact(GeneralDocument, "Document");
      tx1.relate(art1, Dependency__Dependency, art4);
      TransactionId rec1 = tx1.commit();
      assertNotNull(rec1);

      artifact4 = query.fromBranch(COMMON).andIds(art4).getResults().getExactlyOne();
      assertEquals(art4, artifact4);

      artifact1 = artifact4.getRelated(Dependency__Artifact).getExactlyOne();
      assertEquals(art1, artifact1);

      Iterator<ArtifactReadable> iterator = artifact1.getChildren().iterator();
      assertEquals(art2, iterator.next());
      assertEquals(art3, iterator.next());

      TransactionBuilder tx2 = createTx();
      tx2.unrelateFromAll(art1);
      TransactionId rec2 = tx2.commit();
      assertNotNull(rec2);

      artifact1 =
         query.fromBranch(COMMON).andUuid(art1.getUuid()).includeDeletedArtifacts().getResults().getAtMostOneOrNull();
      assertNotNull(artifact1);
      artifact2 = query.fromBranch(COMMON).andUuid(art2.getUuid()).getResults().getAtMostOneOrNull();
      assertNotNull(artifact2);
      artifact3 = query.fromBranch(COMMON).andUuid(art3.getUuid()).getResults().getAtMostOneOrNull();
      assertNotNull(artifact3);
      artifact4 = query.fromBranch(COMMON).andUuid(art4.getUuid()).getResults().getAtMostOneOrNull();
      assertNotNull(artifact4);

      assertEquals(true, artifact1.getChildren().isEmpty());
      assertEquals(true, artifact1.getRelated(Dependency__Dependency).isEmpty());

      assertNull(artifact2.getParent());
      assertNull(artifact3.getParent());

      assertEquals(true, artifact4.getRelated(Dependency__Artifact).isEmpty());
   }

   @Test
   public void testMultiAttriVersionsWriteAndLoading() {
      TransactionBuilder tx = createTx();
      ArtifactId art1 = tx.createArtifact(Component, "A component");
      tx.setSoleAttributeFromString(art1, CoreAttributeTypes.Annotation, "write1");
      tx.commit();

      tx = createTx();
      tx.setSoleAttributeFromString(art1, CoreAttributeTypes.Annotation, "write2");
      tx.commit();

      tx = createTx();
      tx.setSoleAttributeFromString(art1, CoreAttributeTypes.Annotation, "write3");
      tx.commit();

      tx = createTx();
      tx.setSoleAttributeFromString(art1, CoreAttributeTypes.Annotation, "write4");
      tx.commit();

      tx = createTx();
      tx.setSoleAttributeFromString(art1, CoreAttributeTypes.Annotation, "write5");
      TransactionId lastTx = tx.commit();

      ArtifactReadable art = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      ResultSet<? extends AttributeReadable<Object>> attributes = art.getAttributes(CoreAttributeTypes.Annotation);

      assertEquals(1, attributes.size());
      assertEquals("write5", attributes.getExactlyOne().getValue());

      QueryBuilder builder = query.fromBranch(COMMON).fromTransaction(lastTx).andIds(art1);
      ResultSet<ArtifactReadable> results = builder.getResults();
      art = results.getExactlyOne();
      attributes = art.getAttributes(CoreAttributeTypes.Annotation);
      assertEquals(1, attributes.size());
      assertEquals("write5", attributes.getExactlyOne().getValue());
   }

   @Test
   public void testMultiRelationVersionsWriteAndLoading() {
      TransactionBuilder tx = createTx();
      ArtifactId art1 = tx.createArtifact(CoreArtifactTypes.Component, "A component");
      ArtifactId art2 = tx.createArtifact(CoreArtifactTypes.User, "User Artifact");
      tx.relate(art1, CoreRelationTypes.Users_User, art2, "rationale1");
      tx.commit();

      tx = createTx();
      tx.setRationale(art1, CoreRelationTypes.Users_User, art2, "rationale2");
      tx.commit();

      tx = createTx();
      tx.setRationale(art1, CoreRelationTypes.Users_User, art2, "rationale3");
      tx.commit();

      tx = createTx();
      tx.setRationale(art1, CoreRelationTypes.Users_User, art2, "rationale4");
      tx.commit();

      tx = createTx();
      tx.setRationale(art1, CoreRelationTypes.Users_User, art2, "rationale5");
      TransactionId lastTx = tx.commit();

      ArtifactReadable art = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      ResultSet<ArtifactReadable> related = art.getRelated(CoreRelationTypes.Users_User);
      assertEquals(1, related.size());
      ArtifactReadable other = related.getExactlyOne();
      String rationale = art.getRationale(CoreRelationTypes.Users_User, other);

      assertEquals("rationale5", rationale);

      art = query.fromBranch(COMMON).fromTransaction(lastTx).andIds(art1).getResults().getExactlyOne();
      related = art.getRelated(CoreRelationTypes.Users_User);
      assertEquals(1, related.size());
      other = related.getExactlyOne();
      rationale = art.getRationale(CoreRelationTypes.Users_User, other);

      assertEquals("rationale5", rationale);
   }

   @Test
   public void testRelateUnrelateMultipleTimes() {
      TransactionBuilder tx = createTx();
      ArtifactId art1 = tx.createArtifact(CoreArtifactTypes.Component, "A component");
      ArtifactId art2 = tx.createArtifact(CoreArtifactTypes.User, "User Artifact");
      tx.relate(art1, CoreRelationTypes.Users_User, art2, "rationale1");
      tx.commit();

      ArtifactReadable art = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      ArtifactReadable otherSide = art.getRelated(CoreRelationTypes.Users_User).getExactlyOne();
      assertEquals(true, art.areRelated(CoreRelationTypes.Users_User, otherSide));

      tx = createTx();
      tx.unrelate(art1, CoreRelationTypes.Users_User, art2);
      tx.commit();

      art = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      ResultSet<ArtifactReadable> otherSideResults = art.getRelated(CoreRelationTypes.Users_User);
      assertEquals(true, otherSideResults.isEmpty());

      tx = createTx();
      tx.relate(art1, CoreRelationTypes.Users_User, art2);
      tx.commit();

      art = query.fromBranch(COMMON).andIds(art1).getResults().getExactlyOne();
      otherSide = art.getRelated(CoreRelationTypes.Users_User).getExactlyOne();
      assertEquals(true, art.areRelated(CoreRelationTypes.Users_User, otherSide));
   }

   @Test
   public void testSetTransactionComment() throws Exception {
      TransactionBuilder tx = createTx();
      ArtifactId art1 = tx.createArtifact(CoreArtifactTypes.Component, "A component");
      ArtifactId art2 = tx.createArtifact(CoreArtifactTypes.User, "User Artifact");
      tx.relate(art1, CoreRelationTypes.Users_User, art2, "rationale1");
      TransactionReadable transaction = tx.commit();

      assertEquals(testName.getMethodName(), transaction.getComment());

      String expectedComment = "My new Comment";
      txFactory.setTransactionComment(transaction, expectedComment).call();

      TransactionReadable actual = query.transactionQuery().andTxId(transaction).getResults().getExactlyOne();
      assertEquals(transaction, actual);
      assertEquals(expectedComment, actual.getComment());
   }

   @Test(expected = OseeStateException.class)
   public void testAttributeMultiplicity() {
      TransactionBuilder tx = createTx();
      ArtifactId art1 = tx.createArtifact(CoreArtifactTypes.SoftwareRequirement, "SwReq");
      tx.createAttribute(art1, CoreAttributeTypes.ParagraphNumber, "1.1");
      tx.createAttribute(art1, CoreAttributeTypes.ParagraphNumber, "2.2");
   }

   @Test(expected = OseeStateException.class)
   public void testRelationMultiplicity() {
      TransactionBuilder tx = createTx();
      ArtifactId child = tx.createArtifact(CoreArtifactTypes.SoftwareRequirement, "Child");
      ArtifactId parent1 = tx.createArtifact(CoreArtifactTypes.SoftwareRequirement, "Parent1");
      ArtifactId parent2 = tx.createArtifact(CoreArtifactTypes.SoftwareRequirement, "Parent2");
      tx.relate(parent1, Default_Hierarchical__Parent, child);
      tx.relate(parent2, Default_Hierarchical__Parent, child);
   }

   private TransactionBuilder createTx() throws OseeCoreException {
      return txFactory.createTransaction(COMMON, userArtifact, testName.getMethodName());
   }

   private void checkTransaction(TransactionReadable previousTx, TransactionReadable newTx, BranchId branchId, String comment, ArtifactId user) throws OseeCoreException {
      assertTrue(previousTx.isOlderThan(newTx));
      assertEquals(comment, newTx.getComment());
      assertEquals(branchId, newTx.getBranch());
      assertEquals(TransactionDetailsType.NonBaselined, newTx.getTxType());
      assertEquals(user, newTx.getAuthor());
      assertEquals(newTx.getCommitArt(), 0L);
      assertTrue(previousTx.getDate().before(newTx.getDate()));
   }
}

Back to the top