1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-18 04:01:42 +00:00

#256: list versions of a file (API)

This commit is contained in:
Benjamin Gamard
2019-01-30 21:14:07 +01:00
parent 4469bb7bee
commit 8bdab73ae9
4 changed files with 104 additions and 3 deletions

View File

@@ -140,6 +140,7 @@ public class TestFileResource extends BaseJerseyTest {
Assert.assertEquals(2, files.size());
Assert.assertEquals(file1Id, files.getJsonObject(0).getString("id"));
Assert.assertEquals("PIA00452.jpg", files.getJsonObject(0).getString("name"));
Assert.assertEquals("image/jpeg", files.getJsonObject(0).getString("mimetype"));
Assert.assertEquals(0, files.getJsonObject(0).getInt("version"));
Assert.assertEquals(163510L, files.getJsonObject(0).getJsonNumber("size").longValue());
Assert.assertEquals(file2Id, files.getJsonObject(1).getString("id"));
@@ -228,6 +229,19 @@ public class TestFileResource extends BaseJerseyTest {
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file1Token)
.post(Entity.form(new Form()), JsonObject.class);
// Get all versions from a file
json = target().path("/file/" + file2Id + "/versions")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file1Token)
.get(JsonObject.class);
files = json.getJsonArray("files");
Assert.assertEquals(1, files.size());
JsonObject file = files.getJsonObject(0);
Assert.assertEquals(file2Id, file.getString("id"));
Assert.assertEquals("PIA00452.jpg", file.getString("name"));
Assert.assertEquals("image/jpeg", file.getString("mimetype"));
Assert.assertEquals(0, file.getInt("version"));
// Add a new version to a file
String file3Id;
try (InputStream is0 = Resources.getResource("file/document.txt").openStream()) {
@@ -248,6 +262,25 @@ public class TestFileResource extends BaseJerseyTest {
}
}
// Get all versions from a file
json = target().path("/file/" + file2Id + "/versions")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file1Token)
.get(JsonObject.class);
files = json.getJsonArray("files");
Assert.assertEquals(2, files.size());
file = files.getJsonObject(1);
Assert.assertEquals(file3Id, file.getString("id"));
Assert.assertEquals("document.txt", file.getString("name"));
Assert.assertEquals("text/plain", file.getString("mimetype"));
Assert.assertEquals(1, file.getInt("version"));
// Delete the previous version
json = target().path("/file/" + file2Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file1Token)
.delete(JsonObject.class);
Assert.assertEquals("ok", json.getString("status"));
// Check the newly created version
json = target().path("/file/list")
.queryParam("id", document1Id)