mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +01:00
Isolate jUnit tests with separate users
This commit is contained in:
parent
21495f4509
commit
19000d095f
@ -26,12 +26,13 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
*/
|
||||
@Test
|
||||
public void testDocumentResource() throws JSONException {
|
||||
// Login admin
|
||||
String adminAuthenticationToken = clientUtil.login("admin", "admin", false);
|
||||
// Login document1
|
||||
clientUtil.createUser("document1");
|
||||
String document1Token = clientUtil.login("document1");
|
||||
|
||||
// Create a document
|
||||
WebResource documentResource = resource().path("/document");
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
MultivaluedMapImpl postParams = new MultivaluedMapImpl();
|
||||
postParams.add("title", "My super document 1");
|
||||
postParams.add("description", "My super description for document 1");
|
||||
@ -43,7 +44,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
|
||||
// List all documents
|
||||
documentResource = resource().path("/document/list");
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
MultivaluedMapImpl getParams = new MultivaluedMapImpl();
|
||||
getParams.putSingle("sort_column", 3);
|
||||
getParams.putSingle("asc", false);
|
||||
@ -56,7 +57,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
|
||||
// Get a document
|
||||
documentResource = resource().path("/document/" + document1Id);
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
response = documentResource.get(ClientResponse.class);
|
||||
json = response.getEntity(JSONObject.class);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
@ -64,7 +65,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
|
||||
// Update a document
|
||||
documentResource = resource().path("/document/" + document1Id);
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
postParams = new MultivaluedMapImpl();
|
||||
postParams.add("title", "My new super document 1");
|
||||
postParams.add("description", "My new super description for document 1");
|
||||
@ -75,7 +76,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
|
||||
// Get a document
|
||||
documentResource = resource().path("/document/" + document1Id);
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
response = documentResource.get(ClientResponse.class);
|
||||
json = response.getEntity(JSONObject.class);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
@ -84,7 +85,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
|
||||
// Deletes a document
|
||||
documentResource = resource().path("/document/" + document1Id);
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
response = documentResource.delete(ClientResponse.class);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
json = response.getEntity(JSONObject.class);
|
||||
@ -92,7 +93,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
|
||||
// Get a document (KO)
|
||||
documentResource = resource().path("/document/" + document1Id);
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||
response = documentResource.get(ClientResponse.class);
|
||||
json = response.getEntity(JSONObject.class);
|
||||
Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus()));
|
||||
|
@ -34,12 +34,13 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
*/
|
||||
@Test
|
||||
public void testFileResource() throws Exception {
|
||||
// Login admin
|
||||
String adminAuthenticationToken = clientUtil.login("admin", "admin", false);
|
||||
// Login file1
|
||||
clientUtil.createUser("file1");
|
||||
String file1AuthenticationToken = clientUtil.login("file1");
|
||||
|
||||
// Create a document
|
||||
WebResource documentResource = resource().path("/document");
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||
MultivaluedMapImpl postParams = new MultivaluedMapImpl();
|
||||
postParams.add("title", "File test document 1");
|
||||
ClientResponse response = documentResource.put(ClientResponse.class, postParams);
|
||||
@ -50,7 +51,7 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
|
||||
// Add a file
|
||||
WebResource fileResource = resource().path("/file");
|
||||
fileResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||
FormDataMultiPart form = new FormDataMultiPart();
|
||||
InputStream file = this.getClass().getResourceAsStream("/file/PIA00452.jpg");
|
||||
FormDataBodyPart fdp = new FormDataBodyPart("file",
|
||||
@ -65,7 +66,7 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
|
||||
// Get the file
|
||||
fileResource = resource().path("/file/" + file1Id);
|
||||
fileResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||
response = fileResource.get(ClientResponse.class);
|
||||
json = response.getEntity(JSONObject.class);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
@ -74,7 +75,7 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
|
||||
// Get the file data
|
||||
fileResource = resource().path("/file/" + file1Id + "/data");
|
||||
fileResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||
response = fileResource.get(ClientResponse.class);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
InputStream is = response.getEntityInputStream();
|
||||
@ -83,7 +84,7 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
|
||||
// Get all files from a document
|
||||
fileResource = resource().path("/file/list");
|
||||
fileResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||
MultivaluedMapImpl getParams = new MultivaluedMapImpl();
|
||||
getParams.putSingle("id", document1Id);
|
||||
response = fileResource.queryParams(getParams).get(ClientResponse.class);
|
||||
@ -94,7 +95,7 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
|
||||
// Deletes a file
|
||||
documentResource = resource().path("/file/" + file1Id);
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
documentResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||
response = documentResource.delete(ClientResponse.class);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
json = response.getEntity(JSONObject.class);
|
||||
@ -102,7 +103,7 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
|
||||
// Get all files from a document
|
||||
fileResource = resource().path("/file/list");
|
||||
fileResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
||||
fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||
getParams = new MultivaluedMapImpl();
|
||||
getParams.putSingle("id", document1Id);
|
||||
response = fileResource.queryParams(getParams).get(ClientResponse.class);
|
||||
|
Loading…
Reference in New Issue
Block a user