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
|
@Test
|
||||||
public void testDocumentResource() throws JSONException {
|
public void testDocumentResource() throws JSONException {
|
||||||
// Login admin
|
// Login document1
|
||||||
String adminAuthenticationToken = clientUtil.login("admin", "admin", false);
|
clientUtil.createUser("document1");
|
||||||
|
String document1Token = clientUtil.login("document1");
|
||||||
|
|
||||||
// Create a document
|
// Create a document
|
||||||
WebResource documentResource = resource().path("/document");
|
WebResource documentResource = resource().path("/document");
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
MultivaluedMapImpl postParams = new MultivaluedMapImpl();
|
MultivaluedMapImpl postParams = new MultivaluedMapImpl();
|
||||||
postParams.add("title", "My super document 1");
|
postParams.add("title", "My super document 1");
|
||||||
postParams.add("description", "My super description for document 1");
|
postParams.add("description", "My super description for document 1");
|
||||||
@ -43,7 +44,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// List all documents
|
// List all documents
|
||||||
documentResource = resource().path("/document/list");
|
documentResource = resource().path("/document/list");
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
MultivaluedMapImpl getParams = new MultivaluedMapImpl();
|
MultivaluedMapImpl getParams = new MultivaluedMapImpl();
|
||||||
getParams.putSingle("sort_column", 3);
|
getParams.putSingle("sort_column", 3);
|
||||||
getParams.putSingle("asc", false);
|
getParams.putSingle("asc", false);
|
||||||
@ -56,7 +57,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Get a document
|
// Get a document
|
||||||
documentResource = resource().path("/document/" + document1Id);
|
documentResource = resource().path("/document/" + document1Id);
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
response = documentResource.get(ClientResponse.class);
|
response = documentResource.get(ClientResponse.class);
|
||||||
json = response.getEntity(JSONObject.class);
|
json = response.getEntity(JSONObject.class);
|
||||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
@ -64,7 +65,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Update a document
|
// Update a document
|
||||||
documentResource = resource().path("/document/" + document1Id);
|
documentResource = resource().path("/document/" + document1Id);
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
postParams = new MultivaluedMapImpl();
|
postParams = new MultivaluedMapImpl();
|
||||||
postParams.add("title", "My new super document 1");
|
postParams.add("title", "My new super document 1");
|
||||||
postParams.add("description", "My new super description for document 1");
|
postParams.add("description", "My new super description for document 1");
|
||||||
@ -75,7 +76,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Get a document
|
// Get a document
|
||||||
documentResource = resource().path("/document/" + document1Id);
|
documentResource = resource().path("/document/" + document1Id);
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
response = documentResource.get(ClientResponse.class);
|
response = documentResource.get(ClientResponse.class);
|
||||||
json = response.getEntity(JSONObject.class);
|
json = response.getEntity(JSONObject.class);
|
||||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
@ -84,7 +85,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Deletes a document
|
// Deletes a document
|
||||||
documentResource = resource().path("/document/" + document1Id);
|
documentResource = resource().path("/document/" + document1Id);
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
response = documentResource.delete(ClientResponse.class);
|
response = documentResource.delete(ClientResponse.class);
|
||||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
json = response.getEntity(JSONObject.class);
|
json = response.getEntity(JSONObject.class);
|
||||||
@ -92,7 +93,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Get a document (KO)
|
// Get a document (KO)
|
||||||
documentResource = resource().path("/document/" + document1Id);
|
documentResource = resource().path("/document/" + document1Id);
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
|
||||||
response = documentResource.get(ClientResponse.class);
|
response = documentResource.get(ClientResponse.class);
|
||||||
json = response.getEntity(JSONObject.class);
|
json = response.getEntity(JSONObject.class);
|
||||||
Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus()));
|
||||||
|
@ -34,12 +34,13 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFileResource() throws Exception {
|
public void testFileResource() throws Exception {
|
||||||
// Login admin
|
// Login file1
|
||||||
String adminAuthenticationToken = clientUtil.login("admin", "admin", false);
|
clientUtil.createUser("file1");
|
||||||
|
String file1AuthenticationToken = clientUtil.login("file1");
|
||||||
|
|
||||||
// Create a document
|
// Create a document
|
||||||
WebResource documentResource = resource().path("/document");
|
WebResource documentResource = resource().path("/document");
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
documentResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||||
MultivaluedMapImpl postParams = new MultivaluedMapImpl();
|
MultivaluedMapImpl postParams = new MultivaluedMapImpl();
|
||||||
postParams.add("title", "File test document 1");
|
postParams.add("title", "File test document 1");
|
||||||
ClientResponse response = documentResource.put(ClientResponse.class, postParams);
|
ClientResponse response = documentResource.put(ClientResponse.class, postParams);
|
||||||
@ -50,7 +51,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Add a file
|
// Add a file
|
||||||
WebResource fileResource = resource().path("/file");
|
WebResource fileResource = resource().path("/file");
|
||||||
fileResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||||
FormDataMultiPart form = new FormDataMultiPart();
|
FormDataMultiPart form = new FormDataMultiPart();
|
||||||
InputStream file = this.getClass().getResourceAsStream("/file/PIA00452.jpg");
|
InputStream file = this.getClass().getResourceAsStream("/file/PIA00452.jpg");
|
||||||
FormDataBodyPart fdp = new FormDataBodyPart("file",
|
FormDataBodyPart fdp = new FormDataBodyPart("file",
|
||||||
@ -65,7 +66,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Get the file
|
// Get the file
|
||||||
fileResource = resource().path("/file/" + file1Id);
|
fileResource = resource().path("/file/" + file1Id);
|
||||||
fileResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||||
response = fileResource.get(ClientResponse.class);
|
response = fileResource.get(ClientResponse.class);
|
||||||
json = response.getEntity(JSONObject.class);
|
json = response.getEntity(JSONObject.class);
|
||||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
@ -74,7 +75,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Get the file data
|
// Get the file data
|
||||||
fileResource = resource().path("/file/" + file1Id + "/data");
|
fileResource = resource().path("/file/" + file1Id + "/data");
|
||||||
fileResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||||
response = fileResource.get(ClientResponse.class);
|
response = fileResource.get(ClientResponse.class);
|
||||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
InputStream is = response.getEntityInputStream();
|
InputStream is = response.getEntityInputStream();
|
||||||
@ -83,7 +84,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Get all files from a document
|
// Get all files from a document
|
||||||
fileResource = resource().path("/file/list");
|
fileResource = resource().path("/file/list");
|
||||||
fileResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||||
MultivaluedMapImpl getParams = new MultivaluedMapImpl();
|
MultivaluedMapImpl getParams = new MultivaluedMapImpl();
|
||||||
getParams.putSingle("id", document1Id);
|
getParams.putSingle("id", document1Id);
|
||||||
response = fileResource.queryParams(getParams).get(ClientResponse.class);
|
response = fileResource.queryParams(getParams).get(ClientResponse.class);
|
||||||
@ -94,7 +95,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Deletes a file
|
// Deletes a file
|
||||||
documentResource = resource().path("/file/" + file1Id);
|
documentResource = resource().path("/file/" + file1Id);
|
||||||
documentResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
documentResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||||
response = documentResource.delete(ClientResponse.class);
|
response = documentResource.delete(ClientResponse.class);
|
||||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
json = response.getEntity(JSONObject.class);
|
json = response.getEntity(JSONObject.class);
|
||||||
@ -102,7 +103,7 @@ public class TestFileResource extends BaseJerseyTest {
|
|||||||
|
|
||||||
// Get all files from a document
|
// Get all files from a document
|
||||||
fileResource = resource().path("/file/list");
|
fileResource = resource().path("/file/list");
|
||||||
fileResource.addFilter(new CookieAuthenticationFilter(adminAuthenticationToken));
|
fileResource.addFilter(new CookieAuthenticationFilter(file1AuthenticationToken));
|
||||||
getParams = new MultivaluedMapImpl();
|
getParams = new MultivaluedMapImpl();
|
||||||
getParams.putSingle("id", document1Id);
|
getParams.putSingle("id", document1Id);
|
||||||
response = fileResource.queryParams(getParams).get(ClientResponse.class);
|
response = fileResource.queryParams(getParams).get(ClientResponse.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user