mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
Tests for full CRUD functionality on bitstreamformat registry endpoint:
POST /api/core/bitstreamformats PUT /api/core/bitstreamformats/<:id> DELETE /api/core/bitstreamformats/<:id> Signed-off-by: Marie Verdonck <maria.verdonck@atmire.com>
This commit is contained in:
@@ -11,24 +11,45 @@ import static org.hamcrest.Matchers.endsWith;
|
|||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
import org.dspace.app.rest.builder.BitstreamFormatBuilder;
|
import org.dspace.app.rest.builder.BitstreamFormatBuilder;
|
||||||
|
import org.dspace.app.rest.builder.EPersonBuilder;
|
||||||
|
import org.dspace.app.rest.converter.BitstreamFormatConverter;
|
||||||
import org.dspace.app.rest.matcher.BitstreamFormatMatcher;
|
import org.dspace.app.rest.matcher.BitstreamFormatMatcher;
|
||||||
|
import org.dspace.app.rest.model.BitstreamFormatRest;
|
||||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||||
|
|
||||||
import org.dspace.content.BitstreamFormat;
|
import org.dspace.content.BitstreamFormat;
|
||||||
|
import org.dspace.core.I18nUtil;
|
||||||
|
import org.dspace.eperson.EPerson;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jonas Van Goolen - (jonas@atmire.com)
|
* @author Jonas Van Goolen - (jonas@atmire.com)
|
||||||
|
* @author Maria Verdonck
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class BitstreamFormatRestRepositoryIT extends AbstractControllerIntegrationTest {
|
public class BitstreamFormatRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
BitstreamFormatConverter converter;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findAllPaginationTest() throws Exception {
|
public void findAllPaginationTest() throws Exception {
|
||||||
getClient().perform(get("/api/core/bitstreamformats"))
|
getClient().perform(get("/api/core/bitstreamformats"))
|
||||||
@@ -36,8 +57,7 @@ public class BitstreamFormatRestRepositoryIT extends AbstractControllerIntegrati
|
|||||||
.andExpect(content().contentType(contentType))
|
.andExpect(content().contentType(contentType))
|
||||||
.andExpect(jsonPath("$.page.size", is(20)))
|
.andExpect(jsonPath("$.page.size", is(20)))
|
||||||
.andExpect(jsonPath("$._links.self.href", startsWith(REST_SERVER_URL)))
|
.andExpect(jsonPath("$._links.self.href", startsWith(REST_SERVER_URL)))
|
||||||
.andExpect(jsonPath("$._links.self.href", endsWith("/api/core/bitstreamformats")))
|
.andExpect(jsonPath("$._links.self.href", endsWith("/api/core/bitstreamformats")));
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -70,13 +90,10 @@ public class BitstreamFormatRestRepositoryIT extends AbstractControllerIntegrati
|
|||||||
.andExpect(jsonPath("$._embedded.bitstreamformats", Matchers.contains(
|
.andExpect(jsonPath("$._embedded.bitstreamformats", Matchers.contains(
|
||||||
BitstreamFormatMatcher
|
BitstreamFormatMatcher
|
||||||
.matchBitstreamFormat(bitstreamFormat.getMIMEType(), bitstreamFormat.getDescription())
|
.matchBitstreamFormat(bitstreamFormat.getMIMEType(), bitstreamFormat.getDescription())
|
||||||
)))
|
)));
|
||||||
;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void findOne() throws Exception {
|
public void findOne() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
@@ -92,7 +109,354 @@ public class BitstreamFormatRestRepositoryIT extends AbstractControllerIntegrati
|
|||||||
.andExpect(jsonPath("$.type", is("bitstreamformat")))
|
.andExpect(jsonPath("$.type", is("bitstreamformat")))
|
||||||
.andExpect(jsonPath("$._links.self.href", startsWith(REST_SERVER_URL)))
|
.andExpect(jsonPath("$._links.self.href", startsWith(REST_SERVER_URL)))
|
||||||
.andExpect(jsonPath("$._links.self.href",
|
.andExpect(jsonPath("$._links.self.href",
|
||||||
endsWith("/api/core/bitstreamformats/" + bitstreamFormat.getID())))
|
endsWith("/api/core/bitstreamformats/" + bitstreamFormat.getID())));
|
||||||
;
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findOneNonExistentIDInURL() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = this.createRandomMockBitstreamRest(false);
|
||||||
|
|
||||||
|
String nonExistentBitstreamFormatID = "404404404";
|
||||||
|
|
||||||
|
getClient().perform(get("/api/core/bitstreamformats/" + nonExistentBitstreamFormatID))
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createAdminAccess() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = this.createRandomMockBitstreamRest(false);
|
||||||
|
//Create bitstream format
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
MvcResult mvcResult = getClient(token).perform(post("/api/core/bitstreamformats/")
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isCreated())
|
||||||
|
.andReturn();
|
||||||
|
|
||||||
|
String content = mvcResult.getResponse().getContentAsString();
|
||||||
|
Map<String, Object> map = mapper.readValue(content, Map.class);
|
||||||
|
String newlyCreatedBitstreamID = String.valueOf(map.get("id"));
|
||||||
|
//Verify creation
|
||||||
|
getClient().perform(get("/api/core/bitstreamformats/" + newlyCreatedBitstreamID))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$.description", is(bitstreamFormatRest.getDescription())))
|
||||||
|
.andExpect(jsonPath("$.mimetype", is(bitstreamFormatRest.getMimetype())))
|
||||||
|
.andExpect(jsonPath("$.type", is("bitstreamformat")))
|
||||||
|
.andExpect(jsonPath("$._links.self.href", startsWith(REST_SERVER_URL)))
|
||||||
|
.andExpect(jsonPath("$._links.self.href",
|
||||||
|
endsWith("/api/core/bitstreamformats/" + newlyCreatedBitstreamID)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createNoAccess() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = this.createRandomMockBitstreamRest(false);
|
||||||
|
|
||||||
|
//Try to create bitstreamFormat without auth token
|
||||||
|
getClient(null).perform(post("/api/core/bitstreamformats/")
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isUnauthorized());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createNonAdminAccess() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = this.createRandomMockBitstreamRest(false);
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
EPerson user = EPersonBuilder.createEPerson(context)
|
||||||
|
.withNameInMetadata("first", "last")
|
||||||
|
.withEmail("testaze@gmail.com")
|
||||||
|
.withPassword(password)
|
||||||
|
.withLanguage(I18nUtil.getDefaultLocale().getLanguage())
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
//Try to create bitstreamFormat with non-admin auth token
|
||||||
|
String token = getAuthToken(user.getEmail(), password);
|
||||||
|
getClient(token).perform(post("/api/core/bitstreamformats/")
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isForbidden());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createAlreadyExisting() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = this.createRandomMockBitstreamRest(true);
|
||||||
|
//Try to create same bitstream twice
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(token).perform(post("/api/core/bitstreamformats/")
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isCreated());
|
||||||
|
//Second time it fails
|
||||||
|
getClient(token).perform(post("/api/core/bitstreamformats/")
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isInternalServerError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateAdminAccess() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateAdminAccess")
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = converter.fromModel(bitstreamFormat);
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
//Update it
|
||||||
|
bitstreamFormatRest.setShortDescription("Test short UPDATED");
|
||||||
|
getClient(token).perform(put("/api/core/bitstreamformats/" + bitstreamFormat.getID())
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
|
//Verify change
|
||||||
|
getClient().perform(get("/api/core/bitstreamformats/" + bitstreamFormat.getID()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
.andExpect(jsonPath("$.description", is(bitstreamFormatRest.getDescription())))
|
||||||
|
.andExpect(jsonPath("$.mimetype", is(bitstreamFormatRest.getMimetype())))
|
||||||
|
.andExpect(jsonPath("$.type", is("bitstreamformat")))
|
||||||
|
.andExpect(jsonPath("$._links.self.href", startsWith(REST_SERVER_URL)))
|
||||||
|
.andExpect(jsonPath("$._links.self.href",
|
||||||
|
endsWith("/api/core/bitstreamformats/" + bitstreamFormat.getID())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateNonExistingIDInURLAndJSON() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateNonExistingIDInURLAndJSON")
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
int nonExistentBitstreamFormatID = 404404404;
|
||||||
|
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = converter.fromModel(bitstreamFormat);
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
//Update it with non existent ID in URL and in JSON
|
||||||
|
bitstreamFormatRest.setShortDescription("Test short UPDATED");
|
||||||
|
bitstreamFormatRest.setId(nonExistentBitstreamFormatID);
|
||||||
|
getClient(token).perform(put("/api/core/bitstreamformats/" + nonExistentBitstreamFormatID)
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateNonExistingIDInJustURL() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateNonExistingIDInJustURL")
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
int nonExistentBitstreamFormatID = 404404404;
|
||||||
|
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = converter.fromModel(bitstreamFormat);
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
//Update it with non existent ID in URL
|
||||||
|
bitstreamFormatRest.setShortDescription("Test short UPDATED");
|
||||||
|
getClient(token).perform(put("/api/core/bitstreamformats/" + nonExistentBitstreamFormatID)
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateNonExistingIDInJSONButValidInURL() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateNonExistingIDInJSONButValidInURL")
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
int nonExistentBitstreamFormatID = 404404404;
|
||||||
|
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = converter.fromModel(bitstreamFormat);
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
//Update it with non existent ID in JSON, but valid in URL
|
||||||
|
bitstreamFormatRest.setShortDescription("Test short UPDATED");
|
||||||
|
bitstreamFormatRest.setId(nonExistentBitstreamFormatID);
|
||||||
|
getClient(token).perform(put("/api/core/bitstreamformats/" + bitstreamFormat.getID())
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isBadRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateNotMatchingIDsInJSONAndURL() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat1 = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateNotMatchingIDsInJSONAndURL 1")
|
||||||
|
.build();
|
||||||
|
BitstreamFormat bitstreamFormat2 = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateNotMatchingIDsInJSONAndURL 2")
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = converter.fromModel(bitstreamFormat1);
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
//Update but id in body is not same id as in URL
|
||||||
|
bitstreamFormatRest.setShortDescription("Test short UPDATED");
|
||||||
|
bitstreamFormatRest.setId(bitstreamFormat2.getID());
|
||||||
|
getClient(token).perform(put("/api/core/bitstreamformats/" + bitstreamFormat1.getID())
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isBadRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateNoAccess() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateNoAccess")
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = converter.fromModel(bitstreamFormat);
|
||||||
|
|
||||||
|
//Try to update bitstreamFormat without auth token
|
||||||
|
bitstreamFormatRest.setShortDescription("Test short UPDATED");
|
||||||
|
getClient(null).perform(put("/api/core/bitstreamformats/" + bitstreamFormat.getID())
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isUnauthorized());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateNonAdminAccess() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateNonAdminAccess")
|
||||||
|
.build();
|
||||||
|
EPerson user = EPersonBuilder.createEPerson(context)
|
||||||
|
.withNameInMetadata("first", "last")
|
||||||
|
.withEmail("testaze@gmail.com")
|
||||||
|
.withPassword(password)
|
||||||
|
.withLanguage(I18nUtil.getDefaultLocale().getLanguage())
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = converter.fromModel(bitstreamFormat);
|
||||||
|
String token = getAuthToken(user.getEmail(), password);
|
||||||
|
|
||||||
|
//Try to update bitstreamFormat without non-admin auth token
|
||||||
|
bitstreamFormatRest.setShortDescription("Test short UPDATED");
|
||||||
|
getClient(token).perform(put("/api/core/bitstreamformats/" + bitstreamFormat.getID())
|
||||||
|
.content(mapper.writeValueAsBytes(bitstreamFormatRest)).contentType(contentType))
|
||||||
|
.andExpect(status().isForbidden());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteAdminAccess() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateAdminAccess")
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
//Delete it
|
||||||
|
getClient(token).perform(delete("/api/core/bitstreamformats/" + bitstreamFormat.getID()))
|
||||||
|
.andExpect(status().isNoContent());
|
||||||
|
|
||||||
|
//Verify deleted
|
||||||
|
getClient().perform(get("/api/core/bitstreamformats/" + bitstreamFormat.getID()))
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteNonExistingID() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateAdminAccess")
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
String nonExistentID = "404404404";
|
||||||
|
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
//Delete it
|
||||||
|
getClient(token).perform(delete("/api/core/bitstreamformats/" + nonExistentID))
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteNoAccess() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateAdminAccess")
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
//Delete it
|
||||||
|
getClient(null).perform(delete("/api/core/bitstreamformats/" + bitstreamFormat.getID()))
|
||||||
|
.andExpect(status().isUnauthorized());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteNonAdminAccess() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
//Create bitstream format
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
BitstreamFormat bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context)
|
||||||
|
.withMimeType("application/octet-stream")
|
||||||
|
.withDescription("Description - updateAdminAccess")
|
||||||
|
.build();
|
||||||
|
EPerson user = EPersonBuilder.createEPerson(context)
|
||||||
|
.withNameInMetadata("first", "last")
|
||||||
|
.withEmail("testaze@gmail.com")
|
||||||
|
.withPassword(password)
|
||||||
|
.withLanguage(I18nUtil.getDefaultLocale().getLanguage())
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
//Delete it
|
||||||
|
String token = getAuthToken(user.getEmail(), password);
|
||||||
|
getClient(token).perform(delete("/api/core/bitstreamformats/" + bitstreamFormat.getID()))
|
||||||
|
.andExpect(status().isForbidden());
|
||||||
|
}
|
||||||
|
|
||||||
|
private BitstreamFormatRest createRandomMockBitstreamRest(boolean withRand) {
|
||||||
|
BitstreamFormatRest bitstreamFormatRest = new BitstreamFormatRest();
|
||||||
|
String random = null;
|
||||||
|
if (withRand) {
|
||||||
|
Random rand = new Random();
|
||||||
|
random = String.valueOf(rand.nextInt(100) + 1);
|
||||||
|
}
|
||||||
|
bitstreamFormatRest.setShortDescription("Test short" + random);
|
||||||
|
bitstreamFormatRest.setDescription("Full description of Test short");
|
||||||
|
bitstreamFormatRest.setMimetype("text/plain");
|
||||||
|
bitstreamFormatRest.setSupportLevel("KNOWN");
|
||||||
|
bitstreamFormatRest.setInternal(false);
|
||||||
|
bitstreamFormatRest.setExtensions(Arrays.asList("txt", "asc"));
|
||||||
|
return bitstreamFormatRest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user