mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 04:23:13 +00:00
80218: Add ITs for bitstream thumbnail endpoint
This commit is contained in:
@@ -13,7 +13,6 @@ import java.sql.SQLException;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@ import static org.dspace.app.rest.matcher.MetadataMatcher.matchMetadata;
|
|||||||
import static org.dspace.app.rest.matcher.MetadataMatcher.matchMetadataDoesNotExist;
|
import static org.dspace.app.rest.matcher.MetadataMatcher.matchMetadataDoesNotExist;
|
||||||
import static org.dspace.core.Constants.WRITE;
|
import static org.dspace.core.Constants.WRITE;
|
||||||
import static org.hamcrest.Matchers.contains;
|
import static org.hamcrest.Matchers.contains;
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
@@ -46,6 +47,7 @@ import org.dspace.content.service.BitstreamFormatService;
|
|||||||
import org.dspace.content.service.BitstreamService;
|
import org.dspace.content.service.BitstreamService;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
|
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.beans.factory.annotation.Autowired;
|
||||||
@@ -1515,4 +1517,148 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
|
|||||||
.andExpect(status().isNoContent());
|
.andExpect(status().isNoContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void thumbnailEndpointTest() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
|
.withName("Collection 1").build();
|
||||||
|
|
||||||
|
Item item = ItemBuilder.createItem(context, col1)
|
||||||
|
.withTitle("Test item -- thumbnail")
|
||||||
|
.withIssueDate("2017-10-17")
|
||||||
|
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Bundle originalBundle = BundleBuilder.createBundle(context, item)
|
||||||
|
.withName(Constants.DEFAULT_BUNDLE_NAME)
|
||||||
|
.build();
|
||||||
|
Bundle thumbnailBundle = BundleBuilder.createBundle(context, item)
|
||||||
|
.withName("THUMBNAIL")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
InputStream is = IOUtils.toInputStream("dummy", "utf-8");
|
||||||
|
|
||||||
|
Bitstream bitstream = BitstreamBuilder.createBitstream(context, originalBundle, is)
|
||||||
|
.withName("test.pdf")
|
||||||
|
.withMimeType("application/pdf")
|
||||||
|
.build();
|
||||||
|
Bitstream thumbnail = BitstreamBuilder.createBitstream(context, thumbnailBundle, is)
|
||||||
|
.withName("test.pdf.jpg")
|
||||||
|
.withMimeType("image/jpeg")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
String tokenAdmin = getAuthToken(admin.getEmail(), password);
|
||||||
|
|
||||||
|
getClient(tokenAdmin).perform(get("/api/core/bitstreams/" + bitstream.getID() + "/thumbnail"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.uuid", Matchers.is(thumbnail.getID().toString())))
|
||||||
|
.andExpect(jsonPath("$.type", is("bitstream")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void thumbnailEndpointMultipleThumbnailsWithPrimaryBitstreamTest() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
|
.withName("Collection 1").build();
|
||||||
|
|
||||||
|
Item item = ItemBuilder.createItem(context, col1)
|
||||||
|
.withTitle("Test item -- thumbnail")
|
||||||
|
.withIssueDate("2017-10-17")
|
||||||
|
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Bundle originalBundle = BundleBuilder.createBundle(context, item)
|
||||||
|
.withName(Constants.DEFAULT_BUNDLE_NAME)
|
||||||
|
.build();
|
||||||
|
Bundle thumbnailBundle = BundleBuilder.createBundle(context, item)
|
||||||
|
.withName("THUMBNAIL")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
InputStream is = IOUtils.toInputStream("dummy", "utf-8");
|
||||||
|
|
||||||
|
BitstreamBuilder.createBitstream(context, originalBundle, is)
|
||||||
|
.withName("test1.pdf")
|
||||||
|
.withMimeType("application/pdf")
|
||||||
|
.build();
|
||||||
|
BitstreamBuilder.createBitstream(context, originalBundle, is)
|
||||||
|
.withName("test2.pdf")
|
||||||
|
.withMimeType("application/pdf")
|
||||||
|
.build();
|
||||||
|
Bitstream primaryBitstream = BitstreamBuilder.createBitstream(context, originalBundle, is)
|
||||||
|
.withName("test3.pdf")
|
||||||
|
.withMimeType("application/pdf")
|
||||||
|
.build();
|
||||||
|
originalBundle.setPrimaryBitstreamID(primaryBitstream);
|
||||||
|
|
||||||
|
BitstreamBuilder.createBitstream(context, thumbnailBundle, is)
|
||||||
|
.withName("test1.pdf.jpg")
|
||||||
|
.withMimeType("image/jpeg")
|
||||||
|
.build();
|
||||||
|
BitstreamBuilder.createBitstream(context, thumbnailBundle, is)
|
||||||
|
.withName("test2.pdf.jpg")
|
||||||
|
.withMimeType("image/jpeg")
|
||||||
|
.build();
|
||||||
|
Bitstream primaryThumbnail = BitstreamBuilder.createBitstream(context, thumbnailBundle, is)
|
||||||
|
.withName("test3.pdf.jpg")
|
||||||
|
.withMimeType("image/jpeg")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
getClient().perform(get("/api/core/bitstreams/" + primaryBitstream.getID() + "/thumbnail"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.uuid", Matchers.is(primaryThumbnail.getID().toString())))
|
||||||
|
.andExpect(jsonPath("$.type", is("bitstream")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void thumbnailEndpointItemWithoutThumbnailsTest() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
|
.withName("Collection 1").build();
|
||||||
|
|
||||||
|
Item item = ItemBuilder.createItem(context, col1)
|
||||||
|
.withTitle("Test item -- thumbnail")
|
||||||
|
.withIssueDate("2017-10-17")
|
||||||
|
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Bundle originalBundle = BundleBuilder.createBundle(context, item)
|
||||||
|
.withName(Constants.DEFAULT_BUNDLE_NAME)
|
||||||
|
.build();
|
||||||
|
BundleBuilder.createBundle(context, item)
|
||||||
|
.withName("THUMBNAIL")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
InputStream is = IOUtils.toInputStream("dummy", "utf-8");
|
||||||
|
|
||||||
|
Bitstream bitstream = BitstreamBuilder.createBitstream(context, originalBundle, is)
|
||||||
|
.withName("test.pdf")
|
||||||
|
.withMimeType("application/pdf")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
getClient().perform(get("/api/core/bitstreams/" + bitstream.getID() + "/thumbnail"))
|
||||||
|
.andExpect(status().isNoContent());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -101,7 +101,8 @@ public class BitstreamMatcher {
|
|||||||
public static Matcher<? super Object> matchFullEmbeds() {
|
public static Matcher<? super Object> matchFullEmbeds() {
|
||||||
return matchEmbeds(
|
return matchEmbeds(
|
||||||
"bundle",
|
"bundle",
|
||||||
"format"
|
"format",
|
||||||
|
"thumbnail"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +114,8 @@ public class BitstreamMatcher {
|
|||||||
"bundle",
|
"bundle",
|
||||||
"content",
|
"content",
|
||||||
"format",
|
"format",
|
||||||
"self"
|
"self",
|
||||||
|
"thumbnail"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user