mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 18:14:26 +00:00
Half Integration Tests
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -42,3 +42,4 @@ nb-configuration.xml
|
||||
|
||||
##Ignore JRebel project configuration
|
||||
rebel.xml
|
||||
|
||||
|
@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -53,6 +54,9 @@ public class BitstreamRestRepository extends DSpaceRestRepository<BitstreamRest,
|
||||
Bitstream bit = null;
|
||||
try {
|
||||
bit = bs.find(context, id);
|
||||
if (bit.isDeleted() == true) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ package org.dspace.app.rest;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
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;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
@@ -460,20 +461,45 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
|
||||
.build();
|
||||
}
|
||||
|
||||
//Add a logo bitstream to a Community
|
||||
Bitstream logo_bitstream = null;
|
||||
try (InputStream is2 = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
|
||||
logo_bitstream = BitstreamBuilder.
|
||||
createLogoBitstream(context, child1, is2)
|
||||
.withName("Bitstream")
|
||||
.withDescription("Description")
|
||||
.withMimeType("text/plain")
|
||||
.build();
|
||||
}
|
||||
// Verify creation
|
||||
getClient().perform(get("/api/core/bitstreams/" + bitstream.getID()))
|
||||
.andExpect(status().is2xxSuccessful());
|
||||
|
||||
System.out.println(logo_bitstream.getCommunity());
|
||||
getClient().perform(get("/api/core/bitstreams/" + UUID.randomUUID()))
|
||||
// Delete
|
||||
getClient().perform(delete("/api/core/bitstreams/" + bitstream.getID()))
|
||||
.andExpect(status().is2xxSuccessful());
|
||||
|
||||
// Verify 404 after delete
|
||||
getClient().perform(get("/api/core/bitstreams/" + bitstream.getID()))
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteLogo() throws Exception {
|
||||
// We turn off the authorization system in order to create the structure as defined below
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
// ** GIVEN **
|
||||
// 1. A community with a logo
|
||||
parentCommunity = CommunityBuilder.createCommunity(context).withName("Community").withLogo("logo_community")
|
||||
.build();
|
||||
|
||||
// 2. A collection with a logo
|
||||
Collection col = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection")
|
||||
.withLogo("logo_collection").build();
|
||||
// Verify logo retreival
|
||||
getClient().perform(get("/api/core/bitstreams/" + parentCommunity.getLogo().getID()))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
// Verify impossible deletion
|
||||
getClient().perform(delete("/api/core/bitstreams/" + parentCommunity.getLogo().getID()))
|
||||
.andExpect(status().is(422));
|
||||
|
||||
// Verify logo retrieval
|
||||
getClient().perform(get("/api/core/bitstreams/" + col.getLogo().getID())).andExpect(status().isOk());
|
||||
|
||||
// Verify impossible retrieval
|
||||
getClient().perform(delete("/api/core/bitstreams/" + col.getLogo().getID()))
|
||||
.andExpect(status().is(422));
|
||||
}
|
||||
}
|
||||
|
@@ -41,28 +41,18 @@ public class BitstreamBuilder extends AbstractDSpaceObjectBuilder<Bitstream> {
|
||||
|
||||
}
|
||||
|
||||
public static BitstreamBuilder createLogoBitstream(Context context, Community community, InputStream is)
|
||||
throws SQLException, AuthorizeException, IOException {
|
||||
BitstreamBuilder builder = new BitstreamBuilder(context);
|
||||
return builder.create_logo(context, community, is);
|
||||
}
|
||||
|
||||
private BitstreamBuilder create_logo(Context context, Community community, InputStream is)
|
||||
throws SQLException, AuthorizeException, IOException {
|
||||
this.context = context;
|
||||
this.community = community;
|
||||
|
||||
bitstream = bitstreamService.create(context, is);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public static BitstreamBuilder createBitstream(Context context, Item item, InputStream is)
|
||||
throws SQLException, AuthorizeException, IOException {
|
||||
BitstreamBuilder builder = new BitstreamBuilder(context);
|
||||
return builder.create(context, item, is);
|
||||
}
|
||||
|
||||
public static BitstreamBuilder createLogo(Context context, Community community, InputStream is)
|
||||
throws SQLException, AuthorizeException, IOException {
|
||||
BitstreamBuilder builder = new BitstreamBuilder(context);
|
||||
return builder.logo(context, community, is);
|
||||
}
|
||||
|
||||
private BitstreamBuilder create(Context context, Item item, InputStream is)
|
||||
throws SQLException, AuthorizeException, IOException {
|
||||
this.context = context;
|
||||
@@ -75,6 +65,16 @@ public class BitstreamBuilder extends AbstractDSpaceObjectBuilder<Bitstream> {
|
||||
return this;
|
||||
}
|
||||
|
||||
private BitstreamBuilder logo(Context context, Community community, InputStream is)
|
||||
throws SQLException, AuthorizeException, IOException {
|
||||
this.context = context;
|
||||
this.community = community;
|
||||
|
||||
bitstream = communityService.setLogo(context, community, is);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BitstreamBuilder withName(String name) throws SQLException {
|
||||
bitstream.setName(context, name);
|
||||
return this;
|
||||
@@ -140,6 +140,23 @@ public class BitstreamBuilder extends AbstractDSpaceObjectBuilder<Bitstream> {
|
||||
return bitstream;
|
||||
}
|
||||
|
||||
public Bitstream buildLogo() {
|
||||
try {
|
||||
bitstreamService.update(context, bitstream);
|
||||
communityService.update(context, community);
|
||||
|
||||
context.dispatchEvents();
|
||||
|
||||
indexingService.commit();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return bitstream;
|
||||
}
|
||||
|
||||
protected void cleanup() throws Exception {
|
||||
delete(bitstream);
|
||||
}
|
||||
|
Reference in New Issue
Block a user