@Test public void testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsAttributeNamesEqualIgnoreCase() { // Create a business object data attribute definition for a required attribute with attribute name in upper case. BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity(); businessObjectDataAttributeDefinitionEntity.setName(ATTRIBUTE_NAME.toUpperCase()); // Call the method under test with the attribute name specified in lowercase. attributeDaoHelper .validateAttributesAgainstBusinessObjectDataAttributeDefinitions(Arrays.asList(new Attribute(ATTRIBUTE_NAME.toLowerCase(), ATTRIBUTE_VALUE)), Arrays.asList(businessObjectDataAttributeDefinitionEntity)); // Verify the external calls. verifyNoMoreInteractionsHelper(); }
@NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override public BusinessObjectData updateBusinessObjectDataAttributes(BusinessObjectDataKey businessObjectDataKey, BusinessObjectDataAttributesUpdateRequest businessObjectDataAttributesUpdateRequest) { // Validate and trim the business object data key. businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true); // Validate the update request. Assert.notNull(businessObjectDataAttributesUpdateRequest, "A business object data attributes update request must be specified."); Assert.notNull(businessObjectDataAttributesUpdateRequest.getAttributes(), "A list of business object data attributes must be specified."); List<Attribute> attributes = businessObjectDataAttributesUpdateRequest.getAttributes(); // Validate attributes. This is also going to trim the attribute names. attributeHelper.validateAttributes(attributes); // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey); // Validate attributes against attribute definitions. attributeDaoHelper.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(attributes, businessObjectDataEntity.getBusinessObjectFormat().getAttributeDefinitions()); // Update the attributes. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes); // Persist and refresh the entity. businessObjectDataEntity = businessObjectDataDao.saveAndRefresh(businessObjectDataEntity); // Create and return the business object data object from the persisted entity. return businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity); }
@NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override public BusinessObjectData updateBusinessObjectDataAttributes(BusinessObjectDataKey businessObjectDataKey, BusinessObjectDataAttributesUpdateRequest businessObjectDataAttributesUpdateRequest) { // Validate and trim the business object data key. businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true); // Validate the update request. Assert.notNull(businessObjectDataAttributesUpdateRequest, "A business object data attributes update request must be specified."); Assert.notNull(businessObjectDataAttributesUpdateRequest.getAttributes(), "A list of business object data attributes must be specified."); List<Attribute> attributes = businessObjectDataAttributesUpdateRequest.getAttributes(); // Validate attributes. This is also going to trim the attribute names. attributeHelper.validateAttributes(attributes); // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey); // Validate attributes against attribute definitions. attributeDaoHelper.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(attributes, businessObjectDataEntity.getBusinessObjectFormat().getAttributeDefinitions()); // Update the attributes. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes); // Persist and refresh the entity. businessObjectDataEntity = businessObjectDataDao.saveAndRefresh(businessObjectDataEntity); // Create and return the business object data object from the persisted entity. return businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity); }
@Test public void testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsRequiredAttributeIsMissing() { // Create a business object data attribute definition for a required attribute. BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity(); businessObjectDataAttributeDefinitionEntity.setName(ATTRIBUTE_NAME); // Try to call the method under test. 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()); } // Verify the external calls. verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsRequiredAttributeHasBlankValue() { // Create a business object data attribute definition for a required attribute. BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity(); businessObjectDataAttributeDefinitionEntity.setName(ATTRIBUTE_NAME); // Try to call the method under test. 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()); } // Verify the external calls. verifyNoMoreInteractionsHelper(); }
verify(attributeHelper).validateAttributes(attributes); verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey); verify(attributeDaoHelper).validateAttributesAgainstBusinessObjectDataAttributeDefinitions(attributes, attributeDefinitionEntities); verify(attributeDaoHelper).updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes); verify(businessObjectDataDao).saveAndRefresh(businessObjectDataEntity);
.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(request.getAttributes(), businessObjectFormatEntity.getAttributeDefinitions());
.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(request.getAttributes(), businessObjectFormatEntity.getAttributeDefinitions());