80218: Add ITs for bitstream thumbnail endpoint

This commit is contained in:
Yura Bondarenko
2021-06-22 14:49:04 +02:00
parent 47536c007d
commit 2ab5f6edb7
3 changed files with 150 additions and 3 deletions

View File

@@ -13,7 +13,6 @@ import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

View File

@@ -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.core.Constants.WRITE;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
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.get;
@@ -46,6 +47,7 @@ import org.dspace.content.service.BitstreamFormatService;
import org.dspace.content.service.BitstreamService;
import org.dspace.core.Constants;
import org.dspace.eperson.EPerson;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -1515,4 +1517,148 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.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());
}
}

View File

@@ -101,7 +101,8 @@ public class BitstreamMatcher {
public static Matcher<? super Object> matchFullEmbeds() {
return matchEmbeds(
"bundle",
"format"
"format",
"thumbnail"
);
}
@@ -113,7 +114,8 @@ public class BitstreamMatcher {
"bundle",
"content",
"format",
"self"
"self",
"thumbnail"
);
}