@Test public void getShopCategoriesIds() throws Exception { final GenericDAO<Shop, Long> shopDao = this.context.mock(GenericDAO.class, "shopDao"); final GenericDAO<Category, Long> categoryDao = this.context.mock(GenericDAO.class, "categoryDao"); final Shop shop10 = this.context.mock(Shop.class, "shop10"); final ShopCategory shop10sc1 = this.context.mock(ShopCategory.class, "shop10sc1"); final ShopCategory shop10sc2 = this.context.mock(ShopCategory.class, "shop10sc2"); final ShopCategory shop10sc3 = this.context.mock(ShopCategory.class, "shop10sc3"); final Shop shop20 = this.context.mock(Shop.class, "shop20"); final ShopCategory shop20sc1 = this.context.mock(ShopCategory.class, "shop20sc1"); final ShopCategory shop20sc2 = this.context.mock(ShopCategory.class, "shop20sc2"); final Category c101 = this.context.mock(Category.class, "c101"); final Category c102 = this.context.mock(Category.class, "c102"); final Category c103 = this.context.mock(Category.class, "c103"); final Category c104 = this.context.mock(Category.class, "c104"); this.context.checking(new Expectations() {{ allowing(categoryDao).findQueryObjectByNamedQuery("CATEGORY.PARENT.LINK.ALL"); will(returnValue(dbCategories)); allowing(shopDao).findById(10L); will(returnValue(shop10)); allowing(shop10).getShopCategory(); will(returnValue(Arrays.asList(shop10sc1, shop10sc2, shop10sc3))); allowing(shop10sc1).getCategory(); will(returnValue(c101)); allowing(shop10sc2).getCategory(); will(returnValue(c102)); allowing(shop10sc3).getCategory(); will(returnValue(c103)); allowing(shopDao).findById(20L); will(returnValue(shop20)); allowing(shop20).getShopCategory(); will(returnValue(Arrays.asList(shop20sc1, shop20sc2))); allowing(shop20sc1).getCategory(); will(returnValue(c102)); allowing(shop20sc2).getCategory(); will(returnValue(c104)); allowing(c101).getCategoryId(); will(returnValue(101L)); allowing(c102).getCategoryId(); will(returnValue(102L)); allowing(c103).getCategoryId(); will(returnValue(103L)); allowing(c104).getCategoryId(); will(returnValue(104L)); }}); final ShopCategoryRelationshipSupportImpl support = new ShopCategoryRelationshipSupportImpl(shopDao, categoryDao) { @Override public ShopCategoryRelationshipSupport getSelf() { return this; } }; final Set<Long> shop10cats = support.getShopCategoriesIds(10); assertEquals(8, shop10cats.size()); assertTrue(shop10cats.containsAll(Arrays.asList(101L, 1010L, 1011L, 1012L, 102L, 1020L, 1021L, 103L))); final Set<Long> shop20cats = support.getShopCategoriesIds(20); assertEquals(12, shop20cats.size()); assertTrue(shop20cats.containsAll(Arrays.asList(102L, 1020L, 1021L, 104L, 1040L, 10400L, 10401L, 101L, 1010L, 1011L, 1012L, 10402L, 1021L))); this.context.assertIsSatisfied(); }
@Override public Set<Long> getShopCategoriesIds(final long shopId) { final Set<Long> result = new HashSet<>(); final Map<Long, Set<Long>> map = proxy().getAllCategoriesIdsMap(); final Shop shop = shopDao.findById(shopId); if (shop != null && shop.getShopCategory() != null) { for (final ShopCategory shopCategory : shop.getShopCategory()) { appendChildren(result, shopCategory.getCategory().getCategoryId(), map); } } else { LOG.warn(Markers.alert(), "Attempted to get shop categories for shop {} but it either does not exist or has null categories", shopId); } return Collections.unmodifiableSet(result); }
ShopCategoryRelationshipSupportImpl implements ShopCategoryRelationshipSupport { @Override public Set<Long> getShopCategoriesIds(final long shopId) { final Set<Long> result = new HashSet<>(); final Map<Long, Set<Long>> map = proxy().getAllCategoriesIdsMap(); final Shop shop = shopDao.findById(shopId); if (shop != null && shop.getShopCategory() != null) { for (final ShopCategory shopCategory : shop.getShopCategory()) { appendChildren(result, shopCategory.getCategory().getCategoryId(), map); } } else { LOG.warn(Markers.alert(), "Attempted to get shop categories for shop {} but it either does not exist or has null categories", shopId); } return Collections.unmodifiableSet(result); } }
ShopCategoryRelationshipSupportImpl implements ShopCategoryRelationshipSupport { @Override public Set<Long> getShopCategoriesIds(final long shopId) { final Set<Long> result = new HashSet<>(); final Map<Long, Set<Long>> map = proxy().getAllCategoriesIdsMap(); final Shop shop = shopDao.findById(shopId); if (shop != null && shop.getShopCategory() != null) { for (final ShopCategory shopCategory : shop.getShopCategory()) { appendChildren(result, shopCategory.getCategory().getCategoryId(), map); } } else { LOG.warn(Markers.alert(), "Attempted to get shop categories for shop {} but it either does not exist or has null categories", shopId); } return Collections.unmodifiableSet(result); } ShopCategoryRelationshipSupportImpl(final GenericDAO<Shop, Long> shopDao,
                                               final GenericDAO<Category, Long> categoryDao); }
ShopCategoryRelationshipSupportImpl implements ShopCategoryRelationshipSupport { @Override public Set<Long> getShopCategoriesIds(final long shopId) { final Set<Long> result = new HashSet<>(); final Map<Long, Set<Long>> map = proxy().getAllCategoriesIdsMap(); final Shop shop = shopDao.findById(shopId); if (shop != null && shop.getShopCategory() != null) { for (final ShopCategory shopCategory : shop.getShopCategory()) { appendChildren(result, shopCategory.getCategory().getCategoryId(), map); } } else { LOG.warn(Markers.alert(), "Attempted to get shop categories for shop {} but it either does not exist or has null categories", shopId); } return Collections.unmodifiableSet(result); } ShopCategoryRelationshipSupportImpl(final GenericDAO<Shop, Long> shopDao,
                                               final GenericDAO<Category, Long> categoryDao); @Override List<Shop> getAll(); @Override Category getCategoryById(final long pk); @Override CategoryRelationDTO getCategoryRelationById(final long categoryId); @Override Set<Long> getCategoryParentsIds(final long categoryId); @Override Set<Long> getCategoryLinkedIds(long categoryId); @Override Map<Long, Set<Long>> getAllCategoriesIdsMap(); @Override Set<Long> getShopCategoriesIds(final long shopId); @Override Set<Long> getCatalogCategoriesIds(final long branchId); ShopCategoryRelationshipSupport getSelf(); }
ShopCategoryRelationshipSupportImpl implements ShopCategoryRelationshipSupport { @Override public Set<Long> getShopCategoriesIds(final long shopId) { final Set<Long> result = new HashSet<>(); final Map<Long, Set<Long>> map = proxy().getAllCategoriesIdsMap(); final Shop shop = shopDao.findById(shopId); if (shop != null && shop.getShopCategory() != null) { for (final ShopCategory shopCategory : shop.getShopCategory()) { appendChildren(result, shopCategory.getCategory().getCategoryId(), map); } } else { LOG.warn(Markers.alert(), "Attempted to get shop categories for shop {} but it either does not exist or has null categories", shopId); } return Collections.unmodifiableSet(result); } ShopCategoryRelationshipSupportImpl(final GenericDAO<Shop, Long> shopDao,
                                               final GenericDAO<Category, Long> categoryDao); @Override List<Shop> getAll(); @Override Category getCategoryById(final long pk); @Override CategoryRelationDTO getCategoryRelationById(final long categoryId); @Override Set<Long> getCategoryParentsIds(final long categoryId); @Override Set<Long> getCategoryLinkedIds(long categoryId); @Override Map<Long, Set<Long>> getAllCategoriesIdsMap(); @Override Set<Long> getShopCategoriesIds(final long shopId); @Override Set<Long> getCatalogCategoriesIds(final long branchId); ShopCategoryRelationshipSupport getSelf();  }