mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +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;
|
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
|
@Override
|
||||||
public boolean isAllowedToExecute(Context context) {
|
public boolean isAllowedToExecute(Context context) {
|
||||||
try {
|
try {
|
||||||
|
@@ -98,6 +98,7 @@ public class Curator {
|
|||||||
communityService = ContentServiceFactory.getInstance().getCommunityService();
|
communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||||
itemService = ContentServiceFactory.getInstance().getItemService();
|
itemService = ContentServiceFactory.getInstance().getItemService();
|
||||||
handleService = HandleServiceFactory.getInstance().getHandleService();
|
handleService = HandleServiceFactory.getInstance().getHandleService();
|
||||||
|
resolver = new TaskResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,10 +143,10 @@ public class Curator {
|
|||||||
// performance order currently FIFO - to be revisited
|
// performance order currently FIFO - to be revisited
|
||||||
perfList.add(taskName);
|
perfList.add(taskName);
|
||||||
} catch (IOException ioE) {
|
} catch (IOException ioE) {
|
||||||
log.error("Task: '" + taskName + "' initialization failure: " + ioE.getMessage());
|
System.out.println("Task: '" + taskName + "' initialization failure: " + ioE.getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.error("Task: '" + taskName + "' does not resolve");
|
System.out.println("Task: '" + taskName + "' does not resolve");
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -259,13 +260,6 @@ public class Curator {
|
|||||||
/**
|
/**
|
||||||
* Performs all configured tasks upon DSpace object
|
* Performs all configured tasks upon DSpace object
|
||||||
* (Community, Collection or Item).
|
* (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
|
* @param dso the DSpace object
|
||||||
* @throws IOException if IO error
|
* @throws IOException if IO error
|
||||||
*/
|
*/
|
||||||
@@ -325,7 +319,7 @@ public class Curator {
|
|||||||
taskQ.enqueue(queueId, new TaskQueueEntry(c.getCurrentUser().getName(),
|
taskQ.enqueue(queueId, new TaskQueueEntry(c.getCurrentUser().getName(),
|
||||||
System.currentTimeMillis(), perfList, id));
|
System.currentTimeMillis(), perfList, id));
|
||||||
} else {
|
} else {
|
||||||
log.error("curate - no TaskQueue implemented");
|
System.out.println("curate - no TaskQueue implemented");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,7 +340,7 @@ public class Curator {
|
|||||||
try {
|
try {
|
||||||
reporter.append(message);
|
reporter.append(message);
|
||||||
} catch (IOException ex) {
|
} 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);
|
return !suspend(statusCode);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
//log error & pass exception upwards
|
//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;
|
throw ioe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -568,7 +562,7 @@ public class Curator {
|
|||||||
return !suspend(statusCode);
|
return !suspend(statusCode);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
//log error & pass exception upwards
|
//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;
|
throw ioe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ import org.dspace.content.DSpaceObject;
|
|||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
import org.dspace.content.service.SiteService;
|
import org.dspace.content.service.SiteService;
|
||||||
|
import org.dspace.core.factory.CoreServiceFactory;
|
||||||
import org.dspace.ctask.general.NoOpCurationTask;
|
import org.dspace.ctask.general.NoOpCurationTask;
|
||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -29,7 +30,6 @@ import org.mockito.Spy;
|
|||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author mhwood
|
* @author mhwood
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
@@ -51,15 +51,20 @@ public class CuratorTest extends AbstractUnitTest {
|
|||||||
static final String TASK_PROPERTY_NAME = "taskProperty";
|
static final String TASK_PROPERTY_NAME = "taskProperty";
|
||||||
static final String TASK_PROPERTY_VALUE = "a property";
|
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;
|
static String runParameter;
|
||||||
|
|
||||||
/** Value of a known task property, if any. */
|
/**
|
||||||
|
* Value of a known task property, if any.
|
||||||
|
*/
|
||||||
static String taskProperty;
|
static String taskProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of curate method, of class Curator.
|
* Test of curate method, of class Curator.
|
||||||
* Currently this just tests task properties and run parameters.
|
* Currently this just tests task properties and run parameters.
|
||||||
|
*
|
||||||
* @throws java.lang.Exception passed through.
|
* @throws java.lang.Exception passed through.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@@ -71,7 +76,7 @@ public class CuratorTest extends AbstractUnitTest {
|
|||||||
// Configure the task to be run.
|
// Configure the task to be run.
|
||||||
ConfigurationService cfg = kernelImpl.getConfigurationService();
|
ConfigurationService cfg = kernelImpl.getConfigurationService();
|
||||||
cfg.setProperty("plugin.named.org.dspace.curate.CurationTask",
|
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);
|
cfg.setProperty(TASK_NAME + '.' + TASK_PROPERTY_NAME, TASK_PROPERTY_VALUE);
|
||||||
|
|
||||||
// Get and configure a Curator.
|
// Get and configure a Curator.
|
||||||
@@ -90,27 +95,37 @@ public class CuratorTest extends AbstractUnitTest {
|
|||||||
|
|
||||||
// Check the result.
|
// Check the result.
|
||||||
System.out.format("Task %s result was '%s'%n",
|
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",
|
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",
|
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 run parameter", RUN_PARAMETER_VALUE, runParameter);
|
||||||
assertEquals("Wrong task property", TASK_PROPERTY_VALUE, taskProperty);
|
assertEquals("Wrong task property", TASK_PROPERTY_VALUE, taskProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCurate_NoOpTask() throws Exception {
|
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();
|
StringBuilder reporterOutput = new StringBuilder();
|
||||||
curator.setReporter(reporterOutput); // Send any report to our StringBuilder.
|
curator.setReporter(reporterOutput); // Send any report to our StringBuilder.
|
||||||
|
|
||||||
curator.addTask("noop");
|
curator.addTask(TASK_NAME);
|
||||||
Item item = mock(Item.class);
|
Item item = mock(Item.class);
|
||||||
when(item.getType()).thenReturn(2);
|
when(item.getType()).thenReturn(2);
|
||||||
when(item.getHandle()).thenReturn("testHandle");
|
when(item.getHandle()).thenReturn("testHandle");
|
||||||
curator.curate(context, item);
|
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");
|
assertEquals(reporterOutput.toString(), "No operation performed on testHandle");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user