Implemented feedback and testing on item bitstreams post endpoint

This commit is contained in:
Raf Ponsaerts
2019-07-12 11:39:09 +02:00
parent 70b394b57f
commit 3ff164c0fe
5 changed files with 539 additions and 23 deletions

View File

@@ -1,13 +1,17 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.BadRequestException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
@@ -16,18 +20,19 @@ import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.converter.BitstreamConverter;
import org.dspace.app.rest.converter.MetadataConverter;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.PropertiesRest;
import org.dspace.app.rest.model.BitstreamPropertiesRest;
import org.dspace.app.rest.model.hateoas.BitstreamResource;
import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.app.rest.utils.Utils;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Bitstream;
import org.dspace.content.Item;
import org.dspace.content.MetadataValue;
import org.dspace.content.service.BitstreamService;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -57,6 +62,7 @@ public class ItemUploadController {
private MetadataConverter metadataConverter;
@RequestMapping(method = RequestMethod.POST, value = "/bitstreams", headers = "content-type=multipart/form-data")
@PreAuthorize("hasPermission(#uuid, 'ITEM', 'WRITE')")
public BitstreamResource uploadBitstream(HttpServletRequest request, @PathVariable UUID uuid,
@RequestParam("file") MultipartFile uploadfile,
@RequestParam(value = "properties", required = false) String properties) {
@@ -70,15 +76,14 @@ public class ItemUploadController {
log.error("Something went wrong trying to find the Item with uuid: " + uuid, e);
}
if (item == null) {
throw new BadRequestException("The given uuid did not resolve to an Item on the server: " + uuid);
throw new ResourceNotFoundException("The given uuid did not resolve to an Item on the server: " + uuid);
}
String fileName = uploadfile.getName();
InputStream fileInputStream = null;
try {
fileInputStream = uploadfile.getInputStream();
} catch (IOException e) {
log.error("Something went wrong when trying to read the inputstream from the given file in the request");
throw new BadRequestException("The InputStream from the file couldn't be read");
throw new UnprocessableEntityException("The InputStream from the file couldn't be read");
}
try {
bitstream = processBitstreamCreation(context, item, fileInputStream, properties);
@@ -86,7 +91,8 @@ public class ItemUploadController {
context.commit();
} catch (AuthorizeException | IOException | SQLException e) {
log.error(
"Something went wrong with trying to create the single bitstream for file with filename: " + fileName
"Something went wrong with trying to create the single bitstream for file with filename: " + uploadfile
.getOriginalFilename()
+ " for item with uuid: " + uuid + " and possible properties: " + properties);
}
@@ -100,26 +106,29 @@ public class ItemUploadController {
Bitstream bitstream = null;
if (StringUtils.isNotBlank(properties)) {
ObjectMapper mapper = new ObjectMapper();
PropertiesRest propertiesRest = null;
BitstreamPropertiesRest bitstreamPropertiesRest = null;
try {
propertiesRest = mapper.readValue(properties, PropertiesRest.class);
bitstreamPropertiesRest = mapper.readValue(properties, BitstreamPropertiesRest.class);
} catch (Exception e) {
throw new UnprocessableEntityException("The properties parameter was incorrect: " + properties);
}
String bundleName = propertiesRest.getBundleName();
String bundleName = bitstreamPropertiesRest.getBundleName();
if (StringUtils.isBlank(bundleName)) {
throw new BadRequestException("Properties without a bundleName is not allowed");
throw new UnprocessableEntityException("Properties without a bundleName is not allowed");
}
bitstream = itemService.createSingleBitstream(context, fileInputStream, item, bundleName);
metadataConverter.setMetadata(context, bitstream, propertiesRest.getMetadata());
String name = propertiesRest.getName();
if (bitstreamPropertiesRest.getMetadata() != null) {
metadataConverter.setMetadata(context, bitstream, bitstreamPropertiesRest.getMetadata());
}
String name = bitstreamPropertiesRest.getName();
if (StringUtils.isNotBlank(name)) {
bitstream.setName(context, name);
}
String sequenceId = propertiesRest.getSequenceId();
if (StringUtils.isNotBlank(sequenceId)) {
bitstream.setSequenceID(Integer.parseInt(sequenceId));
Integer sequenceId = bitstreamPropertiesRest.getSequenceId();
if (sequenceId != null) {
bitstream.setSequenceID(sequenceId);
}
} else {
bitstream = itemService.createSingleBitstream(context, fileInputStream, item);

View File

@@ -38,6 +38,7 @@ public class BitstreamConverter
@Override
public BitstreamRest fromModel(org.dspace.content.Bitstream obj) {
BitstreamRest b = super.fromModel(obj);
b.setSequenceId(obj.getSequenceID());
List<Bundle> bundles = null;
try {
bundles = obj.getBundles();

View File

@@ -1,10 +1,17 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.model;
public class PropertiesRest {
public class BitstreamPropertiesRest {
private String name;
private String bundleName;
private String sequenceId;
private Integer sequenceId;
private MetadataRest metadata;
public String getName() {
@@ -31,11 +38,11 @@ public class PropertiesRest {
this.metadata = metadata;
}
public String getSequenceId() {
public Integer getSequenceId() {
return sequenceId;
}
public void setSequenceId(String sequenceId) {
public void setSequenceId(Integer sequenceId) {
this.sequenceId = sequenceId;
}
}

View File

@@ -16,7 +16,8 @@ public enum DSpaceRestPermission {
READ(Constants.READ),
WRITE(Constants.WRITE),
DELETE(Constants.DELETE);
DELETE(Constants.DELETE),
ADD(Constants.ADD);
private int dspaceApiActionId;

View File

@@ -0,0 +1,498 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.dspace.app.rest.builder.CollectionBuilder;
import org.dspace.app.rest.builder.CommunityBuilder;
import org.dspace.app.rest.builder.ItemBuilder;
import org.dspace.app.rest.matcher.MetadataMatcher;
import org.dspace.app.rest.model.BitstreamPropertiesRest;
import org.dspace.app.rest.model.MetadataRest;
import org.dspace.app.rest.model.MetadataValueRest;
import org.dspace.app.rest.test.AbstractEntityIntegrationTest;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
import org.dspace.core.Constants;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
@Autowired
private AuthorizeService authorizeService;
@Test
public void uploadBitstreamAllPossibleFieldsProperties() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("OrgUnits").build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Author1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.build();
String token = getAuthToken(admin.getEmail(), password);
String input = "Hello, World!";
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
input.getBytes());
BitstreamPropertiesRest bitstreamPropertiesRest = new BitstreamPropertiesRest();
bitstreamPropertiesRest.setBundleName("ORIGINAL");
bitstreamPropertiesRest.setName("testing");
bitstreamPropertiesRest.setSequenceId(123456);
MetadataRest metadataRest = new MetadataRest();
MetadataValueRest description = new MetadataValueRest();
description.setValue("description");
metadataRest.put("dc.description", description);
MetadataValueRest contents = new MetadataValueRest();
contents.setValue("News");
metadataRest.put("dc.description.tableofcontents", contents);
MetadataValueRest copyright = new MetadataValueRest();
copyright.setValue("Custom Copyright Text");
metadataRest.put("dc.rights", copyright);
MetadataValueRest title = new MetadataValueRest();
title.setValue("Title Text");
metadataRest.put("dc.title", title);
bitstreamPropertiesRest.setMetadata(metadataRest);
ObjectMapper mapper = new ObjectMapper();
context.restoreAuthSystemState();
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(file)
.param("properties", mapper
.writeValueAsString(bitstreamPropertiesRest)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.name", Matchers.is("testing")))
.andExpect(jsonPath("$.bundleName", Matchers.is("ORIGINAL")))
.andExpect(jsonPath("$.sequenceId", Matchers.is(Integer.parseInt("123456"))))
.andExpect(jsonPath("$", Matchers.allOf(
hasJsonPath("$.metadata", Matchers.allOf(
MetadataMatcher.matchMetadata("dc.description",
"description"),
MetadataMatcher.matchMetadata("dc.description.tableofcontents",
"News"),
MetadataMatcher.matchMetadata("dc.rights",
"Custom Copyright Text"),
MetadataMatcher.matchMetadata("dc.title",
"testing")
)))));
}
@Test
public void uploadBitstreamNoProperties() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("OrgUnits").build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Author1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.build();
String token = getAuthToken(admin.getEmail(), password);
String input = "Hello, World!";
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
input.getBytes());
context.restoreAuthSystemState();
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(file))
.andExpect(status().isOk());
}
@Test
public void uploadBitstreamNoPropertiesUserWithItemAddAndWriteRights() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("OrgUnits").build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Author1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.build();
context.setCurrentUser(eperson);
authorizeService.addPolicy(context, item, Constants.ADD, eperson);
authorizeService.addPolicy(context, item, Constants.WRITE, eperson);
String token = getAuthToken(eperson.getEmail(), password);
String input = "Hello, World!";
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
input.getBytes());
context.restoreAuthSystemState();
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(file))
.andExpect(status().isOk())
.andExpect(jsonPath("$.uuid", notNullValue()));
}
@Test
public void uploadBitstreamNoRights() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("OrgUnits").build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Author1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.build();
context.setCurrentUser(eperson);
String token = getAuthToken(eperson.getEmail(), password);
String input = "Hello, World!";
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
input.getBytes());
context.restoreAuthSystemState();
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(file))
.andExpect(status().isForbidden());
}
@Test
public void uploadBitstreamAnonymous() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("OrgUnits").build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Author1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.build();
context.setCurrentUser(eperson);
String token = getAuthToken(eperson.getEmail(), password);
String input = "Hello, World!";
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
input.getBytes());
context.restoreAuthSystemState();
getClient().perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(file))
.andExpect(status().isUnauthorized());
}
@Test
public void uploadBitstreamMinimalProperties() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("OrgUnits").build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Author1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.build();
context.setCurrentUser(eperson);
authorizeService.addPolicy(context, item, Constants.ADD, eperson);
authorizeService.addPolicy(context, item, Constants.WRITE, eperson);
String token = getAuthToken(eperson.getEmail(), password);
String input = "Hello, World!";
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
input.getBytes());
BitstreamPropertiesRest bitstreamPropertiesRest = new BitstreamPropertiesRest();
String originalBundle = "ORIGINAL";
bitstreamPropertiesRest.setBundleName(originalBundle);
ObjectMapper mapper = new ObjectMapper();
context.restoreAuthSystemState();
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(file)
.param("properties", mapper
.writeValueAsString(bitstreamPropertiesRest)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.bundleName", Matchers.is(originalBundle)))
.andExpect(jsonPath("$.uuid", notNullValue()));
}
//TODO This test just fails to run entirely because we cannot pass 'null' to a file upload
// Should we support this test case differently and if so, how?
@Test
@Ignore
public void uploadBitstreamNoFileUnprocessableEntityException() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("OrgUnits").build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Author1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.build();
String token = getAuthToken(admin.getEmail(), password);
context.restoreAuthSystemState();
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(null))
.andExpect(status().isUnprocessableEntity());
}
// TODO This test doesn't work either as it seems that only the first file is ever transfered into the request
// Thus we cannot check for this and we have no way of knowing how many files we gave to the request
@Test
@Ignore
public void uploadBitstreamMultipleFiles() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("OrgUnits").build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Author1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.build();
String token = getAuthToken(admin.getEmail(), password);
String input = "Hello, World!";
MockMultipartFile file = new MockMultipartFile("file", "hello1.txt", MediaType.TEXT_PLAIN_VALUE,
input.getBytes());
MockMultipartFile file2 = new MockMultipartFile("file", "hello2.txt", MediaType.TEXT_PLAIN_VALUE,
input.getBytes());
context.restoreAuthSystemState();
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(file).file(file2))
.andExpect(status().isUnprocessableEntity());
}
@Test
public void uploadBitstreamNoBundleNameInPropertiesUnprocessableException() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("OrgUnits").build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Author1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.build();
context.setCurrentUser(eperson);
authorizeService.addPolicy(context, item, Constants.ADD, eperson);
authorizeService.addPolicy(context, item, Constants.WRITE, eperson);
String token = getAuthToken(eperson.getEmail(), password);
String input = "Hello, World!";
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
input.getBytes());
BitstreamPropertiesRest bitstreamPropertiesRest = new BitstreamPropertiesRest();
ObjectMapper mapper = new ObjectMapper();
context.restoreAuthSystemState();
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(file)
.param("properties", mapper
.writeValueAsString(bitstreamPropertiesRest)))
.andExpect(status().isUnprocessableEntity());
}
//TODO This check on sequence ID doesn't happen
@Test
@Ignore
public void uploadBitstreamSameSequenceIdTwiceUnprocessableEntityException() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
Collection col3 = CollectionBuilder.createCollection(context, child1).withName("OrgUnits").build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Author1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.build();
String token = getAuthToken(admin.getEmail(), password);
String input = "Hello, World!";
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
input.getBytes());
BitstreamPropertiesRest bitstreamPropertiesRest = new BitstreamPropertiesRest();
bitstreamPropertiesRest.setBundleName("ORIGINAL");
bitstreamPropertiesRest.setName("testing");
bitstreamPropertiesRest.setSequenceId(123456);
MetadataRest metadataRest = new MetadataRest();
MetadataValueRest description = new MetadataValueRest();
description.setValue("description");
metadataRest.put("dc.description", description);
MetadataValueRest contents = new MetadataValueRest();
contents.setValue("News");
metadataRest.put("dc.description.tableofcontents", contents);
MetadataValueRest copyright = new MetadataValueRest();
copyright.setValue("Custom Copyright Text");
metadataRest.put("dc.rights", copyright);
MetadataValueRest title = new MetadataValueRest();
title.setValue("Title Text");
metadataRest.put("dc.title", title);
bitstreamPropertiesRest.setMetadata(metadataRest);
ObjectMapper mapper = new ObjectMapper();
context.restoreAuthSystemState();
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(file)
.param("properties", mapper
.writeValueAsString(bitstreamPropertiesRest)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.name", Matchers.is("testing")))
.andExpect(jsonPath("$.bundleName", Matchers.is("ORIGINAL")))
.andExpect(jsonPath("$.sequenceId", Matchers.is(Integer.parseInt("123456"))))
.andExpect(jsonPath("$", Matchers.allOf(
hasJsonPath("$.metadata", Matchers.allOf(
MetadataMatcher.matchMetadata("dc.description",
"description"),
MetadataMatcher.matchMetadata("dc.description.tableofcontents",
"News"),
MetadataMatcher.matchMetadata("dc.rights",
"Custom Copyright Text"),
MetadataMatcher.matchMetadata("dc.title",
"testing")
)))));
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
.file(file)
.param("properties", mapper
.writeValueAsString(bitstreamPropertiesRest)))
.andExpect(status().isUnprocessableEntity());
}
}