Skip to content

Commit

Permalink
Fix broken Unit Tests to align with new code. Remove code duplication…
Browse files Browse the repository at this point in the history
… in EntityServiceImpl by calling itemService.getEntityType()
  • Loading branch information
tdonohue committed Apr 11, 2024
1 parent 10a65f9 commit 2a533e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ public Entity findByItemId(Context context, UUID itemId, Integer limit, Integer
@Override
public EntityType getType(Context context, Entity entity) throws SQLException {
Item item = entity.getItem();
List<MetadataValue> list = itemService.getMetadata(item, "dspace", "entity", "type", Item.ANY, false);
if (!list.isEmpty()) {
return entityTypeService.findByEntityType(context, list.get(0).getValue());
} else {
return null;
}
return itemService.getEntityType(context, item);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public void testGetAllRelationshipTypes() throws Exception {
// Declare objects utilized for this test
Item item = mock(Item.class);
Entity entity = mock(Entity.class);
EntityType entityType = mock(EntityType.class);
RelationshipType relationshipType = mock(RelationshipType.class);
relationshipType.setLeftType(leftType);
relationshipType.setLeftType(rightType);
Expand All @@ -156,7 +157,8 @@ public void testGetAllRelationshipTypes() throws Exception {
// Mock the state of objects utilized in getAllRelationshipTypes()
// to meet the success criteria of the invocation
when(entity.getItem()).thenReturn(item);
when(relationshipTypeService.findByEntityType(context, entityService.getType(context, entity), -1, -1))
when(entityService.getType(context, entity)).thenReturn(entityType);
when(relationshipTypeService.findByEntityType(context, entityType, -1, -1))
.thenReturn(relationshipTypeList);

// The relation(s) reported from our mocked Entity should match our relationshipList
Expand All @@ -181,10 +183,9 @@ public void testGetLeftRelationshipTypes() throws Exception {

// Mock the state of objects utilized in getLeftRelationshipTypes()
// to meet the success criteria of the invocation
when(itemService.getMetadata(item, "dspace", "entity", "type", Item.ANY, false)).thenReturn(metsList);
when(entity.getItem()).thenReturn(item);
when(entityService.getType(context, entity)).thenReturn(entityType);
when(relationshipTypeService.findByEntityType(context, entityService.getType(context, entity), true, -1, -1))
when(relationshipTypeService.findByEntityType(context, entityType, true, -1, -1))
.thenReturn(relationshipTypeList);

// The left relationshipType(s) reported from our mocked Entity should match our relationshipList
Expand All @@ -209,10 +210,9 @@ public void testGetRightRelationshipTypes() throws Exception {

// Mock the state of objects utilized in getRightRelationshipTypes()
// to meet the success criteria of the invocation
when(itemService.getMetadata(item, "dspace", "entity", "type", Item.ANY, false)).thenReturn(metsList);
when(entity.getItem()).thenReturn(item);
when(entityService.getType(context, entity)).thenReturn(entityType);
when(relationshipTypeService.findByEntityType(context, entityService.getType(context, entity), false, -1, -1))
when(relationshipTypeService.findByEntityType(context, entityType, false, -1, -1))
.thenReturn(relationshipTypeList);

// The right relationshipType(s) reported from our mocked Entity should match our relationshipList
Expand Down

0 comments on commit 2a533e7

Please sign in to comment.