mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
DS-3127: Process review feedback and fix tests
This commit is contained in:
@@ -260,15 +260,15 @@ public class BitstreamServiceImpl extends DSpaceObjectServiceImpl<Bitstream> imp
|
||||
bundle.getBitstreams().remove(bitstream);
|
||||
}
|
||||
|
||||
//Remove all bundles from the bitstream object, clearing the connection in 2 ways
|
||||
bundles.clear();
|
||||
|
||||
// Remove bitstream itself
|
||||
bitstream.setDeleted(true);
|
||||
update(context, bitstream);
|
||||
|
||||
// Remove policies only after the bitstream has been updated (otherwise the current user has not WRITE rights)
|
||||
authorizeService.removeAllPolicies(context, bitstream);
|
||||
|
||||
//Remove all bundles from the bitstream object, clearing the connection in 2 ways
|
||||
bundles.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -430,16 +430,15 @@ public class BundleServiceImpl extends DSpaceObjectServiceImpl<Bundle> implement
|
||||
bundle.getName(), getIdentifiers(context, bundle)));
|
||||
|
||||
// Remove bitstreams
|
||||
Iterator<Bitstream> bitstreams = bundle.getBitstreams().iterator();
|
||||
while (bitstreams.hasNext()) {
|
||||
Bitstream bitstream = bitstreams.next();
|
||||
bitstreams.remove();
|
||||
List<Bitstream> bitstreams = new LinkedList<>(bundle.getBitstreams());
|
||||
bundle.getBitstreams().clear();
|
||||
for (Bitstream bitstream : bitstreams) {
|
||||
removeBitstream(context, bundle, bitstream);
|
||||
}
|
||||
|
||||
Iterator<Item> items = bundle.getItems().iterator();
|
||||
while (items.hasNext()) {
|
||||
Item item = items.next();
|
||||
List<Item> items = new LinkedList<>(bundle.getItems());
|
||||
bundle.getItems().clear();
|
||||
for (Item item : items) {
|
||||
item.removeBundle(bundle);
|
||||
}
|
||||
|
||||
|
@@ -16,16 +16,17 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Matchers.*;
|
||||
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -61,19 +62,25 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest{
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
when(bitstream1.getName()).thenReturn("bitstream1");
|
||||
when(bitstream2.getName()).thenReturn("bitstream2");
|
||||
when(bitstream3.getName()).thenReturn("bitstream3");
|
||||
settings.put("citation.prioritized_types", "Adobe PDF, Microsoft Word, RTF, Photoshop");
|
||||
settings.put("citation.prioritized_types", "Adobe PDF, Microsoft Word, RTF, Postscript");
|
||||
List<Bitstream> bitstreams = new ArrayList<>();
|
||||
bitstreams.add(bitstream1);
|
||||
bitstreams.add(bitstream2);
|
||||
bitstreams.add(bitstream3);
|
||||
when(bundle.getBitstreams()).thenReturn(bitstreams);
|
||||
try {
|
||||
when(bitstream1.getFormat(any(Context.class))).thenReturn(bitstreamFormat1);
|
||||
when(bitstream2.getFormat(any(Context.class))).thenReturn(bitstreamFormat2);
|
||||
when(bitstream3.getFormat(any(Context.class))).thenReturn(bitstreamFormat3);
|
||||
} catch (Exception ex) {
|
||||
//will not happen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +111,7 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest{
|
||||
public void testDifferentMimeTypes() throws Exception {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/msword");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/x-photoshop");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/postscript");
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -122,7 +129,7 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest{
|
||||
public void testMimeTypesDifferentSizes() throws Exception {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/x-photoshop");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/postscript");
|
||||
when(bitstream1.getSize()).thenReturn(new Long(100));
|
||||
when(bitstream2.getSize()).thenReturn(new Long(200));
|
||||
when(bitstream3.getSize()).thenReturn(new Long(300));
|
||||
@@ -199,10 +206,10 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest{
|
||||
*/
|
||||
@Test
|
||||
public void testChangePriority() throws Exception{
|
||||
settings.put("citation.prioritized_types", "Photoshop, RTF, Microsoft Word, Adobe PDF");
|
||||
settings.put("citation.prioritized_types", "Postscript, RTF, Microsoft Word, Adobe PDF");
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/msword");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/x-photoshop");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/postscript");
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -264,7 +271,7 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest{
|
||||
settings.put("citation.prioritized_types", "");
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/msword");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/x-photoshop");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/postscript");
|
||||
when(bitstream1.getSize()).thenReturn(new Long(100));
|
||||
when(bitstream2.getSize()).thenReturn(new Long(200));
|
||||
when(bitstream3.getSize()).thenReturn(new Long(300));
|
||||
@@ -284,7 +291,7 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest{
|
||||
settings.remove("citation.prioritized_types");
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/msword");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/x-photoshop");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/postscript");
|
||||
when(bitstream1.getSize()).thenReturn(new Long(100));
|
||||
when(bitstream2.getSize()).thenReturn(new Long(200));
|
||||
when(bitstream3.getSize()).thenReturn(new Long(300));
|
||||
@@ -301,10 +308,10 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest{
|
||||
*/
|
||||
@Test
|
||||
public void testUndefinedShortDescription() {
|
||||
settings.put("citation.prioritized_types", "Photoshop, RTF, Undefined Type, Microsoft Word, Adobe PDF");
|
||||
settings.put("citation.prioritized_types", "Postscript, RTF, Undefined Type, Microsoft Word, Adobe PDF");
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/msword");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/x-photoshop");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/postscript");
|
||||
when(bitstream1.getSize()).thenReturn(new Long(100));
|
||||
when(bitstream2.getSize()).thenReturn(new Long(200));
|
||||
when(bitstream3.getSize()).thenReturn(new Long(300));
|
||||
@@ -321,7 +328,7 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest{
|
||||
*/
|
||||
@Test
|
||||
public void testAddingNewFormat() {
|
||||
settings.put("citation.prioritized_types", "WAV, Adobe PDF, Microsoft Word, RTF, Photoshop");
|
||||
settings.put("citation.prioritized_types", "WAV, Adobe PDF, Microsoft Word, RTF, Postscript");
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/msword");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("audio/x-wav");
|
||||
@@ -341,6 +348,7 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest{
|
||||
public void destroy()
|
||||
{
|
||||
settings = null;
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -10,29 +10,22 @@ package org.dspace.app.util;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.AbstractUnitTest;
|
||||
import org.dspace.app.util.GoogleMetadata;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.*;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.BitstreamFormatService;
|
||||
import org.dspace.content.service.BitstreamService;
|
||||
import org.dspace.content.service.BundleService;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import sun.net.www.content.text.PlainTextInputStream;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
|
||||
@@ -50,6 +43,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
|
||||
private BitstreamService bitstreamService;
|
||||
|
||||
private Community community;
|
||||
|
||||
/**
|
||||
* This method will be run before every test as per @Before. It will
|
||||
* initialize resources required for the tests.
|
||||
@@ -64,7 +59,7 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
try
|
||||
{
|
||||
context.turnOffAuthorisationSystem();
|
||||
Community community = ContentServiceFactory.getInstance().getCommunityService().create(null, context);
|
||||
community = ContentServiceFactory.getInstance().getCommunityService().create(null, context);
|
||||
Collection collection = ContentServiceFactory.getInstance().getCollectionService().create(context, community);
|
||||
WorkspaceItem wi = ContentServiceFactory.getInstance().getWorkspaceItemService().create(context, collection, true);
|
||||
Item item = wi.getItem();
|
||||
@@ -300,6 +295,20 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
try {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//Context might have been committed in the test method, so best to reload to entity so we're sure that it is attached.
|
||||
community = context.reloadEntity(community);
|
||||
ContentServiceFactory.getInstance().getCommunityService().delete(context, community);
|
||||
community = null;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (AuthorizeException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
it = null;
|
||||
super.destroy();
|
||||
}
|
||||
|
@@ -75,7 +75,7 @@ google.citation_technical_report_institution = dc.publisher
|
||||
|
||||
#priority whitelist for citation_pdf_url, shortnames are defined in dspace/config/registries/bitstream-formats.xml
|
||||
#priority order is defined here, where the first type is the most important
|
||||
google.citation.prioritized_types = Adobe PDF, Microsoft Word, Microsoft Word XML, RTF, Photoshop, EPUB
|
||||
google.citation.prioritized_types = Adobe PDF, Postscript, Microsoft Word XML, Microsoft Word, RTF, EPUB
|
||||
|
||||
|
||||
|
||||
|
@@ -727,5 +727,13 @@
|
||||
<extension>rdf</extension>
|
||||
</bitstream-type>
|
||||
|
||||
<bitstream-type>
|
||||
<mimetype>application/epub+zip</mimetype>
|
||||
<short_description>EPUB</short_description>
|
||||
<description>Electronic publishing</description>
|
||||
<support_level>1</support_level>
|
||||
<internal>false</internal>
|
||||
<extension>epub</extension>
|
||||
</bitstream-type>
|
||||
|
||||
</dspace-bitstream-types>
|
||||
|
Reference in New Issue
Block a user