forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue2303.java
More file actions
48 lines (41 loc) · 1.49 KB
/
Issue2303.java
File metadata and controls
48 lines (41 loc) · 1.49 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
package io.jooby;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class Issue2303 {
@Test
public void shouldLoadAbsoluteFile() throws IOException {
String crt = file("ssl", "test.crt");
String key = file("ssl", "test.key");
SslOptions ssl = SslOptions.x509(crt, key);
assertNotNull(ssl);
withResource(ssl, ssl.getCert(), Assertions::assertNotNull);
withResource(ssl, ssl.getPrivateKey(), Assertions::assertNotNull);
}
private void withResource(SslOptions ssl, String file,
SneakyThrows.Consumer<InputStream> consumer) throws IOException {
try (InputStream crtFile = ssl.getResource(getClass().getClassLoader(), file)) {
consumer.accept(crtFile);
}
}
private String file(String... path) {
Path basedir = Paths.get(System.getProperty("user.dir"));
if (Files.exists(basedir.resolve("jooby"))) {
// maven vs IDE
basedir = basedir.resolve("jooby");
}
Path result = basedir.resolve("src").resolve("test").resolve("resources");
for (String segment : path) {
result = result.resolve(segment);
}
result = result.normalize().toAbsolutePath();
assertTrue(Files.exists(result), result.toString());
return result.toString();
}
}