mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 23:43:06 +00:00
[DS-3952] Debug the integration tests (unfinished).
This commit is contained in:

committed by
Mark H. Wood

parent
e1986ad678
commit
a37c658931
@@ -8,19 +8,15 @@
|
||||
|
||||
package org.dspace.builder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.dspace.app.requestitem.RequestItem;
|
||||
import org.dspace.app.requestitem.service.RequestItemService;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Context;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Manage the creation and cleanup of {@link RequestItem}s for testing.
|
||||
@@ -29,60 +25,54 @@ import org.dspace.core.Context;
|
||||
*/
|
||||
public class RequestItemBuilder
|
||||
extends AbstractBuilder<RequestItem, RequestItemService> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RequestItemBuilder.class);
|
||||
|
||||
public static final String REQ_EMAIL = "jsmith@example.com";
|
||||
public static final String REQ_NAME = "John Smith";
|
||||
public static final String REQ_MESSAGE = "Please send me a copy of this.";
|
||||
public static final String REQ_PATH = "test/file";
|
||||
|
||||
private Community community;
|
||||
private Collection collection;
|
||||
private Item item;
|
||||
private Bitstream bitstream;
|
||||
private RequestItem requestItem;
|
||||
|
||||
public RequestItemBuilder(Context context) {
|
||||
protected RequestItemBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup()
|
||||
throws Exception {
|
||||
bitstreamService.delete(context, bitstream);
|
||||
itemService.delete(context, item);
|
||||
collectionService.delete(context, collection);
|
||||
communityService.delete(context, community);
|
||||
LOG.info("cleanup()");
|
||||
delete(context,requestItem);
|
||||
}
|
||||
|
||||
public static RequestItemBuilder createRequestItem(Context ctx, Item item,
|
||||
Bitstream bitstream) {
|
||||
RequestItemBuilder builder = new RequestItemBuilder(ctx);
|
||||
return builder.create(item, bitstream);
|
||||
}
|
||||
|
||||
private RequestItemBuilder create(Item item, Bitstream bitstream) {
|
||||
String token;
|
||||
try {
|
||||
token = requestItemService.createRequest(context, bitstream,
|
||||
item, true, REQ_EMAIL, REQ_NAME, REQ_MESSAGE);
|
||||
} catch (SQLException ex) {
|
||||
return handleException(ex);
|
||||
}
|
||||
this.requestItem = requestItemService.findByToken(context, token);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestItem build() {
|
||||
// Build all the other stuff we need, to request an Item.
|
||||
CommunityBuilder communityBuilder = CommunityBuilder.createCommunity(context);
|
||||
community = communityBuilder.build();
|
||||
CollectionBuilder collectionBuilder = CollectionBuilder.createCollection(context,
|
||||
community);
|
||||
collection = collectionBuilder.build();
|
||||
ItemBuilder itemBuilder = ItemBuilder.createItem(context, collection);
|
||||
item = itemBuilder.build();
|
||||
|
||||
// Request a copy of the Item that we just built.
|
||||
String token;
|
||||
try (InputStream is = new ByteArrayInputStream("".getBytes());) {
|
||||
BitstreamBuilder bitstreamBuilder
|
||||
= BitstreamBuilder.createBitstream(context, item, is);
|
||||
bitstream = bitstreamBuilder.build();
|
||||
token = requestItemService.createRequest(context,
|
||||
bitstream, item, true, REQ_EMAIL, REQ_NAME, REQ_MESSAGE);
|
||||
} catch (SQLException | AuthorizeException | IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
// Return the request.
|
||||
return requestItemService.findByToken(context, token);
|
||||
// Nothing to build.
|
||||
return requestItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Context context, RequestItem request)
|
||||
throws Exception {
|
||||
// N.B. RequestItem cannot be deleted.
|
||||
new RequestItemHelperDAO().delete(context, request.getToken());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user