mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-13 13:03:11 +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;
|
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.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -15,20 +29,8 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
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 static org.hamcrest.CoreMatchers.*;
|
||||||
import mockit.NonStrictExpectations;
|
import static org.junit.Assert.*;
|
||||||
import org.dspace.app.util.AuthorizeUtil;
|
|
||||||
import org.dspace.core.Constants;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit Tests for class Collection
|
* Unit Tests for class Collection
|
||||||
@@ -1823,8 +1825,22 @@ public class CollectionTest extends AbstractDSpaceObjectTest
|
|||||||
@Test
|
@Test
|
||||||
public void testGetCommunities() throws Exception
|
public void testGetCommunities() throws Exception
|
||||||
{
|
{
|
||||||
assertThat("testGetCommunities 0",collection.getCommunities(), notNullValue());
|
context.turnOffAuthorisationSystem();
|
||||||
assertTrue("testGetCommunities 1",collection.getCommunities().size() == 1);
|
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;
|
package org.dspace.content;
|
||||||
|
|
||||||
import java.io.File;
|
import mockit.NonStrictExpectations;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.app.util.AuthorizeUtil;
|
import org.dspace.app.util.AuthorizeUtil;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.Group;
|
import org.dspace.eperson.Group;
|
||||||
import org.junit.*;
|
import org.junit.After;
|
||||||
import static org.junit.Assert.* ;
|
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 static org.hamcrest.CoreMatchers.*;
|
||||||
import mockit.NonStrictExpectations;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit Tests for class Community
|
* Unit Tests for class Community
|
||||||
@@ -681,10 +684,20 @@ public class CommunityTest extends AbstractDSpaceObjectTest
|
|||||||
assertThat("testGetCollections 0",c.getCollections(), notNullValue());
|
assertThat("testGetCollections 0",c.getCollections(), notNullValue());
|
||||||
assertTrue("testGetCollections 1", c.getCollections().size() == 0);
|
assertTrue("testGetCollections 1", c.getCollections().size() == 0);
|
||||||
|
|
||||||
Collection result = collectionService.create(context, c);
|
context.turnOffAuthorisationSystem();
|
||||||
assertThat("testGetCollections 2",c.getCollections(), notNullValue());
|
Collection collection = collectionService.create(context, c);
|
||||||
assertTrue("testGetCollections 3", c.getCollections().size() == 1);
|
collectionService.setMetadataSingleValue(context, collection, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "collection B");
|
||||||
assertThat("testGetCollections 4",c.getCollections().get(0), equalTo(result));
|
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());
|
assertThat("testGetSubcommunities 0",c.getSubcommunities(), notNullValue());
|
||||||
assertTrue("testGetSubcommunities 1", c.getSubcommunities().size() == 0);
|
assertTrue("testGetSubcommunities 1", c.getSubcommunities().size() == 0);
|
||||||
|
|
||||||
//community with parent
|
context.turnOffAuthorisationSystem();
|
||||||
Community son = communityService.create(c, context);
|
Community community = communityService.create(c, context);
|
||||||
assertThat("testGetSubcommunities 2",c.getSubcommunities(), notNullValue());
|
communityService.setMetadataSingleValue(context, community, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY, "subcommunity B");
|
||||||
assertTrue("testGetSubcommunities 3", c.getSubcommunities().size() == 1);
|
community = communityService.create(c, context);
|
||||||
assertThat("testGetSubcommunities 4", c.getSubcommunities().get(0), equalTo(son));
|
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
|
@Test
|
||||||
public void testGetCollections() throws Exception
|
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());
|
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