18
18
package org .apache .atlas .glossary ;
19
19
20
20
import org .apache .atlas .AtlasErrorCode ;
21
+ import org .apache .atlas .RequestContext ;
21
22
import org .apache .atlas .SortOrder ;
22
23
import org .apache .atlas .TestModules ;
23
24
import org .apache .atlas .bulkimport .BulkImportResponse ;
@@ -1035,6 +1036,8 @@ public void testTermAssignmentAndDissociation() {
1035
1036
assetEntity .setAttribute ("qualifiedName" , "testAsset" );
1036
1037
assetEntity .setAttribute ("name" , "testAsset" );
1037
1038
1039
+ long originalUpdateTime = 0L ;
1040
+ long updatedTimeAfterAssignment = 0L ;
1038
1041
try {
1039
1042
EntityMutationResponse response = entityStore .createOrUpdate (new AtlasEntityStream (assetEntity ), false );
1040
1043
AtlasEntityHeader firstEntityCreated = response .getFirstEntityCreated ();
@@ -1045,12 +1048,31 @@ public void testTermAssignmentAndDissociation() {
1045
1048
relatedObjectId .setTypeName (firstEntityCreated .getTypeName ());
1046
1049
1047
1050
assertNotNull (relatedObjectId );
1051
+ AtlasEntity .AtlasEntityWithExtInfo entityInfo = entityStore .getById (relatedObjectId .getGuid ());
1052
+ AtlasEntity createdEntity = entityInfo .getEntity ();
1053
+ assertNotNull (createdEntity );
1054
+ originalUpdateTime = createdEntity .getUpdateTime ().getTime ();
1048
1055
} catch (AtlasBaseException e ) {
1049
1056
fail ("Entity creation should've succeeded" , e );
1050
1057
}
1051
1058
1059
+ long mockRequestTimeAssign = System .currentTimeMillis () + 5000 ; // simulate later timestamp
1052
1060
try {
1053
- glossaryService .assignTermToEntities (fixedRateMortgage .getGuid (), Collections .singletonList (relatedObjectId ));
1061
+ try (MockedStatic <RequestContext > mockedRequestContext = Mockito .mockStatic (RequestContext .class )) {
1062
+ RequestContext mockContext = mock (RequestContext .class );
1063
+ when (mockContext .getRequestTime ()).thenReturn (mockRequestTimeAssign );
1064
+ mockedRequestContext .when (RequestContext ::get ).thenReturn (mockContext );
1065
+
1066
+ glossaryService .assignTermToEntities (fixedRateMortgage .getGuid (), Collections .singletonList (relatedObjectId ));
1067
+
1068
+ //verify updateTime after assignment
1069
+ AtlasEntity .AtlasEntityWithExtInfo updatedInfo = entityStore .getById (relatedObjectId .getGuid ());
1070
+ AtlasEntity updatedEntityAfterAssignment = updatedInfo .getEntity ();
1071
+ updatedTimeAfterAssignment = updatedEntityAfterAssignment .getUpdateTime ().getTime ();
1072
+
1073
+ assertEquals (updatedTimeAfterAssignment , mockRequestTimeAssign );
1074
+ assertTrue (updatedTimeAfterAssignment > originalUpdateTime , "updateTime should have increased after term assignment" );
1075
+ }
1054
1076
} catch (AtlasBaseException e ) {
1055
1077
fail ("Term assignment to asset should've succeeded" , e );
1056
1078
}
@@ -1072,8 +1094,22 @@ public void testTermAssignmentAndDissociation() {
1072
1094
1073
1095
// Dissociate term from entities
1074
1096
try {
1075
- glossaryService .removeTermFromEntities (fixedRateMortgage .getGuid (), Collections .singletonList (relatedObjectId ));
1097
+ long mockRequestTimeRemove = mockRequestTimeAssign + 5000 ;
1098
+ try (MockedStatic <RequestContext > mockedRequestContext = Mockito .mockStatic (RequestContext .class )) {
1099
+ RequestContext mockContext = mock (RequestContext .class );
1100
+ when (mockContext .getRequestTime ()).thenReturn (mockRequestTimeRemove );
1101
+ mockedRequestContext .when (RequestContext ::get ).thenReturn (mockContext );
1102
+
1103
+ glossaryService .removeTermFromEntities (fixedRateMortgage .getGuid (), Collections .singletonList (relatedObjectId ));
1076
1104
1105
+ //verify updateTime after dissociation
1106
+ AtlasEntity .AtlasEntityWithExtInfo updatedInfo = entityStore .getById (relatedObjectId .getGuid ());
1107
+ AtlasEntity updatedEntityAfterDissociation = updatedInfo .getEntity ();
1108
+ long updatedTimeAfterDissociation = updatedEntityAfterDissociation .getUpdateTime ().getTime ();
1109
+
1110
+ assertEquals (updatedTimeAfterDissociation , mockRequestTimeRemove );
1111
+ assertTrue (updatedTimeAfterDissociation > updatedTimeAfterAssignment , "updateTime should have increased after term dissociation" );
1112
+ }
1077
1113
AtlasGlossaryTerm term = glossaryService .getTerm (fixedRateMortgage .getGuid ());
1078
1114
1079
1115
assertNotNull (term );
0 commit comments