7
7
import ca .uhn .fhir .jpa .delete .batch2 .DeleteExpungeSqlBuilder ;
8
8
import ca .uhn .fhir .jpa .model .config .PartitionSettings ;
9
9
import ca .uhn .fhir .jpa .model .dao .JpaPid ;
10
+ import ca .uhn .fhir .jpa .model .entity .ResourceLink ;
11
+ import ca .uhn .fhir .jpa .model .entity .ResourceTable ;
10
12
import ca .uhn .fhir .jpa .util .QueryChunker ;
11
- import org .junit .jupiter .api .BeforeEach ;
12
13
import org .junit .jupiter .api .Test ;
14
+ import org .junit .jupiter .api .extension .ExtendWith ;
15
+ import org .mockito .InjectMocks ;
13
16
import org .mockito .Mock ;
14
17
import org .mockito .MockedStatic ;
15
18
import org .mockito .Mockito ;
16
- import org .springframework . beans . factory . annotation . Autowired ;
19
+ import org .mockito . junit . jupiter . MockitoExtension ;
17
20
18
21
import java .util .List ;
22
+ import java .util .Set ;
19
23
24
+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
20
25
import static org .mockito .ArgumentMatchers .any ;
21
26
import static org .mockito .ArgumentMatchers .anyCollection ;
27
+ import static org .mockito .ArgumentMatchers .anyList ;
22
28
import static org .mockito .Mockito .times ;
29
+ import static org .mockito .Mockito .when ;
23
30
24
- public class DeleteExpungeSqlBuilderTest {
25
- @ Autowired
26
- private ResourceTableFKProvider theResourceTableFKProvider ;
27
- private JpaStorageSettings myStorageSettings = new JpaStorageSettings ();
31
+ @ ExtendWith (MockitoExtension .class )
32
+ class DeleteExpungeSqlBuilderTest {
33
+ @ Mock
34
+ private ResourceTableFKProvider myResourceTableFKProvider ;
35
+ @ Mock
36
+ private JpaStorageSettings myStorageSettings ;
37
+ @ Mock
28
38
private IIdHelperService <JpaPid > myIdHelper ;
29
39
@ Mock
30
- private IResourceLinkDao theResourceLinkDao ;
31
- private PartitionSettings thePartitionSettings = new PartitionSettings ();
40
+ private IResourceLinkDao myResourceLinkDao ;
41
+ @ Mock
42
+ private PartitionSettings myPartitionSettings ;
43
+ @ InjectMocks
32
44
private DeleteExpungeSqlBuilder myDeleteExpungeSqlBuilderTest ;
33
45
34
- @ BeforeEach
35
- public void beforeEach () {
36
- myDeleteExpungeSqlBuilderTest = new DeleteExpungeSqlBuilder (
37
- theResourceTableFKProvider ,
38
- myStorageSettings ,
39
- myIdHelper ,
40
- theResourceLinkDao ,
41
- thePartitionSettings
42
- );
43
- }
44
-
45
46
@ Test
46
47
public void testQueryChunkingWhenFindingChildResources (){
47
48
//Given: We have a list of pids.
@@ -57,4 +58,29 @@ public void testQueryChunkingWhenFindingChildResources(){
57
58
queryChunker .verify (() -> QueryChunker .chunk (anyCollection (), any ()), times (1 ));
58
59
}
59
60
}
61
+
62
+ @ Test
63
+ void testValidateOkToDeleteAndExpunge_whenEnforceReferentialIntegrityDisableForPaths_noException () {
64
+ // Set up
65
+ String path = "Encounter.subject" ;
66
+ when (myStorageSettings .getEnforceReferentialIntegrityOnDeleteDisableForPaths ()).thenReturn (Set .of (path ));
67
+ when (myStorageSettings .isEnforceReferentialIntegrityOnDelete ()).thenReturn (true );
68
+
69
+ ResourceTable sourceRes = new ResourceTable ();
70
+ sourceRes .setId (JpaPid .fromIdAndResourceType (20L , "Encounter" ));
71
+
72
+ ResourceLink resLink = new ResourceLink ();
73
+ resLink .setSourceResource (sourceRes );
74
+ resLink .setSourcePath (path );
75
+
76
+ List <ResourceLink > conflictResourceLinks = List .of (resLink );
77
+ when (myResourceLinkDao .findWithTargetPidIn (anyList ())).thenReturn (conflictResourceLinks );
78
+
79
+ Set <JpaPid > pids = Set .of (JpaPid .fromIdAndResourceType (10L , "Patient" ));
80
+
81
+ // Execute & Verify
82
+ assertDoesNotThrow (() -> {
83
+ myDeleteExpungeSqlBuilderTest .validateOkToDeleteAndExpunge (pids , false , null );
84
+ });
85
+ }
60
86
}
0 commit comments