/** Tests populateParentCategory. */ @Test public void testPopulateParentCategory() { final Category mockCategory = context.mock(Category.class); final CategoryDTO categoryDto = new CategoryDTO(); categoryDto.setParentCategoryCode(null); categoryAdapter.populateParentCategory(mockCategory, categoryDto); categoryDto.setParentCategoryCode(""); categoryAdapter.populateParentCategory(mockCategory, categoryDto); context.checking( new Expectations() { { oneOf(mockCachingService).findCategoryByCode(PARENT_CATEGORY_CODE, CATALOG_CODE); will(returnValue(null)); oneOf(mockCategory).setParent(null); } }); categoryDto.setParentCategoryCode(PARENT_CATEGORY_CODE); categoryDto.setCatalogCode(CATALOG_CODE); categoryAdapter.populateParentCategory(mockCategory, categoryDto); }
/** Tests populateDomain. */ @Test public void testPopulateDomain() { final boolean storeVisible = false; final int categoryOrder = 1; final String categoryCode = "categoryCode"; final String categoryTypeCode = "categoryTypeCode"; final Map<Locale, LocaleDependantFields> localeDependantFieldsMap = new HashMap<Locale, LocaleDependantFields>(); final Catalog catalog = context.mock(Catalog.class); final CategoryType categoryType = context.mock(CategoryType.class); final Category mockCategory = context.mock(Category.class); final CategoryDTO categoryDto = new CategoryDTO(); CategoryAvailabilityDTO categoryAvailabilityDTO = new CategoryAvailabilityDTO(); categoryAvailabilityDTO.setStoreVisible(storeVisible); categoryAvailabilityDTO.setStartDate(START_DATE); categoryAvailabilityDTO.setEndDate(END_DATE); categoryDto.setCategoryCode(categoryCode); categoryDto.setOrder(categoryOrder); categoryDto.setCatalogCode(CATALOG_CODE); categoryDto.setParentCategoryCode(PARENT_CATEGORY_CODE); categoryDto.setCategoryType(categoryTypeCode); categoryDto.setCategoryAvailabilityDTO(categoryAvailabilityDTO); categoryDto.setAttributeGroupDTO(new AttributeGroupDTO()); categoryDto.setSeoDto(new SeoDTO()); context.checking( new Expectations() { { oneOf(mockCategory).setCode(categoryCode); oneOf(mockCategory).setOrdering(categoryOrder); oneOf(mockCategory).setCatalog(catalog); oneOf(mockCategory).setParent(null); oneOf(mockCategory).setCategoryType(categoryType); oneOf(mockCategory).setLocaleDependantFieldsMap(localeDependantFieldsMap); oneOf(mockCategory).setHidden(!storeVisible); oneOf(mockCategory).setStartDate(START_DATE); oneOf(mockCategory).setEndDate(END_DATE); } }); categoryAdapter = new CategoryAdapter() { @Override void populateMasterCatalog(final Category category, final String catalogCode) { assertEquals(CATALOG_CODE, catalogCode); category.setCatalog(catalog); } @Override void populateParentCategory(final Category category, final CategoryDTO categoryDto) { assertEquals(PARENT_CATEGORY_CODE, categoryDto.getParentCategoryCode()); category.setParent(null); // Could not find parent category with code } @Override void populateDomainNameValues(final Category category, final CategoryDTO categoryDto) { assertNotNull(categoryDto.getNameValues()); category.setLocaleDependantFieldsMap(localeDependantFieldsMap); } @Override void populateCategoryType(final Category category, final String categoryTypeName) { assertEquals(categoryTypeCode, categoryTypeName); category.setCategoryType(categoryType); } @Override void populateAvailability( final Category category, final CategoryAvailabilityDTO categoryAvailabilityDTO) { category.setHidden(!categoryAvailabilityDTO.isStoreVisible()); category.setStartDate(categoryAvailabilityDTO.getStartDate()); category.setEndDate(categoryAvailabilityDTO.getEndDate()); } @Override void populateNestedDomainObjects(final Category category, final CategoryDTO categoryDTO) { assertNotNull(category); assertNotNull(categoryDto); } }; categoryAdapter.setElasticPath(mockElasticPath); categoryAdapter.setCachingService(mockCachingService); categoryAdapter.populateDomain(categoryDto, mockCategory); }