@Test(expected = InvalidEntitySettingsException.class) public void shouldSignalInvalidHistoryTrackingSettings() { fixDataModel(); List<EntityDto> entities = getDataModel(); entities.get(0).setRecordHistory(false); EntitySorter.sortByHasARelation(entities, schemaHolder); }
@Test public void shouldProperlySortByHasARelation() { fixDataModel(); List<EntityDto> entities = EntitySorter.sortByHasARelation(getDataModel(), schemaHolder); Assert.assertTrue(entities.indexOf(entity3) < entities.indexOf(entity2)); Assert.assertTrue(entities.indexOf(entity3) < entities.indexOf(entity1)); Assert.assertTrue(entities.indexOf(entity2) < entities.indexOf(entity1)); Assert.assertTrue(entities.indexOf(entity2) > entities.indexOf(entity3)); }
@Test public void shouldNotSignalErrorOnSelfRelation() { fixDataModel(); List<EntityDto> initialList = new ArrayList<>(); initialList.addAll(getDataModel()); initialList.add(binaryTree); List<EntityDto> sortingResult = EntitySorter.sortByHasARelation(initialList, schemaHolder); Assert.assertEquals(sortingResult.size(), 6); Assert.assertTrue(sortingResult.contains(binaryTree)); }
@Test(expected = InvalidRelationshipException.class) public void shouldSignalInvalidBidirectionalRelationship() { EntitySorter.sortByHasARelation(getDataModel(), schemaHolder); }