AttributeDaoHelper { public void validateAttributesAgainstBusinessObjectDataAttributeDefinitions(final List<Attribute> attributes, final Collection<BusinessObjectDataAttributeDefinitionEntity> businessObjectDataAttributeDefinitionEntities) { Map<String, String> attributeMap = new HashMap<>(); if (!CollectionUtils.isEmpty(attributes)) { for (Attribute attribute : attributes) { attributeMap.put(attribute.getName().toLowerCase(), attribute.getValue()); } } for (BusinessObjectDataAttributeDefinitionEntity attributeDefinitionEntity : businessObjectDataAttributeDefinitionEntities) { String attributeDefinitionName = attributeDefinitionEntity.getName().toLowerCase(); if (!attributeMap.containsKey(attributeDefinitionName) || StringUtils.isBlank(attributeMap.get(attributeDefinitionName))) { throw new IllegalArgumentException(String .format("The business object format has a required attribute \"%s\" which was not specified or has a value which is blank.", attributeDefinitionEntity.getName())); } } }  void updateBusinessObjectDataAttributes(BusinessObjectDataEntity businessObjectDataEntity, final List<Attribute> attributes); void validateAttributesAgainstBusinessObjectDataAttributeDefinitions(final List<Attribute> attributes,
        final Collection<BusinessObjectDataAttributeDefinitionEntity> businessObjectDataAttributeDefinitionEntities);  }
@Test public void testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsAttributeNamesEqualIgnoreCase() { BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity(); businessObjectDataAttributeDefinitionEntity.setName(ATTRIBUTE_NAME.toUpperCase()); attributeDaoHelper .validateAttributesAgainstBusinessObjectDataAttributeDefinitions(Arrays.asList(new Attribute(ATTRIBUTE_NAME.toLowerCase(), ATTRIBUTE_VALUE)), Arrays.asList(businessObjectDataAttributeDefinitionEntity)); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsRequiredAttributeHasBlankValue() { BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity(); businessObjectDataAttributeDefinitionEntity.setName(ATTRIBUTE_NAME); try { attributeDaoHelper.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(Arrays.asList(new Attribute(ATTRIBUTE_NAME, BLANK_TEXT)), Arrays.asList(businessObjectDataAttributeDefinitionEntity)); fail(); } catch (IllegalArgumentException e) { assertEquals(String .format("The business object format has a required attribute \"%s\" which was not specified or has a value which is blank.", ATTRIBUTE_NAME), e.getMessage()); } verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsRequiredAttributeIsMissing() { BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity(); businessObjectDataAttributeDefinitionEntity.setName(ATTRIBUTE_NAME); try { attributeDaoHelper .validateAttributesAgainstBusinessObjectDataAttributeDefinitions(NO_ATTRIBUTES, Arrays.asList(businessObjectDataAttributeDefinitionEntity)); fail(); } catch (IllegalArgumentException e) { assertEquals(String .format("The business object format has a required attribute \"%s\" which was not specified or has a value which is blank.", ATTRIBUTE_NAME), e.getMessage()); } verifyNoMoreInteractionsHelper(); }