@Override public BusinessObjectDefinitionTagKeys getBusinessObjectDefinitionTagsByTag(TagKey tagKey) { // Validate the tag key. tagHelper.validateTagKey(tagKey); // Get the tag entity and ensure it exists. TagEntity tagEntity = tagDaoHelper.getTagEntity(tagKey); //Create a list of tag entities along with all its children tags down the hierarchy up to maximum allowed tag nesting level. List<TagEntity> tagEntities = new ArrayList<>(); tagEntities.add(tagEntity); tagEntities.addAll(tagDaoHelper.getTagChildrenEntities(tagEntity)); // Retrieve and return a list of business object definition tag keys. return new BusinessObjectDefinitionTagKeys(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagsByTagEntities(tagEntities)); }
TagEntity tagEntity = tagDaoHelper.getTagEntity(tagKey); tagDaoHelper.assertDisplayNameDoesNotExistForTag(tagKey.getTagTypeCode(), tagUpdateRequest.getDisplayName()); parentTagEntity = tagDaoHelper.getTagEntity(tagUpdateRequest.getParentTagKey()); tagDaoHelper.validateParentTagEntity(tagEntity, parentTagEntity);
@Test public void testValidateParentTagType() { try { // Call the method under test tagDaoHelper.validateParentTagType(TAG_TYPE_CODE, TAG_TYPE_CODE); } catch (IllegalArgumentException illegalArgumentException) { // Confirm the exception does not occur fail("Should not have caught an exception."); } }
@Override public Tag getTag(TagKey tagKey) { // Perform validation and trim. tagHelper.validateTagKey(tagKey); // Retrieve and ensure that a Tag already exists with the specified key. TagEntity tagEntity = tagDaoHelper.getTagEntity(tagKey); // Create and return the tag object from the entity which was retrieved. return createTagFromEntity(tagEntity); }
tagDaoHelper.assertDisplayNameDoesNotExistForTag(request.getTagKey().getTagTypeCode(), request.getDisplayName()); TagEntity parentTagEntity = null; if (request.getParentTagKey() != null) parentTagEntity = tagDaoHelper.getTagEntity(request.getParentTagKey());
@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 testAssertDisplayNameDoesNotExistForTagWithNullTagEntity() { // Setup when clauses when(tagDao.getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME)).thenReturn(null); // Call method under test try { tagDaoHelper.assertDisplayNameDoesNotExistForTag(TAG_CODE, TAG_DISPLAY_NAME); } catch (AlreadyExistsException alreadyExistsException) { // Confirm the exception does not occur fail("Should not have caught an exception."); } // Setup verify clauses verify(tagDao).getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME); verifyNoMoreInteractions(configurationHelper, tagDao); }
@Override public Tag getTag(TagKey tagKey) { // Perform validation and trim. tagHelper.validateTagKey(tagKey); // Retrieve and ensure that a Tag already exists with the specified key. TagEntity tagEntity = tagDaoHelper.getTagEntity(tagKey); // Create and return the tag object from the entity which was retrieved. return createTagFromEntity(tagEntity); }
tagDaoHelper.assertDisplayNameDoesNotExistForTag(request.getTagKey().getTagTypeCode(), request.getDisplayName()); TagEntity parentTagEntity = null; if (request.getParentTagKey() != null) parentTagEntity = tagDaoHelper.getTagEntity(request.getParentTagKey());
@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); }
@Override public BusinessObjectDefinitionTagKeys getBusinessObjectDefinitionTagsByTag(TagKey tagKey) { // Validate the tag key. tagHelper.validateTagKey(tagKey); // Get the tag entity and ensure it exists. TagEntity tagEntity = tagDaoHelper.getTagEntity(tagKey); //Create a list of tag entities along with all its children tags down the hierarchy up to maximum allowed tag nesting level. List<TagEntity> tagEntities = new ArrayList<>(); tagEntities.add(tagEntity); tagEntities.addAll(tagDaoHelper.getTagChildrenEntities(tagEntity)); // Retrieve and return a list of business object definition tag keys. return new BusinessObjectDefinitionTagKeys(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagsByTagEntities(tagEntities)); }
TagEntity tagEntity = tagDaoHelper.getTagEntity(tagKey);
TagEntity tagEntity = tagDaoHelper.getTagEntity(tagKey); tagDaoHelper.assertDisplayNameDoesNotExistForTag(tagKey.getTagTypeCode(), tagUpdateRequest.getDisplayName()); parentTagEntity = tagDaoHelper.getTagEntity(tagUpdateRequest.getParentTagKey()); tagDaoHelper.validateParentTagEntity(tagEntity, parentTagEntity);
@Test public void testValidateParentTagTypeWithUnmatchedTagTypeCode() { try { // Call the method under test tagDaoHelper.validateParentTagType(TAG_TYPE_CODE, TAG_TYPE_CODE_2); 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("Tag type code in parent tag key must match the tag type code in the request."))); } } }
tagDaoHelper.validateParentTagEntity(tagEntity, parentTagEntity); fail("Expected to throw an exception.");
request.getBusinessObjectDefinitionSearchFilters().get(0).getBusinessObjectDefinitionSearchKeys().get(0); TagEntity tagEntity = tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey()); if (BooleanUtils.isTrue(businessObjectDefinitionSearchKey.isIncludeTagHierarchy())) tagEntities.addAll(tagDaoHelper.getTagChildrenEntities(tagEntity));
TagEntity tagEntity = tagDaoHelper.getTagEntity(tagKey);
/** * Validates the tag update request. This method also trims the request parameters. * * @param tagKey the tag key * @param request the specified tag update request */ private void validateTagUpdateRequest(TagKey tagKey, TagUpdateRequest request) { Assert.notNull(request, "A tag update request must be specified."); if (request.getParentTagKey() != null) { tagHelper.validateTagKey(request.getParentTagKey()); tagDaoHelper.validateParentTagType(tagKey.getTagTypeCode(), request.getParentTagKey().getTagTypeCode()); } request.setDisplayName(alternateKeyHelper.validateStringParameter("display name", request.getDisplayName())); validateTagSearchScoreMultiplier(request.getSearchScoreMultiplier()); }