-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathDomainResourceIT.java
More file actions
1362 lines (1132 loc) · 51.2 KB
/
DomainResourceIT.java
File metadata and controls
1362 lines (1132 loc) · 51.2 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
/*
* Copyright 2021 Collate
* 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 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.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.Duration;
import java.util.List;
import java.util.UUID;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openmetadata.it.util.SdkClients;
import org.openmetadata.it.util.TestNamespace;
import org.openmetadata.schema.api.VoteRequest;
import org.openmetadata.schema.api.domains.CreateDomain;
import org.openmetadata.schema.api.domains.CreateDomain.DomainType;
import org.openmetadata.schema.api.teams.CreateUser;
import org.openmetadata.schema.entity.domains.Domain;
import org.openmetadata.schema.entity.teams.User;
import org.openmetadata.schema.type.ChangeEvent;
import org.openmetadata.schema.type.EntityHistory;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.Votes;
import org.openmetadata.sdk.client.OpenMetadataClient;
import org.openmetadata.sdk.models.ListParams;
import org.openmetadata.sdk.models.ListResponse;
import org.openmetadata.sdk.network.HttpMethod;
/**
* Integration tests for Domain entity operations.
*
* <p>
* Extends BaseEntityIT to inherit all common entity tests. Adds domain-specific
* tests for
* hierarchy, experts, domain types, and parent-child relationships.
*
* <p>
* Migrated from: org.openmetadata.service.resources.domains.DomainResourceTest
*/
@Execution(ExecutionMode.CONCURRENT)
public class DomainResourceIT extends BaseEntityIT<Domain, CreateDomain> {
public DomainResourceIT() {
supportsFollowers = false;
supportsTags = true;
supportsDomains = false;
supportsDataProducts = false;
supportsSoftDelete = false;
supportsPatch = true;
supportsOwners = true;
supportsListHistoryByTimestamp = true;
}
@Override
protected CreateDomain createMinimalRequest(TestNamespace ns) {
return new CreateDomain()
.withName(ns.prefix("domain"))
.withDomainType(DomainType.AGGREGATE)
.withDescription("Test domain created by integration test");
}
@Override
protected CreateDomain createRequest(String name, TestNamespace ns) {
return new CreateDomain()
.withName(name)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Test domain");
}
@Override
protected Domain createEntity(CreateDomain createRequest) {
return SdkClients.adminClient().domains().create(createRequest);
}
@Override
protected Domain getEntity(String id) {
return SdkClients.adminClient().domains().get(id);
}
@Override
protected Domain getEntityByName(String fqn) {
return SdkClients.adminClient().domains().getByName(fqn);
}
@Override
protected Domain patchEntity(String id, Domain entity) {
return SdkClients.adminClient().domains().update(id, entity);
}
@Override
protected void deleteEntity(String id) {
SdkClients.adminClient().domains().delete(id);
}
@Override
protected void restoreEntity(String id) {
SdkClients.adminClient().domains().restore(id);
}
@Override
protected void hardDeleteEntity(String id) {
SdkClients.adminClient()
.domains()
.delete(id, java.util.Map.of("hardDelete", "true", "recursive", "true"));
}
@Override
protected String getEntityType() {
return "domain";
}
@Override
protected void validateCreatedEntity(Domain entity, CreateDomain createRequest) {
assertEquals(createRequest.getName(), entity.getName());
assertEquals(createRequest.getDomainType(), entity.getDomainType());
if (createRequest.getDescription() != null) {
assertEquals(createRequest.getDescription(), entity.getDescription());
}
}
@Override
protected Domain getEntityWithFields(String id, String fields) {
return SdkClients.adminClient().domains().get(id, fields);
}
@Override
protected Domain getEntityByNameWithFields(String fqn, String fields) {
return SdkClients.adminClient().domains().getByName(fqn, fields);
}
@Override
protected Domain getEntityIncludeDeleted(String id) {
return SdkClients.adminClient().domains().get(id, null, "deleted");
}
@Override
protected ListResponse<Domain> listEntities(ListParams params) {
return SdkClients.adminClient().domains().list(params);
}
// ===================================================================
// DOMAIN-SPECIFIC TESTS
// ===================================================================
@Test
void test_createDomainWithDifferentTypes(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
DomainType[] types = {
DomainType.AGGREGATE, DomainType.SOURCE_ALIGNED, DomainType.CONSUMER_ALIGNED
};
for (DomainType type : types) {
CreateDomain create =
new CreateDomain()
.withName(ns.prefix("domain_" + type.value()))
.withDomainType(type)
.withDescription("Domain of type " + type.value());
Domain domain = createEntity(create);
assertEquals(type, domain.getDomainType());
}
}
@Test
void test_createSubDomain(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
CreateDomain createParent =
new CreateDomain()
.withName(ns.prefix("parentDomain"))
.withDomainType(DomainType.AGGREGATE)
.withDescription("Parent domain");
Domain parent = createEntity(createParent);
CreateDomain createChild =
new CreateDomain()
.withName(ns.prefix("subDomain"))
.withDomainType(DomainType.SOURCE_ALIGNED)
.withParent(parent.getFullyQualifiedName())
.withDescription("Sub domain");
Domain child = createEntity(createChild);
assertNotNull(child.getParent());
assertEquals(parent.getId(), child.getParent().getId());
}
@Test
void test_createDomainWithExperts(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
String expertFqn = testUser1().getFullyQualifiedName();
CreateDomain create =
new CreateDomain()
.withName(ns.prefix("expertDomain"))
.withDomainType(DomainType.AGGREGATE)
.withExperts(List.of(expertFqn))
.withDescription("Domain with experts");
Domain domain = createEntity(create);
Domain fetched = client.domains().get(domain.getId().toString(), "experts");
assertNotNull(fetched.getExperts());
assertFalse(fetched.getExperts().isEmpty());
}
@Test
void test_createDomainWithOwner(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
EntityReference ownerRef = testUser1().getEntityReference();
CreateDomain create =
new CreateDomain()
.withName(ns.prefix("ownedDomain"))
.withDomainType(DomainType.AGGREGATE)
.withOwners(List.of(ownerRef))
.withDescription("Domain with owner");
Domain domain = createEntity(create);
Domain fetched = client.domains().get(domain.getId().toString(), "owners");
assertNotNull(fetched.getOwners());
assertFalse(fetched.getOwners().isEmpty());
}
@Test
void test_updateDomainType(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
CreateDomain create =
new CreateDomain()
.withName(ns.prefix("updateTypeDomain"))
.withDomainType(DomainType.AGGREGATE)
.withDescription("Domain for type update");
Domain domain = createEntity(create);
assertEquals(DomainType.AGGREGATE, domain.getDomainType());
domain.setDomainType(DomainType.SOURCE_ALIGNED);
Domain updated = patchEntity(domain.getId().toString(), domain);
assertEquals(DomainType.SOURCE_ALIGNED, updated.getDomainType());
}
@Test
void test_updateDomainDescription(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
CreateDomain create = createMinimalRequest(ns);
Domain domain = createEntity(create);
domain.setDescription("Updated domain description");
Domain updated = patchEntity(domain.getId().toString(), domain);
assertEquals("Updated domain description", updated.getDescription());
}
@Test
void test_updateDomainDisplayName(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
CreateDomain create = createMinimalRequest(ns);
Domain domain = createEntity(create);
domain.setDisplayName("My Updated Domain");
Domain updated = patchEntity(domain.getId().toString(), domain);
assertEquals("My Updated Domain", updated.getDisplayName());
}
@Test
void test_addExpertsToDomain(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
CreateDomain create = createMinimalRequest(ns);
Domain domain = createEntity(create);
Domain fetched = client.domains().get(domain.getId().toString(), "experts");
EntityReference expertRef = testUser1().getEntityReference();
fetched.setExperts(List.of(expertRef));
Domain updated = patchEntity(fetched.getId().toString(), fetched);
Domain verify = client.domains().get(updated.getId().toString(), "experts");
assertNotNull(verify.getExperts());
assertTrue(verify.getExperts().stream().anyMatch(e -> e.getId().equals(expertRef.getId())));
}
@Test
void test_hardDeleteDomain(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
CreateDomain create = createMinimalRequest(ns);
Domain domain = createEntity(create);
String domainId = domain.getId().toString();
hardDeleteEntity(domainId);
assertThrows(
Exception.class, () -> getEntity(domainId), "Deleted domain should not be retrievable");
}
@Test
void test_domainVersionHistory(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
CreateDomain create = createMinimalRequest(ns);
Domain domain = createEntity(create);
assertEquals(0.1, domain.getVersion(), 0.001);
domain.setDescription("Updated description v1");
Domain v2 = patchEntity(domain.getId().toString(), domain);
assertEquals(0.2, v2.getVersion(), 0.001);
var history = client.domains().getVersionList(domain.getId());
assertNotNull(history);
assertNotNull(history.getVersions());
assertTrue(history.getVersions().size() >= 2);
}
@Test
void test_listDomains(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
for (int i = 0; i < 3; i++) {
CreateDomain create =
new CreateDomain()
.withName(ns.prefix("listDomain" + i))
.withDomainType(DomainType.AGGREGATE)
.withDescription("Domain for list test");
createEntity(create);
}
ListParams params = new ListParams();
params.setLimit(100);
ListResponse<Domain> response = listEntities(params);
assertNotNull(response);
assertNotNull(response.getData());
assertTrue(response.getData().size() >= 3);
}
@Test
void test_getDomainWithChildren(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
CreateDomain createParent =
new CreateDomain()
.withName(ns.prefix("parentForChildren"))
.withDomainType(DomainType.AGGREGATE)
.withDescription("Parent domain");
Domain parent = createEntity(createParent);
CreateDomain createChild1 =
new CreateDomain()
.withName(ns.prefix("child1"))
.withDomainType(DomainType.SOURCE_ALIGNED)
.withParent(parent.getFullyQualifiedName())
.withDescription("Child domain 1");
Domain child1 = createEntity(createChild1);
CreateDomain createChild2 =
new CreateDomain()
.withName(ns.prefix("child2"))
.withDomainType(DomainType.CONSUMER_ALIGNED)
.withParent(parent.getFullyQualifiedName())
.withDescription("Child domain 2");
Domain child2 = createEntity(createChild2);
Domain fetchedParent = client.domains().get(parent.getId().toString(), "children");
assertNotNull(fetchedParent.getChildren());
assertEquals(2, fetchedParent.getChildren().size());
}
@Test
void test_deleteDomainWithChildren(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
CreateDomain createParent =
new CreateDomain()
.withName(ns.prefix("parentToDelete"))
.withDomainType(DomainType.AGGREGATE)
.withDescription("Parent domain to delete");
Domain parent = createEntity(createParent);
CreateDomain createChild =
new CreateDomain()
.withName(ns.prefix("childToDelete"))
.withDomainType(DomainType.SOURCE_ALIGNED)
.withParent(parent.getFullyQualifiedName())
.withDescription("Child domain to delete");
Domain child = createEntity(createChild);
hardDeleteEntity(parent.getId().toString());
String parentId = parent.getId().toString();
assertThrows(Exception.class, () -> getEntity(parentId), "Parent domain should be deleted");
String childId = child.getId().toString();
assertThrows(
Exception.class, () -> getEntity(childId), "Child domain should be cascade deleted");
}
// ===================================================================
// VERSION HISTORY SUPPORT
// ===================================================================
@Override
protected EntityHistory getVersionHistory(UUID id) {
return SdkClients.adminClient().domains().getVersionList(id);
}
@Override
protected Domain getVersion(UUID id, Double version) {
return SdkClients.adminClient().domains().getVersion(id.toString(), version);
}
// ===================================================================
// SEARCH VERIFICATION HELPER METHODS
// ===================================================================
/**
* Verify domain exists in search index with the expected FQN.
* Queries by domain ID to avoid complex FQN queries that can exceed
* Elasticsearch clause limits.
*/
private void verifyDomainInSearch(String expectedFqn, String domainId) {
OpenMetadataClient client = SdkClients.adminClient();
Awaitility.await("Domain " + domainId + " should appear in search with FQN " + expectedFqn)
.atMost(Duration.ofSeconds(30))
.pollDelay(Duration.ofMillis(500))
.pollInterval(Duration.ofSeconds(1))
.ignoreExceptions()
.untilAsserted(
() -> {
String searchResponse =
client
.search()
.query("id:" + domainId)
.index("domain_search_index")
.size(1)
.execute();
assertTrue(
searchResponse.contains("\"id\":\"" + domainId + "\""),
"Search index should contain domain with ID: " + domainId);
assertTrue(
searchResponse.contains("\"fullyQualifiedName\":\"" + expectedFqn + "\""),
"Search index should contain domain with FQN: " + expectedFqn);
});
}
/**
* Verify domain does NOT exist in search index with the given FQN.
* Searches by partial FQN match to verify old FQN is not in the index.
*/
private void verifyDomainNotInSearch(String fqn) {
OpenMetadataClient client = SdkClients.adminClient();
String domainName = fqn.contains(".") ? fqn.substring(fqn.lastIndexOf(".") + 1) : fqn;
Awaitility.await("Old FQN " + fqn + " should disappear from search")
.atMost(Duration.ofSeconds(30))
.pollDelay(Duration.ofMillis(500))
.pollInterval(Duration.ofSeconds(1))
.ignoreExceptions()
.untilAsserted(
() -> {
String searchResponse =
client
.search()
.query("name:" + domainName)
.index("domain_search_index")
.size(10)
.execute();
assertFalse(
searchResponse.contains("\"fullyQualifiedName\":\"" + fqn + "\""),
"Search index should NOT contain domain with old FQN: " + fqn);
});
}
// ===================================================================
// DOMAIN RENAME TESTS
// Tests that verify domain rename works correctly including:
// 1. Basic domain rename
// 2. Domain rename with data products
// 3. Domain rename with subdomains (cascading FQN updates)
// 4. Rename + consolidation scenarios
// ===================================================================
@Test
void test_renameDomain(TestNamespace ns) {
// Use simple name for rename test (avoid regex metacharacters in
// REGEXP_REPLACE)
String domainName = "domain_" + ns.shortPrefix();
CreateDomain create =
new CreateDomain()
.withName(domainName)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Domain for rename test");
Domain domain = createEntity(create);
String oldName = domain.getName();
String oldFqn = domain.getFullyQualifiedName();
String newName = "renamed_" + oldName;
domain.setName(newName);
Domain renamed = patchEntity(domain.getId().toString(), domain);
assertEquals(newName, renamed.getName());
assertNotEquals(oldFqn, renamed.getFullyQualifiedName());
// Verify we can get by new FQN
Domain fetched = getEntityByName(renamed.getFullyQualifiedName());
assertEquals(newName, fetched.getName());
// Old FQN should not work
assertThrows(Exception.class, () -> getEntityByName(oldFqn));
}
@Test
void test_renameDomainWithDataProducts(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
// Use simple name for rename test
String domainName = "domain_dp_" + ns.shortPrefix();
CreateDomain create =
new CreateDomain()
.withName(domainName)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Domain for rename with data products test");
Domain domain = createEntity(create);
// Create a data product under this domain
org.openmetadata.schema.api.domains.CreateDataProduct createDp =
new org.openmetadata.schema.api.domains.CreateDataProduct()
.withName("dp_under_" + domainName)
.withDescription("Data product under domain")
.withDomains(List.of(domain.getFullyQualifiedName()));
org.openmetadata.schema.entity.domains.DataProduct dataProduct =
client.dataProducts().create(createDp);
String oldDpFqn = dataProduct.getFullyQualifiedName();
// Rename the domain
String oldName = domain.getName();
String newName = "renamed_dp_" + oldName;
domain.setName(newName);
Domain renamed = patchEntity(domain.getId().toString(), domain);
assertEquals(newName, renamed.getName());
// Data product should still be accessible after domain rename
org.openmetadata.schema.entity.domains.DataProduct fetchedDp =
client.dataProducts().get(dataProduct.getId().toString());
assertNotNull(fetchedDp);
}
@Test
void test_renameDomainWithSubdomains(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
// Use simple names to avoid REGEXP_REPLACE issues with special characters
String parentName = "parent_" + ns.shortPrefix();
CreateDomain createParent =
new CreateDomain()
.withName(parentName)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Parent domain for subdomain rename test");
Domain parent = createEntity(createParent);
// Create child subdomains
String child1Name = "child1_" + parentName;
CreateDomain createChild1 =
new CreateDomain()
.withName(child1Name)
.withDomainType(DomainType.SOURCE_ALIGNED)
.withParent(parent.getFullyQualifiedName())
.withDescription("Child domain 1");
Domain child1 = createEntity(createChild1);
String child2Name = "child2_" + parentName;
CreateDomain createChild2 =
new CreateDomain()
.withName(child2Name)
.withDomainType(DomainType.CONSUMER_ALIGNED)
.withParent(parent.getFullyQualifiedName())
.withDescription("Child domain 2");
Domain child2 = createEntity(createChild2);
String oldChild1Fqn = child1.getFullyQualifiedName();
String oldChild2Fqn = child2.getFullyQualifiedName();
// Rename the parent domain
String newParentName = "renamed_" + parentName;
parent.setName(newParentName);
Domain renamedParent = patchEntity(parent.getId().toString(), parent);
assertEquals(newParentName, renamedParent.getName());
assertEquals(newParentName, renamedParent.getFullyQualifiedName());
// Verify child domains' FQNs are updated
Domain updatedChild1 = getEntity(child1.getId().toString());
Domain updatedChild2 = getEntity(child2.getId().toString());
assertTrue(
updatedChild1.getFullyQualifiedName().startsWith(newParentName + "."),
"Child1 FQN should start with new parent name");
assertTrue(
updatedChild2.getFullyQualifiedName().startsWith(newParentName + "."),
"Child2 FQN should start with new parent name");
assertNotEquals(oldChild1Fqn, updatedChild1.getFullyQualifiedName());
assertNotEquals(oldChild2Fqn, updatedChild2.getFullyQualifiedName());
// Verify we can access children by their new FQNs
Domain fetchedChild1 = getEntityByName(updatedChild1.getFullyQualifiedName());
assertEquals(child1.getId(), fetchedChild1.getId());
// Old FQNs should not work
assertThrows(Exception.class, () -> getEntityByName(oldChild1Fqn));
assertThrows(Exception.class, () -> getEntityByName(oldChild2Fqn));
}
@Test
void test_renameDomainWithNestedSubdomains(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
// Create a 3-level hierarchy: grandparent -> parent -> child
String gpName = "gp_" + ns.shortPrefix();
CreateDomain createGp =
new CreateDomain()
.withName(gpName)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Grandparent domain");
Domain grandparent = createEntity(createGp);
String parentName = "parent_" + gpName;
CreateDomain createParent =
new CreateDomain()
.withName(parentName)
.withDomainType(DomainType.SOURCE_ALIGNED)
.withParent(grandparent.getFullyQualifiedName())
.withDescription("Parent domain");
Domain parent = createEntity(createParent);
String childName = "child_" + gpName;
CreateDomain createChild =
new CreateDomain()
.withName(childName)
.withDomainType(DomainType.CONSUMER_ALIGNED)
.withParent(parent.getFullyQualifiedName())
.withDescription("Child domain");
Domain child = createEntity(createChild);
String oldGpFqn = grandparent.getFullyQualifiedName();
String oldParentFqn = parent.getFullyQualifiedName();
String oldChildFqn = child.getFullyQualifiedName();
// Rename the grandparent domain
String newGpName = "renamed_" + gpName;
grandparent.setName(newGpName);
Domain renamedGp = patchEntity(grandparent.getId().toString(), grandparent);
assertEquals(newGpName, renamedGp.getFullyQualifiedName());
// Verify all levels' FQNs are updated
Domain updatedParent = getEntity(parent.getId().toString());
Domain updatedChild = getEntity(child.getId().toString());
assertTrue(
updatedParent.getFullyQualifiedName().startsWith(newGpName + "."),
"Parent FQN should start with new grandparent name");
assertTrue(
updatedChild.getFullyQualifiedName().startsWith(newGpName + "."),
"Child FQN should start with new grandparent name");
// Old FQNs should not work
assertThrows(Exception.class, () -> getEntityByName(oldGpFqn));
assertThrows(Exception.class, () -> getEntityByName(oldParentFqn));
assertThrows(Exception.class, () -> getEntityByName(oldChildFqn));
}
/**
* Test that reproduces the consolidation bug when:
* 1. Domain is renamed
* 2. Another field (description) is updated within the same session
*
* The consolidation logic would revert to the previous version which has the
* OLD name/FQN,
* potentially causing subdomain FQNs to become inconsistent.
*
* Fix: Skip consolidation when name has changed.
*/
@Test
void test_renameAndUpdateDescriptionConsolidation(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
// Use simple name for rename test
String domainName = "domain_consolidate_" + ns.shortPrefix();
CreateDomain create =
new CreateDomain()
.withName(domainName)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Initial description");
Domain domain = createEntity(create);
String oldName = domain.getName();
String newName = "renamed_consolidate_" + oldName;
// Rename the domain
domain.setName(newName);
Domain renamed = patchEntity(domain.getId().toString(), domain);
assertEquals(newName, renamed.getName());
// Update description within the same session (triggers consolidation)
renamed.setDescription("Updated description after rename");
Domain afterDescUpdate = patchEntity(renamed.getId().toString(), renamed);
assertEquals("Updated description after rename", afterDescUpdate.getDescription());
// Name should still be the new name after consolidation
assertEquals(newName, afterDescUpdate.getName());
assertTrue(
afterDescUpdate.getFullyQualifiedName().equals(newName),
"FQN should match new name after consolidation");
// Verify we can still fetch by new FQN
Domain fetched = getEntityByName(afterDescUpdate.getFullyQualifiedName());
assertEquals(newName, fetched.getName());
}
/**
* Test multiple renames followed by updates within the same session.
* This is a more complex scenario that tests the robustness of the
* consolidation fix.
*/
@Test
void test_multipleRenamesWithUpdatesConsolidation(TestNamespace ns) {
// Use simple name for rename test
String domainName = "domain_multi_" + ns.shortPrefix();
CreateDomain create =
new CreateDomain()
.withName(domainName)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Initial description");
Domain domain = createEntity(create);
String[] names = {"renamed_first", "renamed_second", "renamed_third"};
for (int i = 0; i < names.length; i++) {
String newName = names[i] + "_" + UUID.randomUUID().toString().substring(0, 8);
domain.setName(newName);
domain = patchEntity(domain.getId().toString(), domain);
assertEquals(newName, domain.getName(), "Name should match after rename " + (i + 1));
domain.setDescription("Description after rename " + (i + 1));
domain = patchEntity(domain.getId().toString(), domain);
assertEquals(
newName, domain.getName(), "Name should still match after description update " + (i + 1));
// Verify we can fetch by FQN
Domain fetched = getEntityByName(domain.getFullyQualifiedName());
assertEquals(newName, fetched.getName());
}
}
@Test
void test_renameDomainWithSamePrefixDataProduct(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
String domainName = "analytics_" + ns.shortPrefix();
CreateDomain createDomain =
new CreateDomain()
.withName(domainName)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Domain for testing rename with same prefix data product");
Domain domain = createEntity(createDomain);
String subdomainName = "marketing";
CreateDomain createSubdomain =
new CreateDomain()
.withName(subdomainName)
.withDomainType(DomainType.SOURCE_ALIGNED)
.withParent(domain.getFullyQualifiedName())
.withDescription("Subdomain under analytics");
Domain subdomain = createEntity(createSubdomain);
String dataProductName = "analytics_product_" + ns.shortPrefix();
org.openmetadata.schema.api.domains.CreateDataProduct createDp =
new org.openmetadata.schema.api.domains.CreateDataProduct()
.withName(dataProductName)
.withDescription("Data product with same prefix as domain")
.withDomains(List.of(domain.getFullyQualifiedName()));
org.openmetadata.schema.entity.domains.DataProduct dataProduct =
client.dataProducts().create(createDp);
String oldDomainFqn = domain.getFullyQualifiedName();
String oldSubdomainFqn = subdomain.getFullyQualifiedName();
String oldDataProductFqn = dataProduct.getFullyQualifiedName();
String newDomainName = "insights_" + ns.shortPrefix();
domain.setName(newDomainName);
Domain renamedDomain = patchEntity(domain.getId().toString(), domain);
assertEquals(newDomainName, renamedDomain.getName());
assertEquals(newDomainName, renamedDomain.getFullyQualifiedName());
Domain fetchedSubdomain = getEntity(subdomain.getId().toString());
String expectedSubdomainFqn = newDomainName + "." + subdomainName;
assertEquals(expectedSubdomainFqn, fetchedSubdomain.getFullyQualifiedName());
org.openmetadata.schema.entity.domains.DataProduct fetchedDataProduct =
client.dataProducts().get(dataProduct.getId().toString());
assertEquals(
oldDataProductFqn,
fetchedDataProduct.getFullyQualifiedName(),
"Data product FQN should NOT change when domain is renamed");
}
@Test
void test_renameDomainDoesNotMatchSimilarNames(TestNamespace ns) throws Exception {
OpenMetadataClient client = SdkClients.adminClient();
String analyticsName = "analytics_" + ns.shortPrefix();
CreateDomain createAnalytics =
new CreateDomain()
.withName(analyticsName)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Analytics domain");
Domain analytics = createEntity(createAnalytics);
String analyticsV2Name = "anav2" + ns.shortPrefix();
CreateDomain createAnalyticsV2 =
new CreateDomain()
.withName(analyticsV2Name)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Analytics V2 - unrelated domain with similar prefix");
Domain analyticsV2 = createEntity(createAnalyticsV2);
String childName = "subdomain";
CreateDomain createChild =
new CreateDomain()
.withName(childName)
.withDomainType(DomainType.SOURCE_ALIGNED)
.withParent(analytics.getFullyQualifiedName())
.withDescription("Child of analytics domain");
Domain child = createEntity(createChild);
String analyticsV2OldFqn = analyticsV2.getFullyQualifiedName();
String childOldFqn = child.getFullyQualifiedName();
Awaitility.await("Wait for initial indexing of child domain")
.atMost(Duration.ofSeconds(30))
.pollDelay(Duration.ofMillis(500))
.pollInterval(Duration.ofSeconds(1))
.ignoreExceptions()
.until(
() -> {
String searchResponse =
client
.search()
.query("id:" + child.getId())
.index("domain_search_index")
.size(1)
.execute();
return searchResponse.contains("\"id\":\"" + child.getId() + "\"");
});
String newAnalyticsName = "insights_" + ns.shortPrefix();
analytics.setName(newAnalyticsName);
Domain renamedAnalytics = patchEntity(analytics.getId().toString(), analytics);
assertEquals(newAnalyticsName, renamedAnalytics.getName());
assertEquals(newAnalyticsName, renamedAnalytics.getFullyQualifiedName());
// Verify database entities are correct
Domain updatedChild = getEntity(child.getId().toString());
String expectedChildFqn = newAnalyticsName + "." + childName;
assertEquals(
expectedChildFqn,
updatedChild.getFullyQualifiedName(),
"Child domain FQN should be updated to reflect parent rename");
assertNotEquals(childOldFqn, updatedChild.getFullyQualifiedName());
Domain unchangedV2 = getEntity(analyticsV2.getId().toString());
assertEquals(
analyticsV2OldFqn,
unchangedV2.getFullyQualifiedName(),
"Unrelated domain with similar prefix should NOT be updated - this verifies the fix for prefix matching bug");
assertEquals(
analyticsV2Name, unchangedV2.getName(), "Unrelated domain name should remain unchanged");
// === SEARCH VERIFICATION ===
// Verify renamed domain can be found by new FQN in search
verifyDomainInSearch(newAnalyticsName, analytics.getId().toString());
// Verify child domain can be found by new FQN in search
verifyDomainInSearch(expectedChildFqn, child.getId().toString());
// Verify analytics_v2 can still be found by its ORIGINAL FQN
// This proves the bug fix works - without it, this would fail!
verifyDomainInSearch(analyticsV2OldFqn, analyticsV2.getId().toString());
// Verify old FQNs no longer work
verifyDomainNotInSearch(analyticsName);
verifyDomainNotInSearch(childOldFqn);
}
@Test
void test_renameDomainWithTagsAndGlossaryTerms(TestNamespace ns) {
String domainName = "data_domain_" + ns.shortPrefix();
CreateDomain createDomain =
new CreateDomain()
.withName(domainName)
.withDomainType(DomainType.AGGREGATE)
.withDescription("Domain for testing tags and glossary terms on rename");
Domain domain = createEntity(createDomain);
domain.setTags(List.of(piiSensitiveTagLabel(), personalDataTagLabel()));
domain = patchEntity(domain.getId().toString(), domain);
String subdomainName = "customer_data";
CreateDomain createSubdomain =
new CreateDomain()
.withName(subdomainName)
.withDomainType(DomainType.SOURCE_ALIGNED)
.withParent(domain.getFullyQualifiedName())
.withDescription("Subdomain with tags");
Domain subdomain = createEntity(createSubdomain);
subdomain.setTags(List.of(glossaryTermLabel()));
subdomain = patchEntity(subdomain.getId().toString(), subdomain);
String oldDomainFqn = domain.getFullyQualifiedName();
String oldSubdomainFqn = subdomain.getFullyQualifiedName();
Domain domainWithTags = getEntityWithFields(domain.getId().toString(), "tags");
assertEquals(2, domainWithTags.getTags().size(), "Domain should have 2 tags before rename");
Domain subdomainWithTags = getEntityWithFields(subdomain.getId().toString(), "tags");
assertEquals(
1, subdomainWithTags.getTags().size(), "Subdomain should have 1 tag before rename");
String newDomainName = "analytics_domain_" + ns.shortPrefix();
domain.setName(newDomainName);
Domain renamedDomain = patchEntity(domain.getId().toString(), domain);
assertEquals(newDomainName, renamedDomain.getName());
assertEquals(newDomainName, renamedDomain.getFullyQualifiedName());
Domain fetchedDomainAfterRename = getEntityWithFields(domain.getId().toString(), "tags");
assertNotNull(
fetchedDomainAfterRename.getTags(), "Domain tags should not be null after rename");
assertEquals(
2,
fetchedDomainAfterRename.getTags().size(),
"Domain should still have 2 tags after rename");
assertTrue(
fetchedDomainAfterRename.getTags().stream()
.anyMatch(tag -> tag.getTagFQN().equals(piiSensitiveTagLabel().getTagFQN())),
"Domain should still have PII.Sensitive tag after rename");
assertTrue(
fetchedDomainAfterRename.getTags().stream()
.anyMatch(tag -> tag.getTagFQN().equals(personalDataTagLabel().getTagFQN())),
"Domain should still have PersonalData.Personal tag after rename");
Domain fetchedSubdomainAfterRename = getEntityWithFields(subdomain.getId().toString(), "tags");
String expectedSubdomainFqn = newDomainName + "." + subdomainName;
assertEquals(expectedSubdomainFqn, fetchedSubdomainAfterRename.getFullyQualifiedName());
assertNotNull(
fetchedSubdomainAfterRename.getTags(), "Subdomain tags should not be null after rename");
assertEquals(
1,