/** * Creates a new tag type. * * @param request the information needed to create the tag type * * @return the created tag type */ @RequestMapping(value = TAG_TYPES_URI_PREFIX, method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_TAG_TYPES_POST) public TagType createTagType(@RequestBody TagTypeCreateRequest request) { return tagTypeService.createTagType(request); }
/** * Creates a new tag type. * * @param request the information needed to create the tag type * * @return the created tag type */ @RequestMapping(value = TAG_TYPES_URI_PREFIX, method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_TAG_TYPES_POST) public TagType createTagType(@RequestBody TagTypeCreateRequest request) { return tagTypeService.createTagType(request); }
@Test public void testCreateTagType() throws Exception { TagTypeCreateRequest request = new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); TagType tagType = new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); when(tagTypeService.createTagType(request)).thenReturn(tagType); // Create a tag type. TagType resultTagType = tagTypeRestController .createTagType(new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION)); // Verify the external calls. verify(tagTypeService).createTagType(request); verifyNoMoreInteractions(tagTypeService); // Validate the returned object. assertEquals(tagType, resultTagType); }
@Test public void testCreateTagTypeInvalidParameters() { // Try to create a tag type instance when tag type code contains a forward slash character. try { tagTypeService .createTagType(new TagTypeCreateRequest(new TagTypeKey(addSlash(TAG_TYPE)), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION)); fail(); } catch (IllegalArgumentException e) { assertEquals("Tag type code can not contain a forward slash character.", e.getMessage()); } }
@Test public void testCreateTagTypeTagTypeAlreadyExists() { // Create and persist a tag type entity. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); // Try to create a duplicate tag type instance (uses the same tag type code). try { tagTypeService.createTagType(new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2)); fail(); } catch (AlreadyExistsException e) { assertEquals(String.format("Unable to create tag type with code \"%s\" because it already exists.", TAG_TYPE), e.getMessage()); } }
tagTypeService.createTagType(new TagTypeCreateRequest(new TagTypeKey(BLANK_TEXT), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION)); fail(); tagTypeService.createTagType(new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE), BLANK_TEXT, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION)); fail(); tagTypeService.createTagType(new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME, null, TAG_TYPE_DESCRIPTION)); fail();
@Test public void testCreateTagTypeDisplayNameAlreadyExists() { // Create and persist a tag type entity. tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); // Try to create a duplicate tag type instance (uses the same display name). try { tagTypeService.createTagType(new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE_2), TAG_TYPE_DISPLAY_NAME, 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, TAG_TYPE), e.getMessage()); } }
@Test public void testCreateTagType() throws Exception { // Create a tag type. TagType resultTagType = tagTypeService.createTagType(new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION)); // Validate the returned object. assertEquals(new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION), resultTagType); }
@Test public void testCreateTagTypeTrimParameters() throws Exception { // Create a tag type using input parameters with leading and trailing empty spaces. TagType resultTagType = tagTypeService.createTagType( new TagTypeCreateRequest(new TagTypeKey(addWhitespace(TAG_TYPE)), addWhitespace(TAG_TYPE_DISPLAY_NAME), TAG_TYPE_ORDER, addWhitespace(TAG_TYPE_DESCRIPTION))); // Validate the returned object. assertEquals(new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, addWhitespace(TAG_TYPE_DESCRIPTION)), resultTagType); }