/** * 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()); }
@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 = "#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); }
/** * 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())); } }
/** * 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); }
@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); } }
/** * 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()); } }
/** * 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()); } }
/** * 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); }
@Test public void createValidateAttributeValueListKey() { // Create an attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // 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.validateAttributeValueListKey(attributeValueListKey); // 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 AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME), attributeValueListKey); }
@Test public void testDeleteAllowedAttributeValuesMissingAllowedAttributeValue() { // Create attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // Create a delete request without allowed attribute value. AllowedAttributeValuesDeleteRequest request = new AllowedAttributeValuesDeleteRequest(attributeValueListKey, NO_ALLOWED_ATTRIBUTE_VALUES); // Try to call method under test. try { allowedAttributeValueService.deleteAllowedAttributeValues(request); fail(); } catch (IllegalArgumentException e) { assertEquals("At least one allowed attribute value must be specified.", e.getMessage()); } // Verify the external calls. verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey); verifyNoMoreInteractionsHelper(); }
@Test public void testCreateAllowedAttributeValuesMissingAllowedAttributeValue() { // Create attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // Create the request without allowed attribute values. AllowedAttributeValuesCreateRequest request = new AllowedAttributeValuesCreateRequest(attributeValueListKey, NO_ALLOWED_ATTRIBUTE_VALUES); // Try to call method under test. try { allowedAttributeValueService.createAllowedAttributeValues(request); fail(); } catch (IllegalArgumentException e) { assertEquals("At least one allowed attribute value must be specified.", e.getMessage()); } // Verify the external calls. verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey); verifyNoMoreInteractionsHelper(); }
@Test public void testDeleteAttributeValueList() { // Create an attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // Create a namespace entity. NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE); // Create an attribute value list entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); // Mock calls to external methods. when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity); when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod(); // Call the method under test. AttributeValueList result = attributeValueListService.deleteAttributeValueList(attributeValueListKey); // Verify the external calls. verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey); verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey); verify(attributeValueListDao).delete(attributeValueListEntity); verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity); verifyNoMoreInteractionsHelper(); // Validate the result. assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result); }
@Test public void testGetAttributeValueList() { // Create an attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // Create a namespace entity. NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE); // Create an attribute value list entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); // Mock calls to external methods. when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity); when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod(); // Call the method under test. AttributeValueList result = attributeValueListService.getAttributeValueList(attributeValueListKey); // Verify the external calls. verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey); verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey); verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity); verifyNoMoreInteractionsHelper(); // Validate the result. assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result); }