-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package gateway; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import gateway.config.Config; | ||
import gateway.controller.CtrlAccountRegister; | ||
import gateway.controller.CtrlFileUpload; | ||
import gateway.soap.request.Credentials; | ||
import gateway.soap.request.ReqFileUpload; | ||
import gateway.soap.response.ResSession; | ||
import gateway.testutils.TestUtilConfig; | ||
import gateway.testutils.TestUtilGenerator; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ITFileIO | ||
{ | ||
@BeforeEach void setup () { Config.initializeFromEnv (); } | ||
|
||
@Test void uploadFile () | ||
{ | ||
|
||
// register | ||
|
||
ResSession res = CtrlAccountRegister.account_register ( | ||
new Credentials (UUID.randomUUID ().toString (), "pass")); | ||
String token = res.auth.token; | ||
assertEquals (201, res.code, "Login successfully"); | ||
|
||
// 400 field validation | ||
|
||
ReqFileUpload args = new ReqFileUpload (); | ||
assertEquals (400, CtrlFileUpload.file_upload (args).code, "Field validation failed"); | ||
|
||
// 401 auth failed | ||
|
||
args.fileName = UUID.randomUUID ().toString (); | ||
args.fileContent = TestUtilGenerator.randomBytes (1); | ||
args.location = null; | ||
args.token = "invalid token"; | ||
assertEquals (401, CtrlFileUpload.file_upload (args).code, "Authorization failed"); | ||
|
||
// 400 empty file | ||
|
||
args.token = token; | ||
args.fileContent = TestUtilGenerator.randomBytes (0); | ||
assertEquals (400, CtrlFileUpload.file_upload (args).code, "Empty file is rejected"); | ||
|
||
// 413 file too big | ||
|
||
args.fileContent = TestUtilGenerator.randomBytes (100000001); | ||
assertEquals (413, CtrlFileUpload.file_upload (args).code, "Big file is rejected"); | ||
|
||
// 201 file uploaded | ||
|
||
args.fileContent = TestUtilGenerator.randomBytes (1); | ||
assertEquals (201, CtrlFileUpload.file_upload (args).code, "File upload success"); | ||
|
||
args.fileName = UUID.randomUUID ().toString (); | ||
TestUtilConfig.makeInvalidWorker (); | ||
assertEquals (500, CtrlFileUpload.file_upload (args).code, "Can't reach Worker"); | ||
|
||
TestUtilConfig.makeInvalidMetadata (); | ||
assertEquals (500, CtrlFileUpload.file_upload (args).code, "Can't reach Metadata server"); | ||
|
||
TestUtilConfig.makeInvalidAll (); | ||
assertEquals (500, CtrlFileUpload.file_upload (args).code, "Can't reach Auth"); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/test/java/gateway/testutils/TestUtilGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package gateway.testutils; | ||
|
||
import java.util.Random; | ||
|
||
public class TestUtilGenerator | ||
{ | ||
public static byte[] randomBytes (int size) | ||
{ | ||
byte[] buff = new byte[size]; | ||
(new Random ()).nextBytes (buff); | ||
return buff; | ||
} | ||
} |