1
1
package ca .uhn .fhir .jpa .starter .common ;
2
2
3
- import ca .uhn .fhir .jpa .binary .api .IBinaryStorageSvc ;
4
3
import ca .uhn .fhir .jpa .binstore .DatabaseBinaryContentStorageSvcImpl ;
5
4
import ca .uhn .fhir .jpa .binstore .FilesystemBinaryStorageSvcImpl ;
6
5
import ca .uhn .fhir .jpa .starter .AppProperties ;
7
6
import org .junit .jupiter .api .Test ;
8
7
import org .junit .jupiter .api .io .TempDir ;
8
+ import org .springframework .beans .factory .ObjectProvider ;
9
9
10
10
import java .nio .file .Files ;
11
11
import java .nio .file .Path ;
12
+ import java .util .function .Supplier ;
12
13
13
14
import static org .assertj .core .api .Assertions .assertThat ;
14
15
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
@@ -26,7 +27,7 @@ private FhirServerConfigCommon newConfig() {
26
27
void defaultsToDatabaseImplementation () {
27
28
AppProperties props = new AppProperties ();
28
29
29
- IBinaryStorageSvc svc = newConfig (). binaryStorageSvc (props );
30
+ Object svc = binaryStorageSvc (props );
30
31
31
32
assertThat (svc ).isInstanceOf (DatabaseBinaryContentStorageSvcImpl .class );
32
33
}
@@ -39,8 +40,7 @@ void filesystemModeUsesDefaultMinimumWhenUnspecified() throws Exception {
39
40
Files .createDirectories (baseDir );
40
41
props .setBinary_storage_filesystem_base_directory (baseDir .toString ());
41
42
42
- FilesystemBinaryStorageSvcImpl svc =
43
- (FilesystemBinaryStorageSvcImpl ) newConfig ().binaryStorageSvc (props );
43
+ FilesystemBinaryStorageSvcImpl svc = filesystemBinaryStorageSvc (props );
44
44
45
45
assertThat (svc .getMinimumBinarySize ()).isEqualTo (102_400 );
46
46
}
@@ -54,8 +54,7 @@ void filesystemModeHonoursExplicitMinimum() throws Exception {
54
54
Files .createDirectories (baseDir );
55
55
props .setBinary_storage_filesystem_base_directory (baseDir .toString ());
56
56
57
- FilesystemBinaryStorageSvcImpl svc =
58
- (FilesystemBinaryStorageSvcImpl ) newConfig ().binaryStorageSvc (props );
57
+ FilesystemBinaryStorageSvcImpl svc = filesystemBinaryStorageSvc (props );
59
58
60
59
assertThat (svc .getMinimumBinarySize ()).isEqualTo (4096 );
61
60
}
@@ -69,8 +68,7 @@ void filesystemModeSupportsZeroMinimumWhenExplicit() throws Exception {
69
68
Files .createDirectories (baseDir );
70
69
props .setBinary_storage_filesystem_base_directory (baseDir .toString ());
71
70
72
- FilesystemBinaryStorageSvcImpl svc =
73
- (FilesystemBinaryStorageSvcImpl ) newConfig ().binaryStorageSvc (props );
71
+ FilesystemBinaryStorageSvcImpl svc = filesystemBinaryStorageSvc (props );
74
72
75
73
assertThat (svc .getMinimumBinarySize ()).isZero ();
76
74
}
@@ -80,8 +78,44 @@ void filesystemModeRequiresBaseDirectory() {
80
78
AppProperties props = new AppProperties ();
81
79
props .setBinary_storage_mode (AppProperties .BinaryStorageMode .FILESYSTEM );
82
80
83
- assertThatThrownBy (() -> newConfig (). binaryStorageSvc (props ))
81
+ assertThatThrownBy (() -> filesystemBinaryStorageSvc (props ))
84
82
.isInstanceOf (IllegalArgumentException .class )
85
83
.hasMessageContaining ("binary_storage_filesystem_base_directory" );
86
84
}
85
+
86
+ private Object binaryStorageSvc (AppProperties props ) {
87
+ FhirServerConfigCommon config = newConfig ();
88
+ return config .binaryStorageSvc (
89
+ props ,
90
+ provider (() -> config .databaseBinaryStorageSvc (props )),
91
+ provider (() -> config .filesystemBinaryStorageSvc (props )));
92
+ }
93
+
94
+ private FilesystemBinaryStorageSvcImpl filesystemBinaryStorageSvc (AppProperties props ) {
95
+ return (FilesystemBinaryStorageSvcImpl ) binaryStorageSvc (props );
96
+ }
97
+
98
+ private static <T > ObjectProvider <T > provider (Supplier <T > supplier ) {
99
+ return new ObjectProvider <>() {
100
+ @ Override
101
+ public T getObject (Object ... args ) {
102
+ return supplier .get ();
103
+ }
104
+
105
+ @ Override
106
+ public T getObject () {
107
+ return supplier .get ();
108
+ }
109
+
110
+ @ Override
111
+ public T getIfAvailable () {
112
+ return supplier .get ();
113
+ }
114
+
115
+ @ Override
116
+ public T getIfUnique () {
117
+ return supplier .get ();
118
+ }
119
+ };
120
+ }
87
121
}
0 commit comments