23
23
24
24
import io .dropwizard .testing .DropwizardTestSupport ;
25
25
26
+ import java .io .FileInputStream ;
26
27
import java .io .IOException ;
27
28
import java .io .InputStream ;
29
+ import java .io .UncheckedIOException ;
28
30
import java .net .URI ;
31
+ import java .nio .file .Path ;
32
+ import java .nio .file .Paths ;
33
+ import java .security .AccessController ;
34
+ import java .security .PrivilegedActionException ;
35
+ import java .security .PrivilegedExceptionAction ;
29
36
import java .util .HashMap ;
30
37
import java .util .List ;
31
38
import java .util .Map ;
32
39
import java .util .UUID ;
33
- import java .util .concurrent . CompletableFuture ;
40
+ import java .util .function . Supplier ;
34
41
35
42
import javax .net .ssl .SSLContext ;
36
43
37
- import java .net .http .HttpRequest ;
38
- import java .net .http .HttpResponse ;
39
-
40
44
import org .apache .commons .rdf .api .IRI ;
41
45
import org .apache .commons .rdf .jena .JenaRDF ;
42
46
import org .junit .jupiter .api .AfterAll ;
57
61
public class H2ClientTest {
58
62
private static final DropwizardTestSupport <TrellisConfiguration > APP = new DropwizardTestSupport <>(
59
63
TrellisApplication .class , resourceFilePath ("trellis-config.yml" ), config ("server"
60
- + ".applicationConnectors[1].port" , "8446" ), config ("binaries" , resourceFilePath ("data" )
61
- + "/binaries" ), config ("mementos" , resourceFilePath ("data" ) + "/mementos" ), config ("namespaces" ,
62
- resourceFilePath ("data/namespaces.json" )), config ("server.applicationConnectors[1].keyStorePath" ,
63
- resourceFilePath ("keystore/trellis.jks" )));
64
+ + ".applicationConnectors[1].port" , "8446" ), config ("binaries" , resourceFilePath ("data" )
65
+ + "/binaries" ), config ("mementos" , resourceFilePath ("data" ) + "/mementos" ), config ("namespaces" ,
66
+ resourceFilePath ("data/namespaces.json" )), config ("server.applicationConnectors[1].keyStorePath" ,
67
+ resourceFilePath ("keystore/trellis.jks" )));
64
68
private static final JenaRDF rdf = new JenaRDF ();
65
69
private static String baseUrl ;
66
70
private static String pid ;
@@ -93,8 +97,8 @@ void init() {
93
97
void tearDown () {
94
98
}
95
99
96
- private static InputStream getTestJsonResource () {
97
- return H2ClientTest .class .getResourceAsStream ("/webanno.complete-embedded.json" );
100
+ private static Path getTestJsonResource () {
101
+ return Paths . get ( H2ClientTest .class .getResource ("/webanno.complete-embedded.json" ). getPath () );
98
102
}
99
103
100
104
private static InputStream getTestN3Resource () {
@@ -117,7 +121,7 @@ void testRepeatedPutH2N3Resource() throws Exception {
117
121
void testRepeatedPutH2JsonResource () throws Exception {
118
122
try {
119
123
final IRI identifier = rdf .createIRI (baseUrl + pid );
120
- h2client .put (identifier , getTestJsonResource (), contentTypeJSONLD );
124
+ h2client .putSupplier (identifier , fileInputStreamSupplier ( getTestJsonResource () ), contentTypeJSONLD );
121
125
final Map <String , List <String >> headers = h2client .head (identifier );
122
126
assertTrue (headers .containsKey (LINK ));
123
127
} catch (Exception ex ) {
@@ -143,4 +147,19 @@ void testJoiningCompletableFuturePut() throws Exception {
143
147
}
144
148
}
145
149
150
+ static Supplier <FileInputStream > fileInputStreamSupplier (Path f ) {
151
+ return new Supplier <>() {
152
+ Path file = f ;
153
+ @ Override
154
+ public FileInputStream get () {
155
+ try {
156
+ PrivilegedExceptionAction <FileInputStream > pa =
157
+ () -> new FileInputStream (file .toFile ());
158
+ return AccessController .doPrivileged (pa );
159
+ } catch (PrivilegedActionException x ) {
160
+ throw new UncheckedIOException ((IOException )x .getCause ());
161
+ }
162
+ }
163
+ };
164
+ }
146
165
}
0 commit comments