-
Notifications
You must be signed in to change notification settings - Fork 188
/
PrismAsserts.java
1145 lines (974 loc) · 51.9 KB
/
PrismAsserts.java
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
/*
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.prism.util;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.prism.path.ItemPathSegment;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import com.evolveum.midpoint.prism.ComplexTypeDefinition;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismReference;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.OriginType;
import com.evolveum.midpoint.prism.Visitable;
import com.evolveum.midpoint.prism.Visitor;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ContainerDelta;
import com.evolveum.midpoint.prism.delta.DeltaSetTriple;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.match.MatchingRule;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.AndFilter;
import com.evolveum.midpoint.prism.query.EqualFilter;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.OrFilter;
import com.evolveum.midpoint.prism.query.RefFilter;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.prism.xnode.ListXNode;
import com.evolveum.midpoint.prism.xnode.MapXNode;
import com.evolveum.midpoint.prism.xnode.PrimitiveXNode;
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
/**
* Set of prism-related asserts.
*
* DO NOT use this in the main code. Although it is placed in "main" for convenience, is should only be used in tests.
*
* @author Radovan Semancik
*
*/
public class PrismAsserts {
private static final Trace LOGGER = TraceManager.getTrace(PrismAsserts.class);
// VALUE asserts
public static <T> void assertPropertyValue(PrismContainer<?> container, QName propQName, T... realPropValues) {
PrismContainerValue<?> containerValue = container.getValue();
assertSame("Wrong parent for value of container "+container, container, containerValue.getParent());
assertPropertyValue(containerValue, propQName, realPropValues);
}
public static <T> void assertPropertyValue(PrismContainerValue<?> containerValue, QName propQName, T... realPropValues) {
PrismProperty<T> property = containerValue.findProperty(propQName);
assertNotNull("Property " + propQName + " not found in " + containerValue.getParent(), property);
assertSame("Wrong parent for property " + property, containerValue, property.getParent());
assertPropertyValueDesc(property, containerValue.getParent().toString(), realPropValues);
}
public static <T> void assertPropertyValue(PrismContainer<?> container, ItemPath propPath, T... realPropValues) {
PrismContainerValue<?> containerValue = container.getValue();
assertSame("Wrong parent for value of container "+container, container, containerValue.getParent());
assertPropertyValue(containerValue, propPath, realPropValues);
}
public static <T> void assertPropertyValue(PrismContainerValue<?> containerValue, ItemPath propPath, T... realPropValues) {
PrismProperty<T> property = containerValue.findProperty(propPath);
assertNotNull("Property " + propPath + " not found in " + containerValue.getParent(), property);
assertPropertyValueDesc(property, containerValue.getParent().toString(), realPropValues);
}
public static <T> void assertPropertyValue(PrismProperty<T> property, T... expectedPropValues) {
assertPropertyValueDesc(property, null, expectedPropValues);
}
public static <T> void assertPropertyValueDesc(PrismProperty<T> property, String contextDescrition, T... expectedPropValues) {
Collection<PrismPropertyValue<T>> pvals = property.getValues();
QName propQName = property.getElementName();
assert pvals != null && !pvals.isEmpty() : "Empty property "+propQName;
assertSet("property "+propQName + (contextDescrition == null ? "" : " in " + contextDescrition),
"value", pvals, expectedPropValues);
}
public static <T> void assertPropertyValues(String message, Collection<T> expected, Collection<PrismPropertyValue<T>> results) {
assertEquals(message+" - unexpected number of results", expected.size(), results.size());
Set<Object> values = new HashSet<Object>();
for (PrismPropertyValue<T> result : results) {
values.add(result.getValue());
}
assertEquals(message, expected, values);
}
public static <T> void assertPropertyValues(String message, Collection<PrismPropertyValue<T>> results, T... expectedValues) {
assertSet(message, "value", results, expectedValues);
}
public static void assertReferenceValues(PrismReference ref, String... oids) {
assert oids.length == ref.getValues().size() : "Wrong number of values in "+ref+"; expected "+oids.length+" but was "+ref.getValues().size();
for (String oid: oids) {
assertReferenceValue(ref, oid);
}
}
public static void assertReferenceValue(PrismReference ref, String oid) {
for (PrismReferenceValue val: ref.getValues()) {
if (oid.equals(val.getOid())) {
return;
}
}
fail("Oid "+oid+" not found in reference "+ref);
}
public static void assertNoItem(PrismContainer<?> object, QName itemName) {
assertNoItem(object, new ItemPath(itemName));
}
public static void assertNoItem(PrismContainer<?> object, ItemPath itemPath) {
Item<?,?> item = object.findItem(itemPath);
assert item == null : "Unexpected item "+item+" in "+object;
}
public static void assertNotEmpty(Item<?,?> item) {
assert !item.isEmpty() : "Item "+item+" is empty";
}
public static void assertNoEmptyItem(PrismContainer<?> container) {
Visitor visitor = new Visitor() {
@Override
public void visit(Visitable visitable) {
if (visitable != null && visitable instanceof Item) {
assertNotEmpty((Item<?,?>)visitable);
}
}
};
container.accept(visitor);
}
// DEFINITION asserts
public static <T extends Objectable> void assertObjectDefinition(PrismObjectDefinition<T> objDef, QName elementName,
QName typeName, Class<T> compileTimeClass) {
assertNotNull("No definition", objDef);
assertEquals("Wrong elementName for "+objDef, elementName, objDef.getName());
assertEquals("Wrong typeName for "+objDef, typeName, objDef.getTypeName());
assertEquals("Wrong compileTimeClass for " + objDef, compileTimeClass, objDef.getCompileTimeClass());
}
public static void assertDefinition(Item item, QName type, int minOccurs, int maxOccurs) {
ItemDefinition definition = item.getDefinition();
assertDefinition(definition, item.getElementName(), type, minOccurs, maxOccurs);
}
public static void assertPropertyDefinition(PrismContainer<?> container, QName propertyName, QName type, int minOccurs, int maxOccurs) {
PrismProperty<?> findProperty = container.findProperty(propertyName);
PrismPropertyDefinition<?> definition = findProperty.getDefinition();
assertDefinition(definition, propertyName, type, minOccurs, maxOccurs);
}
public static void assertPropertyDefinition(ComplexTypeDefinition container, QName propertyName, QName type, int minOccurs, int maxOccurs) {
PrismPropertyDefinition<?> definition = container.findPropertyDefinition(propertyName);
assertDefinition(definition, propertyName, type, minOccurs, maxOccurs);
}
public static void assertPropertyDefinition(PrismProperty property, QName type, int minOccurs, int maxOccurs, Boolean indexed) {
assertDefinition(property, type, minOccurs, maxOccurs);
PrismPropertyDefinition definition = property.getDefinition();
assert equals(indexed, definition.isIndexed()) : "Property should have indexed=" + indexed + ", but it has indexed=" + definition.isIndexed();
}
public static void assertPropertyDefinition(PrismContainerDefinition<?> containerDef, QName propertyName, QName type, int minOccurs, int maxOccurs, boolean indexed) {
assertPropertyDefinition(containerDef, propertyName, type, minOccurs, maxOccurs);
PrismPropertyDefinition definition = containerDef.findPropertyDefinition(propertyName);
assert equals(indexed, definition.isIndexed()) : "Property should have indexed=" + indexed + ", but it has indexed=" + definition.isIndexed();
}
public static void assertPropertyDefinition(PrismContainerDefinition<?> containerDef, QName propertyName, QName type, int minOccurs, int maxOccurs) {
PrismPropertyDefinition definition = containerDef.findPropertyDefinition(propertyName);
assertDefinition(definition, propertyName, type, minOccurs, maxOccurs);
}
public static void assertItemDefinitionDisplayName(PrismContainerDefinition<?> containerDef, QName propertyName, String expectedDisplayName) {
ItemDefinition definition = containerDef.findItemDefinition(propertyName);
assert equals(expectedDisplayName, definition.getDisplayName()) : "Wrong display name for item "+propertyName+", expected " +
expectedDisplayName + ", was " + definition.getDisplayName();
}
public static void assertItemDefinitionDisplayName(ComplexTypeDefinition containerDef, QName propertyName, String expectedDisplayName) {
ItemDefinition definition = containerDef.findItemDefinition(propertyName, ItemDefinition.class);
assert equals(expectedDisplayName, definition.getDisplayName()) : "Wrong display name for item "+propertyName+", expected " +
expectedDisplayName + ", was " + definition.getDisplayName();
}
public static void assertItemDefinitionDisplayOrder(PrismContainerDefinition<?> containerDef, QName propertyName, Integer expectedDisplayOrder) {
ItemDefinition definition = containerDef.findItemDefinition(propertyName);
assert equals(expectedDisplayOrder, definition.getDisplayOrder()) : "Wrong display order for item "+propertyName+", expected " +
expectedDisplayOrder + ", was " + definition.getDisplayOrder();
}
public static void assertItemDefinitionDisplayOrder(ComplexTypeDefinition containerDef, QName propertyName, Integer expectedDisplayOrder) {
ItemDefinition definition = containerDef.findItemDefinition(propertyName, ItemDefinition.class);
assert equals(expectedDisplayOrder, definition.getDisplayOrder()) : "Wrong display order for item "+propertyName+", expected " +
expectedDisplayOrder + ", was " + definition.getDisplayOrder();
}
public static void assertItemDefinitionHelp(PrismContainerDefinition<?> containerDef, QName propertyName, String expectedHelp) {
ItemDefinition definition = containerDef.findItemDefinition(propertyName);
assert equals(expectedHelp, definition.getHelp()) : "Wrong help for item "+propertyName+", expected " +
expectedHelp + ", was " + definition.getHelp();
}
public static void assertDefinition(ItemDefinition definition, QName itemName, QName type, int minOccurs, int maxOccurs) {
assertNotNull("No definition for "+itemName, definition);
assertEquals("Wrong definition type for "+itemName, type, definition.getTypeName());
assertEquals("Wrong definition minOccurs for "+itemName, minOccurs, definition.getMinOccurs());
assertEquals("Wrong definition maxOccurs for "+itemName, maxOccurs, definition.getMaxOccurs());
}
public static void assertIndexed(PrismContainerDefinition<? extends Containerable> containerDef, QName itemQName,
Boolean expected) {
PrismPropertyDefinition propertyDefinition = containerDef.findPropertyDefinition(itemQName);
assertEquals("Wrong value of 'indexed' in property '"+PrettyPrinter.prettyPrint(itemQName)+" in "+containerDef, expected, propertyDefinition.isIndexed());
}
public static void assertEmphasized(ItemDefinition itemDef, Boolean expected) {
assertEquals("Wrong value of 'emphasized' in "+itemDef, expected, itemDef.isEmphasized());
}
public static void assertEmphasized(PrismContainerDefinition<? extends Containerable> containerDef, QName itemQName,
Boolean expected) {
PrismPropertyDefinition propertyDefinition = containerDef.findPropertyDefinition(itemQName);
assertEquals("Wrong value of 'emphasized' in property '"+PrettyPrinter.prettyPrint(itemQName)+" in "+containerDef, expected, propertyDefinition.isEmphasized());
}
public static<C extends Containerable> void assertValueId(Long expectedId, PrismContainer<C> container) {
List<Long> ids = new ArrayList<Long>();
for (PrismContainerValue<C> value: container.getValues()) {
if (MiscUtil.equals(expectedId, value.getId())) {
return;
}
ids.add(value.getId());
}
assert false : "Expected that container "+container+" will have value id '"+expectedId+"' but it has not; existing IDs: "+ids;
}
// MISC asserts
public static void assertParentConsistency(PrismContainerValue<?> pval) {
if (pval.getItems() != null) {
for (Item<?,?> item : pval.getItems()) {
assert item.getParent() == pval : "Wrong parent in " + item;
assertParentConsistency(item);
}
}
}
public static void assertParentConsistency(Item<?,?> item) {
for (PrismValue pval: item.getValues()) {
assert pval.getParent() == item : "Wrong parent of "+pval+" in "+PrettyPrinter.prettyPrint(item.getElementName());
if (pval instanceof PrismContainerValue) {
assertParentConsistency((PrismContainerValue)pval);
}
}
}
// DELTA asserts
public static void assertModifications(ObjectDelta<?> objectDelta, int expectedNumberOfModifications) {
assertModifications(null, objectDelta, expectedNumberOfModifications);
}
public static void assertModifications(String message, ObjectDelta<?> objectDelta, int expectedNumberOfModifications) {
assertIsModify(objectDelta);
assert objectDelta.getModifications().size() == expectedNumberOfModifications :
(message == null ? "" : (message + ": ")) +
"Wrong number of modifications in object delta "
+ objectDelta + ". Expected "+expectedNumberOfModifications+", was "+objectDelta.getModifications().size();
}
public static void assertIsModify(ObjectDelta<?> objectDelta) {
assert objectDelta.isModify() : "Expected that object delta "+objectDelta+" is MODIFY, but it is "+objectDelta.getChangeType();
}
public static void assertIsAdd(ObjectDelta<?> objectDelta) {
assert objectDelta.isAdd() : "Expected that object delta "+objectDelta+" is ADD, but it is "+objectDelta.getChangeType();
assert objectDelta.getObjectToAdd() != null : "Object to add is null in add delta " + objectDelta;
}
public static void assertIsDelete(ObjectDelta<?> objectDelta) {
assert objectDelta.isDelete() : "Expected that object delta "+objectDelta+" is DELETE, but it is "+objectDelta.getChangeType();
}
public static void assertEmpty(ObjectDelta<?> objectDelta) {
assert objectDelta.isEmpty() : "Expected that object delta "+objectDelta+" is empty, but it is not";
}
public static void assertEmpty(String message, ObjectDelta<?> objectDelta) {
assert objectDelta.isEmpty() : "Expected that object delta "+message+" is empty, but it is: "+objectDelta;
}
public static void assertPropertyReplace(ObjectDelta<?> objectDelta, QName propertyName, Object... expectedValues) {
PropertyDelta<Object> propertyDelta = objectDelta.findPropertyDelta(propertyName);
assertNotNull("Property delta for "+propertyName+" not found",propertyDelta);
assertReplace(propertyDelta, expectedValues);
}
public static void assertPropertyReplaceSimple(ObjectDelta<?> objectDelta, QName propertyName) {
PropertyDelta<Object> propertyDelta = objectDelta.findPropertyDelta(propertyName);
assertNotNull("Property delta for "+propertyName+" not found",propertyDelta);
assertTrue("No values to replace", propertyDelta.getValuesToReplace() != null && !propertyDelta.getValuesToReplace().isEmpty());
}
public static <T> void assertReplace(PropertyDelta<T> propertyDelta, T... expectedValues) {
assertSet("delta "+propertyDelta+" for "+propertyDelta.getElementName(), "replace", propertyDelta.getValuesToReplace(), expectedValues);
}
public static void assertPropertyAdd(ObjectDelta<?> objectDelta, QName propertyName, Object... expectedValues) {
PropertyDelta propertyDelta = objectDelta.findPropertyDelta(propertyName);
assertNotNull("Property delta for "+propertyName+" not found",propertyDelta);
assertSet("delta "+propertyDelta+" for "+propertyName, "add", propertyDelta.getValuesToAdd(), expectedValues);
}
public static void assertPropertyDelete(ObjectDelta<?> objectDelta, QName propertyName, Object... expectedValues) {
PropertyDelta propertyDelta = objectDelta.findPropertyDelta(propertyName);
assertNotNull("Property delta for "+propertyName+" not found",propertyDelta);
assertSet("delta "+propertyDelta+" for "+propertyName, "delete", propertyDelta.getValuesToDelete(), expectedValues);
}
public static <T> void assertPropertyReplace(ObjectDelta<?> userDelta, ItemPath propertyPath, T... expectedValues) {
PropertyDelta<T> propertyDelta = userDelta.findPropertyDelta(propertyPath);
assertNotNull("Property delta for "+propertyPath+" not found",propertyDelta);
assertSet("delta " + propertyDelta + " for " + propertyPath.last(), "replace", propertyDelta.getValuesToReplace(), expectedValues);
}
public static void assertPropertyAdd(ObjectDelta<?> userDelta, ItemPath propertyPath, Object... expectedValues) {
PropertyDelta<Object> propertyDelta = userDelta.findPropertyDelta(propertyPath);
assertNotNull("Property delta for "+propertyPath+" not found",propertyDelta);
assertAdd(propertyDelta, expectedValues);
}
public static <T> void assertAdd(PropertyDelta<T> propertyDelta, T... expectedValues) {
assertSet("delta "+propertyDelta+" for "+propertyDelta.getElementName(), "add", propertyDelta.getValuesToAdd(), expectedValues);
}
public static <T> void assertDelete(PropertyDelta<T> propertyDelta, T... expectedValues) {
assertSet("delta "+propertyDelta+" for "+propertyDelta.getElementName(), "delete", propertyDelta.getValuesToDelete(), expectedValues);
}
public static void assertPropertyDelete(ObjectDelta<?> userDelta, ItemPath propertyPath, Object... expectedValues) {
PropertyDelta propertyDelta = userDelta.findPropertyDelta(propertyPath);
assertNotNull("Property delta for "+propertyPath+" not found",propertyDelta);
assertSet("delta "+propertyDelta+" for "+propertyPath.last(), "delete", propertyDelta.getValuesToDelete(), expectedValues);
}
public static void assertPropertyReplace(Collection<? extends ItemDelta> modifications, ItemPath propertyPath, Object... expectedValues) {
PropertyDelta propertyDelta = ItemDelta.findPropertyDelta(modifications, propertyPath);
assertNotNull("Property delta for "+propertyPath+" not found",propertyDelta);
assertSet("delta "+propertyDelta+" for "+propertyPath.last(), "replace", propertyDelta.getValuesToReplace(), expectedValues);
}
public static void assertPropertyAdd(Collection<? extends ItemDelta> modifications, ItemPath propertyPath, Object... expectedValues) {
PropertyDelta propertyDelta = ItemDelta.findPropertyDelta(modifications, propertyPath);
assertNotNull("Property delta for "+propertyPath+" not found",propertyDelta);
assertSet("delta "+propertyDelta+" for "+propertyPath.last(), "add", propertyDelta.getValuesToAdd(), expectedValues);
}
public static void assertPropertyDelete(Collection<? extends ItemDelta> modifications, ItemPath propertyPath, Object... expectedValues) {
PropertyDelta propertyDelta = ItemDelta.findPropertyDelta(modifications, propertyPath);
assertNotNull("Property delta for "+propertyPath+" not found",propertyDelta);
assertSet("delta "+propertyDelta+" for "+propertyPath.last(), "delete", propertyDelta.getValuesToDelete(), expectedValues);
}
public static void assertReferenceAdd(ObjectDelta<?> objectDelta, QName refName, String... expectedOids) {
ReferenceDelta refDelta = objectDelta.findReferenceModification(refName);
assertNotNull("Reference delta for "+refName+" not found",refDelta);
assertOidSet("delta "+refDelta+" for "+refName, "add", refDelta.getValuesToAdd(), expectedOids);
}
public static void assertReferenceDelete(ObjectDelta<?> objectDelta, QName refName, String... expectedOids) {
ReferenceDelta refDelta = objectDelta.findReferenceModification(refName);
assertNotNull("Reference delta for "+refName+" not found",refDelta);
assertOidSet("delta "+refDelta+" for "+refName, "delete", refDelta.getValuesToDelete(), expectedOids);
}
public static void assertReferenceReplace(ObjectDelta<?> objectDelta, QName refName, String... expectedOids) {
ReferenceDelta refDelta = objectDelta.findReferenceModification(refName);
assertNotNull("Reference delta for "+refName+" not found",refDelta);
assertOidSet("delta "+refDelta+" for "+refName, "replace", refDelta.getValuesToReplace(), expectedOids);
}
public static void assertNoItemDelta(ObjectDelta<?> objectDelta, QName itemName) {
assertNoItemDelta(objectDelta, new ItemPath(itemName));
}
public static void assertNoItemDelta(ObjectDelta<?> objectDelta, ItemPath itemPath) {
if (objectDelta == null) {
return;
}
assert !objectDelta.hasItemDelta(itemPath) : "Delta for item "+itemPath+" present while not expecting it";
}
public static ContainerDelta<?> assertContainerAddGetContainerDelta(ObjectDelta<?> objectDelta, QName name) {
return assertContainerAddGetContainerDelta(objectDelta, new ItemPath(name));
}
public static ContainerDelta<?> assertContainerAddGetContainerDelta(ObjectDelta<?> objectDelta, ItemPath propertyPath) {
ContainerDelta<?> delta = objectDelta.findContainerDelta(propertyPath);
assertNotNull("Container delta for "+propertyPath+" not found",delta);
assert !delta.isEmpty() : "Container delta for "+propertyPath+" is empty";
assert delta.getValuesToAdd() != null : "Container delta for "+propertyPath+" has null values to add";
assert !delta.getValuesToAdd().isEmpty() : "Container delta for "+propertyPath+" has empty values to add";
return delta;
}
public static ContainerDelta<?> assertContainerDeleteGetContainerDelta(ObjectDelta<?> objectDelta, QName name) {
return assertContainerDeleteGetContainerDelta(objectDelta, new ItemPath(name));
}
public static ContainerDelta<?> assertContainerDeleteGetContainerDelta(ObjectDelta<?> objectDelta, ItemPath propertyPath) {
ContainerDelta<?> delta = objectDelta.findContainerDelta(propertyPath);
assertNotNull("Container delta for "+propertyPath+" not found",delta);
assert !delta.isEmpty() : "Container delta for "+propertyPath+" is empty";
assert delta.getValuesToDelete() != null : "Container delta for "+propertyPath+" has null values to delete";
assert !delta.getValuesToDelete().isEmpty() : "Container delta for "+propertyPath+" has empty values to delete";
return delta;
}
public static <C extends Containerable> void assertContainerAdd(ObjectDelta<?> objectDelta, QName itemName, C... containerables) {
assertContainerAdd(objectDelta, new ItemPath(itemName), containerables);
}
public static <C extends Containerable> void assertContainerAdd(ObjectDelta<?> objectDelta, ItemPath propertyPath, C... containerables) {
List<PrismContainerValue<C>> expectedCVals = new ArrayList<>();
for (C expectedContainerable: containerables) {
expectedCVals.add(expectedContainerable.asPrismContainerValue());
}
}
public static <C extends Containerable> void assertContainerAdd(ObjectDelta<?> objectDelta, QName itemName,
PrismContainerValue<C>... expectedCVals) {
assertContainerAdd(objectDelta, new ItemPath(itemName), expectedCVals);
}
public static <C extends Containerable> void assertContainerAdd(ObjectDelta<?> objectDelta, ItemPath propertyPath,
PrismContainerValue<C>... expectedCVals) {
ContainerDelta<C> delta = objectDelta.findContainerDelta(propertyPath);
assertNotNull("Container delta for "+propertyPath+" not found",delta);
assert !delta.isEmpty() : "Container delta for "+propertyPath+" is empty";
assert delta.getValuesToAdd() != null : "Container delta for "+propertyPath+" has null values to add";
assert !delta.getValuesToAdd().isEmpty() : "Container delta for "+propertyPath+" has empty values to add";
assertEquivalentContainerValues("Wrong values in container delta for "+propertyPath,
delta.getValuesToAdd(), expectedCVals);
}
private static <C extends Containerable> void assertEquivalentContainerValues(String message, Collection<PrismContainerValue<C>> haveValues,
PrismContainerValue<C>[] expectedCVals) {
List<PrismContainerValue<C>> expectedValues = Arrays.asList(expectedCVals);
Comparator<PrismContainerValue<C>> comparator = new Comparator<PrismContainerValue<C>>() {
@Override
public int compare(PrismContainerValue<C> a, PrismContainerValue<C> b) {
if (a.equivalent(b)) {
return 0;
}
return 1;
}
};
assert MiscUtil.unorderedCollectionEquals(haveValues, expectedValues, comparator) : message;
}
public static <T> void assertOrigin(ObjectDelta<?> objectDelta, final OriginType... expectedOriginTypes) {
assertOrigin(objectDelta, null, expectedOriginTypes);
}
public static <T> void assertOrigin(Visitable visitableItem, final OriginType... expectedOriginTypes) {
assertOrigin(visitableItem, null, expectedOriginTypes);
}
public static void assertOrigin(ObjectDelta<?> objectDelta, final Objectable expectedOriginObject, final OriginType... expectedOriginTypes) {
Visitor visitor = createOriginVisitor(objectDelta, expectedOriginObject, expectedOriginTypes);
objectDelta.accept(visitor, false);
}
public static <T> void assertOrigin(Visitable visitableItem, final Objectable expectedOriginObject, final OriginType... expectedOriginTypes) {
Visitor visitor = createOriginVisitor(visitableItem, expectedOriginObject, expectedOriginTypes);
visitableItem.accept(visitor);
}
private static <T> Visitor createOriginVisitor(final Visitable visitableItem, final Objectable expectedOriginObject, final OriginType... expectedOriginTypes) {
return new Visitor() {
@Override
public void visit(Visitable visitable) {
if (visitable instanceof PrismValue) {
PrismValue pval = (PrismValue)visitable;
assert MiscUtil.contains(pval.getOriginType(), expectedOriginTypes) : "Wrong origin type in "+visitable+" in "+visitableItem+
"; expected "+expectedOriginTypes+", was "+pval.getOriginType();
if (expectedOriginObject != null) {
assert pval.getOriginObject() == expectedOriginObject : "Wrong origin object in "+visitable+" in "+visitableItem+
"; expected "+expectedOriginObject+", was "+pval.getOriginObject();
}
}
}
};
}
public static void asserHasDelta(String message, Collection<? extends ObjectDelta<? extends Objectable>> deltas, ChangeType expectedChangeType, Class<?> expectedClass) {
for (ObjectDelta<?> delta: deltas) {
if (delta.getObjectTypeClass() == expectedClass && delta.getChangeType() == expectedChangeType) {
return;
}
}
assert false : message+": Delta for "+expectedClass+" of type "+expectedChangeType+" was not found in collection "+deltas;
}
public static <IV extends PrismValue,ID extends ItemDefinition> void assertNoReplace(ItemDelta<IV,ID> delta) {
assertNoReplace(null, delta);
}
public static <IV extends PrismValue,ID extends ItemDefinition> void assertNoReplace(String message, ItemDelta<IV,ID> delta) {
assertNoSet(message, "replace", delta.getValuesToReplace());
}
public static <IV extends PrismValue,ID extends ItemDefinition> void assertNoAdd(ItemDelta<IV,ID> delta) {
assertNoAdd(null, delta);
}
public static <IV extends PrismValue,ID extends ItemDefinition> void assertNoAdd(String message, ItemDelta<IV,ID> delta) {
assertNoSet(message, "add", delta.getValuesToAdd());
}
public static <IV extends PrismValue,ID extends ItemDefinition> void assertNoDelete(ItemDelta<IV,ID> delta) {
assertNoDelete(null, delta);
}
public static <IV extends PrismValue,ID extends ItemDefinition> void assertNoDelete(String message, ItemDelta<IV,ID> delta) {
assertNoSet(message, "delete", delta.getValuesToDelete());
}
private static <V extends PrismValue> void assertNoSet(String message, String type, Collection<V> set) {
assert set == null : (message == null ? "" : message + ": ") + "Delta "+type+" set expected to be null but it is "+set;
}
public static void assertNoDelta(String message, ObjectDelta<?> delta) {
assert delta == null : "Unexpected "+message+"; got "+delta;
}
// DeltaSetTriple asserts
public static <T, V extends PrismValue> void assertTriplePlus(PrismValueDeltaSetTriple<V> triple, T... expectedValues) {
assert triple != null : "triple is null";
assertTripleSet("plus set", triple.getPlusSet(), expectedValues);
}
public static <T, V extends PrismValue> void assertTripleZero(PrismValueDeltaSetTriple<V> triple, T... expectedValues) {
assert triple != null : "triple is null";
assertTripleSet("zero set", triple.getZeroSet(), expectedValues);
}
public static <T, V extends PrismValue> void assertTripleMinus(PrismValueDeltaSetTriple<V> triple, T... expectedValues) {
assert triple != null : "triple is null";
assertTripleSet("minus set", triple.getMinusSet(), expectedValues);
}
public static <T, V extends PrismValue> void assertTripleSet(String setName, Collection<V> tripleSet, T... expectedValues) {
assert tripleSet.size() == expectedValues.length : "Unexpected number of elements in triple "+setName+", expected "+
expectedValues.length + ", was " + tripleSet.size() + ": "+tripleSet;
for (T expectedValue: expectedValues) {
boolean found = false;
for (V tval: tripleSet) {
if (tval instanceof PrismPropertyValue) {
PrismPropertyValue<T> pval = (PrismPropertyValue<T>)tval;
if (expectedValue.equals(pval.getValue())) {
found = true;
break;
}
} else {
throw new IllegalArgumentException("Unknown type of prism value "+tval);
}
}
if (!found) {
assert false : "Expected value '"+DebugUtil.valueAndClass(expectedValue)+"' was not found in triple "+setName+"; values :"+tripleSet;
}
}
}
public static void assertTripleNoPlus(DeltaSetTriple<?> triple) {
assert triple != null : "triple is null";
assertTripleNoSet("plus set", triple.getPlusSet());
}
public static void assertTripleNoZero(DeltaSetTriple<?> triple) {
assert triple != null : "triple is null";
assertTripleNoSet("zero set", triple.getZeroSet());
}
public static void assertTripleNoMinus(DeltaSetTriple<?> triple) {
assert triple != null : "triple is null";
assertTripleNoSet("minus set", triple.getMinusSet());
}
public static void assertTripleNoSet(String setName, Collection<?> set) {
assert set == null || set.isEmpty() : "Expected triple "+setName+" to be empty, but it was: "+set;
}
public static void assertTripleEmpty(DeltaSetTriple<?> triple) {
assert triple != null : "triple is null (expected it to be empty)";
assert triple.isEmpty() : "triple is not empty, it is: "+triple;
}
public static void assertEquals(String message, PolyString expected, PolyString actual) {
assert expected.equals(actual) : message + "; expected " + DebugUtil.dump(expected) + ", was " +
DebugUtil.dump(actual);
}
public static void assertEqualsPolyString(String message, String expectedOrig, PolyString actual) {
PolyString expected = new PolyString(expectedOrig);
expected.recompute(PrismTestUtil.getPrismContext().getDefaultPolyStringNormalizer());
assertEquals(message, expected, actual);
}
public static void assertEqualsPolyString(String message, String expectedOrig, PolyStringType actual) {
if (expectedOrig == null && actual == null) {
return;
}
assert actual != null : message + ": null value";
assert MiscUtil.equals(expectedOrig, actual.getOrig()) : message+"; expected orig '"+expectedOrig+ "' but was '" + actual.getOrig() + "'";
PolyString expected = new PolyString(expectedOrig);
expected.recompute(PrismTestUtil.getPrismContext().getDefaultPolyStringNormalizer());
assert MiscUtil.equals(expected.getNorm(), actual.getNorm()) : message+"; expected norm '"+expected.getNorm()+ "' but was '" + actual.getNorm() + "'";
}
public static void assertEqualsPolyString(String message, PolyStringType expected, PolyStringType actual) {
assert actual != null : message + ": null value";
assert MiscUtil.equals(expected.getOrig(), actual.getOrig()) : message+"; expected orig '"+expected.getOrig()+ "' but was '" + actual.getOrig() + "'";
assert MiscUtil.equals(expected.getNorm(), actual.getNorm()) : message+"; expected norm '"+expected.getNorm()+ "' but was '" + actual.getNorm() + "'";
}
// Calendar asserts
public static void assertEquals(String message, XMLGregorianCalendar expected, Object actual) {
if (actual instanceof XMLGregorianCalendar) {
XMLGregorianCalendar actualXmlCal = (XMLGregorianCalendar)actual;
assertEquals(message, XmlTypeConverter.toMillis(expected), XmlTypeConverter.toMillis(actualXmlCal));
} else {
assert false : message+": expected instance of XMLGregorianCalendar but got "+actual.getClass().getName();
}
}
// Misc
public static void assertClass(String message, Class<?> expectedClass, PrismObject<?> actualObject) {
assert actualObject != null : message + "is null";
Class<?> actualCompileTimeClass = actualObject.getCompileTimeClass();
assert actualCompileTimeClass == expectedClass : message+" wrong class, expected "+expectedClass+" but was "+actualCompileTimeClass;
}
public static void assertClass(String message, Class<?> expectedClass, Objectable actualObject) {
assert actualObject != null : message + "is null";
Class<?> actualCompileTimeClass = actualObject.getClass();
assert actualCompileTimeClass == expectedClass : message+" wrong class, expected "+expectedClass+" but was "+actualCompileTimeClass;
}
public static void assertClass(String message, Class<?> expectedClass, ObjectDelta<?> actualDelta) {
assert actualDelta != null : message + "is null";
Class<?> actualCompileTimeClass = actualDelta.getObjectTypeClass();
assert actualCompileTimeClass == expectedClass : message+" wrong class, expected "+expectedClass+" but was "+actualCompileTimeClass;
}
// OBJECT asserts
public static void assertElementsEquals(Object expected, Object actual) throws SchemaException {
assertEquals(elementToPrism(expected), elementToPrism(actual));
}
public static void assertEquals(File fileNewXml, String objectString) throws SchemaException, IOException {
assertEquals(toPrism(fileNewXml), toPrism(objectString));
}
public static void assertEquals(Objectable expected, Objectable actual) throws SchemaException {
assertEquals(actual.asPrismObject(), actual.asPrismObject());
}
public static void assertEquals(File fileNewXml, Objectable objectable) throws SchemaException, IOException {
assertEquals(toPrism(fileNewXml), objectable.asPrismObject());
}
public static <O extends Objectable> void assertEquals(File fileNewXml, PrismObject<O> actual) throws SchemaException, IOException {
PrismObject<O> expected = toPrism(fileNewXml);
assertEquals(expected, actual);
}
public static <O extends Objectable> void assertEquals(PrismObject<O> prism1, PrismObject<O> prism2) {
assertEquals(null, prism1, prism2);
}
public static <O extends Objectable> void assertEquals(String message, PrismObject<O> expected, PrismObject<O> actual) {
if (expected == null && actual == null) {
return;
}
if (expected == null) {
fail(message + ": expected null, was "+actual);
}
if (actual == null) {
fail(message + ": expected "+expected+", was null");
}
if (expected.equals(actual)) {
return;
}
if (message == null) {
message = "Prism object not equal";
}
ObjectDelta delta = expected.diff(actual);
String suffix = "the difference: "+delta;
if (delta.isEmpty()) {
suffix += ": Empty delta. The difference is most likely in meta-data";
}
LOGGER.error("ASSERT: {}: {} and {} not equals, delta:\n{}", message, expected, actual, delta.debugDump());
assert false: message + ": " + suffix;
}
public static <O extends Objectable> void assertEquivalent(File expectedFile, PrismObject<O> actual) throws SchemaException, IOException {
assertEquivalent("Object "+actual+" not equivalent to that from file "+expectedFile,expectedFile,actual);
}
public static <O extends Objectable> void assertEquivalent(String message, File expectedFile, PrismObject<O> actual) throws SchemaException, IOException {
PrismObject<O> expected = toPrism(expectedFile);
assertEquivalent(message, expected, actual);
}
public static <O extends Objectable> void assertEquivalent(String message, PrismObject<O> expected, PrismObject<O> actual) {
if (expected == null && actual == null) {
return;
}
if (expected == null) {
fail(message + ": expected null, was "+actual);
}
if (actual == null) {
fail(message + ": expected "+expected+", was null");
}
if (expected.equivalent(actual)) {
return;
}
if (message == null) {
message = "Prism object not equal";
}
ObjectDelta<O> delta = expected.diff(actual);
String suffix = "the difference: "+delta;
if (delta.isEmpty()) {
suffix += ": Empty delta. This is not expected. Somethig has got quite wrong here.";
}
LOGGER.error("ASSERT: {}: {} and {} not equivalent, delta:\n{}", new Object[]{
message, expected, actual, delta.debugDump()
});
assert false: message + ": " + suffix;
}
private static <T> void assertSet(String inMessage, String setName, Collection<PrismPropertyValue<T>> actualPValues, T[] expectedValues) {
assertValues(setName + " set in " + inMessage, actualPValues, expectedValues);
}
public static <T> void assertValues(String message, Collection<PrismPropertyValue<T>> actualPValues, T... expectedValues) {
assertNotNull("Null set in " + message, actualPValues);
if (expectedValues.length != actualPValues.size()) {
fail("Wrong number of values in " + message+ "; expected "+expectedValues.length+" (real values) "
+PrettyPrinter.prettyPrint(expectedValues)+"; has "+actualPValues.size()+" (pvalues) "+actualPValues);
}
for (PrismPropertyValue<?> actualPValue: actualPValues) {
boolean found = false;
for (T value: expectedValues) {
if (value.equals(actualPValue.getValue())) {
found = true;
}
}
if (!found) {
fail("Unexpected value "+actualPValue+" in " + message + "; expected (real values) "
+PrettyPrinter.prettyPrint(expectedValues)+"; has (pvalues) "+actualPValues);
}
}
}
private static void assertOidSet(String inMessage, String setName, Collection<PrismReferenceValue> actualPValues, String... expectedOids) {
assertOidValues(setName + " set in " + inMessage, actualPValues, expectedOids);
}
public static void assertOidValues(String message, Collection<PrismReferenceValue> actualRValues, String... expectedOids) {
assertNotNull("Null set in " + message, actualRValues);
if (expectedOids.length != actualRValues.size()) {
fail("Wrong number of values in " + message+ "; expected "+expectedOids.length+" (oids) "
+PrettyPrinter.prettyPrint(expectedOids)+"; has "+actualRValues.size()+" (rvalues) "+actualRValues);
}
for (PrismReferenceValue actualRValue: actualRValues) {
boolean found = false;
for (String oid: expectedOids) {
if (oid.equals(actualRValue.getOid())) {
found = true;
}
}
if (!found) {
fail("Unexpected value "+actualRValue+" in " + message + "; expected (oids) "
+PrettyPrinter.prettyPrint(expectedOids)+"; has (rvalues) "+actualRValues);
}
}
}
public static <T> void assertSets(String message, Collection<T> actualValues, T... expectedValues) {
try {
assertSets(message, null, actualValues, expectedValues);
} catch (SchemaException e) {
// no matching rule. should not happen
throw new IllegalStateException(e.getMessage(), e);
}
}
public static <T> void assertSets(String message, MatchingRule<T> matchingRule, Collection<T> actualValues, T... expectedValues) throws SchemaException {
assertNotNull("Null set in " + message, actualValues);
assertEquals("Wrong number of values in " + message+ "; expected (real values) "
+PrettyPrinter.prettyPrint(expectedValues)+"; has (pvalues) "+actualValues,
expectedValues.length, actualValues.size());
for (T actualValue: actualValues) {
boolean found = false;
for (T value: expectedValues) {
if (matchingRule == null) {
if (value.equals(actualValue)) {
found = true;
}
} else {
if (matchingRule.match(value, actualValue)) {
found = true;
}
}
}
if (!found) {
fail("Unexpected value "+actualValue+" in " + message + "; expected (real values) "
+PrettyPrinter.prettyPrint(expectedValues)+"; has (pvalues) "+actualValues);
}
}
}
private static <O extends Objectable> PrismObject<O> toPrism(String objectString) throws SchemaException {
return PrismTestUtil.parseObject(objectString);
}
private static <O extends Objectable> PrismObject<O> toPrism(File objectFile) throws SchemaException, IOException {
return PrismTestUtil.parseObject(objectFile);
}
private static <O extends Objectable> PrismObject<O> toPrism(Element domNode) throws SchemaException {
return PrismTestUtil.parseObject(domNode);
}
private static <O extends Objectable> PrismObject<O> elementToPrism(Object element) throws SchemaException {
if (element instanceof Element) {
return toPrism((Element)element);
} else if (element instanceof JAXBElement<?>) {
JAXBElement<?> jaxbElement = (JAXBElement)element;
Object value = jaxbElement.getValue();
if (value instanceof Objectable) {
return ((Objectable)value).asPrismObject();
} else {
throw new IllegalArgumentException("Unknown JAXB element value "+value);
}
} else {
throw new IllegalArgumentException("Unknown element type "+element);
}
}
public static void assertOids(Collection<? extends PrismObject<?>> objects, String... expectedOids) {
if ((objects == null || objects.isEmpty()) && expectedOids.length == 0) {
return;
}
if (objects == null) {
fail("Expected OIDs "+Arrays.toString(expectedOids)+", but got no object");
}
if (objects.size() != expectedOids.length) {
fail("Expected OIDs "+Arrays.toString(expectedOids)+", but got "+objects);
}
for (String expectedOid: expectedOids) {
boolean found = false;
for (PrismObject<?> object: objects) {
if (expectedOid.equals(object.getOid())) {
found = true;
break;
}
}
if (!found) {
fail("Expected OIDs "+Arrays.toString(expectedOids)+", but got "+objects);
}
}
}
// XNode asserts
public static void assertSize(MapXNode xmap, int expectedSize) {
assertEquals("Wrong size of "+xmap, expectedSize, xmap.size());
}
public static void assertSize(ListXNode xlist, int expectedSize) {
assertEquals("Wrong size of "+xlist, expectedSize, xlist.size());
}
public static void assertSubnode(MapXNode xmap, QName key, Class expectedClass) {
XNode xsubnode = xmap.get(key);
assert xsubnode != null : "No subnode "+key+" in "+xmap;
assert expectedClass.isAssignableFrom(xsubnode.getClass()) : "Wrong class of subnode "+key+" in "+xmap+"; expected "+expectedClass+", got "+xsubnode.getClass();
}
public static void assertAllParsedNodes(XNode xnode) {
Visitor visitor = new Visitor() {
@Override
public void visit(Visitable visitable) {
if ((visitable instanceof PrimitiveXNode<?>)) {
assert ((PrimitiveXNode<?>)visitable).isParsed() : "Xnode "+visitable+" is not parsed";
}
}
};
xnode.accept(visitor);
}
// Query asserts
public static void assertOrFilter(ObjectFilter filter, int conditions) {
assertEquals("Wrong filter class", OrFilter.class, filter.getClass());
assertEquals("Wrong number of filter conditions", conditions, ((OrFilter) filter).getConditions().size());
}
public static void assertAndFilter(ObjectFilter filter, int conditions) {
assertEquals("Wrong filter class", AndFilter.class, filter.getClass());
assertEquals("Wrong number of filter conditions", conditions, ((AndFilter) filter).getConditions().size());
}
public static void assertEqualsFilter(ObjectFilter objectFilter, QName expectedFilterDef,
QName expectedTypeName, ItemPath path) {
assertEquals("Wrong filter class", EqualFilter.class, objectFilter.getClass());
EqualFilter filter = (EqualFilter) objectFilter;
//we don't have definition in all situation..this is almost OK..it will be computed dynamicaly
if (filter.getDefinition() != null){
assertEquals("Wrong filter definition element name", expectedFilterDef, filter.getDefinition().getName());
assertEquals("Wrong filter definition type", expectedTypeName, filter.getDefinition().getTypeName());
}
assertPathEquivalent("Wrong filter path", path, filter.getFullPath());
}