/** * Updates and persists the tag entity per the specified update request. * * @param tagEntity the tag entity * @param request the tag update request * @param parentTagEntity the parent tag entity, maybe null */ private void updateTagEntity(TagEntity tagEntity, TagUpdateRequest request, TagEntity parentTagEntity) { tagEntity.setDisplayName(request.getDisplayName()); tagEntity.setSearchScoreMultiplier(request.getSearchScoreMultiplier()); tagEntity.setDescription(request.getDescription()); tagEntity.setParentTagEntity(parentTagEntity); tagDao.saveAndRefresh(tagEntity); }
/** * Updates and persists the tag entity per the specified update request. * * @param tagEntity the tag entity * @param request the tag update request * @param parentTagEntity the parent tag entity, maybe null */ private void updateTagEntity(TagEntity tagEntity, TagUpdateRequest request, TagEntity parentTagEntity) { tagEntity.setDisplayName(request.getDisplayName()); tagEntity.setSearchScoreMultiplier(request.getSearchScoreMultiplier()); tagEntity.setDescription(request.getDescription()); tagEntity.setParentTagEntity(parentTagEntity); tagDao.saveAndRefresh(tagEntity); }
@Test public void testGetTagChildrenEntities() { // Create a tag type entity TagTypeEntity tagTypeEntity = new TagTypeEntity(); tagTypeEntity.setCode(TAG_TYPE_CODE); // Create a tag entity TagEntity tagEntity = new TagEntity(); tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(TAG_CODE); tagEntity.setDisplayName(TAG_DISPLAY_NAME); // Create a parent tag entities array list List<TagEntity> parentTagEntities = new ArrayList<>(); parentTagEntities.add(tagEntity); // Setup when clauses when(configurationHelper.getProperty(ConfigurationValue.MAX_ALLOWED_TAG_NESTING, Integer.class)).thenReturn(1); when(tagDao.getChildrenTags(parentTagEntities)).thenReturn(parentTagEntities); // Call the method under test List<TagEntity> result = tagDaoHelper.getTagChildrenEntities(tagEntity); // Confirm the result value assertThat("Result not equal to parent tag entities list.", result, is(equalTo(parentTagEntities))); // Setup verify clauses verify(configurationHelper).getProperty(ConfigurationValue.MAX_ALLOWED_TAG_NESTING, Integer.class); verify(tagDao).getChildrenTags(parentTagEntities); verifyNoMoreInteractions(configurationHelper, tagDao); }
@Test public void testValidateParentTagEntityWithTagEntityEqualToParentTagEntity() { // Create a tag type entity TagTypeEntity tagTypeEntity = new TagTypeEntity(); tagTypeEntity.setCode(TAG_TYPE_CODE); // Create a tag entity TagEntity tagEntity = new TagEntity(); tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(TAG_CODE); tagEntity.setDisplayName(TAG_DISPLAY_NAME); // Setup when clauses when(configurationHelper.getProperty(ConfigurationValue.MAX_ALLOWED_TAG_NESTING, Integer.class)).thenReturn(0); // Call the method under test try { tagDaoHelper.validateParentTagEntity(tagEntity, tagEntity); fail("Expected to throw an exception."); } catch (IllegalArgumentException illegalArgumentException) { // Confirm the exception message is correct assertThat("Exception message is not correct.", illegalArgumentException.getMessage(), is(equalTo("Parent tag key cannot be the requested tag key or any of its children’s tag keys."))); } // Setup verify clauses verify(configurationHelper).getProperty(ConfigurationValue.MAX_ALLOWED_TAG_NESTING, Integer.class); verifyNoMoreInteractions(configurationHelper, tagDao); }
@Test public void testGetTagEntity() { // Create a tag type entity TagTypeEntity tagTypeEntity = new TagTypeEntity(); tagTypeEntity.setCode(TAG_TYPE_CODE); // Create a tag entity TagEntity tagEntity = new TagEntity(); tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(TAG_CODE); tagEntity.setDisplayName(TAG_DISPLAY_NAME); // Create a tag key TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE); // Setup when clauses when(tagDao.getTagByKey(tagKey)).thenReturn(tagEntity); // Call method under test TagEntity result = tagDaoHelper.getTagEntity(tagKey); // Confirm the result value assertThat("Result not equal to tag entity.", result, is(equalTo(tagEntity))); // Setup verify clauses verify(tagDao).getTagByKey(tagKey); verifyNoMoreInteractions(configurationHelper, tagDao); }
tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(TAG_CODE); tagEntity.setDisplayName(TAG_DISPLAY_NAME); parentTagEntity.setTagType(tagTypeEntity); parentTagEntity.setTagCode(TAG_CODE_2); parentTagEntity.setDisplayName(TAG_DISPLAY_NAME_2); parentTagEntity.setChildrenTagEntities(Lists.newArrayList(tagEntity));
@Test public void testValidateParentTagEntity() { // Create a tag type entity TagTypeEntity tagTypeEntity = new TagTypeEntity(); tagTypeEntity.setCode(TAG_TYPE_CODE); // Create a tag entity TagEntity tagEntity = new TagEntity(); tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(TAG_CODE); tagEntity.setDisplayName(TAG_DISPLAY_NAME); // Create a parent tag entity TagEntity parentTagEntity = new TagEntity(); parentTagEntity.setTagType(tagTypeEntity); parentTagEntity.setTagCode(TAG_CODE_2); parentTagEntity.setDisplayName(TAG_DISPLAY_NAME_2); parentTagEntity.setChildrenTagEntities(Lists.newArrayList(tagEntity)); // Set the parent tag entity on the child tag entity tagEntity.setParentTagEntity(parentTagEntity); // Setup when clauses when(configurationHelper.getProperty(ConfigurationValue.MAX_ALLOWED_TAG_NESTING, Integer.class)).thenReturn(1); // Call the method under test tagDaoHelper.validateParentTagEntity(tagEntity, parentTagEntity); // Setup verify clauses verify(configurationHelper).getProperty(ConfigurationValue.MAX_ALLOWED_TAG_NESTING, Integer.class); verifyNoMoreInteractions(configurationHelper, tagDao); }
@Test public void testAssertDisplayNameDoesNotExistForTag() { // Create a tag type entity TagTypeEntity tagTypeEntity = new TagTypeEntity(); tagTypeEntity.setCode(TAG_TYPE_CODE); // Create a tag entity TagEntity tagEntity = new TagEntity(); tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(TAG_CODE); tagEntity.setDisplayName(TAG_DISPLAY_NAME); // Setup when clauses when(tagDao.getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME)).thenReturn(tagEntity); // Call method under test try { tagDaoHelper.assertDisplayNameDoesNotExistForTag(TAG_CODE, TAG_DISPLAY_NAME); fail("Expected to throw an exception."); } catch (AlreadyExistsException alreadyExistsException) { // Confirm the exception message is correct assertThat("Exception message is not correct.", alreadyExistsException.getMessage(), is(equalTo(String .format("Display name \"%s\" already exists for a tag with tag type \"%s\" and tag code \"%s\".", TAG_DISPLAY_NAME, tagEntity.getTagType().getCode(), tagEntity.getTagCode())))); } // Setup verify clauses verify(tagDao).getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME); verifyNoMoreInteractions(configurationHelper, tagDao); }
/** * Creates and persists a new Tag entity. * * @param request the tag create request * @param tagTypeEntity the specified tag type entity. * @param parentTagEntity the specified parent tag entity * * @return the newly created tag entity. */ private TagEntity createTagEntity(TagCreateRequest request, TagTypeEntity tagTypeEntity, TagEntity parentTagEntity) { TagEntity tagEntity = new TagEntity(); tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(request.getTagKey().getTagCode()); tagEntity.setDisplayName(request.getDisplayName()); tagEntity.setSearchScoreMultiplier(request.getSearchScoreMultiplier()); tagEntity.setDescription(request.getDescription()); tagEntity.setParentTagEntity(parentTagEntity); return tagDao.saveAndRefresh(tagEntity); }
/** * Creates and persists a new Tag entity. * * @param request the tag create request * @param tagTypeEntity the specified tag type entity. * @param parentTagEntity the specified parent tag entity * * @return the newly created tag entity. */ private TagEntity createTagEntity(TagCreateRequest request, TagTypeEntity tagTypeEntity, TagEntity parentTagEntity) { TagEntity tagEntity = new TagEntity(); tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(request.getTagKey().getTagCode()); tagEntity.setDisplayName(request.getDisplayName()); tagEntity.setSearchScoreMultiplier(request.getSearchScoreMultiplier()); tagEntity.setDescription(request.getDescription()); tagEntity.setParentTagEntity(parentTagEntity); return tagDao.saveAndRefresh(tagEntity); }
/** * Creates and persists a new tag entity. * * @param tagTypeEntity the tag type entity * @param tagCode the tag code * @param tagDisplayName the tag display name * @param tagSearchScoreMultiplier the tag's search score multiplier * @param tagDescription the description of the tag * @param parentTagEntity the parent tag entity * * @return the newly created tag entity */ public TagEntity createTagEntity(TagTypeEntity tagTypeEntity, String tagCode, String tagDisplayName, BigDecimal tagSearchScoreMultiplier, String tagDescription, TagEntity parentTagEntity) { TagEntity tagEntity = new TagEntity(); tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(tagCode); tagEntity.setDisplayName(tagDisplayName); tagEntity.setSearchScoreMultiplier(tagSearchScoreMultiplier); tagEntity.setDescription(tagDescription); tagEntity.setParentTagEntity(parentTagEntity); return tagDao.saveAndRefresh(tagEntity); } }