@Test public void createValidateAttributeValueListCreateRequestMissingRequiredParameters() { // Try to call the method under test. try { attributeValueListHelper.validateAttributeValueListCreateRequest(null); } catch (IllegalArgumentException e) { assertEquals("An attribute value list create request must be specified.", e.getMessage()); } // Verify the external calls. verifyNoMoreInteractions(alternateKeyHelper); }
/** * Validates an attribute value list create request. * * @param attributeValueListCreateRequest the attribute value list request */ public void validateAttributeValueListCreateRequest(AttributeValueListCreateRequest attributeValueListCreateRequest) { Assert.notNull(attributeValueListCreateRequest, "An attribute value list create request must be specified."); validateAttributeValueListKey(attributeValueListCreateRequest.getAttributeValueListKey()); }
/** * Validates an attribute value list create request. * * @param attributeValueListCreateRequest the attribute value list request */ public void validateAttributeValueListCreateRequest(AttributeValueListCreateRequest attributeValueListCreateRequest) { Assert.notNull(attributeValueListCreateRequest, "An attribute value list create request must be specified."); validateAttributeValueListKey(attributeValueListCreateRequest.getAttributeValueListKey()); }
@Test public void createValidateAttributeValueListCreateRequest() { // Create an attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // Create an attribute value list create request. AttributeValueListCreateRequest request = new AttributeValueListCreateRequest(attributeValueListKey); // Mock calls to external methods. when(alternateKeyHelper.validateStringParameter("namespace", ATTRIBUTE_VALUE_LIST_NAMESPACE)).thenReturn(ATTRIBUTE_VALUE_LIST_NAMESPACE); when(alternateKeyHelper.validateStringParameter("An", "attribute value list name", ATTRIBUTE_VALUE_LIST_NAME)).thenReturn(ATTRIBUTE_VALUE_LIST_NAME); // Call the method under test. attributeValueListHelper.validateAttributeValueListCreateRequest(request); // Verify the external calls. verify(alternateKeyHelper).validateStringParameter("namespace", ATTRIBUTE_VALUE_LIST_NAMESPACE); verify(alternateKeyHelper).validateStringParameter("An", "attribute value list name", ATTRIBUTE_VALUE_LIST_NAME); verifyNoMoreInteractions(alternateKeyHelper); // Validate the result. assertEquals(new AttributeValueListCreateRequest(attributeValueListKey), request); }
@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.READ) @Override public AttributeValueList getAttributeValueList(AttributeValueListKey attributeValueListKey) { // Perform validation and trim. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that an attribute value list already exists with the specified key. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Create and return the attribute value list object from the deleted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public AttributeValueList createAttributeValueList(AttributeValueListCreateRequest request) { // Validate and trim the request parameters. attributeValueListHelper.validateAttributeValueListCreateRequest(request); // Get the attribute value list key. AttributeValueListKey attributeValueListKey = request.getAttributeValueListKey(); // Retrieve the namespace entity and validate it exists. NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getAttributeValueListKey().getNamespace()); // Validate the attribute value list does not already exist. if (attributeValueListDao.getAttributeValueListByKey(request.getAttributeValueListKey()) != null) { throw new AlreadyExistsException(String .format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", attributeValueListKey.getAttributeValueListName(), attributeValueListKey.getNamespace())); } // Create and persist a new attribute value list entity from the request information. AttributeValueListEntity attributeValueListEntity = createAttributeValueListEntity(request, namespaceEntity); // Create and return the attribute value list object from the persisted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.READ) @Override public AttributeValueList getAttributeValueList(AttributeValueListKey attributeValueListKey) { // Perform validation and trim. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that an attribute value list already exists with the specified key. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Create and return the attribute value list object from the deleted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public AttributeValueList createAttributeValueList(AttributeValueListCreateRequest request) { // Validate and trim the request parameters. attributeValueListHelper.validateAttributeValueListCreateRequest(request); // Get the attribute value list key. AttributeValueListKey attributeValueListKey = request.getAttributeValueListKey(); // Retrieve the namespace entity and validate it exists. NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getAttributeValueListKey().getNamespace()); // Validate the attribute value list does not already exist. if (attributeValueListDao.getAttributeValueListByKey(request.getAttributeValueListKey()) != null) { throw new AlreadyExistsException(String .format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", attributeValueListKey.getAttributeValueListName(), attributeValueListKey.getNamespace())); } // Create and persist a new attribute value list entity from the request information. AttributeValueListEntity attributeValueListEntity = createAttributeValueListEntity(request, namespaceEntity); // Create and return the attribute value list object from the persisted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
/** * Validates the allowed attribute values create request. This method also trims request parameters. * * @param request the allowed attribute values create request * * @throws IllegalArgumentException if any validation errors were found */ private void validateAllowedAttributeValuesCreateRequest(AllowedAttributeValuesCreateRequest request) { Assert.notNull(request, "An allowed attribute value create request must be specified."); // Perform validation and trim of the attribute value list key. attributeValueListHelper.validateAttributeValueListKey(request.getAttributeValueListKey()); // Perform validation and trim of the allowed attribute values. request.setAllowedAttributeValues(validateAllowedAttributeValues(request.getAllowedAttributeValues())); }
verify(attributeValueListHelper).validateAttributeValueListCreateRequest(request); verify(namespaceDaoHelper).getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE); verify(attributeValueListDao).getAttributeValueListByKey(attributeValueListKey);
/** * Validates the allowed attribute values delete request. This method also trims request parameters. * * @param request the allowed attribute values delete request * * @throws IllegalArgumentException if any validation errors were found */ private void validateAllowedAttributeValuesDeleteRequest(AllowedAttributeValuesDeleteRequest request) { Assert.notNull(request, "An allowed attribute value delete request must be specified."); // Perform validation and trim of the attribute value list key. attributeValueListHelper.validateAttributeValueListKey(request.getAttributeValueListKey()); // Perform validation and trim of allowed attribute values. request.setAllowedAttributeValues(validateAllowedAttributeValues(request.getAllowedAttributeValues())); } }
@Test public void createAttributeValueListAlreadyExists() { // Create an attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // Create an attribute value list create request. AttributeValueListCreateRequest request = new AttributeValueListCreateRequest(attributeValueListKey); // Mock calls to external methods. when(namespaceDaoHelper.getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE)).thenReturn(new NamespaceEntity()); when(attributeValueListDao.getAttributeValueListByKey(attributeValueListKey)).thenReturn(new AttributeValueListEntity()); // Try to call the method under test. try { attributeValueListService.createAttributeValueList(request); fail(); } catch (AlreadyExistsException e) { assertEquals(String .format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", ATTRIBUTE_VALUE_LIST_NAME, ATTRIBUTE_VALUE_LIST_NAMESPACE), e.getMessage()); } // Verify the external calls. verify(attributeValueListHelper).validateAttributeValueListCreateRequest(request); verify(namespaceDaoHelper).getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE); verify(attributeValueListDao).getAttributeValueListByKey(attributeValueListKey); verifyNoMoreInteractionsHelper(); }
/** * Validates the allowed attribute values create request. This method also trims request parameters. * * @param request the allowed attribute values create request * * @throws IllegalArgumentException if any validation errors were found */ private void validateAllowedAttributeValuesCreateRequest(AllowedAttributeValuesCreateRequest request) { Assert.notNull(request, "An allowed attribute value create request must be specified."); // Perform validation and trim of the attribute value list key. attributeValueListHelper.validateAttributeValueListKey(request.getAttributeValueListKey()); // Perform validation and trim of the allowed attribute values. request.setAllowedAttributeValues(validateAllowedAttributeValues(request.getAllowedAttributeValues())); }
/** * Validates the allowed attribute values delete request. This method also trims request parameters. * * @param request the allowed attribute values delete request * * @throws IllegalArgumentException if any validation errors were found */ private void validateAllowedAttributeValuesDeleteRequest(AllowedAttributeValuesDeleteRequest request) { Assert.notNull(request, "An allowed attribute value delete request must be specified."); // Perform validation and trim of the attribute value list key. attributeValueListHelper.validateAttributeValueListKey(request.getAttributeValueListKey()); // Perform validation and trim of allowed attribute values. request.setAllowedAttributeValues(validateAllowedAttributeValues(request.getAllowedAttributeValues())); } }
@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override public AttributeValueList deleteAttributeValueList(AttributeValueListKey attributeValueListKey) { // Perform validation and trim. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that an attribute value list already exists with the specified key. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Delete the attribute value list. attributeValueListDao.delete(attributeValueListEntity); // Create and return the attribute value list object from the deleted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override public AttributeValueList deleteAttributeValueList(AttributeValueListKey attributeValueListKey) { // Perform validation and trim. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that an attribute value list already exists with the specified key. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Delete the attribute value list. attributeValueListDao.delete(attributeValueListEntity); // Create and return the attribute value list object from the deleted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
/** * Validates the global Attribute Definition create request. This method also trims the request parameters. Currently only format level is supported * * @param request the global Attribute Definition create request * * @throws IllegalArgumentException throws exception if any other level other than format is specified */ private void validateGlobalAttributeDefinitionCreateRequest(GlobalAttributeDefinitionCreateRequest request) { Assert.notNull(request, "A global attribute definition create request must be specified."); globalAttributeDefinitionHelper.validateGlobalAttributeDefinitionKey(request.getGlobalAttributeDefinitionKey()); if (!GlobalAttributeDefinitionLevelEntity.GlobalAttributeDefinitionLevels.BUS_OBJCT_FRMT.name() .equalsIgnoreCase(request.getGlobalAttributeDefinitionKey().getGlobalAttributeDefinitionLevel())) { throw new IllegalArgumentException(String.format("Global attribute definition with level \"%s\" is not supported.", request.getGlobalAttributeDefinitionKey().getGlobalAttributeDefinitionLevel())); } if (request.getAttributeValueListKey() != null) { attributeValueListHelper.validateAttributeValueListKey(request.getAttributeValueListKey()); } }
@Test public void createValidateAttributeValueListKeyMissingRequiredParameters() { // Try to call the method under test. try { attributeValueListHelper.validateAttributeValueListKey(null); } catch (IllegalArgumentException e) { assertEquals("An attribute value list key must be specified.", e.getMessage()); } // Verify the external calls. verifyNoMoreInteractions(alternateKeyHelper); } }
/** * Retrieves existing allowed attribute values based on the specified key * * @param attributeValueListKey the attribute value list key * * @return the allowed attribute values information */ @NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.READ) @Override public AllowedAttributeValuesInformation getAllowedAttributeValues(AttributeValueListKey attributeValueListKey) { // Perform validation and trim of the input parameters. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that a attribute value list exists with the specified name. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Retrieve a list of allowed attribute values. List<AllowedAttributeValueEntity> allowedAttributeValueEntities = allowedAttributeValueDao.getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey); return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, allowedAttributeValueEntities); }
/** * Validates the global Attribute Definition create request. This method also trims the request parameters. Currently only format level is supported * * @param request the global Attribute Definition create request * * @throws IllegalArgumentException throws exception if any other level other than format is specified */ private void validateGlobalAttributeDefinitionCreateRequest(GlobalAttributeDefinitionCreateRequest request) { Assert.notNull(request, "A global attribute definition create request must be specified."); globalAttributeDefinitionHelper.validateGlobalAttributeDefinitionKey(request.getGlobalAttributeDefinitionKey()); if (!GlobalAttributeDefinitionLevelEntity.GlobalAttributeDefinitionLevels.BUS_OBJCT_FRMT.name() .equalsIgnoreCase(request.getGlobalAttributeDefinitionKey().getGlobalAttributeDefinitionLevel())) { throw new IllegalArgumentException(String.format("Global attribute definition with level \"%s\" is not supported.", request.getGlobalAttributeDefinitionKey().getGlobalAttributeDefinitionLevel())); } if (request.getAttributeValueListKey() != null) { attributeValueListHelper.validateAttributeValueListKey(request.getAttributeValueListKey()); } }