@Test public void shouldGetAllGroupsOfAProject() throws NotFoundException { User user = new User(); user.setId(USER_ID); Project project = new Project(); project.setId(PROJECT_ID); List<SymbolGroup> groups = createGroupsList(); groups.forEach(g -> g.setProject(project)); given(projectRepository.findById(PROJECT_ID)).willReturn(Optional.of(project)); given(symbolGroupRepository.findAllByProject_IdAndParent_id(PROJECT_ID, null)).willReturn(groups); List<SymbolGroup> allGroups = symbolGroupDAO.getAll(user, PROJECT_ID); assertThat(allGroups.size(), is(equalTo(groups.size()))); for (SymbolGroup g : allGroups) { assertTrue(groups.contains(g)); } }
public List<SymbolGroup> getAll(User user, long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); projectDAO.checkAccess(user, project); final List<SymbolGroup> groups = symbolGroupRepository.findAllByProject_IdAndParent_id(projectId, null); for (SymbolGroup group : groups) { loadLazyRelations(group); } return groups; }
SymbolGroupDAO { public List<SymbolGroup> getAll(User user, long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); projectDAO.checkAccess(user, project); final List<SymbolGroup> groups = symbolGroupRepository.findAllByProject_IdAndParent_id(projectId, null); for (SymbolGroup group : groups) { loadLazyRelations(group); } return groups; } }
SymbolGroupDAO { public List<SymbolGroup> getAll(User user, long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); projectDAO.checkAccess(user, project); final List<SymbolGroup> groups = symbolGroupRepository.findAllByProject_IdAndParent_id(projectId, null); for (SymbolGroup group : groups) { loadLazyRelations(group); } return groups; } @Autowired  SymbolGroupDAO(ProjectRepository projectRepository, ProjectDAO projectDAO,
                          SymbolGroupRepository symbolGroupRepository, SymbolRepository symbolRepository,
                          @Lazy SymbolDAO symbolDAO, ObjectMapper objectMapper); }
SymbolGroupDAO { public List<SymbolGroup> getAll(User user, long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); projectDAO.checkAccess(user, project); final List<SymbolGroup> groups = symbolGroupRepository.findAllByProject_IdAndParent_id(projectId, null); for (SymbolGroup group : groups) { loadLazyRelations(group); } return groups; } @Autowired  SymbolGroupDAO(ProjectRepository projectRepository, ProjectDAO projectDAO,
                          SymbolGroupRepository symbolGroupRepository, SymbolRepository symbolRepository,
                          @Lazy SymbolDAO symbolDAO, ObjectMapper objectMapper); List<SymbolGroup> importGroups(User user, Long projectId, SymbolGroupsImportableEntity importableEntity); List<SymbolGroup> importGroups(User user, Project project, List<SymbolGroup> groups, Map<String, SymbolImportConflictResolutionStrategy> conflictResolutions); void create(User user, SymbolGroup group); List<SymbolGroup> create(User user, Long projectId, List<SymbolGroup> groups); List<SymbolGroup> getAll(User user, long projectId); SymbolGroup get(User user, long projectId, Long groupId); void update(User user, SymbolGroup group); SymbolGroup move(User user, SymbolGroup group); void delete(User user, long projectId, Long groupId); void checkAccess(User user, Project project, SymbolGroup group); }
SymbolGroupDAO { public List<SymbolGroup> getAll(User user, long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); projectDAO.checkAccess(user, project); final List<SymbolGroup> groups = symbolGroupRepository.findAllByProject_IdAndParent_id(projectId, null); for (SymbolGroup group : groups) { loadLazyRelations(group); } return groups; } @Autowired  SymbolGroupDAO(ProjectRepository projectRepository, ProjectDAO projectDAO,
                          SymbolGroupRepository symbolGroupRepository, SymbolRepository symbolRepository,
                          @Lazy SymbolDAO symbolDAO, ObjectMapper objectMapper); List<SymbolGroup> importGroups(User user, Long projectId, SymbolGroupsImportableEntity importableEntity); List<SymbolGroup> importGroups(User user, Project project, List<SymbolGroup> groups, Map<String, SymbolImportConflictResolutionStrategy> conflictResolutions); void create(User user, SymbolGroup group); List<SymbolGroup> create(User user, Long projectId, List<SymbolGroup> groups); List<SymbolGroup> getAll(User user, long projectId); SymbolGroup get(User user, long projectId, Long groupId); void update(User user, SymbolGroup group); SymbolGroup move(User user, SymbolGroup group); void delete(User user, long projectId, Long groupId); void checkAccess(User user, Project project, SymbolGroup group);  }