/
TestSupportedEntityProxyLifecycle.java
1588 lines (1309 loc) · 70.5 KB
/
TestSupportedEntityProxyLifecycle.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
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */
package org.odpi.openmetadata.conformance.tests.repository.instances;
import org.odpi.openmetadata.conformance.ffdc.ConformanceSuiteAuditCode;
import org.odpi.openmetadata.conformance.ffdc.exception.AssertionFailureException;
import org.odpi.openmetadata.conformance.tests.repository.RepositoryConformanceTestCase;
import org.odpi.openmetadata.conformance.workbenches.repository.RepositoryConformanceProfileRequirement;
import org.odpi.openmetadata.conformance.workbenches.repository.RepositoryConformanceWorkPad;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.OMRSMetadataCollection;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityProxy;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntitySummary;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceStatus;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.EntityDef;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.RelationshipDef;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryConnector;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityProxyOnlyException;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.FunctionNotSupportedException;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidParameterException;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.RelationshipNotKnownException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* Test that all defined entities can be stored and retrieved as proxies, that the proxies support all (and only) valid operations, and that they can be deleted/purged.
*/
public class TestSupportedEntityProxyLifecycle extends RepositoryConformanceTestCase
{
private static final String testCaseId = "repository-entity-proxy-lifecycle";
private static final String testCaseName = "Repository entity proxy lifecycle test case";
private static final String assertion1 = testCaseId + "-01";
private static final String assertionMsg1 = " repository does not support entity types required for ends of relationship of type ";
private static final String assertion2 = testCaseId + "-2";
private static final String assertionMsg2 = " repository does not support creation of entity proxies for type ";
private static final String assertion3 = testCaseId + "-03";
private static final String assertionMsg3 = " repository supports retrieval of entity proxy as an EntitySummary for type ";
private static final String assertion4 = testCaseId + "-04";
private static final String assertionMsg4 = " repository disallows retrieval of entity proxy as an EntityDetail for type ";
private static final String assertion5 = testCaseId + "-05";
private static final String assertionMsg5 = " repository disallows isEntityKnown for entity proxy for type ";
private static final String assertion6 = testCaseId + "-06";
private static final String assertionMsg6 = " repository does not support creation of relationship instance for type ";
private static final String assertion7 = testCaseId + "-07";
private static final String assertionMsg7 = " repository supports soft delete of relationship instance for type ";
private static final String assertion8 = testCaseId + "-08";
private static final String assertionMsg8 = " repository supports delete of entity proxy of type ";
private static final String assertion9 = testCaseId + "-09";
private static final String assertionMsg9 = " entity proxy status cannot be updated ";
private static final String assertion10 = testCaseId + "-10";
private static final String assertionMsg10 = " entity proxy properties cannot be updated ";
private static final String assertion11 = testCaseId + "-11";
private static final String assertionMsg11 = " entity proxy type cannot be updated ";
private static final String assertion12 = testCaseId + "-12";
private static final String assertionMsg12 = " entity proxy identity cannot be updated ";
private final List<EntityDetail> createdEntitiesCTS = new ArrayList<>(); // these are all master instances
private final List<EntityDetail> createdEntitiesTUT = new ArrayList<>(); // these are all master instances
private final List<EntityDetail> createdEntityRefCopiesTUT = new ArrayList<>(); // these are all ref copies
private final List<EntityProxy> createdEntityProxiesTUT = new ArrayList<>(); // these are all proxy instances
private final List<Relationship> createdRelationshipsTUT = new ArrayList<>(); // these are all master instances
/*
* This testcase:
*
* Accepts a RelationshipDef and the set of EntityDefs supported by the TUT.
* This allows the creation of a relationship and a pair of entities (one for each end of the relationship).
*
* 1. Creates an entity E1 in the CTS server
* 1a. The master instance of E1 is created in the CTS server's repository
* 1b. A NEW_ENTITY_EVENT is flowed to the TUT for E1
* 1c. The TUT should create a reference copy of E1 - we are not interested in the ref copy, but we need to be aware of it and purge it.
*
* 2. The E1ref copy is purged from the TUT
*
* 3. A proxy of E1 is created at the TUT
* 3a. The entity E1 is retrieved from the CTS
* 3b. The entity instance is transformed (in memory) into a proxy
* 3c. The proxy E1' is installed in the TUT by a REST call to the TUT's metadataCollection addEntityProxy method
* 3d. The TUT creates an E1' proxy.
*
* 4. All the above is repeated for a second entity. This avoids requiring that the TUT supports creation of locally mastered entities or reference copies.
* It would be sufficient to support the ENTITY_PROXIES profile if the TUT only supports the creation of proxies of entities mastered elsewhere (in this test at the CTS)
*
* 5. Perform retrieval tests on the E1' proxy:
* 5a. The proxy should be able to be retrieved using getEntitySummary()
* 5b. The proxy should NOT be able to be retrieved using getEntityDetail()
* 5c. The proxy should NOT be able to be retrieved using isEntityKnown()
*
*
* 6. Create a relationship between E1' (proxy) and E2' (proxy)
* 6a. Create the relationship at the TUT and verify it succeeds
* 6b. Delete and purge the relationship
*
* 7. Delete E1 (master)
* 7a. The master instance of E1 is deleted at the CTS
* 7b. This will flow a DELETED_ENTITY event to the TUT, which should (soft) delete the E1' proxy - this tests that proxies are handled effectively like ref copies
* 7c. The master instance of E1 is purged at the CTS
* 7d. This will flow a PYRGED_ENTITY event to the TUT, which should purge the E1' entity proxy - this tests that proxies are handled effectively like ref copies
* 7e. Verify that the E1' proxy has been removed from the TUT
*
* 8. Repeat step 7 for E2.
*/
private final RepositoryConformanceWorkPad workPad;
private final Map<String, EntityDef> entityDefs;
private final RelationshipDef relationshipDef;
private final String testTypeName;
/*
* A propagation timeout is used to limit how long the testcase will wait for
* the propagation of an OMRS instance event and consequent processing at the TUT (or CTS).
* Each time the testcase waits it does so in a 100ms polling loop, to minimise overall delay.
* The wait loops will wait for pollCount iterations of pollPeriod, so a pollCount of x10
* results in a 1000ms (1s) timeout.
*
*/
private Integer pollCount = 100;
private Integer pollPeriod = 100; // milliseconds
/**
* Typical constructor sets up superclass and discovered information needed for tests
*
* @param workPad place for parameters and results
* @param entityDefs types of valid entities
* @param relationshipDef type of relationship to test
*/
public TestSupportedEntityProxyLifecycle(RepositoryConformanceWorkPad workPad,
Map<String, EntityDef> entityDefs,
RelationshipDef relationshipDef)
{
super(workPad,
RepositoryConformanceProfileRequirement.RETRIEVE_ENTITY_PROXIES.getProfileId(),
RepositoryConformanceProfileRequirement.RETRIEVE_ENTITY_PROXIES.getRequirementId());
this.workPad = workPad;
this.relationshipDef = relationshipDef;
this.entityDefs = entityDefs;
/*
* Although this is test case is concerned with proxies - it is desirable to have a relationship to test with.
* The testcase is named after the relationship type.
*/
this.testTypeName = this.updateTestIdByType(relationshipDef.getName(),
testCaseId,
testCaseName);
/*
* Enforce minimum pollPeriod and pollCount.
*/
this.pollPeriod = Math.max(this.pollPeriod, 100);
this.pollCount = Math.max(this.pollCount, 1);
}
/**
* Method implemented by the actual test case.
*
* @throws Exception something went wrong with the test.
*/
protected void run() throws Exception
{
/*
* This test case does not perform entity or relationship type validation - this is tested in other test cases.
*/
/*
* Get access to the repositoryHelper - we'll need it in a while....
*/
OMRSRepositoryHelper repositoryHelper = null;
if (workPad != null) {
OMRSRepositoryConnector cohortRepositoryConnector = workPad.getTutRepositoryConnector();
repositoryHelper = cohortRepositoryConnector.getRepositoryHelper();
if (repositoryHelper == null) {
/*
* Critical failure - give up
*/
return;
}
}
/*
* Get the TUT metadataCollection
*/
OMRSMetadataCollection metadataCollection = super.getMetadataCollection();
/*
* This test needs a connector to the local repository - i.e. the in-memory repository running locally to the CTS server.
*/
OMRSMetadataCollection ctsMetadataCollection = repositoryConformanceWorkPad.getLocalRepositoryConnector().getMetadataCollection();
String ctsMetadataCollectionName = repositoryConformanceWorkPad.getLocalRepositoryConnector().getMetadataCollectionName();
if (ctsMetadataCollectionName == null) {
ctsMetadataCollectionName = "dummyMetadataCollectionName";
}
/*
* Find all the entity types that we could use at the ends of the requested relationship type
*
* In this testcase the repository is believed to support the relationship type defined by
* relationshipDef - but may not support all the entity inheritance hierarchy - it may only
* support a subset of entity types. So although the relationship type may have end definitions
* each specifying a given entity type - the repository may only support certain sub-types of the
* specified type. This is OK, and the testcase needs to only try to use entity types that are
* supported by the repository being tested. To do this it needs to start with the specified
* end type, e.g. Referenceable, and walk down the hierarchy looking for each subtype that
* is supported by the repository (i.e. is in the entityDefs map). The test is run for
* each combination of end1Type and end2Type - but only for types that are within the
* active set for this repository.
*/
String end1DefName = relationshipDef.getEndDef1().getEntityType().getName();
List<String> end1DefTypeNames = new ArrayList<>();
end1DefTypeNames.add(end1DefName);
if (this.workPad != null && this.workPad.getEntitySubTypes(end1DefName) != null) {
end1DefTypeNames.addAll(this.workPad.getEntitySubTypes(end1DefName));
}
String end2DefName = relationshipDef.getEndDef2().getEntityType().getName();
List<String> end2DefTypeNames = new ArrayList<>();
end2DefTypeNames.add(end2DefName);
if (this.workPad.getEntitySubTypes(end2DefName) != null) {
end2DefTypeNames.addAll(this.workPad.getEntitySubTypes(end2DefName));
}
/*
* Filter the possible types to only include types that are supported by the repository
*/
List<String> end1SupportedTypeNames = new ArrayList<>();
for (String end1TypeName : end1DefTypeNames) {
if (entityDefs.get(end1TypeName) != null)
end1SupportedTypeNames.add(end1TypeName);
}
List<String> end2SupportedTypeNames = new ArrayList<>();
for (String end2TypeName : end2DefTypeNames) {
if (entityDefs.get(end2TypeName) != null)
end2SupportedTypeNames.add(end2TypeName);
}
/*
* Check that neither list is empty
*/
if (end1SupportedTypeNames.isEmpty() || end2SupportedTypeNames.isEmpty()) {
/*
* There are no supported types for at least one of the ends - the repository cannot test this relationship type.
*/
assertCondition((false),
assertion1,
testTypeName + assertionMsg1,
RepositoryConformanceProfileRequirement.RELATIONSHIP_LIFECYCLE.getProfileId(),
RepositoryConformanceProfileRequirement.RELATIONSHIP_LIFECYCLE.getRequirementId());
}
/*
* It is not practical to iterate over all combinations of feasible (supported) end types as it takes too long to run.
* For now, this test verifies relationship operation over a limited set of end types. The limitation is extreme in
* that it ONLY takes the first available type for each end. This is undesirable for two reasons - one is that it
* provides less test coverage; the other is that the types chosen depend on the order in the lists and this could
* vary, making results non-repeatable. For now though, it seems these limitations are necessary.
*
* A full permutation across end types would use the following nested loops...
* for (String end1TypeName : end1SupportedTypeNames) {
* for (String end2TypeName : end2SupportedTypeNames) {
* test logic as below...
* }
* }
*/
String end1TypeName = end1SupportedTypeNames.get(0);
String end2TypeName = end2SupportedTypeNames.get(0);
/*
* Create E1 at the CTS
*/
EntityDef end1Type = entityDefs.get(end1TypeName);
/*
* Generate property values for all the type's defined properties, including inherited properties
* This ensures that any properties defined as mandatory by Egeria property cardinality are provided
* thereby getting into the connector-logic beyond the property validation. It also creates an
* entity that is logically complete - versus an instance with just the locally-defined properties.
*/
EntityDetail entity1 = ctsMetadataCollection.addEntity(workPad.getLocalServerUserId(),
end1Type.getGUID(),
super.getAllPropertiesForInstance(workPad.getLocalServerUserId(), end1Type),
null,
null);
createdEntitiesCTS.add(entity1);
/*
* This test does not verify the content of the entity - that is tested in the entity-lifecycle tests
*/
/*
* A reference copy of the entity should be created in the TUT
*/
EntityDetail entity1Ref = null;
/*
* Retrieve the ref copy from the TUT - if it does not exist, assert that ref copies are not a discovered property
* Have to be prepared to wait until event has propagated and TUT has created a reference copy of the entity.
*/
try
{
Integer remainingCount = this.pollCount;
while (entity1Ref == null && remainingCount > 0)
{
entity1Ref = metadataCollection.isEntityKnown(workPad.getLocalServerUserId(), entity1.getGUID());
Thread.sleep(this.pollPeriod);
remainingCount--;
}
if (entity1Ref == null && remainingCount == 0)
{
workPad.getAuditLog()
.logMessage(assertion2,
ConformanceSuiteAuditCode.POLLING_OVERFLOW.getMessageDefinition(pollCount.toString(), pollPeriod.toString()));
}
}
catch (Exception exc)
{
/*
* We are not expecting any exceptions from this method call. Log and fail the test.
*/
String methodName = "isEntityKnown";
String operationDescription = "retrieve an entity of type " + end1Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("entityGUID", entity1.getGUID());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
createdEntityRefCopiesTUT.add(entity1Ref);
/*
* This test needs to eliminate the reference copy - so that a proxy of E1 can be created at the TUT.
*/
if (entity1Ref != null)
{
/*
* If we retrieved the reference copy of the entity - we must purge it.
*
* If there is no reference copy it may be because the TUT does not support ref copies - that's OK, we can continue with the test of proxy support
*/
try
{
metadataCollection.purgeEntityReferenceCopy(workPad.getLocalServerUserId(), entity1Ref);
}
catch (Exception exc)
{
/*
* We are not expecting any other exceptions from this method call. Log and fail the test.
*/
String methodName = "purgeEntityReferenceCopy";
String operationDescription = "purge a reference copy of an entity of type " + end1Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("typeDefGUID", entity1Ref.getType().getTypeDefGUID());
parameters.put("typeDefName", entity1Ref.getType().getTypeDefName());
parameters.put("deletedEntityGUID", entity1Ref.getGUID());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
}
/*
* Retrieve the master instance of entity1 from the CTS and fashion a proxy from it.
*/
EntityDetail retrievedEntity1 = ctsMetadataCollection.getEntityDetail(workPad.getLocalServerUserId(), entity1.getGUID());
EntityProxy entity1Proxy;
if (retrievedEntity1 != null && repositoryHelper != null) {
entity1Proxy = repositoryHelper.getNewEntityProxy(ctsMetadataCollectionName, retrievedEntity1);
} else {
/*
* If we cannot retrieve the entity (detail) from the CTS repository then we are in deep trouble.
* The CTS is (most probably) using the in-memory repository which absolutely should support retrieval.
* If this is not working do not pursue the test any further. By returning we will report UNKNOWN_STATUS
* for the proxies profile for the repository actually being tested - which is a sensible outcome.
*/
return;
}
/*
* Ask the TUT to add the entity proxy to its repository
*/
long elapsedTime;
try
{
long start = System.currentTimeMillis();
metadataCollection.addEntityProxy(workPad.getLocalServerUserId(), entity1Proxy);
elapsedTime = System.currentTimeMillis() - start;
assertCondition((true),
assertion2,
assertionMsg2 + end1TypeName,
RepositoryConformanceProfileRequirement.STORE_ENTITY_PROXIES.getProfileId(),
RepositoryConformanceProfileRequirement.STORE_ENTITY_PROXIES.getRequirementId(),
"addEntityProxy",
elapsedTime);
createdEntityProxiesTUT.add(entity1Proxy);
}
catch (FunctionNotSupportedException exception)
{
/*
* Report that the TUT does not support the creation of proxies - and do not pursue the test any further
*/
super.addNotSupportedAssertion(assertion2,
assertionMsg2 + end1TypeName,
RepositoryConformanceProfileRequirement.STORE_ENTITY_PROXIES.getProfileId(),
RepositoryConformanceProfileRequirement.STORE_ENTITY_PROXIES.getRequirementId());
return;
}
catch (AssertionFailureException exception)
{
/*
* Re throw this exception, so it is not masked by Exception (below).
*/
throw exception;
}
catch (Exception exc)
{
/*
* We are not expecting any exceptions from this method call. Log and fail the test.
*/
String methodName = "addEntityProxy";
String operationDescription = "add a proxy instance for an entity of type " + end1Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("entityProxy", entity1Proxy.toString());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
/*
* Create E2 at the CTS
*/
EntityDef end2Type = entityDefs.get(end2TypeName);
/*
* Generate property values for all the type's defined properties, including inherited properties
* This ensures that any properties defined as mandatory by Egeria property cardinality are provided
* thereby getting into the connector-logic beyond the property validation. It also creates an
* entity that is logically complete - versus an instance with just the locally-defined properties.
*/
EntityDetail entity2 = ctsMetadataCollection.addEntity(workPad.getLocalServerUserId(),
end2Type.getGUID(),
super.getAllPropertiesForInstance(workPad.getLocalServerUserId(), end2Type),
null,
null);
createdEntitiesCTS.add(entity2);
/*
* This test does not verify the content of the entity - that is tested in the entity-lifecycle tests
*/
/*
* A reference copy of the entity should be created in the TUT
*/
EntityDetail entity2Ref = null;
/*
* Retrieve the ref copy from the TUT - if it does not exist, assert that ref copies are not a discovered property
* Have to be prepared to wait until event has propagated and TUT has created a reference copy of the entity.
*/
try
{
Integer remainingCount = this.pollCount;
while (entity2Ref == null && remainingCount > 0)
{
entity2Ref = metadataCollection.isEntityKnown(workPad.getLocalServerUserId(), entity2.getGUID());
Thread.sleep(this.pollPeriod);
remainingCount--;
}
if (entity2Ref == null && remainingCount == 0)
{
workPad.getAuditLog()
.logMessage(assertion2,
ConformanceSuiteAuditCode.POLLING_OVERFLOW.getMessageDefinition(pollCount.toString(), pollPeriod.toString()));
}
}
catch (Exception exc)
{
/*
* We are not expecting any exceptions from this method call. Log and fail the test.
*/
String methodName = "isEntityKnown";
String operationDescription = "retrieve an entity of type " + end2Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("entityGUID", entity2.getGUID());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
createdEntityRefCopiesTUT.add(entity2Ref);
/*
* This test needs to eliminate the reference copy - so that a proxy of E2 can be created at the TUT.
*/
if (entity2Ref != null)
{
/*
* If we retrieved the reference copy of the entity - we must purge it.
*
* If there is no reference copy it may be because the TUT does not support ref copies - that's OK, we can continue with the test of proxy support
*/
try
{
metadataCollection.purgeEntityReferenceCopy(workPad.getLocalServerUserId(), entity2Ref);
}
catch (Exception exc)
{
/*
* We are not expecting any other exceptions from this method call. Log and fail the test.
*/
String methodName = "purgeEntityReferenceCopy";
String operationDescription = "purge a reference copy an entity of type " + end2Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("typeDefGUID", entity2Ref.getType().getTypeDefGUID());
parameters.put("typeDefName", entity2Ref.getType().getTypeDefName());
parameters.put("deletedEntityGUID", entity2Ref.getGUID());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
}
/*
* Retrieve the master instance of entity2 from the CTS and fashion a proxy from it.
*/
EntityDetail retrievedEntity2 = ctsMetadataCollection.getEntityDetail(workPad.getLocalServerUserId(), entity2.getGUID());
EntityProxy entity2Proxy;
if (retrievedEntity2 != null) {
entity2Proxy = repositoryHelper.getNewEntityProxy(ctsMetadataCollectionName, retrievedEntity2);
} else {
/*
* If we cannot retrieve the entity (detail) from the CTS repository then we are in deep trouble.
* The CTS is (most probably) using the in-memory repository which absolutely should support retrieval.
* If this is not working do not pursue the test any further. By returning we will report UNKNOWN_STATUS
* for the proxies profile for the repository actually being tested - which is a sensible outcome.
*/
return;
}
/*
* Ask the TUT to add the E2' entity proxy to its repository
*/
try {
long start = System.currentTimeMillis();
metadataCollection.addEntityProxy(workPad.getLocalServerUserId(), entity2Proxy);
elapsedTime = System.currentTimeMillis() - start;
assertCondition((true),
assertion2,
assertionMsg2 + end2TypeName,
RepositoryConformanceProfileRequirement.STORE_ENTITY_PROXIES.getProfileId(),
RepositoryConformanceProfileRequirement.STORE_ENTITY_PROXIES.getRequirementId(),
"addEntityProxy",
elapsedTime);
createdEntityProxiesTUT.add(entity2Proxy);
} catch (FunctionNotSupportedException excpetion) {
/*
* Report that the TUT does not support the creation of proxies - and do not pursue the test any further
*/
super.addNotSupportedAssertion(assertion2,
assertionMsg2 + end2TypeName,
RepositoryConformanceProfileRequirement.STORE_ENTITY_PROXIES.getProfileId(),
RepositoryConformanceProfileRequirement.STORE_ENTITY_PROXIES.getRequirementId());
return;
} catch (Exception exc) {
/*
* We are not expecting any exceptions from this method call. Log and fail the test.
*/
String methodName = "addEntityProxy";
String operationDescription = "add a proxy instance for an entity of type " + end2Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("entityProxy", entity2Proxy.toString());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
/*
* Perform retrieval tests on the E1 proxy (only - these tests are not repeated for E2 proxy).
*/
/*
* It SHOULD be possible to retrieve the proxy as an EntitySummary
*/
EntitySummary retrievedEntity1Summary = null;
try
{
long start = System.currentTimeMillis();
retrievedEntity1Summary = metadataCollection.getEntitySummary(workPad.getLocalServerUserId(), entity1.getGUID());
elapsedTime = System.currentTimeMillis() - start;
}
catch (Exception exc)
{
/*
* We are not expecting any exceptions from this method call. Log and fail the test.
*/
String methodName = "getEntitySummary";
String operationDescription = "retrieve an entity of type " + end1Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("entityGUID", entity1.getGUID());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
assertCondition((retrievedEntity1Summary != null),
assertion3,
assertionMsg3 + end1TypeName,
RepositoryConformanceProfileRequirement.RETRIEVE_ENTITY_PROXIES.getProfileId(),
RepositoryConformanceProfileRequirement.RETRIEVE_ENTITY_PROXIES.getRequirementId(),
"getEntitySummary",
elapsedTime);
/*
* It SHOULD NOT be possible to retrieve the proxy as an EntityDetail - this should throw EntityProxyOnlyException
*/
long start = System.currentTimeMillis();
try
{
EntityDetail retrievedEntity1Detail = metadataCollection.getEntityDetail(workPad.getLocalServerUserId(), entity1.getGUID());
elapsedTime = System.currentTimeMillis() - start;
assertCondition((false),
assertion4,
assertionMsg4 + end1TypeName,
RepositoryConformanceProfileRequirement.RETRIEVE_ENTITY_PROXIES.getProfileId(),
RepositoryConformanceProfileRequirement.RETRIEVE_ENTITY_PROXIES.getRequirementId(),
"getEntityDetail-negative",
elapsedTime);
}
catch (EntityProxyOnlyException exception)
{
elapsedTime = System.currentTimeMillis() - start;
assertCondition((true),
assertion4,
assertionMsg4 + end1TypeName,
RepositoryConformanceProfileRequirement.RETRIEVE_ENTITY_PROXIES.getProfileId(),
RepositoryConformanceProfileRequirement.RETRIEVE_ENTITY_PROXIES.getRequirementId(),
"getEntityDetail-negative",
elapsedTime);
}
catch (AssertionFailureException exception)
{
/*
* Re throw this exception, so it is not masked by Exception (below).
*/
throw exception;
}
catch (Exception exc)
{
/*
* We are not expecting any other exceptions from this method call. Log and fail the test.
*/
String methodName = "getEntityDetail";
String operationDescription = "retrieve an entity of type " + end1Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("entityGUID", entity1.getGUID());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
/*
* It SHOULD NOT be possible to retrieve the proxy using isEntityKnown - this should return null
*/
try
{
start = System.currentTimeMillis();
EntityDetail retrievedEntity1Detail = metadataCollection.isEntityKnown(workPad.getLocalServerUserId(), entity1.getGUID());
elapsedTime = System.currentTimeMillis() - start;
assertCondition((retrievedEntity1Detail == null),
assertion5,
assertionMsg5 + end1TypeName,
RepositoryConformanceProfileRequirement.RETRIEVE_ENTITY_PROXIES.getProfileId(),
RepositoryConformanceProfileRequirement.RETRIEVE_ENTITY_PROXIES.getRequirementId(),
"isEntityKnown-negative",
elapsedTime);
}
catch (AssertionFailureException exception)
{
/*
* Re throw this exception, so it is not masked by Exception (below).
*/
throw exception;
}
catch (Exception exc)
{
/*
* We are not expecting any other exceptions from this method call. Log and fail the test.
*/
String methodName = "isEntityKnown";
String operationDescription = "retrieve an entity of type " + end1Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("entityGUID", entity1.getGUID());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
/*
* Verify that operations that should not be valid on a proxy are correctly disallowed.
* These tests are all performed on the E1 proxy.
*
* It SHOULD NOT be possible to perform any of the following operations.
*/
/*
* If the entity def has any valid status values (including DELETED), attempt
* to modify the status of the entity proxy - this should fail
*/
for (InstanceStatus validInstanceStatus : end1Type.getValidInstanceStatusList())
{
try
{
start = System.currentTimeMillis();
EntityDetail updatedEntity = metadataCollection.updateEntityStatus(workPad.getLocalServerUserId(), entity1.getGUID(), validInstanceStatus);
elapsedTime = System.currentTimeMillis() - start;
assertCondition((false),
assertion9,
testTypeName + assertionMsg9,
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getProfileId(),
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getRequirementId(),
"updateEntityStatus-negative",
elapsedTime);
}
catch (InvalidParameterException e)
{
/*
* We are not expecting the status update to work - it should have thrown an InvalidParameterException
*/
elapsedTime = System.currentTimeMillis() - start;
assertCondition((true),
assertion9,
testTypeName + assertionMsg9,
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getProfileId(),
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getRequirementId(),
"updateEntityStatus-negative",
elapsedTime);
}
catch (AssertionFailureException exception)
{
/*
* Re throw this exception, so it is not masked by Exception (below).
*/
throw exception;
}
catch (Exception exc)
{
/*
* We are not expecting any exceptions from this method call. Log and fail the test.
*/
String methodName = "updateEntityStatus";
String operationDescription = "update the status of an entity of type " + end1Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("entityGUID", entity1.getGUID());
parameters.put("newStatus", validInstanceStatus.toString());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
}
/*
* Attempt to modify one or more property of the entity proxy. This is illegal so it should fail.
*/
if ((entity1.getProperties() != null) &&
(entity1.getProperties().getInstanceProperties() != null) &&
(!entity1.getProperties().getInstanceProperties().isEmpty())) {
InstanceProperties minEntityProps = super.getMinPropertiesForInstance(workPad.getLocalServerUserId(), end1Type);
try
{
start = System.currentTimeMillis();
EntityDetail minPropertiesEntity = metadataCollection.updateEntityProperties(workPad.getLocalServerUserId(), entity1.getGUID(), minEntityProps);
elapsedTime = System.currentTimeMillis() - start;
assertCondition((false),
assertion10,
testTypeName + assertionMsg10,
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getProfileId(),
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getRequirementId(),
"updateEntityProperties-negative",
elapsedTime);
}
catch (InvalidParameterException e)
{
/*
* We are not expecting the status update to work - it should have thrown an InvalidParameterException
*/
elapsedTime = System.currentTimeMillis() - start;
assertCondition((true),
assertion10,
testTypeName + assertionMsg10,
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getProfileId(),
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getRequirementId(),
"updateEntityProperties-negative",
elapsedTime);
}
catch (AssertionFailureException exception)
{
/*
* Re throw this exception, so it is not masked by Exception (below).
*/
throw exception;
}
catch (Exception exc)
{
/*
* We are not expecting any other exceptions from this method call. Log and fail the test.
*/
String methodName = "updateEntityProperties";
String operationDescription = "update the properties of an entity of type " + end1Type.getName();
Map<String, String> parameters = new HashMap<>();
parameters.put("entityGUID", entity1.getGUID());
parameters.put("properties", minEntityProps.toString());
String msg = this.buildExceptionMessage(testCaseId, methodName, operationDescription, parameters, exc.getClass().getSimpleName(), exc.getMessage());
throw new Exception(msg, exc);
}
}
/*
* Verify that it is not possible to re-type the entity proxy.
* This test is performed using the same type as the original - the repository should not get as far as
* even looking at the type or considering changing it. For simplicity of testcode this test therefore
* uses the original type.
* This test is performed against the TUT.
*/
try
{
start = System.currentTimeMillis();
EntityDetail reTypedEntity = metadataCollection.reTypeEntity(workPad.getLocalServerUserId(),
entity1.getGUID(),
end1Type,
end1Type); // see comment above about using original type
elapsedTime = System.currentTimeMillis() - start;
assertCondition((false),
assertion11,
testTypeName + assertionMsg11,
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getProfileId(),
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getRequirementId(),
"reTypeEntity-negative",
elapsedTime);
}
catch (InvalidParameterException e)
{
/*
* We are not expecting the type update to work - it should have thrown an InvalidParameterException
*/
elapsedTime = System.currentTimeMillis() - start;
assertCondition((true),
assertion11,
testTypeName + assertionMsg11,
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getProfileId(),
RepositoryConformanceProfileRequirement.ENTITY_PROXY_LOCKING.getRequirementId(),
"reTypeEntity-negative",
elapsedTime);
}
catch (AssertionFailureException exception)