mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-19 16:03:07 +00:00
DSpace refactored service api
This commit is contained in:
@@ -7,14 +7,15 @@
|
||||
*/
|
||||
package org.dspace.content;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.AbstractUnitTest;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.*;
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.* ;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
@@ -32,7 +33,12 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
/**
|
||||
* MetadataValue instance for the tests
|
||||
*/
|
||||
private MetadataValue mv;
|
||||
private MetadataValue mv = null;
|
||||
|
||||
private Collection collection;
|
||||
private Community owningCommunity;
|
||||
private Item it;
|
||||
|
||||
|
||||
/**
|
||||
* MetadataField instance for the tests
|
||||
@@ -49,6 +55,13 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
*/
|
||||
private String qualifier = "author";
|
||||
|
||||
private MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
|
||||
private MetadataValueService metadataValueService = ContentServiceFactory.getInstance().getMetadataValueService();
|
||||
protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||
protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
|
||||
protected InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService();
|
||||
|
||||
/**
|
||||
* This method will be run before every test as per @Before. It will
|
||||
* initialize resources required for the tests.
|
||||
@@ -64,12 +77,14 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
try
|
||||
{
|
||||
context.turnOffAuthorisationSystem();
|
||||
this.mf = MetadataField.findByElement(context,
|
||||
MetadataSchema.DC_SCHEMA_ID, element, qualifier);
|
||||
this.mv = new MetadataValue(mf);
|
||||
this.mv.setResourceId(Item.create(context).getID());
|
||||
this.mv.setResourceTypeId(Constants.ITEM);
|
||||
context.commit();
|
||||
this.owningCommunity = communityService.create(null, context);
|
||||
this.collection = collectionService.create(context, owningCommunity);
|
||||
WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, false);
|
||||
this.it = installItemService.installItem(context, workspaceItem);
|
||||
|
||||
this.mf = metadataFieldService.findByElement(context,
|
||||
MetadataSchema.DC_SCHEMA, element, qualifier);
|
||||
this.mv = metadataValueService.create(context, it , mf);
|
||||
context.restoreAuthSystemState();
|
||||
}
|
||||
catch (AuthorizeException ex)
|
||||
@@ -95,6 +110,16 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
try {
|
||||
context.turnOffAuthorisationSystem();
|
||||
communityService.delete(context, owningCommunity);
|
||||
} catch (SQLException | AuthorizeException | IOException ex) {
|
||||
log.error("Error in destroy", ex);
|
||||
fail("Error in destroy: " + ex.getMessage());
|
||||
}finally {
|
||||
context.restoreAuthSystemState();
|
||||
}
|
||||
|
||||
mf = null;
|
||||
mv = null;
|
||||
super.destroy();
|
||||
@@ -107,41 +132,18 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
public void testGetFieldId()
|
||||
{
|
||||
MetadataValue instance = new MetadataValue();
|
||||
assertThat("testGetFieldId 0", instance.getFieldId(), equalTo(0));
|
||||
assertThat("testGetFieldId 0", instance.getValueId(), equalTo(0));
|
||||
|
||||
assertThat("testGetFieldId 1", mv.getFieldId(), equalTo(mf.getFieldID()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of setFieldId method, of class MetadataValue.
|
||||
*/
|
||||
@Test
|
||||
public void testSetFieldId()
|
||||
{
|
||||
int fieldId = 66;
|
||||
mv.setFieldId(fieldId);
|
||||
assertThat("testSetFieldId 0", mv.getFieldId(), equalTo(fieldId));
|
||||
assertThat("testGetFieldId 1", mv.getMetadataField().getFieldID(), equalTo(mf.getFieldID()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getItemId method, of class MetadataValue.
|
||||
*/
|
||||
@Test
|
||||
public void testGetItemId()
|
||||
public void testGetDSpaceObject()
|
||||
{
|
||||
assertTrue("testGetItemId 0", mv.getResourceId() >= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of setItemId method, of class MetadataValue.
|
||||
*/
|
||||
@Test
|
||||
public void testSetItemId()
|
||||
{
|
||||
int itemId = 55;
|
||||
mv.setResourceId(itemId);
|
||||
mv.setResourceTypeId(Constants.ITEM);
|
||||
assertThat("testSetItemId 0", mv.getResourceId(), equalTo(itemId));
|
||||
assertTrue("testGetItemId 0", mv.getDSpaceObject().equals(it));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +192,7 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
@Test
|
||||
public void testGetValueId()
|
||||
{
|
||||
assertThat("testGetValueId 0",mv.getValueId(), equalTo(0));
|
||||
assertThat("testGetValueId 0",mv.getValueId(), notNullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,7 +241,7 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
@Test
|
||||
public void testGetConfidence()
|
||||
{
|
||||
assertThat("testGetConfidence 0",mv.getConfidence(), equalTo(0));
|
||||
assertThat("testGetConfidence 0",mv.getConfidence(), equalTo(-1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,7 +261,7 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
@Test
|
||||
public void testCreate() throws Exception
|
||||
{
|
||||
mv.create(context);
|
||||
metadataValueService.create(context, it, mf);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -268,9 +270,9 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
@Test
|
||||
public void testFind() throws Exception
|
||||
{
|
||||
mv.create(context);
|
||||
metadataValueService.create(context, it, mf);
|
||||
int id = mv.getValueId();
|
||||
MetadataValue found = MetadataValue.find(context, id);
|
||||
MetadataValue found = metadataValueService.find(context, id);
|
||||
assertThat("testFind 0",found, notNullValue());
|
||||
assertThat("testFind 1",found.getValueId(), equalTo(id));
|
||||
}
|
||||
@@ -281,9 +283,8 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
@Test
|
||||
public void testFindByField() throws Exception
|
||||
{
|
||||
mv.create(context);
|
||||
int fieldId = mv.getFieldId();
|
||||
List<MetadataValue> found = MetadataValue.findByField(context, fieldId);
|
||||
metadataValueService.create(context, it, mf);
|
||||
List<MetadataValue> found = metadataValueService.findByField(context, mf);
|
||||
assertThat("testFind 0",found, notNullValue());
|
||||
assertTrue("testFind 1",found.size() >= 1);
|
||||
}
|
||||
@@ -294,21 +295,9 @@ public class MetadataValueTest extends AbstractUnitTest
|
||||
@Test
|
||||
public void testUpdate() throws Exception
|
||||
{
|
||||
mv.create(context);
|
||||
mv.update(context);
|
||||
metadataValueService.create(context, it, mf);
|
||||
metadataValueService.update(context, mv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of delete method, of class MetadataValue.
|
||||
*/
|
||||
@Test
|
||||
public void testDelete() throws Exception
|
||||
{
|
||||
mv.create(context);
|
||||
int id = mv.getValueId();
|
||||
mv.delete(context);
|
||||
MetadataValue found = MetadataValue.find(context, id);
|
||||
assertThat("testDelete 0",found, nullValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user