Search in sources :

Example 1 with CreateIssueCommentParams

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

the class IssueServiceImplTest_updateComment method updateComment.

@Test
public void updateComment() throws Exception {
    Issue issue = this.createIssue(CreateIssueParams.create().title("issue-1"));
    final Instant created = Instant.now().minus(1, ChronoUnit.MINUTES);
    final PrincipalKey creator = PrincipalKey.from("user:store:me");
    final String creatorDisplayName = "Me Myself";
    final CreateIssueCommentParams params = CreateIssueCommentParams.create().text("text").issue(issue.getId()).creator(creator).creatorDisplayName(creatorDisplayName).created(created).build();
    final IssueComment comment = this.issueService.createComment(params);
    final IssueComment updatedComment = this.issueService.updateComment(UpdateIssueCommentParams.create().comment(comment.getId()).text("updated text").build());
    assertNotNull(updatedComment);
    assertEquals("updated text", updatedComment.getText());
    assertEquals(creator, updatedComment.getCreator());
    assertEquals(creatorDisplayName, updatedComment.getCreatorDisplayName());
    assertEquals(created, updatedComment.getCreated());
}
Also used : Issue(com.enonic.xp.issue.Issue) Instant(java.time.Instant) IssueComment(com.enonic.xp.issue.IssueComment) PrincipalKey(com.enonic.xp.security.PrincipalKey) CreateIssueCommentParams(com.enonic.xp.issue.CreateIssueCommentParams) Test(org.junit.jupiter.api.Test)

Example 2 with CreateIssueCommentParams

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

the class CreateIssueCommentCommandTest method create.

@Test
public void create() {
    final Node issueNode = Node.create().name("parent-issue").build();
    final PrincipalKey creator = PrincipalKey.from("user:store:one");
    final CreateIssueCommentParams params = CreateIssueCommentParams.create().issue(IssueId.create()).creator(creator).creatorDisplayName("Creator One").text("Comment text...").build();
    final CreateIssueCommentCommand command = createIssueCommentCommand(params);
    Mockito.when(this.nodeService.findByQuery(Mockito.any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().build());
    Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenReturn(issueNode);
    final IssueComment comment = command.execute();
    assertNotNull(comment);
    assertEquals("Comment text...", comment.getText());
    assertEquals(creator, comment.getCreator());
    assertEquals("Creator One", comment.getCreatorDisplayName());
}
Also used : Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) IssueComment(com.enonic.xp.issue.IssueComment) PrincipalKey(com.enonic.xp.security.PrincipalKey) CreateIssueCommentParams(com.enonic.xp.issue.CreateIssueCommentParams) Test(org.junit.jupiter.api.Test)

Example 3 with CreateIssueCommentParams

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

the class CreateIssueCommentCommandTest method createIssueNotExists.

@Test
public void createIssueNotExists() {
    final PrincipalKey creator = PrincipalKey.from("user:store:one");
    final CreateIssueCommentParams params = CreateIssueCommentParams.create().creator(creator).issue(IssueId.create()).creatorDisplayName("Creator One").text("Comment text...").build();
    final CreateIssueCommentCommand command = createIssueCommentCommand(params);
    Mockito.when(this.nodeService.findByQuery(Mockito.any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().build());
    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) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) PrincipalKey(com.enonic.xp.security.PrincipalKey) CreateIssueCommentParams(com.enonic.xp.issue.CreateIssueCommentParams) Test(org.junit.jupiter.api.Test)

Example 4 with CreateIssueCommentParams

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

the class CreateIssueCommentCommandTest method testNoIssueId.

@Test
public void testNoIssueId() {
    final CreateIssueCommentParams params = CreateIssueCommentParams.create().text("text").build();
    final CreateIssueCommentCommand command = createIssueCommentCommand(params);
    assertThrows(IllegalArgumentException.class, () -> command.execute());
}
Also used : CreateIssueCommentParams(com.enonic.xp.issue.CreateIssueCommentParams) Test(org.junit.jupiter.api.Test)

Example 5 with CreateIssueCommentParams

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

the class IssueCommentDataSerializerTest method testCreate.

@Test
public void testCreate() {
    final CreateIssueCommentParams params = CreateIssueCommentParams.create().issue(IssueId.create()).creator(creator).creatorDisplayName("Creator One").text("Comment text...").created(createdTime).build();
    final PropertyTree data = serializer.toCreateNodeData(params);
    assertNotNull(data);
    assertEquals("Comment text...", data.getString(TEXT));
    assertEquals("Creator One", data.getString(CREATOR_DISPLAY_NAME));
    assertEquals(creator.toString(), data.getString(CREATOR));
    assertEquals(createdTime, data.getInstant(CREATED_TIME));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) CreateIssueCommentParams(com.enonic.xp.issue.CreateIssueCommentParams) Test(org.junit.jupiter.api.Test)

Aggregations

CreateIssueCommentParams (com.enonic.xp.issue.CreateIssueCommentParams)8 Test (org.junit.jupiter.api.Test)8 PrincipalKey (com.enonic.xp.security.PrincipalKey)5 IssueComment (com.enonic.xp.issue.IssueComment)3 Instant (java.time.Instant)3 Issue (com.enonic.xp.issue.Issue)2 NodeId (com.enonic.xp.node.NodeId)2 NodeQuery (com.enonic.xp.node.NodeQuery)2 PropertyTree (com.enonic.xp.data.PropertyTree)1 Node (com.enonic.xp.node.Node)1 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)1