mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 12:33:18 +00:00
DS-3406 unit tests for getCollection/getCommunity for different dspace objects
This commit is contained in:
@@ -7,6 +7,20 @@
|
||||
*/
|
||||
package org.dspace.content;
|
||||
|
||||
import mockit.NonStrictExpectations;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.AuthorizeUtil;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.factory.CoreServiceFactory;
|
||||
import org.dspace.core.service.LicenseService;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -15,20 +29,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.factory.CoreServiceFactory;
|
||||
import org.dspace.core.service.LicenseService;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.* ;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import mockit.NonStrictExpectations;
|
||||
import org.dspace.app.util.AuthorizeUtil;
|
||||
import org.dspace.core.Constants;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit Tests for class Collection
|
||||
@@ -1823,8 +1825,22 @@ public class CollectionTest extends AbstractDSpaceObjectTest
|
||||
@Test
|
||||
public void testGetCommunities() throws Exception
|
||||
{
|
||||
assertThat("testGetCommunities 0",collection.getCommunities(), notNullValue());
|
||||
assertTrue("testGetCommunities 1",collection.getCommunities().size() == 1);
|
||||
context.turnOffAuthorisationSystem();
|
||||
Community community = communityService.create(null, context);
|
||||
communityService.setMetadataSingleValue(context, community, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "community 3");
|
||||
this.collection.addCommunity(community);
|
||||
community = communityService.create(null, context);
|
||||
communityService.setMetadataSingleValue(context, community, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "community 1");
|
||||
this.collection.addCommunity(community);
|
||||
community = communityService.create(null, context);
|
||||
communityService.setMetadataSingleValue(context, community, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "community 2");
|
||||
this.collection.addCommunity(community);
|
||||
context.restoreAuthSystemState();
|
||||
assertTrue("testGetCommunities 0",collection.getCommunities().size() == 4);
|
||||
//Communities should be sorted by name
|
||||
assertTrue("testGetCommunities 1",collection.getCommunities().get(1).getName().equals("community 1"));
|
||||
assertTrue("testGetCommunities 1",collection.getCommunities().get(2).getName().equals("community 2"));
|
||||
assertTrue("testGetCommunities 1",collection.getCommunities().get(3).getName().equals("community 3"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -8,22 +8,25 @@
|
||||
|
||||
package org.dspace.content;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import mockit.NonStrictExpectations;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.AuthorizeUtil;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.* ;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import mockit.NonStrictExpectations;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit Tests for class Community
|
||||
@@ -681,10 +684,20 @@ public class CommunityTest extends AbstractDSpaceObjectTest
|
||||
assertThat("testGetCollections 0",c.getCollections(), notNullValue());
|
||||
assertTrue("testGetCollections 1", c.getCollections().size() == 0);
|
||||
|
||||
Collection result = collectionService.create(context, c);
|
||||
assertThat("testGetCollections 2",c.getCollections(), notNullValue());
|
||||
assertTrue("testGetCollections 3", c.getCollections().size() == 1);
|
||||
assertThat("testGetCollections 4",c.getCollections().get(0), equalTo(result));
|
||||
context.turnOffAuthorisationSystem();
|
||||
Collection collection = collectionService.create(context, c);
|
||||
collectionService.setMetadataSingleValue(context, collection, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "collection B");
|
||||
collection = collectionService.create(context, c);
|
||||
collectionService.setMetadataSingleValue(context, collection, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "collection C");
|
||||
collection = collectionService.create(context, c);
|
||||
collectionService.setMetadataSingleValue(context, collection, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "collection A");
|
||||
//we need to commit the changes so we don't block the table for testing
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
//sorted
|
||||
assertTrue("testGetCollections 2",c.getCollections().get(0).getName().equals("collection A"));
|
||||
assertTrue("testGetCollections 3",c.getCollections().get(1).getName().equals("collection B"));
|
||||
assertTrue("testGetCollections 4",c.getCollections().get(2).getName().equals("collection C"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -707,11 +720,20 @@ public class CommunityTest extends AbstractDSpaceObjectTest
|
||||
assertThat("testGetSubcommunities 0",c.getSubcommunities(), notNullValue());
|
||||
assertTrue("testGetSubcommunities 1", c.getSubcommunities().size() == 0);
|
||||
|
||||
//community with parent
|
||||
Community son = communityService.create(c, context);
|
||||
assertThat("testGetSubcommunities 2",c.getSubcommunities(), notNullValue());
|
||||
assertTrue("testGetSubcommunities 3", c.getSubcommunities().size() == 1);
|
||||
assertThat("testGetSubcommunities 4", c.getSubcommunities().get(0), equalTo(son));
|
||||
context.turnOffAuthorisationSystem();
|
||||
Community community = communityService.create(c, context);
|
||||
communityService.setMetadataSingleValue(context, community, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "subcommunity B");
|
||||
community = communityService.create(c, context);
|
||||
communityService.setMetadataSingleValue(context, community, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "subcommunity A");
|
||||
community = communityService.create(c, context);
|
||||
communityService.setMetadataSingleValue(context, community, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "subcommunity C");
|
||||
//we need to commit the changes so we don't block the table for testing
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
//get Subcommunities sorted
|
||||
assertTrue("testGetCollections 2",c.getSubcommunities().get(0).getName().equals("subcommunity A"));
|
||||
assertTrue("testGetCollections 3",c.getSubcommunities().get(1).getName().equals("subcommunity B"));
|
||||
assertTrue("testGetCollections 4",c.getSubcommunities().get(2).getName().equals("subcommunity C"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -615,8 +615,18 @@ public class ItemTest extends AbstractDSpaceObjectTest
|
||||
@Test
|
||||
public void testGetCollections() throws Exception
|
||||
{
|
||||
context.turnOffAuthorisationSystem();
|
||||
Collection collection = collectionService.create(context, owningCommunity);
|
||||
collectionService.setMetadataSingleValue(context, collection, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "collection B");
|
||||
it.addCollection(collection);
|
||||
collection = collectionService.create(context, owningCommunity);
|
||||
collectionService.setMetadataSingleValue(context, collection, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "collection A");
|
||||
it.addCollection(collection);
|
||||
context.restoreAuthSystemState();
|
||||
assertThat("testGetCollections 0", it.getCollections(), notNullValue());
|
||||
assertTrue("testGetCollections 1", it.getCollections().size() == 1);
|
||||
assertTrue("testGetCollections 1", it.getCollections().size() == 3);
|
||||
assertTrue("testGetCollections 2", it.getCollections().get(1).getName().equals("collection A"));
|
||||
assertTrue("testGetCollections 3", it.getCollections().get(2).getName().equals("collection B"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user