Search in sources :

Example 1 with TagUpdateRequest

use of org.finra.herd.model.api.xml.TagUpdateRequest in project herd by FINRAOS.

the class TagRestControllerTest method testUpdateTag.

@Test
public void testUpdateTag() {
    // Create a parent tag key.
    TagKey parentTagKey = new TagKey(TAG_TYPE, TAG_CODE);
    TagUpdateRequest request = new TagUpdateRequest(TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, parentTagKey);
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE_2);
    Tag tag = getNewTag(tagKey);
    when(tagService.updateTag(tagKey, request)).thenReturn(tag);
    // Update the tag.
    Tag updatedTag = tagRestController.updateTag(TAG_TYPE, TAG_CODE_2, request);
    // Verify the external calls.
    verify(tagService).updateTag(tagKey, request);
    verifyNoMoreInteractions(tagService);
    // Validate the returned object.
    assertEquals(tag, updatedTag);
    ;
}
Also used : TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) Test(org.junit.Test)

Example 2 with TagUpdateRequest

use of org.finra.herd.model.api.xml.TagUpdateRequest in project herd by FINRAOS.

the class TagServiceTest method testUpdateTag.

@Test
public void testUpdateTag() {
    // Create a parent tag key.
    TagKey parentTagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create a parent tag entity.
    tagDaoTestHelper.createTagEntity(parentTagKey, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE_2);
    // Create and persist a tag entity without a parent tag.
    TagEntity tagEntity = tagDaoTestHelper.createTagEntity(tagKey, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2);
    // Update the tag.
    Tag updatedTag = tagService.updateTag(tagKey, new TagUpdateRequest(TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, parentTagKey));
    // Validate the returned object.
    assertEquals(new Tag(tagEntity.getId(), tagKey, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, tagEntity.getCreatedBy(), tagEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(tagEntity.getUpdatedOn()), parentTagKey, NO_TAG_HAS_CHILDREN_FLAG), updatedTag);
}
Also used : TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) Test(org.junit.Test)

Example 3 with TagUpdateRequest

use of org.finra.herd.model.api.xml.TagUpdateRequest in project herd by FINRAOS.

the class TagServiceTest method testUpdateTagNoChangesToDisplayNameExceptForCase.

@Test
public void testUpdateTagNoChangesToDisplayNameExceptForCase() {
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create and persist a tag entity.
    TagEntity tagEntity = tagDaoTestHelper.createTagEntity(tagKey, TAG_DISPLAY_NAME.toUpperCase(), TAG_DESCRIPTION);
    // Update the tag without changing it's display name except for the case.
    Tag updatedTag = tagService.updateTag(tagKey, new TagUpdateRequest(TAG_DISPLAY_NAME.toLowerCase(), TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, NO_PARENT_TAG_KEY));
    // Validate the returned object.
    assertEquals(new Tag(tagEntity.getId(), tagKey, TAG_DISPLAY_NAME.toLowerCase(), TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, tagEntity.getCreatedBy(), tagEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(tagEntity.getUpdatedOn()), NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG), updatedTag);
}
Also used : TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) Test(org.junit.Test)

Example 4 with TagUpdateRequest

use of org.finra.herd.model.api.xml.TagUpdateRequest in project herd by FINRAOS.

the class TagServiceTest method testUpdateTagParentTagIsChild.

@Test
public void testUpdateTagParentTagIsChild() {
    // Create and persist a root tag entity.
    TagEntity rootTagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
    // Create a child tag entity.
    TagEntity childTagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE_2, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, rootTagEntity);
    // Create a grandchild tag entity.
    TagEntity grandchildTagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE_3, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, childTagEntity);
    // Try to update the root tag using a parent tag set to the tag itself and it's children.
    for (TagEntity tagEntity : Arrays.asList(rootTagEntity, childTagEntity, grandchildTagEntity)) {
        try {
            tagService.updateTag(new TagKey(TAG_TYPE, TAG_CODE), new TagUpdateRequest(TAG_DISPLAY_NAME_4, TAG_SEARCH_SCORE_MULTIPLIER_4, TAG_DESCRIPTION_4, new TagKey(tagEntity.getTagType().getCode(), tagEntity.getTagCode())));
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals("Parent tag key cannot be the requested tag key or any of its children’s tag keys.", e.getMessage());
        }
    }
}
Also used : TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Example 5 with TagUpdateRequest

use of org.finra.herd.model.api.xml.TagUpdateRequest in project herd by FINRAOS.

the class TagServiceTest method testUpdateTagNoChangesToDisplayName.

@Test
public void testUpdateTagNoChangesToDisplayName() {
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create and persist a tag entity.
    TagEntity tagEntity = tagDaoTestHelper.createTagEntity(tagKey, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
    // Update the tag without changing it's display name except for the case.
    Tag updatedTag = tagService.updateTag(tagKey, new TagUpdateRequest(TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, NO_PARENT_TAG_KEY));
    // Validate the returned object.
    assertEquals(new Tag(tagEntity.getId(), tagKey, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, tagEntity.getCreatedBy(), tagEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(tagEntity.getUpdatedOn()), NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG), updatedTag);
}
Also used : TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) Test(org.junit.Test)

Aggregations

TagKey (org.finra.herd.model.api.xml.TagKey)17 TagUpdateRequest (org.finra.herd.model.api.xml.TagUpdateRequest)17 Test (org.junit.Test)17 TagEntity (org.finra.herd.model.jpa.TagEntity)11 Tag (org.finra.herd.model.api.xml.Tag)10 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 HashMap (java.util.HashMap)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1