mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +01:00
Fix tests, add logs for #117
This commit is contained in:
parent
b36d08db8e
commit
1d78551f4c
@ -94,6 +94,7 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
|
|||||||
|
|
||||||
// Upload files after edition
|
// Upload files after edition
|
||||||
promise.then(function(data) {
|
promise.then(function(data) {
|
||||||
|
console.log('document created, adding file', $scope.newFiles);
|
||||||
$scope.fileProgress = 0;
|
$scope.fileProgress = 0;
|
||||||
|
|
||||||
// When all files upload are over, attach orphan files and move on
|
// When all files upload are over, attach orphan files and move on
|
||||||
@ -133,6 +134,7 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Build the payload
|
// Build the payload
|
||||||
|
console.log('sending file', key, $scope.newFiles[key], data);
|
||||||
var file = $scope.newFiles[key];
|
var file = $scope.newFiles[key];
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
formData.append('id', data.id);
|
formData.append('id', data.id);
|
||||||
@ -147,6 +149,7 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
|
|||||||
contentType: false,
|
contentType: false,
|
||||||
processData: false,
|
processData: false,
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
console.log('file uploaded successfully', formData);
|
||||||
deferred.resolve(response);
|
deferred.resolve(response);
|
||||||
},
|
},
|
||||||
error: function(jqXHR) {
|
error: function(jqXHR) {
|
||||||
@ -192,11 +195,13 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
|
|||||||
var then = function() {
|
var then = function() {
|
||||||
key++;
|
key++;
|
||||||
if ($scope.newFiles[key]) {
|
if ($scope.newFiles[key]) {
|
||||||
|
console.log('sending new file');
|
||||||
sendFile(key).then(then);
|
sendFile(key).then(then);
|
||||||
} else {
|
} else {
|
||||||
$scope.fileIsUploading = false;
|
$scope.fileIsUploading = false;
|
||||||
$scope.fileProgress = 0;
|
$scope.fileProgress = 0;
|
||||||
$rootScope.pageTitle = 'Sismics Docs';
|
$rootScope.pageTitle = 'Sismics Docs';
|
||||||
|
console.log('finished sending files, bye');
|
||||||
navigateNext();
|
navigateNext();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -124,7 +124,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
// Check that the files are not readable directly from FS
|
// Check that the files are not readable directly from FS
|
||||||
Path storedFile = DirectoryUtil.getStorageDirectory().resolve(file1Id);
|
Path storedFile = DirectoryUtil.getStorageDirectory().resolve(file1Id);
|
||||||
try (InputStream storedFileInputStream = new BufferedInputStream(Files.newInputStream(storedFile))) {
|
try (InputStream storedFileInputStream = new BufferedInputStream(Files.newInputStream(storedFile))) {
|
||||||
Assert.assertNull(MimeTypeUtil.guessMimeType(storedFileInputStream));
|
Assert.assertEquals(MimeType.DEFAULT, MimeTypeUtil.guessMimeType(storedFileInputStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all files from a document
|
// Get all files from a document
|
||||||
@ -245,9 +245,9 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOrphanFile() throws Exception {
|
public void testOrphanFile() throws Exception {
|
||||||
// Login file2
|
// Login file3
|
||||||
clientUtil.createUser("file2");
|
clientUtil.createUser("file3");
|
||||||
String file2Token = clientUtil.login("file2");
|
String file3Token = clientUtil.login("file3");
|
||||||
|
|
||||||
// Add a file
|
// Add a file
|
||||||
String file1Id;
|
String file1Id;
|
||||||
@ -257,7 +257,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
JsonObject json = target()
|
JsonObject json = target()
|
||||||
.register(MultiPartFeature.class)
|
.register(MultiPartFeature.class)
|
||||||
.path("/file").request()
|
.path("/file").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
|
||||||
.put(Entity.entity(multiPart.bodyPart(streamDataBodyPart),
|
.put(Entity.entity(multiPart.bodyPart(streamDataBodyPart),
|
||||||
MediaType.MULTIPART_FORM_DATA_TYPE), JsonObject.class);
|
MediaType.MULTIPART_FORM_DATA_TYPE), JsonObject.class);
|
||||||
file1Id = json.getString("id");
|
file1Id = json.getString("id");
|
||||||
@ -267,14 +267,14 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Get all orphan files
|
// Get all orphan files
|
||||||
JsonObject json = target().path("/file/list").request()
|
JsonObject json = target().path("/file/list").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
|
||||||
.get(JsonObject.class);
|
.get(JsonObject.class);
|
||||||
JsonArray files = json.getJsonArray("files");
|
JsonArray files = json.getJsonArray("files");
|
||||||
Assert.assertEquals(1, files.size());
|
Assert.assertEquals(1, files.size());
|
||||||
|
|
||||||
// Get the file data
|
// Get the file data
|
||||||
Response response = target().path("/file/" + file1Id + "/data").request()
|
Response response = target().path("/file/" + file1Id + "/data").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
|
||||||
.get();
|
.get();
|
||||||
InputStream is = (InputStream) response.getEntity();
|
InputStream is = (InputStream) response.getEntity();
|
||||||
byte[] fileBytes = ByteStreams.toByteArray(is);
|
byte[] fileBytes = ByteStreams.toByteArray(is);
|
||||||
@ -283,7 +283,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Create a document
|
// Create a document
|
||||||
json = target().path("/document").request()
|
json = target().path("/document").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
|
||||||
.put(Entity.form(new Form()
|
.put(Entity.form(new Form()
|
||||||
.param("title", "File test document 1")
|
.param("title", "File test document 1")
|
||||||
.param("language", "eng")), JsonObject.class);
|
.param("language", "eng")), JsonObject.class);
|
||||||
@ -292,7 +292,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Attach a file to a document
|
// Attach a file to a document
|
||||||
target().path("/file/" + file1Id).request()
|
target().path("/file/" + file1Id).request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
|
||||||
.post(Entity.form(new Form()
|
.post(Entity.form(new Form()
|
||||||
.param("id", document1Id)), JsonObject.class);
|
.param("id", document1Id)), JsonObject.class);
|
||||||
|
|
||||||
@ -300,7 +300,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
json = target().path("/file/list")
|
json = target().path("/file/list")
|
||||||
.queryParam("id", document1Id)
|
.queryParam("id", document1Id)
|
||||||
.request()
|
.request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
|
||||||
.get(JsonObject.class);
|
.get(JsonObject.class);
|
||||||
files = json.getJsonArray("files");
|
files = json.getJsonArray("files");
|
||||||
Assert.assertEquals(1, files.size());
|
Assert.assertEquals(1, files.size());
|
||||||
@ -313,7 +313,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
json = target()
|
json = target()
|
||||||
.register(MultiPartFeature.class)
|
.register(MultiPartFeature.class)
|
||||||
.path("/file").request()
|
.path("/file").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
|
||||||
.put(Entity.entity(multiPart.bodyPart(streamDataBodyPart),
|
.put(Entity.entity(multiPart.bodyPart(streamDataBodyPart),
|
||||||
MediaType.MULTIPART_FORM_DATA_TYPE), JsonObject.class);
|
MediaType.MULTIPART_FORM_DATA_TYPE), JsonObject.class);
|
||||||
file2Id = json.getString("id");
|
file2Id = json.getString("id");
|
||||||
@ -323,7 +323,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Deletes a file
|
// Deletes a file
|
||||||
json = target().path("/file/" + file2Id).request()
|
json = target().path("/file/" + file2Id).request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
|
||||||
.delete(JsonObject.class);
|
.delete(JsonObject.class);
|
||||||
Assert.assertEquals("ok", json.getString("status"));
|
Assert.assertEquals("ok", json.getString("status"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user