mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +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.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.I18nUtil;
|
||||
import org.dspace.discovery.MockIndexEventConsumer;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.search.DSIndexer;
|
||||
import org.dspace.servicemanager.DSpaceKernelImpl;
|
||||
@@ -52,7 +54,7 @@ import org.xml.sax.SAXException;
|
||||
*
|
||||
* @author pvillega
|
||||
*/
|
||||
@UsingMocksAndStubs({MockDatabaseManager.class, MockBrowseCreateDAOOracle.class})
|
||||
@UsingMocksAndStubs({MockDatabaseManager.class, MockBrowseCreateDAOOracle.class, MockIndexEventConsumer.class})
|
||||
public class AbstractUnitTest
|
||||
{
|
||||
/** log4j category */
|
||||
@@ -147,6 +149,7 @@ public class AbstractUnitTest
|
||||
eperson.setLastName("last");
|
||||
eperson.setEmail("test@email.com");
|
||||
eperson.setCanLogIn(true);
|
||||
eperson.setLanguage(I18nUtil.getDefaultLocale().getLanguage());
|
||||
}
|
||||
|
||||
//Create search and browse indexes
|
||||
@@ -349,6 +352,7 @@ public class AbstractUnitTest
|
||||
if(context != null && context.isValid())
|
||||
{
|
||||
context.abort();
|
||||
context = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -61,7 +61,7 @@ public class BitstreamFormatTest extends AbstractUnitTest
|
||||
catch (SQLException 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) {
|
||||
log.error("IO Error in init", ex);
|
||||
fail("SQL Error in init");
|
||||
fail("SQL Error in init: " + ex.getMessage());
|
||||
}
|
||||
catch (SQLException 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());
|
||||
Bitstream created = Bitstream.create(context, new FileInputStream(f));
|
||||
context.commit();
|
||||
|
||||
//the item created by default has no name nor type set
|
||||
assertThat("testCreate 0", created.getFormat().getMIMEType(), equalTo("application/octet-stream"));
|
||||
assertThat("testCreate 1", created.getName(), nullValue());
|
||||
|
@@ -66,7 +66,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
catch (SQLException ex)
|
||||
{
|
||||
log.error("SQL Error in init", ex);
|
||||
fail("SQL Error in init");
|
||||
fail("SQL Error in init: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
b.addBitstream(bs);
|
||||
assertThat("testGetHandle 1", b.getBitstreamByName(name), notNullValue());
|
||||
assertThat("testGetHandle 2", b.getBitstreamByName(name), equalTo(bs));
|
||||
assertThat("testGetHandle 3", b.getBitstreamByName(name).getName(), equalTo(name));
|
||||
assertThat("testGetHandle 3", b.getBitstreamByName(name).getName(), equalTo(name));
|
||||
context.commit();
|
||||
}
|
||||
|
||||
|
@@ -63,12 +63,12 @@ public class CollectionTest extends AbstractDSpaceObjectTest
|
||||
catch (AuthorizeException ex)
|
||||
{
|
||||
log.error("Authorization Error in init", ex);
|
||||
fail("Authorization Error in init");
|
||||
fail("Authorization Error in init: " + ex.getMessage());
|
||||
}
|
||||
catch (SQLException 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();
|
||||
int step = 1;
|
||||
Group g = Group.create(context);
|
||||
context.commit();
|
||||
context.restoreAuthSystemState();
|
||||
c.setWorkflowGroup(step, g);
|
||||
assertThat("testSetWorkflowGroup 0",c.getWorkflowGroup(step), notNullValue());
|
||||
@@ -1868,6 +1869,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest
|
||||
context.turnOffAuthorisationSystem();
|
||||
Community parent = Community.create(null, context);
|
||||
parent.addCollection(c);
|
||||
context.commit();
|
||||
context.restoreAuthSystemState();
|
||||
assertThat("testGetParentObject 1", c.getParentObject(), notNullValue());
|
||||
assertThat("testGetParentObject 2", (Community)c.getParentObject(), equalTo(parent));
|
||||
|
@@ -63,12 +63,12 @@ public class CommunityTest extends AbstractDSpaceObjectTest
|
||||
catch (AuthorizeException ex)
|
||||
{
|
||||
log.error("Authorization Error in init", ex);
|
||||
fail("Authorization Error in init");
|
||||
fail("Authorization Error in init:" + ex.getMessage());
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
log.error("SQL Error in init", ex);
|
||||
fail("SQL Error in init");
|
||||
fail("SQL Error in init:" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -87,7 +87,7 @@ public class InstallItemTest extends AbstractUnitTest
|
||||
String handle = "1345/567";
|
||||
Collection col = Collection.create(context);
|
||||
WorkspaceItem is = WorkspaceItem.create(context, col, false);
|
||||
|
||||
|
||||
//Test assigning a specified handle to an item
|
||||
// (this handle should not already be used by system, as it doesn't start with "1234567689" prefix)
|
||||
Item result = InstallItem.installItem(context, is, handle);
|
||||
|
@@ -76,12 +76,12 @@ public class ItemTest extends AbstractDSpaceObjectTest
|
||||
catch (AuthorizeException ex)
|
||||
{
|
||||
log.error("Authorization Error in init", ex);
|
||||
fail("Authorization Error in init");
|
||||
fail("Authorization Error in init:" + ex.getMessage());
|
||||
}
|
||||
catch (SQLException 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
|
||||
context.turnOffAuthorisationSystem();
|
||||
Collection col = Collection.create(context);
|
||||
col.update();
|
||||
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
|
||||
context.commit();
|
||||
context.restoreAuthSystemState();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
log.error("IO Error in init", ex);
|
||||
fail("IO Error in init");
|
||||
fail("IO Error in init: " + ex.getMessage());
|
||||
}
|
||||
catch (AuthorizeException ex)
|
||||
{
|
||||
log.error("Authorization Error in init", ex);
|
||||
fail("Authorization Error in init");
|
||||
fail("Authorization Error in init: " + ex.getMessage());
|
||||
}
|
||||
catch (SQLException 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;
|
||||
|
||||
coll = Collection.create(context);
|
||||
coll.update();
|
||||
template = false;
|
||||
created = WorkspaceItem.create(context, coll, template);
|
||||
context.commit();
|
||||
assertThat("testCreate 0",created,notNullValue());
|
||||
assertTrue("testCreate 1",created.getID() >= 0);
|
||||
assertThat("testCreate 2",created.getCollection(),equalTo(coll));
|
||||
|
||||
coll = Collection.create(context);
|
||||
coll.update();
|
||||
template = true;
|
||||
created = WorkspaceItem.create(context, coll, template);
|
||||
context.commit();
|
||||
assertThat("testCreate 3",created,notNullValue());
|
||||
assertTrue("testCreate 4",created.getID() >= 0);
|
||||
assertThat("testCreate 5",created.getCollection(),equalTo(coll));
|
||||
@@ -161,7 +159,7 @@ public class WorkspaceItemTest extends AbstractUnitTest
|
||||
WorkspaceItem created = null;
|
||||
|
||||
coll = Collection.create(context);
|
||||
coll.update();
|
||||
context.commit();
|
||||
template = false;
|
||||
created = WorkspaceItem.create(context, coll, template);
|
||||
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