/** * Updates an existing tag type. * * @param tagTypeCode the tag type code * @param request the information needed to update the tag type * * @return the updated tag type */ @RequestMapping(value = TAG_TYPES_URI_PREFIX + "/{tagTypeCode}", method = RequestMethod.PUT, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_TAG_TYPES_PUT) public TagType updateTagType(@PathVariable("tagTypeCode") String tagTypeCode, @RequestBody TagTypeUpdateRequest request) { return tagTypeService.updateTagType(new TagTypeKey(tagTypeCode), request); } }
/** * Updates an existing tag type. * * @param tagTypeCode the tag type code * @param request the information needed to update the tag type * * @return the updated tag type */ @RequestMapping(value = TAG_TYPES_URI_PREFIX + "/{tagTypeCode}", method = RequestMethod.PUT, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_TAG_TYPES_PUT) public TagType updateTagType(@PathVariable("tagTypeCode") String tagTypeCode, @RequestBody TagTypeUpdateRequest request) { return tagTypeService.updateTagType(new TagTypeKey(tagTypeCode), request); } }
@Test public void testUpdateTagTypeLowerCaseParameters() { // Create and persist a tag type entity. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); // Update the tag type using lower case input parameters. TagType resultTagType = tagTypeService.updateTagType(new TagTypeKey(TAG_TYPE.toLowerCase()), new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME_2.toLowerCase(), TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2.toLowerCase())); // Validate the returned object. assertEquals(new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME_2.toLowerCase(), TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2.toLowerCase()), resultTagType); }
@Test public void testUpdateTagTypeUpperCaseParameters() { // Create and persist a tag type entity. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); // Update the tag type using upper case input parameters. TagType resultTagType = tagTypeService.updateTagType(new TagTypeKey(TAG_TYPE.toUpperCase()), new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME_2.toUpperCase(), TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2.toUpperCase())); // Validate the returned object. assertEquals(new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME_2.toUpperCase(), TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2.toUpperCase()), resultTagType); }
@Test public void testUpdateTagTypeNoChangesToDisplayNameExceptForCase() { // Create and persist a tag type entity. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, INTEGER_VALUE, TAG_TYPE_DESCRIPTION); // Update the tag type with the new display name that only changes case. TagType updatedTagType = tagTypeService .updateTagType(new TagTypeKey(TAG_TYPE), new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME.toLowerCase(), INTEGER_VALUE_2, TAG_TYPE_DESCRIPTION_2)); // Validate the returned object. assertEquals(new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME.toLowerCase(), INTEGER_VALUE_2, TAG_TYPE_DESCRIPTION_2), updatedTagType); }
@Test public void testUpdateTagType() throws Exception { TagTypeKey tagTypeKey = new TagTypeKey(TAG_TYPE); TagType tagType = new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2); TagTypeUpdateRequest request = new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2); when(tagTypeService.updateTagType(tagTypeKey, request)).thenReturn(tagType); // Retrieve the tag type. TagType resultTagType = tagTypeRestController.updateTagType(TAG_TYPE, request); // Validate the returned object. assertEquals(tagType, resultTagType); } }
@Test public void testUpdateTagTypeTagTypeNotExists() { // Try to update a tag type instance when display name is not specified. try { tagTypeService.updateTagType(new TagTypeKey(TAG_TYPE), new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION)); fail(); } catch (ObjectNotFoundException e) { assertEquals(String.format("Tag type with code \"%s\" doesn't exist.", TAG_TYPE), e.getMessage()); } }
.updateTagType(new TagTypeKey(BLANK_TEXT), new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2)); fail(); tagTypeService.updateTagType(new TagTypeKey(TAG_TYPE), new TagTypeUpdateRequest(BLANK_TEXT, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2)); fail(); tagTypeService.updateTagType(new TagTypeKey(TAG_TYPE), new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME_2, null, TAG_TYPE_DESCRIPTION_2)); fail();
@Test public void testUpdateTagTypeDisplayNameAlreadyExists() { // Create and persist two tag type entities with the second one having display name that we want to update to. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE_2, TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2); // Try to update a tag type instance when display name already exists. try { tagTypeService.updateTagType(new TagTypeKey(TAG_TYPE), new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2)); fail(); } catch (AlreadyExistsException e) { assertEquals(String.format("Display name \"%s\" already exists for tag type \"%s\".", TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_2), e.getMessage()); } }
@Test public void testUpdateTagType() { // Create and persist a tag type entity. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); // Update the tag type. TagType resultTagType = tagTypeService.updateTagType(new TagTypeKey(TAG_TYPE), new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2)); // Validate the returned object. assertEquals(new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2), resultTagType); }
@Test public void testUpdateTagTypeNoChangesToDisplayName() { // Create and persist a tag type entity. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, INTEGER_VALUE, TAG_TYPE_DESCRIPTION); // Update the tag type without changing the display name. TagType updatedTagType = tagTypeService.updateTagType(new TagTypeKey(TAG_TYPE), new TagTypeUpdateRequest(TAG_TYPE_DISPLAY_NAME, INTEGER_VALUE_2, TAG_TYPE_DESCRIPTION_2)); // Validate the returned object. assertEquals(new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME, INTEGER_VALUE_2, TAG_TYPE_DESCRIPTION_2), updatedTagType); }
@Test public void testUpdateTagTypeTrimParameters() { // Create and persist a tag type entity. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); // Update the tag type using input parameters with leading and trailing empty spaces. TagType resultTagType = tagTypeService.updateTagType(new TagTypeKey(addWhitespace(TAG_TYPE)), new TagTypeUpdateRequest(addWhitespace(TAG_TYPE_DISPLAY_NAME_2), TAG_TYPE_ORDER_2, addWhitespace(TAG_TYPE_DESCRIPTION_2))); // Validate the returned object. assertEquals(new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, addWhitespace(TAG_TYPE_DESCRIPTION_2)), resultTagType); }