mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 22:13:08 +00:00
71629: fix testCurate_NoOpTask
This commit is contained in:
@@ -37,6 +37,11 @@ public class CurationScriptConfiguration<T extends CurationCli> extends ScriptCo
|
||||
this.dspaceRunnableClass = dspaceRunnableClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only admin can run Curation script via the scripts and processes endpoints.
|
||||
* @param context The relevant DSpace context
|
||||
* @return True if currentUser is admin, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean isAllowedToExecute(Context context) {
|
||||
try {
|
||||
|
@@ -98,6 +98,7 @@ public class Curator {
|
||||
communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||
itemService = ContentServiceFactory.getInstance().getItemService();
|
||||
handleService = HandleServiceFactory.getInstance().getHandleService();
|
||||
resolver = new TaskResolver();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,10 +143,10 @@ public class Curator {
|
||||
// performance order currently FIFO - to be revisited
|
||||
perfList.add(taskName);
|
||||
} catch (IOException ioE) {
|
||||
log.error("Task: '" + taskName + "' initialization failure: " + ioE.getMessage());
|
||||
System.out.println("Task: '" + taskName + "' initialization failure: " + ioE.getMessage());
|
||||
}
|
||||
} else {
|
||||
log.error("Task: '" + taskName + "' does not resolve");
|
||||
System.out.println("Task: '" + taskName + "' does not resolve");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -259,13 +260,6 @@ public class Curator {
|
||||
/**
|
||||
* Performs all configured tasks upon DSpace object
|
||||
* (Community, Collection or Item).
|
||||
* <P>
|
||||
* Note: Site-wide tasks will default to running as
|
||||
* an Anonymous User unless you call the Site-wide task
|
||||
* via the {@link curate(Context,String)} or
|
||||
* {@link #curate(Context, DSpaceObject)} method with an
|
||||
* authenticated Context object.
|
||||
*
|
||||
* @param dso the DSpace object
|
||||
* @throws IOException if IO error
|
||||
*/
|
||||
@@ -325,7 +319,7 @@ public class Curator {
|
||||
taskQ.enqueue(queueId, new TaskQueueEntry(c.getCurrentUser().getName(),
|
||||
System.currentTimeMillis(), perfList, id));
|
||||
} else {
|
||||
log.error("curate - no TaskQueue implemented");
|
||||
System.out.println("curate - no TaskQueue implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,7 +340,7 @@ public class Curator {
|
||||
try {
|
||||
reporter.append(message);
|
||||
} catch (IOException ex) {
|
||||
log.error("Task reporting failure", ex);
|
||||
System.out.println("Task reporting failure: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -552,7 +546,7 @@ public class Curator {
|
||||
return !suspend(statusCode);
|
||||
} catch (IOException ioe) {
|
||||
//log error & pass exception upwards
|
||||
log.error("Error executing curation task '" + task.getName() + "'", ioe);
|
||||
System.out.println("Error executing curation task '" + task.getName() + "'; " + ioe);
|
||||
throw ioe;
|
||||
}
|
||||
}
|
||||
@@ -568,7 +562,7 @@ public class Curator {
|
||||
return !suspend(statusCode);
|
||||
} catch (IOException ioe) {
|
||||
//log error & pass exception upwards
|
||||
log.error("Error executing curation task '" + task.getName() + "'", ioe);
|
||||
System.out.println("Error executing curation task '" + task.getName() + "'; " + ioe);
|
||||
throw ioe;
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.SiteService;
|
||||
import org.dspace.core.factory.CoreServiceFactory;
|
||||
import org.dspace.ctask.general.NoOpCurationTask;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.junit.Test;
|
||||
@@ -29,7 +30,6 @@ import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mhwood
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -51,15 +51,20 @@ public class CuratorTest extends AbstractUnitTest {
|
||||
static final String TASK_PROPERTY_NAME = "taskProperty";
|
||||
static final String TASK_PROPERTY_VALUE = "a property";
|
||||
|
||||
/** Value of a known runtime parameter, if any. */
|
||||
/**
|
||||
* Value of a known runtime parameter, if any.
|
||||
*/
|
||||
static String runParameter;
|
||||
|
||||
/** Value of a known task property, if any. */
|
||||
/**
|
||||
* Value of a known task property, if any.
|
||||
*/
|
||||
static String taskProperty;
|
||||
|
||||
/**
|
||||
* Test of curate method, of class Curator.
|
||||
* Currently this just tests task properties and run parameters.
|
||||
*
|
||||
* @throws java.lang.Exception passed through.
|
||||
*/
|
||||
@Test
|
||||
@@ -71,7 +76,7 @@ public class CuratorTest extends AbstractUnitTest {
|
||||
// Configure the task to be run.
|
||||
ConfigurationService cfg = kernelImpl.getConfigurationService();
|
||||
cfg.setProperty("plugin.named.org.dspace.curate.CurationTask",
|
||||
DummyTask.class.getName() + " = " + TASK_NAME);
|
||||
DummyTask.class.getName() + " = " + TASK_NAME);
|
||||
cfg.setProperty(TASK_NAME + '.' + TASK_PROPERTY_NAME, TASK_PROPERTY_VALUE);
|
||||
|
||||
// Get and configure a Curator.
|
||||
@@ -90,27 +95,37 @@ public class CuratorTest extends AbstractUnitTest {
|
||||
|
||||
// Check the result.
|
||||
System.out.format("Task %s result was '%s'%n",
|
||||
TASK_NAME, instance.getResult(TASK_NAME));
|
||||
TASK_NAME, instance.getResult(TASK_NAME));
|
||||
System.out.format("Task %s status was %d%n",
|
||||
TASK_NAME, instance.getStatus(TASK_NAME));
|
||||
TASK_NAME, instance.getStatus(TASK_NAME));
|
||||
assertEquals("Unexpected task status",
|
||||
Curator.CURATE_SUCCESS, instance.getStatus(TASK_NAME));
|
||||
Curator.CURATE_SUCCESS, instance.getStatus(TASK_NAME));
|
||||
assertEquals("Wrong run parameter", RUN_PARAMETER_VALUE, runParameter);
|
||||
assertEquals("Wrong task property", TASK_PROPERTY_VALUE, taskProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurate_NoOpTask() throws Exception {
|
||||
|
||||
CoreServiceFactory.getInstance().getPluginService().clearNamedPluginClasses();
|
||||
|
||||
final String TASK_NAME = "noop";
|
||||
|
||||
// Configure the noop task to be run.
|
||||
ConfigurationService cfg = kernelImpl.getConfigurationService();
|
||||
cfg.setProperty("plugin.named.org.dspace.curate.CurationTask",
|
||||
NoOpCurationTask.class.getName() + " = " + TASK_NAME);
|
||||
|
||||
StringBuilder reporterOutput = new StringBuilder();
|
||||
curator.setReporter(reporterOutput); // Send any report to our StringBuilder.
|
||||
|
||||
curator.addTask("noop");
|
||||
curator.addTask(TASK_NAME);
|
||||
Item item = mock(Item.class);
|
||||
when(item.getType()).thenReturn(2);
|
||||
when(item.getHandle()).thenReturn("testHandle");
|
||||
curator.curate(context, item);
|
||||
|
||||
assertEquals(Curator.CURATE_SUCCESS, curator.getStatus("noop"));
|
||||
assertEquals(Curator.CURATE_SUCCESS, curator.getStatus(TASK_NAME));
|
||||
assertEquals(reporterOutput.toString(), "No operation performed on testHandle");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user