CategoryServiceImpl extends BaseGenericServiceImpl<Category> implements CategoryService { @Override public List<Long> getChildCategoriesRecursiveIdsAndLinkIds(final long categoryId) { final Set<Category> cats = proxy().getChildCategoriesRecursive(categoryId); if (cats.isEmpty()) { return Collections.emptyList(); } final Set<Long> result = new LinkedHashSet<>(cats.size()); for (Category category : cats) { result.add(category.getCategoryId()); if (category.getLinkToId() != null) { result.addAll(getChildCategoriesRecursiveIdsAndLinkIds(category.getLinkToId())); } } return Collections.unmodifiableList(new ArrayList<>(result)); } CategoryServiceImpl(final GenericDAO<Category, Long> categoryDao,
                               final ShopCategoryRelationshipSupport shopCategoryRelationshipSupport); @Override Category getRootCategory(); @Override List<Long> getCategoryLinks(final long categoryId); @Override String getCategoryTemplate(final long categoryId); @Override String getCategorySearchTemplate(final long categoryId); @Override Long getCategoryProductTypeId(final long categoryId); @Override boolean isCategoryHasChildren(final long categoryId); @Override List<Category> getChildCategories(final long categoryId); @Override List<Category> findChildCategoriesWithAvailability(final long categoryId, final boolean withAvailability); @Override Set<Category> getChildCategoriesRecursive(final long categoryId); @Override Set<Long> getAllCategoryIds(final Collection<String> guids); @Override List<Long> getChildCategoriesRecursiveIds(final long categoryId); @Override List<Long> getChildCategoriesRecursiveIdsAndLinkIds(final long categoryId); @Override List<Category> findCategories(final int start, final int offset, final String sort, final boolean sortDescending, final Map<String, List> filter); @Override int findCategoryCount(final Map<String, List> filter); @Override List<Long> getCategoryIdAndLinkId(final long categoryId); @Override boolean isCategoryHasSubcategory(final long topCategoryId, final long subCategoryId); @Override Category getById(final long pk); @Override Long findCategoryIdBySeoUri(final String seoUri); @Override Long findCategoryIdByGUID(final String guid); @Override String findSeoUriByCategoryId(final Long categoryId); @Override Category findCategoryIdBySeoUriOrGuid(final String seoUriOrGuid); @Override List<Category> findByProductId(final long productId); CategoryService getSelf();  }
@Test public void testGetChildCategoriesRecursiveIdsWithLinksTest() { Set<Long> categoryIds = new HashSet<>(); categoryIds.addAll(Arrays.asList(101L, 102L, 103L, 104L, 105L, 143L, 144L)); List<Long> categories = categoryService.getChildCategoriesRecursiveIdsAndLinkIds(101L); assertEquals(categoryIds.size(), categories.size()); assertTrue(categoryIds.containsAll(categories)); }
@Test public void testGetChildCategoriesRecursiveIdsWithLinksLinkedTest() { Set<Long> categoryIds = new HashSet<>(); categoryIds.addAll(Arrays.asList(401L, 411L, 312L, 313L)); List<Long> categories = categoryService.getChildCategoriesRecursiveIdsAndLinkIds(401L); assertEquals(categoryIds.size(), categories.size()); assertTrue(categoryIds.containsAll(categories)); }