Search in sources :

Example 11 with TagUpdateRequest

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

the class TagServiceTest method testUpdateTagMissingRequiredParameters.

@Test
public void testUpdateTagMissingRequiredParameters() {
    // Try to update a tag when tag type is not specified.
    try {
        tagService.updateTag(new TagKey(BLANK_TEXT, TAG_CODE), new TagUpdateRequest(TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, NO_PARENT_TAG_KEY));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A tag type code must be specified.", e.getMessage());
    }
    // Try to update a tag when tag code is not specified.
    try {
        tagService.updateTag(new TagKey(TAG_TYPE, BLANK_TEXT), new TagUpdateRequest(TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, NO_PARENT_TAG_KEY));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A tag code must be specified.", e.getMessage());
    }
    // Try to update a tag when tag display name is not specified.
    try {
        tagService.updateTag(new TagKey(TAG_TYPE, TAG_CODE), new TagUpdateRequest(BLANK_TEXT, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, NO_PARENT_TAG_KEY));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A display name must be specified.", e.getMessage());
    }
    // Try to update a tag when parent tag type is not specified.
    try {
        tagService.updateTag(new TagKey(TAG_TYPE, TAG_CODE_2), new TagUpdateRequest(TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, new TagKey(BLANK_TEXT, TAG_CODE)));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A tag type code must be specified.", e.getMessage());
    }
    // Try to update a tag when parent tag code is not specified.
    try {
        tagService.updateTag(new TagKey(TAG_TYPE, TAG_CODE_2), new TagUpdateRequest(TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, new TagKey(TAG_TYPE, BLANK_TEXT)));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A tag code must be specified.", e.getMessage());
    }
}
Also used : TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Example 12 with TagUpdateRequest

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

the class TagServiceTest method testUpdateTagParentTagMaxAllowedNestingExceeds.

@Test
public void testUpdateTagParentTagMaxAllowedNestingExceeds() throws Exception {
    // 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);
    // Override the configuration to set max allowed tag nesting to 1.
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.MAX_ALLOWED_TAG_NESTING.getKey(), 1);
    modifyPropertySourceInEnvironment(overrideMap);
    try {
        // Try to update the tag using it's child as a parent tag.
        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(childTagEntity.getTagType().getCode(), childTagEntity.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());
        }
        // Try to update the tag using it's grandchild as a parent tag.
        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(grandchildTagEntity.getTagType().getCode(), grandchildTagEntity.getTagCode())));
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals("Exceeds maximum allowed tag nesting level of 1", e.getMessage());
        }
    } finally {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}
Also used : TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) HashMap(java.util.HashMap) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Example 13 with TagUpdateRequest

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

the class TagServiceTest method testUpdateTagTagNoExists.

@Test
public void testUpdateTagTagNoExists() {
    // Try to update a non-existing tag.
    try {
        tagService.updateTag(new TagKey(TAG_TYPE, TAG_CODE_2), new TagUpdateRequest(TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, new TagKey(TAG_TYPE, TAG_CODE)));
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Tag with code \"%s\" doesn't exist for tag type \"%s\".", TAG_CODE_2, TAG_TYPE), e.getMessage());
    }
}
Also used : TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Example 14 with TagUpdateRequest

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

the class TagServiceTest method testUpdateTagMissingOptionalParametersPassedAsWhitespace.

@Test
public void testUpdateTagMissingOptionalParametersPassedAsWhitespace() {
    // Create a parent tag key.
    TagKey parentTagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create a parent tag entity.
    TagEntity parentTagEntity = 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 with a parent tag.
    TagEntity tagEntity = tagDaoTestHelper.createTagEntity(tagKey, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, parentTagEntity);
    // Update the tag with description passed as whitespace.
    Tag updatedTag = tagService.updateTag(tagKey, new TagUpdateRequest(TAG_DISPLAY_NAME_3, NO_TAG_SEARCH_SCORE_MULTIPLIER, BLANK_TEXT, NO_PARENT_TAG_KEY));
    // Validate the returned object.
    assertEquals(new Tag(tagEntity.getId(), tagKey, TAG_DISPLAY_NAME_3, NO_TAG_SEARCH_SCORE_MULTIPLIER, BLANK_TEXT, 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 15 with TagUpdateRequest

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

the class TagServiceTest method testUpdateTagMissingOptionalParametersPassedAsNulls.

@Test
public void testUpdateTagMissingOptionalParametersPassedAsNulls() {
    // Create a parent tag key.
    TagKey parentTagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create a parent tag entity.
    TagEntity parentTagEntity = 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 with a parent tag.
    TagEntity tagEntity = tagDaoTestHelper.createTagEntity(tagKey, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, parentTagEntity);
    // Update the tag with description and parent tag passed in as nulls.
    Tag updatedTag = tagService.updateTag(tagKey, new TagUpdateRequest(TAG_DISPLAY_NAME_3, NO_TAG_SEARCH_SCORE_MULTIPLIER, NO_TAG_DESCRIPTION, NO_PARENT_TAG_KEY));
    // Validate the returned object.
    assertEquals(new Tag(tagEntity.getId(), tagKey, TAG_DISPLAY_NAME_3, NO_TAG_SEARCH_SCORE_MULTIPLIER, NO_TAG_DESCRIPTION, 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