DS-4244 Improve comments for relationship concept unit test

This commit is contained in:
Andrew Wood
2019-06-25 12:47:53 -04:00
parent 2a32c7ec02
commit c7aded19a8
10 changed files with 293 additions and 20 deletions

View File

@@ -58,20 +58,26 @@ public class EntityServiceImplTest {
@Test
public void testfindByItemId() throws Exception {
// Declare objects utilized in unit test
Item item = mock(Item.class);
List<Relationship> relationshipList = new ArrayList<>();
Relationship relationship = mock(Relationship.class);
relationship.setId(9);
relationshipList.add(relationship);
// Mock the state of objects utilized in findByItemId() to meet the success criteria of an invocation
when(itemService.find(any(), any())).thenReturn(item);
when(item.getName()).thenReturn("ItemName");
when(relationshipService.findByItem(any(), any())).thenReturn(relationshipList);
// The returned Entity's item should match the mocked item's name
assertEquals("TestFindByItem 0", "ItemName",
entityService.findByItemId(context, item.getID()).getItem().getName());
}
@Test
public void testGetType() throws Exception {
// Declare objects utilized in unit test
Entity entity = mock(Entity.class);
EntityTypeService entityTypeService = mock(EntityTypeService.class);
Item item = mock(Item.class);
@@ -79,71 +85,96 @@ public class EntityServiceImplTest {
MetadataValue metadataValue = mock(MetadataValue.class);
list.add(metadataValue);
EntityType entityType = entityTypeService.findByEntityType(context, "testType");
// Mock the state of objects utilized in getType() to meet the success criteria of an invocation
when(metadataValue.getValue()).thenReturn("testType");
when(itemService.getMetadata(item, "relationship", "type", null, Item.ANY)).thenReturn(list);
// The returned EntityType should equal our defined entityType case
assertEquals("TestGetType 0", entityType, entityService.getType(context, entity));
}
@Test
public void testGetLeftRelation() {
// Declare objects utilized in unit test
Item item = mock(Item.class);
UUID uuid = UUID.randomUUID();
Relationship relationship = mock(Relationship.class);
List<Relationship> relationshipList = new ArrayList<>();
relationshipList.add(relationship);
Entity entity = mock(Entity.class);
// Mock the state of objects utilized in getLeftRelation() to meet the success criteria of an invocation
when(entity.getItem()).thenReturn(item);
when(relationship.getLeftItem()).thenReturn(item);
when(item.getID()).thenReturn(uuid);
when(entity.getRelationships()).thenReturn(relationshipList);
// The left relation(s) reported from our mocked Entity should match our relationshipList
assertEquals("TestGetLeftRelations 0", relationshipList, entityService.getLeftRelations(context, entity));
}
@Test
public void testGetRightRelation() {
// Declare objects utilized in unit test
Item item = mock(Item.class);
UUID uuid = UUID.randomUUID();
Relationship relationship = mock(Relationship.class);
List<Relationship> relationshipList = new ArrayList<>();
relationshipList.add(relationship);
Entity entity = mock(Entity.class);
// Mock the state of objects utilized in getRightRelation() to meet the success criteria of an invocation
when(entity.getItem()).thenReturn(item);
when(relationship.getRightItem()).thenReturn(item);
when(item.getID()).thenReturn(uuid);
when(entity.getRelationships()).thenReturn(relationshipList);
// The right relation(s) reported from our mocked Entity should match our relationshipList
assertEquals("TestGetLeftRelations 0", relationshipList, entityService.getRightRelations(context, entity));
}
@Test
public void testGetRelationsByLabel() throws Exception {
// Declare objects utilized in unit test
Relationship relationship = mock(Relationship.class);
RelationshipType relationshipType = mock(RelationshipType.class);
relationship.setRelationshipType(relationshipType);
// Currently this unit test will only test one case with one relationship
List<Relationship> relationshipList = new ArrayList<>();
relationshipList.add(relationship);
// Mock the state of objects utilized in getRelationsByLabel() to meet the success criteria of an invocation
when(relationshipService.findAll(context)).thenReturn(relationshipList);
when(relationship.getRelationshipType()).thenReturn(relationshipType);
when(relationshipType.getLeftLabel()).thenReturn("leftLabel");
when(relationshipType.getRightLabel()).thenReturn("rightLabel");
// The relation(s) reported from our defined label should match our relationshipList
assertEquals("TestGetRelationsByLabel 0", relationshipList,
entityService.getRelationsByLabel(context, "leftLabel"));
}
@Test
public void testGetAllRelationshipTypes() throws Exception {
// Declare objects utilized for this test
List<MetadataValue> list = new ArrayList<>();
MetadataValue metadataValue = mock(MetadataValue.class);
list.add(metadataValue);
Item item = mock(Item.class);
RelationshipTypeDAO relationshipTypeDAO = mock(RelationshipTypeDAO.class);
Entity entity = mock(Entity.class);
Relationship relationship = mock(Relationship.class);
RelationshipType relationshipType = mock(RelationshipType.class);
relationship.setRelationshipType(relationshipType);
relationshipType.setLeftType(leftType);
relationshipType.setLeftType(rightType);
// Currently this unit test will only test one case with one relationshipType
List<RelationshipType> relationshipTypeList = new ArrayList<>();
relationshipTypeList.add(relationshipType);
// Mock the state of objects utilized in getAllRelationshipTypes()
// to meet the success criteria of the invocation
when(metadataValue.getValue()).thenReturn("testType");
when(entity.getItem()).thenReturn(item);
when(itemService.getMetadata(item, "relationship", "type", null, Item.ANY)).thenReturn(list);
@@ -154,22 +185,30 @@ public class EntityServiceImplTest {
when(entityTypeService.findByEntityType(context, "value")).thenReturn(leftType);
when(leftType.getID()).thenReturn(0);
when(rightType.getID()).thenReturn(1);
when(entityService.getType(context, entity)).thenReturn(leftType);
when(entityService.getType(context, entity)).thenReturn(leftType); // Mock
// The relation(s) reported from our mocked Entity should match our relationshipList
assertEquals("TestGetAllRelationshipTypes 0", relationshipTypeList,
entityService.getAllRelationshipTypes(context, entity));
}
@Test
public void testGetLeftRelationshipTypes() throws Exception {
// Declare objects utilized in unit test
Item item = mock(Item.class);
Entity entity = mock(Entity.class);
EntityType entityType = mock(EntityType.class);
RelationshipType relationshipType = mock(RelationshipType.class);
// Currently this unit test will only test one case with one relationshipType
List<RelationshipType> relationshipTypeList = new LinkedList<>();
relationshipTypeList.add(relationshipType);
List<MetadataValue> metsList = new ArrayList<>();
MetadataValue metadataValue = mock(MetadataValue.class);
metsList.add(metadataValue);
// Mock the state of objects utilized in getLeftRelationshipTypes()
// to meet the success criteria of the invocation
when(itemService.getMetadata(any(), any(), any(), any(), any())).thenReturn(metsList);
when(entity.getItem()).thenReturn(item);
when(entityType.getID()).thenReturn(0);
@@ -178,21 +217,28 @@ public class EntityServiceImplTest {
when(entityService.getType(context, entity)).thenReturn(entityType);
when(entityTypeService.findByEntityType(any(), any())).thenReturn(entityType);
// The left relationshipType(s) reported from our mocked Entity should match our relationshipList
assertEquals("TestGetLeftRelationshipTypes 0", relationshipTypeList,
entityService.getLeftRelationshipTypes(context, entity));
}
@Test
public void testGetRightRelationshipTypes() throws Exception {
// Declare objects utilized in unit test
Item item = mock(Item.class);
Entity entity = mock(Entity.class);
EntityType entityType = mock(EntityType.class);
RelationshipType relationshipType = mock(RelationshipType.class);
// Currently this unit test will only test one case with one relationshipType
List<RelationshipType> relationshipTypeList = new LinkedList<>();
relationshipTypeList.add(relationshipType);
List<MetadataValue> metsList = new ArrayList<>();
MetadataValue metadataValue = mock(MetadataValue.class);
metsList.add(metadataValue);
// Mock the state of objects utilized in getRightRelationshipTypes()
// to meet the success criteria of the invocation
when(itemService.getMetadata(any(), any(), any(), any(), any())).thenReturn(metsList);
when(entity.getItem()).thenReturn(item);
when(entityType.getID()).thenReturn(0);
@@ -201,6 +247,7 @@ public class EntityServiceImplTest {
when(entityService.getType(context, entity)).thenReturn(entityType);
when(entityTypeService.findByEntityType(any(), any())).thenReturn(entityType);
// The right relationshipType(s) reported from our mocked Entity should match our relationshipList
assertEquals("TestGetRightRelationshipTypes 0", relationshipTypeList,
entityService.getRightRelationshipTypes(context, entity));
}
@@ -208,12 +255,18 @@ public class EntityServiceImplTest {
@Test
public void testGetRelationshipTypesByLabel() throws Exception {
// Declare objects utilized in unit test
List<RelationshipType> list = new LinkedList<>();
RelationshipType relationshipType = mock(RelationshipType.class);
list.add(relationshipType);
// Mock the state of objects utilized in getRelationshipTypesByLabel()
// to meet the success criteria of the invocation
when(relationshipTypeService.findAll(context)).thenReturn(list);
when(relationshipType.getLeftLabel()).thenReturn("leftLabel");
when(relationshipType.getRightLabel()).thenReturn("rightLabel");
// The RelationshipType(s) reported from our mocked Entity should match our list
assertEquals("TestGetRelationshipTypesByLabel 0", list,
entityService.getRelationshipTypesByLabel(context, "leftLabel"));
}