Search in sources :

Example 1 with TagSearchRequest

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

the class TagRestControllerTest method testSearchTags.

@Test
public void testSearchTags() {
    TagSearchResponse tagSearchResponse = new TagSearchResponse(Arrays.asList(new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_3), TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN), new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_2), TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN)));
    Set<String> searchFields = Sets.newHashSet(TagServiceImpl.DISPLAY_NAME_FIELD, TagServiceImpl.DESCRIPTION_FIELD, TagServiceImpl.PARENT_TAG_KEY_FIELD, TagServiceImpl.HAS_CHILDREN_FIELD);
    TagSearchRequest tagSearchRequest = new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE, TAG_CODE, NO_IS_PARENT_TAG_NULL_FLAG)))));
    when(tagService.searchTags(tagSearchRequest, searchFields)).thenReturn(tagSearchResponse);
    // Search the tags.
    TagSearchResponse resultTagSearchResponse = tagRestController.searchTags(tagSearchRequest, searchFields);
    // Verify the external calls.
    verify(tagService).searchTags(tagSearchRequest, searchFields);
    verifyNoMoreInteractions(tagService);
    // Validate the returned object.
    assertEquals(tagSearchResponse, resultTagSearchResponse);
}
Also used : TagSearchFilter(org.finra.herd.model.api.xml.TagSearchFilter) TagSearchKey(org.finra.herd.model.api.xml.TagSearchKey) TagSearchResponse(org.finra.herd.model.api.xml.TagSearchResponse) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) TagSearchRequest(org.finra.herd.model.api.xml.TagSearchRequest) Test(org.junit.Test)

Example 2 with TagSearchRequest

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

the class TagServiceTest method testSearchTagsWithIsParentTagNullFlag.

@Test
public void testSearchTagsWithIsParentTagNullFlag() {
    // Create and persist database entities required for testing.
    createDatabaseEntitiesForTagSearchTesting();
    // Get root tag entities (parent tag must not be set).
    assertEquals(new TagSearchResponse(Arrays.asList(new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE), NO_TAG_DISPLAY_NAME, NO_TAG_SEARCH_SCORE_MULTIPLIER, NO_TAG_DESCRIPTION, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG))), tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE, NO_PARENT_TAG_CODE, PARENT_TAG_IS_NULL))))), NO_SEARCH_RESPONSE_FIELDS));
    // Get all non-root tag entities (parent tag must be set).
    assertEquals(new TagSearchResponse(Arrays.asList(new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_3), NO_TAG_DISPLAY_NAME, NO_TAG_SEARCH_SCORE_MULTIPLIER, NO_TAG_DESCRIPTION, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG), new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_2), NO_TAG_DISPLAY_NAME, NO_TAG_SEARCH_SCORE_MULTIPLIER, NO_TAG_DESCRIPTION, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG))), tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE, NO_PARENT_TAG_CODE, PARENT_TAG_IS_NOT_NULL))))), NO_SEARCH_RESPONSE_FIELDS));
}
Also used : TagSearchFilter(org.finra.herd.model.api.xml.TagSearchFilter) TagSearchKey(org.finra.herd.model.api.xml.TagSearchKey) TagSearchResponse(org.finra.herd.model.api.xml.TagSearchResponse) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) TagSearchRequest(org.finra.herd.model.api.xml.TagSearchRequest) Test(org.junit.Test)

Example 3 with TagSearchRequest

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

the class TagServiceTest method testSearchTags.

@Test
public void testSearchTags() {
    // Create and persist database entities required for testing.
    createDatabaseEntitiesForTagSearchTesting();
    // Search the tags.
    TagSearchResponse tagSearchResponse = tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE, TAG_CODE, NO_IS_PARENT_TAG_NULL_FLAG))))), Sets.newHashSet(TagServiceImpl.DISPLAY_NAME_FIELD, TagServiceImpl.SEARCH_SCORE_MULTIPLIER_FIELD, TagServiceImpl.DESCRIPTION_FIELD, TagServiceImpl.PARENT_TAG_KEY_FIELD, TagServiceImpl.HAS_CHILDREN_FIELD));
    // Validate the returned object.
    assertEquals(new TagSearchResponse(Arrays.asList(new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_3), TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN), new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_2), TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN))), tagSearchResponse);
}
Also used : TagSearchFilter(org.finra.herd.model.api.xml.TagSearchFilter) TagSearchKey(org.finra.herd.model.api.xml.TagSearchKey) TagSearchResponse(org.finra.herd.model.api.xml.TagSearchResponse) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) TagSearchRequest(org.finra.herd.model.api.xml.TagSearchRequest) Test(org.junit.Test)

Example 4 with TagSearchRequest

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

the class TagServiceTest method testSearchTagsInvalidParameters.

@Test
public void testSearchTagsInvalidParameters() {
    // Try to search tags when there are more than one tag search filter is specified.
    try {
        tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(), new TagSearchFilter())), NO_SEARCH_RESPONSE_FIELDS);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("At most one tag search filter must be specified.", e.getMessage());
    }
    // Try to search tags when there are more than one tag search key is specified.
    try {
        tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(), new TagSearchKey())))), NO_SEARCH_RESPONSE_FIELDS);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Exactly one tag search key must be specified.", e.getMessage());
    }
    // Try to search tags for a non-existing tag type.
    try {
        tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey("I_DO_NOT_EXIST", NO_PARENT_TAG_CODE, NO_IS_PARENT_TAG_NULL_FLAG))))), NO_SEARCH_RESPONSE_FIELDS);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals("Tag type with code \"I_DO_NOT_EXIST\" doesn't exist.", e.getMessage());
    }
    // Try to search tags using a un-supported search response field option.
    try {
        tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE, NO_PARENT_TAG_CODE, NO_IS_PARENT_TAG_NULL_FLAG))))), Sets.newHashSet("INVALID_FIELD_OPTION"));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Search response field \"invalid_field_option\" is not supported.", e.getMessage());
    }
    // Try to search tags when parent tag code is specified along with "is parent tag null" flag set to true.
    try {
        tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE, TAG_CODE, PARENT_TAG_IS_NULL))))), NO_SEARCH_RESPONSE_FIELDS);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("A parent tag code can not be specified when isParentTagNull flag is set to true.", e.getMessage());
    }
}
Also used : TagSearchFilter(org.finra.herd.model.api.xml.TagSearchFilter) TagSearchKey(org.finra.herd.model.api.xml.TagSearchKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) TagSearchRequest(org.finra.herd.model.api.xml.TagSearchRequest) Test(org.junit.Test)

Example 5 with TagSearchRequest

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

the class TagServiceTest method testSearchTagsLowerCaseParameters.

@Test
public void testSearchTagsLowerCaseParameters() {
    // Create and persist database entities required for testing.
    createDatabaseEntitiesForTagSearchTesting();
    // Search the tags using lower case input parameters.
    TagSearchResponse tagSearchResponse = tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE.toLowerCase(), TAG_CODE.toLowerCase(), NO_IS_PARENT_TAG_NULL_FLAG))))), Sets.newHashSet(TagServiceImpl.DISPLAY_NAME_FIELD.toLowerCase(), TagServiceImpl.SEARCH_SCORE_MULTIPLIER_FIELD.toLowerCase(), TagServiceImpl.DESCRIPTION_FIELD.toLowerCase(), TagServiceImpl.PARENT_TAG_KEY_FIELD.toLowerCase(), TagServiceImpl.HAS_CHILDREN_FIELD.toLowerCase()));
    // Validate the returned object.
    assertEquals(new TagSearchResponse(Arrays.asList(new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_3), TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN), new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_2), TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN))), tagSearchResponse);
}
Also used : TagSearchFilter(org.finra.herd.model.api.xml.TagSearchFilter) TagSearchKey(org.finra.herd.model.api.xml.TagSearchKey) TagSearchResponse(org.finra.herd.model.api.xml.TagSearchResponse) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) TagSearchRequest(org.finra.herd.model.api.xml.TagSearchRequest) Test(org.junit.Test)

Aggregations

TagSearchFilter (org.finra.herd.model.api.xml.TagSearchFilter)9 TagSearchKey (org.finra.herd.model.api.xml.TagSearchKey)9 TagSearchRequest (org.finra.herd.model.api.xml.TagSearchRequest)9 Test (org.junit.Test)9 Tag (org.finra.herd.model.api.xml.Tag)7 TagKey (org.finra.herd.model.api.xml.TagKey)7 TagSearchResponse (org.finra.herd.model.api.xml.TagSearchResponse)7 ArrayList (java.util.ArrayList)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1