mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-19 07:53:08 +00:00
Merge branch 'master' into DS-4351-upgrade-dependencies
This commit is contained in:
@@ -66,7 +66,7 @@ public class RelationshipServiceImplTest {
|
||||
@Test
|
||||
public void testFindAll() throws Exception {
|
||||
// Mock DAO to return our mocked relationshipsList
|
||||
when(relationshipDAO.findAll(context, Relationship.class)).thenReturn(relationshipsList);
|
||||
when(relationshipDAO.findAll(context, Relationship.class, -1, -1)).thenReturn(relationshipsList);
|
||||
// The reported Relationship(s) should match our relationshipsList
|
||||
assertEquals("TestFindAll 0", relationshipsList, relationshipService.findAll(context));
|
||||
}
|
||||
@@ -84,23 +84,22 @@ public class RelationshipServiceImplTest {
|
||||
RelationshipType hasDog = new RelationshipType();
|
||||
RelationshipType hasFather = new RelationshipType();
|
||||
RelationshipType hasMother = new RelationshipType();
|
||||
hasDog.setLeftLabel("hasDog");
|
||||
hasDog.setRightLabel("isDogOf");
|
||||
hasFather.setLeftLabel("hasFather");
|
||||
hasFather.setRightLabel("isFatherOf");
|
||||
hasMother.setLeftLabel("hasMother");
|
||||
hasMother.setRightLabel("isMotherOf");
|
||||
hasDog.setLeftwardType("hasDog");
|
||||
hasDog.setRightwardType("isDogOf");
|
||||
hasFather.setLeftwardType("hasFather");
|
||||
hasFather.setRightwardType("isFatherOf");
|
||||
hasMother.setLeftwardType("hasMother");
|
||||
hasMother.setRightwardType("isMotherOf");
|
||||
|
||||
relationshipTest.add(getRelationship(cindy, spot, hasDog,0,0));
|
||||
relationshipTest.add(getRelationship(cindy, jasper, hasDog,0,1));
|
||||
relationshipTest.add(getRelationship(cindy, hank, hasFather,0,0));
|
||||
relationshipTest.add(getRelationship(fred, cindy, hasMother,0,0));
|
||||
relationshipTest.add(getRelationship(bob, cindy, hasMother,1,0));
|
||||
when(relationshipService.findByItem(context, cindy)).thenReturn(relationshipTest);
|
||||
when(relationshipDAO.findByItem(context, cindy)).thenReturn(relationshipTest);
|
||||
when(relationshipService.findByItem(context, cindy, -1, -1)).thenReturn(relationshipTest);
|
||||
|
||||
// Mock the state of objects utilized in findByItem() to meet the success criteria of the invocation
|
||||
when(relationshipDAO.findByItem(context, cindy)).thenReturn(relationshipTest);
|
||||
when(relationshipDAO.findByItem(context, cindy, -1, -1)).thenReturn(relationshipTest);
|
||||
|
||||
List<Relationship> results = relationshipService.findByItem(context, cindy);
|
||||
assertEquals("TestFindByItem 0", relationshipTest, results);
|
||||
@@ -115,11 +114,11 @@ public class RelationshipServiceImplTest {
|
||||
Item item = mock(Item.class);
|
||||
|
||||
// Mock DAO to return mocked left place as 0
|
||||
when(relationshipDAO.findLeftPlaceByLeftItem(context, item)).thenReturn(0);
|
||||
when(relationshipDAO.findNextLeftPlaceByLeftItem(context, item)).thenReturn(0);
|
||||
|
||||
// The left place reported from out mocked item should match the DAO's report of the left place
|
||||
assertEquals("TestFindLeftPlaceByLeftItem 0", relationshipDAO.findLeftPlaceByLeftItem(context, item),
|
||||
relationshipService.findLeftPlaceByLeftItem(context, item));
|
||||
assertEquals("TestFindLeftPlaceByLeftItem 0", relationshipDAO.findNextLeftPlaceByLeftItem(context, item),
|
||||
relationshipService.findNextLeftPlaceByLeftItem(context, item));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,11 +127,11 @@ public class RelationshipServiceImplTest {
|
||||
Item item = mock(Item.class);
|
||||
|
||||
// Mock lower level DAO to return mocked right place as 0
|
||||
when(relationshipDAO.findRightPlaceByRightItem(context, item)).thenReturn(0);
|
||||
when(relationshipDAO.findNextRightPlaceByRightItem(context, item)).thenReturn(0);
|
||||
|
||||
// The right place reported from out mocked item should match the DAO's report of the right place
|
||||
assertEquals("TestFindRightPlaceByRightItem 0", relationshipDAO.findRightPlaceByRightItem(context, item),
|
||||
relationshipService.findRightPlaceByRightItem(context, item));
|
||||
assertEquals("TestFindRightPlaceByRightItem 0", relationshipDAO.findNextRightPlaceByRightItem(context, item),
|
||||
relationshipService.findNextRightPlaceByRightItem(context, item));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -194,8 +193,8 @@ public class RelationshipServiceImplTest {
|
||||
EntityType rightEntityType = mock(EntityType.class);
|
||||
testRel.setLeftType(leftEntityType);
|
||||
testRel.setRightType(rightEntityType);
|
||||
testRel.setLeftLabel("Entitylabel");
|
||||
testRel.setRightLabel("Entitylabel");
|
||||
testRel.setLeftwardType("Entitylabel");
|
||||
testRel.setRightwardType("Entitylabel");
|
||||
metsList.add(metVal);
|
||||
relationship = getRelationship(leftItem, rightItem, testRel, 0,0);
|
||||
leftTypelist.add(relationship);
|
||||
@@ -243,8 +242,8 @@ public class RelationshipServiceImplTest {
|
||||
EntityType rightEntityType = mock(EntityType.class);
|
||||
testRel.setLeftType(leftEntityType);
|
||||
testRel.setRightType(rightEntityType);
|
||||
testRel.setLeftLabel("Entitylabel");
|
||||
testRel.setRightLabel("Entitylabel");
|
||||
testRel.setLeftwardType("Entitylabel");
|
||||
testRel.setRightwardType("Entitylabel");
|
||||
testRel.setLeftMinCardinality(0);
|
||||
testRel.setRightMinCardinality(0);
|
||||
metsList.add(metVal);
|
||||
@@ -261,6 +260,11 @@ public class RelationshipServiceImplTest {
|
||||
when(relationshipService.findByItem(context,rightItem)).thenReturn(rightTypelist);
|
||||
when(relationshipService.findByItemAndRelationshipType(context, leftItem, testRel, true))
|
||||
.thenReturn(leftTypelist);
|
||||
when(relationshipService.findByItemAndRelationshipType(context, rightItem, testRel, false))
|
||||
.thenReturn(rightTypelist);
|
||||
when(itemService.getMetadata(leftItem, "relationship", "type", null, Item.ANY)).thenReturn(metsList);
|
||||
when(itemService.getMetadata(rightItem, "relationship", "type", null, Item.ANY)).thenReturn(metsList);
|
||||
when(relationshipDAO.create(any(), any())).thenReturn(relationship);
|
||||
when(relationshipService.find(context,0)).thenReturn(relationship);
|
||||
|
||||
// Invoke delete()
|
||||
@@ -285,8 +289,8 @@ public class RelationshipServiceImplTest {
|
||||
EntityType rightEntityType = mock(EntityType.class);
|
||||
testRel.setLeftType(leftEntityType);
|
||||
testRel.setRightType(rightEntityType);
|
||||
testRel.setLeftLabel("Entitylabel");
|
||||
testRel.setRightLabel("Entitylabel");
|
||||
testRel.setLeftwardType("Entitylabel");
|
||||
testRel.setRightwardType("Entitylabel");
|
||||
testRel.setLeftMinCardinality(0);
|
||||
testRel.setRightMinCardinality(0);
|
||||
metsList.add(metVal);
|
||||
@@ -305,6 +309,12 @@ public class RelationshipServiceImplTest {
|
||||
Mockito.verify(relationshipDAO).save(context, relationship);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountTotal() throws Exception {
|
||||
when(relationshipDAO.countRows(context)).thenReturn(0);
|
||||
assertEquals("TestCountTotal 1", 0, relationshipService.countTotal(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a configured Relationship
|
||||
* @param leftItem Relationship's left item
|
||||
|
Reference in New Issue
Block a user