-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathBaseEntityIT.java
More file actions
6446 lines (5345 loc) · 237 KB
/
BaseEntityIT.java
File metadata and controls
6446 lines (5345 loc) · 237 KB
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
package org.openmetadata.it.tests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openmetadata.it.bootstrap.SharedEntities;
import org.openmetadata.it.util.EntityValidation;
import org.openmetadata.it.util.SdkClients;
import org.openmetadata.it.util.TestNamespace;
import org.openmetadata.it.util.TestNamespaceExtension;
import org.openmetadata.it.util.UpdateType;
import org.openmetadata.schema.EntityInterface;
import org.openmetadata.schema.type.ApiStatus;
import org.openmetadata.schema.type.ChangeDescription;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.schema.type.api.BulkOperationResult;
import org.openmetadata.schema.type.api.BulkResponse;
import org.openmetadata.schema.type.csv.CsvImportResult;
import org.openmetadata.schema.utils.JsonUtils;
import org.openmetadata.sdk.client.OpenMetadataClient;
import org.openmetadata.sdk.exceptions.InvalidRequestException;
import org.openmetadata.sdk.fluent.Users;
import org.openmetadata.sdk.network.HttpMethod;
import org.openmetadata.service.util.TestUtils;
/**
* Base class for all entity integration tests.
*
* Migrated from: org.openmetadata.service.resources.EntityResourceTest
* Purpose: Provides common test methods that apply to ALL entities (CRUD, permissions, tags, etc.)
*
* This class replicates the pattern from EntityResourceTest but uses:
* - SDK client instead of WebTarget
* - TestNamespace for isolation instead of TestInfo
* - Typed exceptions instead of HTTP status codes
* - Feature flags to conditionally run tests based on entity capabilities
*
* Subclasses must implement:
* - createMinimalRequest() - Create a minimal valid create request
* - getEntityClient() - Return the appropriate entity client
* - validateCreatedEntity() - Entity-specific validation
*
* @param <T> Entity type (e.g., Database, Table, User)
* @param <K> Create request type (e.g., CreateDatabase, CreateTable)
*/
@Slf4j
@ExtendWith(TestNamespaceExtension.class)
public abstract class BaseEntityIT<T extends EntityInterface, K> {
// ===================================================================
// ABSTRACT METHODS - Must be implemented by subclasses
// ===================================================================
/**
* Create a minimal valid create request for this entity.
* This should include all required fields but minimal optional fields.
*/
protected abstract K createMinimalRequest(TestNamespace ns);
/**
* Create a request with a specific name.
*/
protected abstract K createRequest(String name, TestNamespace ns);
/**
* Create the entity using the fluent API.
*/
protected abstract T createEntity(K createRequest);
/**
* Get entity by ID.
*/
protected abstract T getEntity(String id);
/**
* Get entity by fully qualified name.
*/
protected abstract T getEntityByName(String fqn);
/**
* Update entity using PATCH (returns updated entity).
*/
protected abstract T patchEntity(String id, T entity);
/**
* Delete entity (soft delete if supported).
*/
protected abstract void deleteEntity(String id);
/**
* Restore a soft-deleted entity.
*/
protected abstract void restoreEntity(String id);
/**
* Hard delete an entity (permanently remove).
*/
protected abstract void hardDeleteEntity(String id);
/**
* Get the entity type name (e.g., "database", "table", "user").
*/
protected abstract String getEntityType();
/**
* Get the resource path for this entity (e.g., "/v1/tables", "/v1/databases").
* Used for making raw HTTP calls to endpoints not exposed through the SDK.
*/
protected String getResourcePath() {
return "/v1/" + TestUtils.plurializeEntityType(getEntityType()) + "/";
}
/**
* Validate that the created entity matches the create request.
* Subclasses should add entity-specific validations.
*/
protected abstract void validateCreatedEntity(T entity, K createRequest);
// ===================================================================
// FEATURE FLAGS - Control which tests run for this entity
// ===================================================================
protected boolean supportsFollowers = true;
protected boolean supportsOwners = true;
protected boolean supportsTags = true;
protected boolean supportsDomains = true;
protected boolean supportsPatchDomains = true; // Can domains be changed via PATCH after creation?
protected boolean supportsDataProducts = true;
protected boolean supportsDataContract = false;
protected boolean supportsSoftDelete = true;
protected boolean supportsCustomExtension = true;
protected boolean supportsFieldsQueryParam = true;
protected boolean supportsPatch = true;
protected boolean supportsEmptyDescription = true;
protected boolean supportsNameLengthValidation = true;
protected boolean supportsBulkAPI = false; // Override in subclasses that support bulk API
protected boolean supportsSearchIndex = true; // Override in subclasses that don't support search
protected boolean supportsVersionHistory =
true; // Override in subclasses that don't support version history
protected boolean supportsGetByVersion =
true; // Override if get specific version is not supported
protected boolean supportsIncludeDeleted =
true; // Override if include=deleted query param not supported
protected boolean supportsImportExport =
false; // Override in subclasses that support CSV import/export
protected boolean supportsListHistoryByTimestamp =
false; // Override in subclasses that support listing all versions by timestamp
// ===================================================================
// CHANGE TYPE - Controls how version changes are validated
// ===================================================================
/**
* Get the default change type for updates in session.
* Most entities use MINOR_UPDATE, but some may need CHANGE_CONSOLIDATED
* when changes happen within the same session window.
*
* <p>Matches EntityResourceTest.getChangeType() pattern.
*
* @return The default UpdateType for changes made within the same session
*/
public UpdateType getChangeType() {
return UpdateType.MINOR_UPDATE;
}
// ===================================================================
// SHARED ENTITY ACCESSORS - Session-scoped entities for cross-test use
// ===================================================================
/**
* Access to session-scoped shared entities.
* These entities are created ONCE at session start and shared across all tests.
* Tests should use these as read-only references for ownership, team membership, etc.
*/
protected SharedEntities shared() {
return SharedEntities.get();
}
/** Convenience accessor for shared USER1 */
protected org.openmetadata.schema.entity.teams.User testUser1() {
return shared().USER1;
}
/** Convenience accessor for shared USER2 */
protected org.openmetadata.schema.entity.teams.User testUser2() {
return shared().USER2;
}
/** Convenience accessor for shared USER3 */
protected org.openmetadata.schema.entity.teams.User testUser3() {
return shared().USER3;
}
/** Convenience accessor for shared USER1 EntityReference */
protected org.openmetadata.schema.type.EntityReference testUser1Ref() {
return shared().USER1_REF;
}
/** Convenience accessor for shared USER2 EntityReference */
protected org.openmetadata.schema.type.EntityReference testUser2Ref() {
return shared().USER2_REF;
}
/** Convenience accessor for shared TEAM1 */
protected org.openmetadata.schema.entity.teams.Team testTeam1() {
return shared().TEAM1;
}
/** Convenience accessor for shared TEAM2 */
protected org.openmetadata.schema.entity.teams.Team testTeam2() {
return shared().TEAM2;
}
/** Convenience accessor for shared TEAM11 (Group type - can own entities) */
protected org.openmetadata.schema.entity.teams.Team testGroupTeam() {
return shared().TEAM11;
}
/** Convenience accessor for shared DOMAIN */
protected org.openmetadata.schema.entity.domains.Domain testDomain() {
return shared().DOMAIN;
}
/** Convenience accessor for shared SUB_DOMAIN */
protected org.openmetadata.schema.entity.domains.Domain testSubDomain() {
return shared().SUB_DOMAIN;
}
/** Convenience accessor for shared DATA_STEWARD_ROLE */
protected org.openmetadata.schema.entity.teams.Role dataStewardRole() {
return shared().DATA_STEWARD_ROLE;
}
/** Convenience accessor for shared DATA_CONSUMER_ROLE */
protected org.openmetadata.schema.entity.teams.Role dataConsumerRole() {
return shared().DATA_CONSUMER_ROLE;
}
/** Convenience accessor for shared PERSONAL_DATA_TAG_LABEL */
protected TagLabel personalDataTagLabel() {
return shared().PERSONAL_DATA_TAG_LABEL;
}
/** Convenience accessor for shared PII_SENSITIVE_TAG_LABEL */
protected TagLabel piiSensitiveTagLabel() {
return shared().PII_SENSITIVE_TAG_LABEL;
}
/** Convenience accessor for shared GLOSSARY1_TERM1_LABEL */
protected TagLabel glossaryTermLabel() {
return shared().GLOSSARY1_TERM1_LABEL;
}
/** Convenience accessor for shared MYSQL_SERVICE reference */
protected org.openmetadata.schema.type.EntityReference mysqlServiceRef() {
return shared().MYSQL_REFERENCE;
}
// ===================================================================
// VALIDATION HELPER METHODS
// ===================================================================
/**
* Helper method to patch entity and validate version, ChangeDescription.
* Similar to patchEntityAndCheck in EntityResourceTest.
*
* @param entity Entity with updated values
* @param updateType Expected type of update
* @param expectedChange Expected ChangeDescription (can be null for simple cases)
* @return Updated entity
*/
protected T patchEntityAndCheck(
T entity, UpdateType updateType, ChangeDescription expectedChange) {
// Capture version before update
Double previousVersion = entity.getVersion();
// Perform the update
T updated = patchEntity(entity.getId().toString(), entity);
// Validate version changed correctly
EntityValidation.validateVersion(updated, updateType, previousVersion);
// Validate ChangeDescription
EntityValidation.validateChangeDescription(updated, updateType, expectedChange);
// Verify changes persisted by getting entity again
T fetched = getEntity(updated.getId().toString());
assertEquals(updated.getVersion(), fetched.getVersion(), "Version mismatch after fetch");
return updated;
}
// ===================================================================
// COMMON CRUD TESTS (Phase 1 - 10 tests)
// ===================================================================
/**
* Test: Create entity with minimal required fields
* Equivalent to: post_entityCreate_200_OK in EntityResourceTest
*/
@Test
void post_entityCreate_200_OK(TestNamespace ns) {
// Create entity with minimal fields
K createRequest = createMinimalRequest(ns);
T entity = createEntity(createRequest);
// Common validations
assertNotNull(entity.getId(), "Entity ID should not be null");
assertNotNull(entity.getFullyQualifiedName(), "Entity FQN should not be null");
assertNotNull(entity.getName(), "Entity name should not be null");
// Validate version and ChangeDescription for newly created entity
EntityValidation.validateVersion(entity, UpdateType.CREATED, null);
EntityValidation.validateChangeDescription(entity, UpdateType.CREATED, null);
// Entity-specific validations
validateCreatedEntity(entity, createRequest);
// Verify entity can be retrieved
T fetched = getEntity(entity.getId().toString());
assertEquals(entity.getId(), fetched.getId());
assertEquals(entity.getFullyQualifiedName(), fetched.getFullyQualifiedName());
assertEquals(entity.getVersion(), fetched.getVersion(), "Version should match after fetch");
}
/**
* Test: Create entity with invalid name (special characters, too long, etc.)
* Equivalent to: post_entityCreateWithInvalidName_400 in EntityResourceTest
*/
@Test
void post_entityCreateWithInvalidName_400(TestNamespace ns) {
// Test invalid name patterns that OpenMetadata actually rejects
// Empty name
K emptyNameRequest = createRequest("", ns);
assertThrows(
InvalidRequestException.class,
() -> createEntity(emptyNameRequest),
"Expected InvalidRequestException for empty name");
// Name with newline character
K newlineNameRequest = createRequest("name with\nnewline", ns);
assertThrows(
InvalidRequestException.class,
() -> createEntity(newlineNameRequest),
"Expected InvalidRequestException for name with newline");
// Name too long (>256 chars typically) - only if entity supports this validation
if (supportsNameLengthValidation) {
K longNameRequest = createRequest("a".repeat(300), ns);
assertThrows(
InvalidRequestException.class,
() -> createEntity(longNameRequest),
"Expected InvalidRequestException for name too long");
}
}
/**
* Test: Create duplicate entity should fail
* Equivalent to: post_entityAlreadyExists_409_conflict in EntityResourceTest
*/
@Test
void post_duplicateEntity_409(TestNamespace ns) {
// Create first entity with a specific request
K createRequest = createMinimalRequest(ns);
T entity = createEntity(createRequest);
assertNotNull(entity.getId());
// Attempt to create duplicate using the SAME create request
// This ensures we're truly creating a duplicate (same name, same parent service)
assertThrows(
Exception.class, // May be ConflictException or similar
() -> createEntity(createRequest),
"Creating duplicate entity should fail");
}
/**
* Test: Get entity by ID
* Equivalent to: get_entity_200_OK in EntityResourceTest
*/
@Test
void get_entity_200_OK(TestNamespace ns) {
// Create entity
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
// Get entity by ID
T fetched = getEntity(created.getId().toString());
assertNotNull(fetched);
assertEquals(created.getId(), fetched.getId());
assertEquals(created.getName(), fetched.getName());
assertEquals(created.getFullyQualifiedName(), fetched.getFullyQualifiedName());
}
/**
* Test: Get entity by fully qualified name
* Equivalent to: get_entityByName_200_OK in EntityResourceTest
*/
@Test
void get_entityByName_200_OK(TestNamespace ns) {
// Create entity
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
// Get entity by FQN
T fetched = getEntityByName(created.getFullyQualifiedName());
assertNotNull(fetched);
assertEquals(created.getId(), fetched.getId());
assertEquals(created.getFullyQualifiedName(), fetched.getFullyQualifiedName());
}
/**
* Test: Get non-existent entity should fail
* Equivalent to: get_entityNotFound_404 in EntityResourceTest
*/
@Test
void get_entityNotFound_404(TestNamespace ns) {
// Try to get non-existent entity by ID
String fakeId = "00000000-0000-0000-0000-000000000000";
assertThrows(
Exception.class, () -> getEntity(fakeId), "Getting non-existent entity should fail");
// Try to get non-existent entity by name
String fakeName = ns.prefix("nonExistent");
assertThrows(
Exception.class,
() -> getEntityByName(fakeName),
"Getting non-existent entity by name should fail");
}
/**
* Test: Update entity description
* Equivalent to: patch_entityAttributes_200_OK in EntityResourceTest
*/
@Test
void patch_entityDescription_200_OK(TestNamespace ns) {
if (!supportsPatch) return;
// Create entity
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
// Validate initial version
assertEquals(0.1, created.getVersion(), 0.001, "Initial version should be 0.1");
// Update description
String oldDescription = created.getDescription();
String newDescription = "Updated description via integration test";
created.setDescription(newDescription);
// Create expected ChangeDescription
ChangeDescription expectedChange =
EntityValidation.getChangeDescription(created, UpdateType.MINOR_UPDATE);
EntityValidation.fieldUpdated(expectedChange, "description", oldDescription, newDescription);
// Perform update with validation
T updated = patchEntityAndCheck(created, UpdateType.MINOR_UPDATE, expectedChange);
// Validate description was updated
assertEquals(newDescription, updated.getDescription());
assertEquals(0.2, updated.getVersion(), 0.001, "Version should increment to 0.2");
// Verify ChangeDescription is present and correct
assertNotNull(updated.getChangeDescription(), "ChangeDescription should be present");
assertEquals(
0.1,
updated.getChangeDescription().getPreviousVersion(),
0.001,
"Previous version should be 0.1");
}
/**
* Test: Soft delete entity
* Equivalent to: delete_entity_soft_200 in EntityResourceTest
*/
@Test
void delete_entity_soft_200(TestNamespace ns) {
if (!supportsSoftDelete) return;
// Create entity
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
String entityId = created.getId().toString();
// Soft delete
deleteEntity(entityId);
// Entity should not be retrievable by default
assertThrows(
Exception.class, () -> getEntity(entityId), "Deleted entity should not be retrievable");
}
// ===================================================================
// AUTHORIZATION TESTS (Phase 1 - JWT-based)
// ===================================================================
/**
* Test: Non-admin user cannot create entity
* Equivalent to: post_entity_as_non_admin_401 in EntityResourceTest
*
* Uses JWT-based authentication with a regular user (no admin role).
*/
// TODO: Authorization tests need rework for fluent API pattern
// These tests require using different clients (admin vs non-admin)
// which conflicts with the static default client approach.
// Subclasses can implement entity-specific authorization tests if needed.
// @Test
// void post_entity_as_non_admin_401(TestNamespace ns) { ... }
// @Test
// void delete_entity_as_non_admin_401(TestNamespace ns) { ... }
/**
* Test: Creating duplicate entity should fail with conflict
* Equivalent to: post_entityAlreadyExists_409_conflict in EntityResourceTest
*/
@Test
public void post_entityAlreadyExists_409_conflict(TestNamespace ns) {
// Create first entity
K createRequest = createRequest(ns.prefix("duplicate"), ns);
T created = createEntity(createRequest);
assertNotNull(created.getId());
// Attempt to create duplicate - should fail
assertThrows(
Exception.class,
() -> createEntity(createRequest),
"Creating duplicate entity should fail with conflict");
}
/**
* Test: Entity names with dots should be properly quoted in FQN
* Equivalent to: post_entityWithDots_200 in EntityResourceTest
*/
@Test
void post_entityWithDots_200(TestNamespace ns) {
// Create entity with dots in name
String nameWithDots = ns.prefix("foo.bar");
K createRequest = createRequest(nameWithDots, ns);
T created = createEntity(createRequest);
// Verify entity created
assertNotNull(created.getId());
assertEquals(nameWithDots, created.getName());
// FQN should contain quotes if hierarchical, or exact name if not
String fqn = created.getFullyQualifiedName();
boolean isHierarchical = !fqn.equals(created.getName());
if (isHierarchical) {
assertTrue(fqn.contains("\""), "Hierarchical FQN with dots should contain quotes: " + fqn);
}
}
// ===================================================================
// PUT (UPSERT) TESTS
// ===================================================================
/**
* Test: PUT can create new entity (upsert)
* Equivalent to: put_entityCreate_200 in EntityResourceTest
*/
@Test
void put_entityCreate_200(TestNamespace ns) {
// Create entity using PUT (upsert with no existing entity)
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
// Verify entity was created
assertNotNull(created.getId());
assertEquals(0.1, created.getVersion(), 0.001);
validateCreatedEntity(created, createRequest);
}
/**
* Test: PUT with no changes should not increment version
* Equivalent to: put_entityUpdateWithNoChange_200 in EntityResourceTest
*/
@Test
void put_entityUpdateWithNoChange_200(TestNamespace ns) {
if (!supportsPatch) return;
// Create entity
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
Double originalVersion = created.getVersion();
// Update with same data (no change)
T updated = patchEntity(created.getId().toString(), created);
// Version should NOT change when there's no actual change
assertEquals(
originalVersion, updated.getVersion(), 0.001, "Version should not change for no-op update");
}
// ===================================================================
// DELETE RESTORE TESTS
// ===================================================================
/**
* Test: Soft deleted entity can be restored
* Equivalent to: delete_restore_entity_200 in EntityResourceTest
*
* Note: This test verifies the restore functionality for soft-deleted entities.
* The original test uses a PUT request to restore. Since we're using the SDK,
* we'll verify that after soft delete, the entity can be restored and is functional.
*/
@Test
void delete_restore_entity_200(TestNamespace ns) {
if (!supportsSoftDelete) return;
// Create entity
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
String entityId = created.getId().toString();
// Soft delete entity
deleteEntity(entityId);
// Verify entity is deleted (should not be retrievable by default)
assertThrows(
Exception.class,
() -> getEntity(entityId),
"Deleted entity should not be retrievable without include=deleted");
// TODO: Add restore functionality once SDK supports it
// For now, this test verifies soft delete works correctly
}
// ===================================================================
// OWNER VALIDATION TESTS
// ===================================================================
/**
* Test: PATCH entity with non-existent owner should fail
* Equivalent to: post_entityWithNonExistentOwner_4xx in EntityResourceTest
*/
@Test
void patch_entityWithNonExistentOwner_4xx(TestNamespace ns) {
if (!supportsOwners) return;
// Create entity without owner
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
// Try to set a non-existent owner
org.openmetadata.schema.type.EntityReference nonExistentOwner =
new org.openmetadata.schema.type.EntityReference()
.withId(java.util.UUID.randomUUID())
.withType("user")
.withName("nonexistent@example.com");
created.setOwners(List.of(nonExistentOwner));
String entityId = created.getId().toString();
assertThrows(
Exception.class,
() -> patchEntity(entityId, created),
"Patching entity with non-existent owner should fail");
}
/**
* Test: PATCH to update owner
* Equivalent to: patch_entityUpdateOwner_200 in EntityResourceTest
*/
@Test
void patch_entityUpdateOwner_200(TestNamespace ns) {
if (!supportsOwners || !supportsPatch) return;
// Create entity without owner
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
// Verify no owner initially
T fetched = getEntityWithFields(created.getId().toString(), "owners");
assertTrue(
fetched.getOwners() == null || fetched.getOwners().isEmpty(),
"Entity should not have owner initially");
// Get ingestion-bot user to use as owner (bots are auto-created)
org.openmetadata.schema.entity.teams.User botUser = Users.getByName("ingestion-bot");
org.openmetadata.schema.type.EntityReference ownerRef =
new org.openmetadata.schema.type.EntityReference()
.withId(botUser.getId())
.withType("user")
.withName(botUser.getName())
.withFullyQualifiedName(botUser.getFullyQualifiedName());
// Set owner via PATCH
fetched.setOwners(List.of(ownerRef));
T updated = patchEntity(fetched.getId().toString(), fetched);
// Verify owner was set
T updatedFetched = getEntityWithFields(updated.getId().toString(), "owners");
assertNotNull(updatedFetched.getOwners(), "Entity should have owners");
assertEquals(1, updatedFetched.getOwners().size(), "Entity should have 1 owner");
assertEquals(
botUser.getId(),
updatedFetched.getOwners().get(0).getId(),
"Owner should be ingestion-bot user");
}
/**
* Test: Change owner from one user to another
* Equivalent to: put_entityUpdateOwner_200 in EntityResourceTest
*/
@Test
void patch_entityChangeOwner_200(TestNamespace ns) {
if (!supportsOwners || !supportsPatch) return;
// Create entity and set initial owner
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
// Set ingestion-bot as owner
org.openmetadata.schema.entity.teams.User botUser = Users.getByName("ingestion-bot");
org.openmetadata.schema.type.EntityReference botRef =
new org.openmetadata.schema.type.EntityReference()
.withId(botUser.getId())
.withType("user")
.withName(botUser.getName());
created.setOwners(List.of(botRef));
T withOwner = patchEntity(created.getId().toString(), created);
// Verify owner was set
T fetchedWithOwner = getEntityWithFields(withOwner.getId().toString(), "owners");
assertNotNull(fetchedWithOwner.getOwners());
assertEquals(1, fetchedWithOwner.getOwners().size());
assertEquals(botUser.getId(), fetchedWithOwner.getOwners().get(0).getId());
// Clear the owner by setting empty list
fetchedWithOwner.setOwners(new ArrayList<>());
T withoutOwner = patchEntity(fetchedWithOwner.getId().toString(), fetchedWithOwner);
// Verify owner was removed
T finalFetch = getEntityWithFields(withoutOwner.getId().toString(), "owners");
assertTrue(
finalFetch.getOwners() == null || finalFetch.getOwners().isEmpty(),
"Owner should be removed");
}
// ===================================================================
// VERSION-BASED CONCURRENCY TESTS (Using entity version for optimistic locking)
// ===================================================================
/**
* Test: Concurrent updates - version acts as optimistic lock
* Equivalent to: patch_concurrent_updates_with_etag in EntityResourceTest
*
* In OpenMetadata, entity version acts as optimistic lock. When two concurrent updates
* happen, the second one will see a different version and should handle it appropriately.
*/
@Test
void patch_concurrentUpdates_optimisticLock(TestNamespace ns) {
if (!supportsPatch) return;
// Create entity
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
Double originalVersion = created.getVersion();
// First update - change description to unique value
String firstDesc = "Concurrent update 1 - " + System.currentTimeMillis();
created.setDescription(firstDesc);
T afterFirst = patchEntity(created.getId().toString(), created);
// Version should have changed
assertTrue(
afterFirst.getVersion() > originalVersion,
"Version should increment after update, was: " + afterFirst.getVersion());
// Get fresh copy for second update
T fresh = getEntity(afterFirst.getId().toString());
// Second update with different description
String secondDesc = "Concurrent update 2 - " + System.currentTimeMillis();
fresh.setDescription(secondDesc);
T afterSecond = patchEntity(fresh.getId().toString(), fresh);
// Version should increment or stay same (depending on consolidation window)
assertTrue(
afterSecond.getVersion() >= afterFirst.getVersion(),
"Version should be >= previous, got: "
+ afterSecond.getVersion()
+ " vs "
+ afterFirst.getVersion());
}
/**
* Test: Version changes on updates (optimistic locking verification)
* Equivalent to: patch_with_valid_etag / patch_with_stale_etag concepts
*
* This test verifies that version tracking works correctly for detecting changes.
*/
@Test
void patch_versionTracking_200(TestNamespace ns) {
if (!supportsPatch) return;
// Create entity
K createRequest = createMinimalRequest(ns);
T created = createEntity(createRequest);
assertEquals(0.1, created.getVersion(), 0.001, "Initial version should be 0.1");
// Update 1: Change description
created.setDescription("Version tracking update 1 - " + System.currentTimeMillis());
T updated1 = patchEntity(created.getId().toString(), created);
assertEquals(0.2, updated1.getVersion(), 0.001, "Version should be 0.2 after first update");
// Update 2: Change description to a DIFFERENT value
updated1.setDescription("Version tracking update 2 - " + System.currentTimeMillis());
T updated2 = patchEntity(updated1.getId().toString(), updated1);
// Version should increment (will be 0.3 if it's a new change, or same if consolidated)
assertTrue(
updated2.getVersion() >= 0.2,
"Version should be at least 0.2, got: " + updated2.getVersion());
// Fetch entity and verify version persisted
T fetched = getEntity(updated2.getId().toString());
assertEquals(
updated2.getVersion(),
fetched.getVersion(),
0.001,
"Fetched version should match updated version");
}
// ===================================================================
// PHASE 2: Advanced GET Operations
// ===================================================================
@Test
void get_entityWithDifferentFields_200_OK(TestNamespace ns) {
if (!supportsOwners && !supportsTags) {
return; // Skip if entity doesn't support fields testing
}
K createRequest = createMinimalRequest(ns);
T entity = createEntity(createRequest);
// GET with no fields - should return basic fields only
T entityWithoutFields = getEntity(entity.getId().toString());
assertNotNull(entityWithoutFields);
assertNotNull(entityWithoutFields.getId());
// GET with specific fields - owners, tags (if supported)
String fields = buildFieldsParam();
if (fields != null && !fields.isEmpty()) {
T entityWithFields = getEntityWithFields(entity.getId().toString(), fields);
assertNotNull(entityWithFields);
assertNotNull(entityWithFields.getId());
// Validate by name as well
T entityByName = getEntityByNameWithFields(entity.getFullyQualifiedName(), fields);
assertNotNull(entityByName);
assertEquals(entity.getId(), entityByName.getId());
}
}
@Test
void get_entityIncludeDeleted_200(TestNamespace ns) {
Assumptions.assumeTrue(supportsSoftDelete, "Entity does not support soft delete");
Assumptions.assumeTrue(supportsIncludeDeleted, "Entity does not support include=deleted");
K createRequest = createMinimalRequest(ns);
T entity = createEntity(createRequest);
String entityId = entity.getId().toString();
// Soft delete the entity
deleteEntity(entityId);
// GET without include=deleted should throw exception
assertThrows(
Exception.class,
() -> getEntity(entityId),
"Getting deleted entity without include=deleted should fail");
// GET with include=deleted should succeed
T deletedEntity = getEntityIncludeDeleted(entityId);
assertNotNull(deletedEntity);
assertEquals(entity.getId(), deletedEntity.getId());
assertTrue(deletedEntity.getDeleted(), "Entity should be marked as deleted");
}
// ===================================================================
// HELPER METHODS FOR PHASE 2
// ===================================================================
/**
* Build fields parameter based on entity capabilities.
*/
private String buildFieldsParam() {
List<String> fields = new ArrayList<>();
if (supportsOwners) fields.add("owners");
if (supportsTags) fields.add("tags");
if (supportsFollowers) fields.add("followers");
return String.join(",", fields);
}
/**
* Get entity with specific fields parameter.
* Subclasses can override if they have a different mechanism.
*/
protected T getEntityWithFields(String id, String fields) {
// Default implementation - subclasses should override
return getEntity(id);
}
/**
* Get entity by name with specific fields parameter.
* Subclasses can override if they have a different mechanism.
*/
protected T getEntityByNameWithFields(String fqn, String fields) {
// Default implementation - subclasses should override
return getEntityByName(fqn);
}
/**
* Get entity with include=deleted parameter.
* Subclasses can override if they have a different mechanism.
*/
protected T getEntityIncludeDeleted(String id) {
// Default implementation - subclasses should override
throw new UnsupportedOperationException("Include deleted not implemented");
}
// ===================================================================
// PHASE 3: Pagination & List Operations
// ===================================================================
/**
* Pagination test is disabled in BaseEntityIT to avoid conflicts with parallel tests.
* Comprehensive pagination testing is done in PaginationIT which runs in isolation.
* This test just verifies basic list functionality works.
*/
@Test
void get_entityListWithPagination_200(TestNamespace ns) {
// Create a few entities
for (int i = 0; i < 3; i++) {
K createRequest = createRequest(ns.prefix("list" + i), ns);
createEntity(createRequest);
}
Awaitility.await("Wait for entities to be listable")
.pollDelay(Duration.ofMillis(500))
.pollInterval(Duration.ofSeconds(1))
.atMost(Duration.ofSeconds(15))
.untilAsserted(
() -> {
org.openmetadata.sdk.models.ListParams params =
new org.openmetadata.sdk.models.ListParams();
params.setLimit(10);
org.openmetadata.sdk.models.ListResponse<T> response = listEntities(params);
assertNotNull(response, "List response should not be null");
assertNotNull(response.getData(), "List data should not be null");
assertTrue(response.getData().size() > 0, "Should have entities in list");
});
}
@Test
void get_entityListWithInvalidLimit_4xx(TestNamespace ns) {
// Test with invalid limit (negative)
org.openmetadata.sdk.models.ListParams params = new org.openmetadata.sdk.models.ListParams();
params.setLimit(-1);
assertThrows(
Exception.class, () -> listEntities(params), "Listing with negative limit should fail");