Search in sources :

Example 1 with IssueCommentQuery

use of com.enonic.xp.issue.IssueCommentQuery in project xp by enonic.

the class IssueServiceImplTest_findComments method comments_find.

@Test
public void comments_find() throws Exception {
    IssueCommentQuery query = IssueCommentQuery.create().issue(this.issue.getId()).build();
    final FindIssueCommentsResult result = this.issueService.findComments(query);
    assertNotNull(result);
    assertEquals(3, result.getHits());
}
Also used : FindIssueCommentsResult(com.enonic.xp.issue.FindIssueCommentsResult) IssueCommentQuery(com.enonic.xp.issue.IssueCommentQuery) Test(org.junit.jupiter.api.Test)

Example 2 with IssueCommentQuery

use of com.enonic.xp.issue.IssueCommentQuery in project xp by enonic.

the class FindIssueCommentsCommandTest method testFindIssuesNoIssue.

@Test
public void testFindIssuesNoIssue() throws Exception {
    final PrincipalKey creator = PrincipalKey.from("user:store:one");
    final IssueCommentQuery commentQuery = IssueCommentQuery.create().from(0).size(20).creator(creator).build();
    final FindIssueCommentsCommand command = createCommand(commentQuery);
    assertThrows(IllegalArgumentException.class, () -> command.execute());
}
Also used : IssueCommentQuery(com.enonic.xp.issue.IssueCommentQuery) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 3 with IssueCommentQuery

use of com.enonic.xp.issue.IssueCommentQuery in project xp by enonic.

the class FindIssueCommentsCommandTest method testFindIssues.

@Test
public void testFindIssues() throws Exception {
    final IssueId issueId = IssueId.create();
    final Node issueNode = Node.create().id(NodeId.from(issueId)).name("parent-issue").build();
    final PrincipalKey creator = PrincipalKey.from("user:store:one");
    final IssueCommentQuery commentQuery = IssueCommentQuery.create().from(0).size(20).issue(issueId).creator(creator).build();
    final FindIssueCommentsCommand command = createCommand(commentQuery);
    Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenReturn(issueNode);
    Mockito.when(nodeService.findByQuery(Mockito.any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().hits(20).totalHits(40).build());
    Mockito.when(nodeService.getByIds(Mockito.any(NodeIds.class))).thenReturn(Nodes.from(IssueCommentNodeTranslatorTest.createNode(Instant.now())));
    FindIssueCommentsResult result = command.execute();
    Mockito.verify(nodeService, Mockito.times(1)).findByQuery(Mockito.any(NodeQuery.class));
    Mockito.verify(nodeService, Mockito.times(1)).getByIds(Mockito.any(NodeIds.class));
    assertEquals(20, result.getHits());
    assertEquals(40, result.getTotalHits());
    assertEquals(1, result.getIssueComments().size());
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) FindIssueCommentsResult(com.enonic.xp.issue.FindIssueCommentsResult) IssueId(com.enonic.xp.issue.IssueId) IssueCommentQuery(com.enonic.xp.issue.IssueCommentQuery) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 4 with IssueCommentQuery

use of com.enonic.xp.issue.IssueCommentQuery in project xp by enonic.

the class FindIssueCommentsCommandTest method testFindIssuesIssueNotExists.

@Test
public void testFindIssuesIssueNotExists() throws Exception {
    final IssueId issueId = IssueId.create();
    final PrincipalKey creator = PrincipalKey.from("user:store:one");
    final IssueCommentQuery commentQuery = IssueCommentQuery.create().from(0).size(20).issue(issueId).creator(creator).build();
    final FindIssueCommentsCommand command = createCommand(commentQuery);
    Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenThrow(new NodeNotFoundException("Node not found"));
    assertThrows(NodeNotFoundException.class, () -> command.execute());
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeId(com.enonic.xp.node.NodeId) IssueId(com.enonic.xp.issue.IssueId) IssueCommentQuery(com.enonic.xp.issue.IssueCommentQuery) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 5 with IssueCommentQuery

use of com.enonic.xp.issue.IssueCommentQuery in project xp by enonic.

the class IssueServiceImplTest_findComments method comments_findByUser.

@Test
public void comments_findByUser() throws Exception {
    IssueCommentQuery query = IssueCommentQuery.create().issue(this.issue.getId()).creator(User.ANONYMOUS.getKey()).build();
    final FindIssueCommentsResult result = this.issueService.findComments(query);
    assertNotNull(result);
    assertEquals(2, result.getHits());
    assertTrue(result.getIssueComments().stream().allMatch(c -> c.getCreator().equals(User.ANONYMOUS.getKey())));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) User(com.enonic.xp.security.User) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Issue(com.enonic.xp.issue.Issue) IssueComment(com.enonic.xp.issue.IssueComment) CreateIssueParams(com.enonic.xp.issue.CreateIssueParams) FindIssueCommentsResult(com.enonic.xp.issue.FindIssueCommentsResult) Test(org.junit.jupiter.api.Test) PrincipalKey(com.enonic.xp.security.PrincipalKey) CreateIssueCommentParams(com.enonic.xp.issue.CreateIssueCommentParams) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IssueCommentQuery(com.enonic.xp.issue.IssueCommentQuery) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FindIssueCommentsResult(com.enonic.xp.issue.FindIssueCommentsResult) IssueCommentQuery(com.enonic.xp.issue.IssueCommentQuery) Test(org.junit.jupiter.api.Test)

Aggregations

IssueCommentQuery (com.enonic.xp.issue.IssueCommentQuery)5 Test (org.junit.jupiter.api.Test)5 PrincipalKey (com.enonic.xp.security.PrincipalKey)4 FindIssueCommentsResult (com.enonic.xp.issue.FindIssueCommentsResult)3 IssueId (com.enonic.xp.issue.IssueId)2 NodeId (com.enonic.xp.node.NodeId)2 CreateIssueCommentParams (com.enonic.xp.issue.CreateIssueCommentParams)1 CreateIssueParams (com.enonic.xp.issue.CreateIssueParams)1 Issue (com.enonic.xp.issue.Issue)1 IssueComment (com.enonic.xp.issue.IssueComment)1 Node (com.enonic.xp.node.Node)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 User (com.enonic.xp.security.User)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1