Addressed review comments

This commit is contained in:
suneet.gupta
2023-02-27 20:00:29 +05:30
parent dbe0d75764
commit bb5e4d42ac
2 changed files with 18 additions and 11 deletions

View File

@@ -130,7 +130,8 @@ public class TagsImpl implements Tags
for(Pair<String, NodeRef> pair : tagNodeRefs) for(Pair<String, NodeRef> pair : tagNodeRefs)
{ {
Tag createdTag=new Tag(pair.getSecond(), pair.getFirst()); Tag createdTag=new Tag(pair.getSecond(), pair.getFirst());
createdTag.setCount(Optional.ofNullable(tagsCountMap.get(createdTag.getTag())).map(cnt->cnt+1).orElse(1)); // The new use of the tag will not be indexed yet, so add one to whatever count we get back
createdTag.setCount(Optional.ofNullable(tagsCountMap.get(createdTag.getTag())).orElse(0) + 1);
ret.add(createdTag); ret.add(createdTag);
} }
return ret; return ret;

View File

@@ -35,7 +35,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.then;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -95,14 +94,6 @@ public class TagsImplTest
given(createdNodeMock.getNodeId()).willReturn(NODE_ID); given(createdNodeMock.getNodeId()).willReturn(NODE_ID);
given(typeConstraint.matches(any())).willReturn(true); given(typeConstraint.matches(any())).willReturn(true);
given(taggingServiceMock.getTagName(TAG_NODE_REF)).willReturn(TAG_NAME); given(taggingServiceMock.getTagName(TAG_NODE_REF)).willReturn(TAG_NAME);
given(taggingServiceMock.findTaggedNodesAndCountByTagName(any())).willReturn(createTagsCountPairList());
}
public List<Pair<String,Integer>> createTagsCountPairList()
{
List<Pair<String,Integer>> tagsCountPairList = new ArrayList<>();
tagsCountPairList.add(new Pair<>("tag-node-id",1));
return tagsCountPairList;
} }
@Test @Test
@@ -327,7 +318,7 @@ public class TagsImplTest
@Test @Test
public void testAddTagsToNode() public void testAddTagsToNode()
{ {
final List<String> tagNames = List.of("tag1"); final List<String> tagNames = List.of("tag1","tag2");
final List<Tag> tagsToCreate = createTags(tagNames); final List<Tag> tagsToCreate = createTags(tagNames);
given(taggingServiceMock.addTags(any(), any())).willAnswer(invocation -> createTagAndNodeRefPairs(invocation.getArgument(1))); given(taggingServiceMock.addTags(any(), any())).willAnswer(invocation -> createTagAndNodeRefPairs(invocation.getArgument(1)));
final List<Tag> actualCreatedTags = objectUnderTest.addTags(nodesMock.getNode(any()).getNodeId(),tagsToCreate); final List<Tag> actualCreatedTags = objectUnderTest.addTags(nodesMock.getNode(any()).getNodeId(),tagsToCreate);
@@ -338,4 +329,19 @@ public class TagsImplTest
.isEqualTo(expectedTags); .isEqualTo(expectedTags);
} }
@Test
public void testAddTagsToNodeWithResponseNotIndexed()
{
final List<String> tagNames = List.of("tag1","tag2");
final List<Tag> tagsToCreate = createTags(tagNames);
given(taggingServiceMock.addTags(any(), any())).willAnswer(invocation -> createTagAndNodeRefPairs(invocation.getArgument(1)));
given(taggingServiceMock.findTaggedNodesAndCountByTagName(any())).willReturn(Collections.emptyList());
final List<Tag> actualCreatedTags = objectUnderTest.addTags(nodesMock.getNode(any()).getNodeId(),tagsToCreate);
then(taggingServiceMock).should().addTags(TAG_NODE_REF, tagNames);
final List<Tag> expectedTags = createTagsWithNodeRefs(tagNames);
assertThat(actualCreatedTags)
.isNotNull()
.isEqualTo(expectedTags);
}
} }