@Test public void testAllSearchableAttributeCodes() { Set<String> codes = attributeService.getAllSearchableAttributeCodes(); assertNotNull(codes); assertFalse(codes.isEmpty()); Map<String, I18NModel> map = attributeService.getAttributeNamesByCodes(codes); assertNotNull(map); }
/** * Prove of availability to getByKey list of attributes, that can have muptiple values within * given <code>attributeGroupCode</code>. */ @Test public void testFindAttributesWithMultipleValues2() { // product has 5 attributes with allowed multiple values List<Attribute> list = attributeService.findAttributesWithMultipleValues(AttributeGroupNames.PRODUCT); assertNotNull(list); assertEquals(5, list.size()); // shop has not attributes with multiple values list = attributeService.findAttributesWithMultipleValues(AttributeGroupNames.SHOP); assertNull(list); }
@Test public void testFindAvailableAttributes1() { List<Attribute> attrs = attributeService.findAvailableAttributes(AttributeGroupNames.PRODUCT, null); // getByKey all assertEquals(24, attrs.size()); List<String> assignedAttributes = new ArrayList<String>(); for (Attribute attr : attrs) { assignedAttributes.add(attr.getCode()); } attrs = attributeService.findAvailableAttributes(AttributeGroupNames.PRODUCT, assignedAttributes); assertEquals(0, attrs.size()); }
/** * Prove of availability to getByKey list of available attributes within given <code> * attributeGroupCode</code>, that can be assigned to business entity. */ @Test public void testFindAvailableAttributes2() { List<String> allCodes = Arrays.asList( "URI", "CATEGORY_ITEMS_PER_PAGE", "CATEGORY_IMAGE_RETRIEVE_STRATEGY", "CATEGORY_IMAGE0", "CATEGORY_DESCRIPTION_en", "CATEGORY_DESCRIPTION_ru", "CONTENT_BODY_ru_1", "CONTENT_BODY_ru_2", "CONTENT_BODY_en_1", "CONTENT_BODY_en_2"); // getByKey all attributes available for category List<Attribute> attributes = attributeService.findAvailableAttributes(AttributeGroupNames.CATEGORY, null); assertNotNull(attributes); assertFalse(attributes.isEmpty()); for (Attribute attr : attributes) { assertTrue(allCodes.contains(attr.getCode())); } // category already has all attributes attributes = attributeService.findAvailableAttributes(AttributeGroupNames.CATEGORY, allCodes); assertNotNull(attributes); assertTrue(attributes.isEmpty()); // get all except URI attributes = attributeService.findAvailableAttributes( AttributeGroupNames.CATEGORY, Arrays.asList("URI")); assertNotNull(attributes); assertFalse(attributes.isEmpty()); assertEquals("CATEGORY_ITEMS_PER_PAGE", attributes.get(0).getCode()); // get just URI attributes = attributeService.findAttributesByCodes(AttributeGroupNames.CATEGORY, Arrays.asList("URI")); assertNotNull(attributes); assertFalse(attributes.isEmpty()); assertEquals("URI", attributes.get(0).getCode()); }
/** {@inheritDoc} */ @Override public boolean doImageImport( final JobStatusListener statusListener, final String fileName, final String code, final String suffix, final String locale) { final Category category = categoryService.findCategoryIdBySeoUriOrGuid(code); if (category == null) { final String warn = MessageFormat.format("category with code {0} not found.", code); statusListener.notifyWarning(warn); return false; } validateAccessBeforeUpdate(category, Category.class); final String attributeCode = AttributeNamesKeys.Category.CATEGORY_IMAGE_PREFIX + suffix + (StringUtils.isNotEmpty(locale) ? "_" + locale : ""); AttrValueCategory imageAttributeValue = (AttrValueCategory) category.getAttributeByCode(attributeCode); if (imageAttributeValue == null) { final List<Attribute> imageAttributes = attributeService.getAvailableImageAttributesByGroupCode(AttributeGroupNames.CATEGORY); Attribute attribute = null; for (final Attribute imageAttribute : imageAttributes) { if (attributeCode.equals(imageAttribute.getCode())) { attribute = imageAttribute; break; } } if (attribute == null) { final String warn = MessageFormat.format("attribute with code {0} not found.", attributeCode); statusListener.notifyWarning(warn); return false; } imageAttributeValue = categoryService.getGenericDao().getEntityFactory().getByIface(AttrValueCategory.class); imageAttributeValue.setCategory(category); imageAttributeValue.setAttribute(attribute); category.getAttributes().add(imageAttributeValue); } else if (isInsertOnly()) { return false; } imageAttributeValue.setVal(fileName); final String info = MessageFormat.format( "file {0} attached as {1} to category {2}", fileName, attributeCode, category.getName()); statusListener.notifyMessage(info); try { categoryService.update(category); return true; } catch (DataIntegrityViolationException e) { final String err = MessageFormat.format( "image {0} for category with code {1} could not be added (db error).", fileName, category.getGuid()); statusListener.notifyError(err, e); return false; } }
@Test public void testFindAttributesWithMultipleValues1() { assertEquals( 5, attributeService.findAttributesWithMultipleValues(AttributeGroupNames.PRODUCT).size()); }
@Test public void testFindByAttributeCode() { Attribute attrs = attributeService.findByAttributeCode(AttributeNamesKeys.CUSTOMER_PHONE); assertNotNull(attrs); }
// TODO: YC-64 fix to not depend on order or running @Test public void testFindByAttributeGroupCode() { List<Attribute> attrs = attributeService.findByAttributeGroupCode(AttributeGroupNames.CUSTOMER); assertEquals(1, attrs.size()); }