Fix tests, add logs for #117

This commit is contained in:
jendib 2016-11-20 18:52:47 +01:00
parent b36d08db8e
commit 1d78551f4c
2 changed files with 17 additions and 12 deletions

View File

@ -94,6 +94,7 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
// Upload files after edition
promise.then(function(data) {
console.log('document created, adding file', $scope.newFiles);
$scope.fileProgress = 0;
// 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
console.log('sending file', key, $scope.newFiles[key], data);
var file = $scope.newFiles[key];
var formData = new FormData();
formData.append('id', data.id);
@ -147,6 +149,7 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
contentType: false,
processData: false,
success: function(response) {
console.log('file uploaded successfully', formData);
deferred.resolve(response);
},
error: function(jqXHR) {
@ -192,11 +195,13 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
var then = function() {
key++;
if ($scope.newFiles[key]) {
console.log('sending new file');
sendFile(key).then(then);
} else {
$scope.fileIsUploading = false;
$scope.fileProgress = 0;
$rootScope.pageTitle = 'Sismics Docs';
console.log('finished sending files, bye');
navigateNext();
}
};

View File

@ -124,7 +124,7 @@ public class TestFileResource extends BaseJerseyTest {
// Check that the files are not readable directly from FS
Path storedFile = DirectoryUtil.getStorageDirectory().resolve(file1Id);
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
@ -245,9 +245,9 @@ public class TestFileResource extends BaseJerseyTest {
*/
@Test
public void testOrphanFile() throws Exception {
// Login file2
clientUtil.createUser("file2");
String file2Token = clientUtil.login("file2");
// Login file3
clientUtil.createUser("file3");
String file3Token = clientUtil.login("file3");
// Add a file
String file1Id;
@ -257,7 +257,7 @@ public class TestFileResource extends BaseJerseyTest {
JsonObject json = target()
.register(MultiPartFeature.class)
.path("/file").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.put(Entity.entity(multiPart.bodyPart(streamDataBodyPart),
MediaType.MULTIPART_FORM_DATA_TYPE), JsonObject.class);
file1Id = json.getString("id");
@ -267,14 +267,14 @@ public class TestFileResource extends BaseJerseyTest {
// Get all orphan files
JsonObject json = target().path("/file/list").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.get(JsonObject.class);
JsonArray files = json.getJsonArray("files");
Assert.assertEquals(1, files.size());
// Get the file data
Response response = target().path("/file/" + file1Id + "/data").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.get();
InputStream is = (InputStream) response.getEntity();
byte[] fileBytes = ByteStreams.toByteArray(is);
@ -283,7 +283,7 @@ public class TestFileResource extends BaseJerseyTest {
// Create a document
json = target().path("/document").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.put(Entity.form(new Form()
.param("title", "File test document 1")
.param("language", "eng")), JsonObject.class);
@ -292,7 +292,7 @@ public class TestFileResource extends BaseJerseyTest {
// Attach a file to a document
target().path("/file/" + file1Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.post(Entity.form(new Form()
.param("id", document1Id)), JsonObject.class);
@ -300,7 +300,7 @@ public class TestFileResource extends BaseJerseyTest {
json = target().path("/file/list")
.queryParam("id", document1Id)
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.get(JsonObject.class);
files = json.getJsonArray("files");
Assert.assertEquals(1, files.size());
@ -313,7 +313,7 @@ public class TestFileResource extends BaseJerseyTest {
json = target()
.register(MultiPartFeature.class)
.path("/file").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.put(Entity.entity(multiPart.bodyPart(streamDataBodyPart),
MediaType.MULTIPART_FORM_DATA_TYPE), JsonObject.class);
file2Id = json.getString("id");
@ -323,7 +323,7 @@ public class TestFileResource extends BaseJerseyTest {
// Deletes a file
json = target().path("/file/" + file2Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.delete(JsonObject.class);
Assert.assertEquals("ok", json.getString("status"));
}