AttributeDaoHelper { public void updateBusinessObjectDataAttributes(BusinessObjectDataEntity businessObjectDataEntity, final List<Attribute> attributes) { Map<String, BusinessObjectDataAttributeEntity> existingAttributeEntities = new HashMap<>(); for (BusinessObjectDataAttributeEntity attributeEntity : businessObjectDataEntity.getAttributes()) { String mapKey = attributeEntity.getName().toLowerCase(); if (existingAttributeEntities.containsKey(mapKey)) { throw new IllegalStateException(String .format("Found duplicate attribute with name \"%s\" for business object data. Business object data: {%s}", mapKey, businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity))); } existingAttributeEntities.put(mapKey, attributeEntity); } List<BusinessObjectDataAttributeEntity> createdAttributeEntities = new ArrayList<>(); List<BusinessObjectDataAttributeEntity> retainedAttributeEntities = new ArrayList<>(); if (!CollectionUtils.isEmpty(attributes)) { for (Attribute attribute : attributes) { String lowercaseAttributeName = attribute.getName().toLowerCase(); if (existingAttributeEntities.containsKey(lowercaseAttributeName)) { BusinessObjectDataAttributeEntity attributeEntity = existingAttributeEntities.get(lowercaseAttributeName); if (!StringUtils.equals(attribute.getValue(), attributeEntity.getValue())) { attributeEntity.setValue(attribute.getValue()); } retainedAttributeEntities.add(attributeEntity); } else { BusinessObjectDataAttributeEntity attributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataEntity.getAttributes().add(attributeEntity); attributeEntity.setBusinessObjectData(businessObjectDataEntity); attributeEntity.setName(attribute.getName()); attributeEntity.setValue(attribute.getValue()); createdAttributeEntities.add(attributeEntity); } } } businessObjectDataEntity.getAttributes().retainAll(retainedAttributeEntities); businessObjectDataEntity.getAttributes().addAll(createdAttributeEntities); }  void updateBusinessObjectDataAttributes(BusinessObjectDataEntity businessObjectDataEntity, final List<Attribute> attributes); void validateAttributesAgainstBusinessObjectDataAttributeDefinitions(final List<Attribute> attributes,
        final Collection<BusinessObjectDataAttributeDefinitionEntity> businessObjectDataAttributeDefinitionEntities);  }
@Test public void testUpdateBusinessObjectDataAttributesAttributeAdded() { List<Attribute> attributes = Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE)); BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setAttributes(new ArrayList<>()); attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes); verifyNoMoreInteractionsHelper(); assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(businessObjectDataEntity, businessObjectDataAttributeEntity.getBusinessObjectData()); assertEquals(ATTRIBUTE_NAME, businessObjectDataAttributeEntity.getName()); assertEquals(ATTRIBUTE_VALUE, businessObjectDataAttributeEntity.getValue()); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeDeleted() { BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, NO_ATTRIBUTES); verifyNoMoreInteractionsHelper(); assertEquals(0, CollectionUtils.size(businessObjectDataEntity.getAttributes())); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueNotUpdated() { BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE))); verifyNoMoreInteractionsHelper(); assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME, result.getName()); assertEquals(ATTRIBUTE_VALUE, result.getValue()); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueUpdated() { BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE_2))); verifyNoMoreInteractionsHelper(); assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME, result.getName()); assertEquals(ATTRIBUTE_VALUE_2, result.getValue()); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueUpdatedAttributeNamesEqualIgnoreCase() { BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME.toUpperCase()); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); attributeDaoHelper .updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME.toLowerCase(), ATTRIBUTE_VALUE_2))); verifyNoMoreInteractionsHelper(); assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME.toUpperCase(), result.getName()); assertEquals(ATTRIBUTE_VALUE_2, result.getValue()); }
@Test public void testUpdateBusinessObjectDataAttributesDuplicateAttributes() { BusinessObjectDataAttributeEntity businessObjectDataAttributeEntityA = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntityA.setName(ATTRIBUTE_NAME.toUpperCase()); businessObjectDataAttributeEntityA.setValue(ATTRIBUTE_VALUE); BusinessObjectDataAttributeEntity businessObjectDataAttributeEntityB = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntityB.setName(ATTRIBUTE_NAME.toLowerCase()); businessObjectDataAttributeEntityB.setValue(ATTRIBUTE_VALUE_2); BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntityA); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntityB); when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); try { attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, NO_ATTRIBUTES); fail(); } catch (IllegalStateException e) { assertEquals(String .format("Found duplicate attribute with name \"%s\" for business object data. Business object data: {%s}", ATTRIBUTE_NAME.toLowerCase(), BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }