-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathS3ResourcesTest.java
87 lines (73 loc) · 2.92 KB
/
S3ResourcesTest.java
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package org.acme.s3;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.util.Map;
import jakarta.ws.rs.core.Response.Status;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import io.quarkus.test.junit.QuarkusTest;
@QuarkusTest
public class S3ResourcesTest {
private static final String FILE_NAME_PREFIX = "test-file-";
private static final String FILE_MIMETYPE = "text/plain";
private static final Map<String, File> FRUITS = Map.of(
"cherry", testFile("cherry"),
"pear", testFile("pear"));
private static File testFile(String name) {
return new File("./src/test/resources/" + name);
}
@ParameterizedTest
@ValueSource(strings = {"s3", "async-s3"})
void testResource(final String testedResource) {
//Upload files
FRUITS.forEach((name, file) -> {
given()
.pathParam("resource", testedResource)
.multiPart("file", file)
.multiPart("filename", FILE_NAME_PREFIX + name)
.multiPart("mimetype", FILE_MIMETYPE)
.when()
.post("/{resource}/upload")
.then()
.statusCode(Status.CREATED.getStatusCode());
}
);
//List files
given()
.pathParam("resource", testedResource)
.when().get("/{resource}")
.then()
.statusCode(200)
//Objects are sorted by objectKey
.body("size()", equalTo(2))
.body("[0].objectKey", equalTo(FILE_NAME_PREFIX + "cherry"))
.body("[0].size", equalTo(fruitFileLength("cherry")))
.body("[1].objectKey", equalTo(FILE_NAME_PREFIX + "pear"))
.body("[1].size", equalTo(fruitFileLength("pear")));
//Download file
FRUITS.forEach((name, file) -> {
try {
given()
.pathParam("resource", testedResource)
.pathParam("objectKey", FILE_NAME_PREFIX + name)
.when().get("/{resource}/download/{objectKey}")
.then()
.statusCode(200)
.body(equalTo(fruitFileData(name))
);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
private String fruitFileData(String name) throws IOException {
return Files.readString(FRUITS.get(name).toPath());
}
private int fruitFileLength(String name) {
return (int) FRUITS.get(name).length();
}
}