mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
Several Unit test fixes. Add a Mock Indexer for Solr. Add a language for primary test Eperson. Do better context cleanup. Improve fail messages with actual errors.
This commit is contained in:
@@ -33,6 +33,8 @@ import org.dspace.content.MetadataField;
|
|||||||
import org.dspace.content.NonUniqueMetadataException;
|
import org.dspace.content.NonUniqueMetadataException;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.core.I18nUtil;
|
||||||
|
import org.dspace.discovery.MockIndexEventConsumer;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.search.DSIndexer;
|
import org.dspace.search.DSIndexer;
|
||||||
import org.dspace.servicemanager.DSpaceKernelImpl;
|
import org.dspace.servicemanager.DSpaceKernelImpl;
|
||||||
@@ -52,7 +54,7 @@ import org.xml.sax.SAXException;
|
|||||||
*
|
*
|
||||||
* @author pvillega
|
* @author pvillega
|
||||||
*/
|
*/
|
||||||
@UsingMocksAndStubs({MockDatabaseManager.class, MockBrowseCreateDAOOracle.class})
|
@UsingMocksAndStubs({MockDatabaseManager.class, MockBrowseCreateDAOOracle.class, MockIndexEventConsumer.class})
|
||||||
public class AbstractUnitTest
|
public class AbstractUnitTest
|
||||||
{
|
{
|
||||||
/** log4j category */
|
/** log4j category */
|
||||||
@@ -147,6 +149,7 @@ public class AbstractUnitTest
|
|||||||
eperson.setLastName("last");
|
eperson.setLastName("last");
|
||||||
eperson.setEmail("test@email.com");
|
eperson.setEmail("test@email.com");
|
||||||
eperson.setCanLogIn(true);
|
eperson.setCanLogIn(true);
|
||||||
|
eperson.setLanguage(I18nUtil.getDefaultLocale().getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create search and browse indexes
|
//Create search and browse indexes
|
||||||
@@ -349,6 +352,7 @@ public class AbstractUnitTest
|
|||||||
if(context != null && context.isValid())
|
if(context != null && context.isValid())
|
||||||
{
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
|
context = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,7 +61,7 @@ public class BitstreamFormatTest extends AbstractUnitTest
|
|||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
log.error("SQL Error in init", ex);
|
log.error("SQL Error in init", ex);
|
||||||
fail("SQL Error in init");
|
fail("SQL Error in init: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -58,12 +58,12 @@ public class BitstreamTest extends AbstractDSpaceObjectTest
|
|||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
log.error("IO Error in init", ex);
|
log.error("IO Error in init", ex);
|
||||||
fail("SQL Error in init");
|
fail("SQL Error in init: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
log.error("SQL Error in init", ex);
|
log.error("SQL Error in init", ex);
|
||||||
fail("SQL Error in init");
|
fail("SQL Error in init: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +128,8 @@ public class BitstreamTest extends AbstractDSpaceObjectTest
|
|||||||
{
|
{
|
||||||
File f = new File(testProps.get("test.bitstream").toString());
|
File f = new File(testProps.get("test.bitstream").toString());
|
||||||
Bitstream created = Bitstream.create(context, new FileInputStream(f));
|
Bitstream created = Bitstream.create(context, new FileInputStream(f));
|
||||||
|
context.commit();
|
||||||
|
|
||||||
//the item created by default has no name nor type set
|
//the item created by default has no name nor type set
|
||||||
assertThat("testCreate 0", created.getFormat().getMIMEType(), equalTo("application/octet-stream"));
|
assertThat("testCreate 0", created.getFormat().getMIMEType(), equalTo("application/octet-stream"));
|
||||||
assertThat("testCreate 1", created.getName(), nullValue());
|
assertThat("testCreate 1", created.getName(), nullValue());
|
||||||
|
@@ -66,7 +66,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
|||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
log.error("SQL Error in init", ex);
|
log.error("SQL Error in init", ex);
|
||||||
fail("SQL Error in init");
|
fail("SQL Error in init: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -63,12 +63,12 @@ public class CollectionTest extends AbstractDSpaceObjectTest
|
|||||||
catch (AuthorizeException ex)
|
catch (AuthorizeException ex)
|
||||||
{
|
{
|
||||||
log.error("Authorization Error in init", ex);
|
log.error("Authorization Error in init", ex);
|
||||||
fail("Authorization Error in init");
|
fail("Authorization Error in init: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
log.error("SQL Error in init", ex);
|
log.error("SQL Error in init", ex);
|
||||||
fail("SQL Error in init");
|
fail("SQL Error in init: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,6 +471,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest
|
|||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
int step = 1;
|
int step = 1;
|
||||||
Group g = Group.create(context);
|
Group g = Group.create(context);
|
||||||
|
context.commit();
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
c.setWorkflowGroup(step, g);
|
c.setWorkflowGroup(step, g);
|
||||||
assertThat("testSetWorkflowGroup 0",c.getWorkflowGroup(step), notNullValue());
|
assertThat("testSetWorkflowGroup 0",c.getWorkflowGroup(step), notNullValue());
|
||||||
@@ -1868,6 +1869,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest
|
|||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
Community parent = Community.create(null, context);
|
Community parent = Community.create(null, context);
|
||||||
parent.addCollection(c);
|
parent.addCollection(c);
|
||||||
|
context.commit();
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
assertThat("testGetParentObject 1", c.getParentObject(), notNullValue());
|
assertThat("testGetParentObject 1", c.getParentObject(), notNullValue());
|
||||||
assertThat("testGetParentObject 2", (Community)c.getParentObject(), equalTo(parent));
|
assertThat("testGetParentObject 2", (Community)c.getParentObject(), equalTo(parent));
|
||||||
|
@@ -63,12 +63,12 @@ public class CommunityTest extends AbstractDSpaceObjectTest
|
|||||||
catch (AuthorizeException ex)
|
catch (AuthorizeException ex)
|
||||||
{
|
{
|
||||||
log.error("Authorization Error in init", ex);
|
log.error("Authorization Error in init", ex);
|
||||||
fail("Authorization Error in init");
|
fail("Authorization Error in init:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
log.error("SQL Error in init", ex);
|
log.error("SQL Error in init", ex);
|
||||||
fail("SQL Error in init");
|
fail("SQL Error in init:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -76,12 +76,12 @@ public class ItemTest extends AbstractDSpaceObjectTest
|
|||||||
catch (AuthorizeException ex)
|
catch (AuthorizeException ex)
|
||||||
{
|
{
|
||||||
log.error("Authorization Error in init", ex);
|
log.error("Authorization Error in init", ex);
|
||||||
fail("Authorization Error in init");
|
fail("Authorization Error in init:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
log.error("SQL Error in init", ex);
|
log.error("SQL Error in init", ex);
|
||||||
fail("SQL Error in init");
|
fail("SQL Error in init:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,26 +53,24 @@ public class WorkspaceItemTest extends AbstractUnitTest
|
|||||||
//we have to create a new community in the database
|
//we have to create a new community in the database
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
Collection col = Collection.create(context);
|
Collection col = Collection.create(context);
|
||||||
col.update();
|
|
||||||
this.wi = WorkspaceItem.create(context, col, true);
|
this.wi = WorkspaceItem.create(context, col, true);
|
||||||
this.wi.update();
|
|
||||||
//we need to commit the changes so we don't block the table for testing
|
//we need to commit the changes so we don't block the table for testing
|
||||||
context.commit();
|
context.commit();
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
log.error("IO Error in init", ex);
|
log.error("IO Error in init", ex);
|
||||||
fail("IO Error in init");
|
fail("IO Error in init: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
catch (AuthorizeException ex)
|
catch (AuthorizeException ex)
|
||||||
{
|
{
|
||||||
log.error("Authorization Error in init", ex);
|
log.error("Authorization Error in init", ex);
|
||||||
fail("Authorization Error in init");
|
fail("Authorization Error in init: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
log.error("SQL Error in init", ex);
|
log.error("SQL Error in init", ex);
|
||||||
fail("SQL Error in init");
|
fail("SQL Error in init:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,17 +123,17 @@ public class WorkspaceItemTest extends AbstractUnitTest
|
|||||||
WorkspaceItem created = null;
|
WorkspaceItem created = null;
|
||||||
|
|
||||||
coll = Collection.create(context);
|
coll = Collection.create(context);
|
||||||
coll.update();
|
|
||||||
template = false;
|
template = false;
|
||||||
created = WorkspaceItem.create(context, coll, template);
|
created = WorkspaceItem.create(context, coll, template);
|
||||||
|
context.commit();
|
||||||
assertThat("testCreate 0",created,notNullValue());
|
assertThat("testCreate 0",created,notNullValue());
|
||||||
assertTrue("testCreate 1",created.getID() >= 0);
|
assertTrue("testCreate 1",created.getID() >= 0);
|
||||||
assertThat("testCreate 2",created.getCollection(),equalTo(coll));
|
assertThat("testCreate 2",created.getCollection(),equalTo(coll));
|
||||||
|
|
||||||
coll = Collection.create(context);
|
coll = Collection.create(context);
|
||||||
coll.update();
|
|
||||||
template = true;
|
template = true;
|
||||||
created = WorkspaceItem.create(context, coll, template);
|
created = WorkspaceItem.create(context, coll, template);
|
||||||
|
context.commit();
|
||||||
assertThat("testCreate 3",created,notNullValue());
|
assertThat("testCreate 3",created,notNullValue());
|
||||||
assertTrue("testCreate 4",created.getID() >= 0);
|
assertTrue("testCreate 4",created.getID() >= 0);
|
||||||
assertThat("testCreate 5",created.getCollection(),equalTo(coll));
|
assertThat("testCreate 5",created.getCollection(),equalTo(coll));
|
||||||
@@ -161,7 +159,7 @@ public class WorkspaceItemTest extends AbstractUnitTest
|
|||||||
WorkspaceItem created = null;
|
WorkspaceItem created = null;
|
||||||
|
|
||||||
coll = Collection.create(context);
|
coll = Collection.create(context);
|
||||||
coll.update();
|
context.commit();
|
||||||
template = false;
|
template = false;
|
||||||
created = WorkspaceItem.create(context, coll, template);
|
created = WorkspaceItem.create(context, coll, template);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
|
@@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.discovery;
|
||||||
|
|
||||||
|
import mockit.Mock;
|
||||||
|
import mockit.MockClass;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.event.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy Discovery IndexEventConsumer. It essentially does nothing,
|
||||||
|
* as Discovery/Solr is not actively running during unit testing.
|
||||||
|
*
|
||||||
|
* @author tdonohue
|
||||||
|
*/
|
||||||
|
@MockClass(realClass=IndexEventConsumer.class)
|
||||||
|
public class MockIndexEventConsumer {
|
||||||
|
|
||||||
|
//public void initialize() throws Exception {
|
||||||
|
//do nothing
|
||||||
|
//}
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
public void consume(Context ctx, Event event) throws Exception {
|
||||||
|
//do nothing - Solr is not running during unit testing, so we cannot index test content in Solr
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
public void end(Context ctx) throws Exception {
|
||||||
|
//do nothing - Solr is not running during unit testing, so we cannot index test content in Solr
|
||||||
|
}
|
||||||
|
|
||||||
|
//public void finish(Context ctx) throws Exception {
|
||||||
|
//do nothing
|
||||||
|
//}
|
||||||
|
}
|
Reference in New Issue
Block a user