Search in sources :

Example 1 with IssueQuery

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

the class CreateIssueCommand method countTotalIssues.

private long countTotalIssues() {
    final IssueQuery query = IssueQuery.create().size(0).count(true).build();
    final NodeQuery nodeQuery = IssueQueryNodeQueryTranslator.translate(query);
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    return result.getTotalHits();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) IssueQuery(com.enonic.xp.issue.IssueQuery)

Example 2 with IssueQuery

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

the class FindIssuesCommandTest method testFindIssuesByItems.

@Test
public void testFindIssuesByItems() throws Exception {
    final IssueQuery issueQuery = IssueQuery.create().from(0).size(20).status(IssueStatus.OPEN).items(ContentIds.from("content-id")).build();
    final FindIssuesCommand command = createCommand(issueQuery);
    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(IssueNodeTranslatorTest.createNode()));
    FindIssuesResult 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.getIssues().size());
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) NodeQuery(com.enonic.xp.node.NodeQuery) IssueQuery(com.enonic.xp.issue.IssueQuery) FindIssuesResult(com.enonic.xp.issue.FindIssuesResult) Test(org.junit.jupiter.api.Test)

Example 3 with IssueQuery

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

the class FindIssuesCommandTest method testFindIssues.

@Test
public void testFindIssues() throws Exception {
    final IssueQuery issueQuery = IssueQuery.create().from(0).size(20).status(IssueStatus.OPEN).build();
    final FindIssuesCommand command = createCommand(issueQuery);
    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(IssueNodeTranslatorTest.createNode()));
    FindIssuesResult 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.getIssues().size());
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) NodeQuery(com.enonic.xp.node.NodeQuery) IssueQuery(com.enonic.xp.issue.IssueQuery) FindIssuesResult(com.enonic.xp.issue.FindIssuesResult) Test(org.junit.jupiter.api.Test)

Example 4 with IssueQuery

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

the class IssueServiceImplTest_findIssues method findByContentId1.

@Test
public void findByContentId1() throws Exception {
    ContentId contentId = ContentId.from("issue-item-1");
    IssueQuery query = IssueQuery.create().items(ContentIds.from(contentId)).build();
    final FindIssuesResult result = this.issueService.findIssues(query);
    assertNotNull(result);
    assertEquals(2, result.getHits());
    assertTrue(result.getIssues().stream().allMatch(issue -> issue.getPublishRequest().getItems().stream().anyMatch(item -> item.getId().equals(contentId))));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Issue(com.enonic.xp.issue.Issue) PublishRequestItem(com.enonic.xp.issue.PublishRequestItem) CreateIssueParams(com.enonic.xp.issue.CreateIssueParams) Test(org.junit.jupiter.api.Test) ContentId(com.enonic.xp.content.ContentId) ContentIds(com.enonic.xp.content.ContentIds) IssueQuery(com.enonic.xp.issue.IssueQuery) FindIssuesResult(com.enonic.xp.issue.FindIssuesResult) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PublishRequest(com.enonic.xp.issue.PublishRequest) ContentId(com.enonic.xp.content.ContentId) IssueQuery(com.enonic.xp.issue.IssueQuery) FindIssuesResult(com.enonic.xp.issue.FindIssuesResult) Test(org.junit.jupiter.api.Test)

Example 5 with IssueQuery

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

the class IssueServiceImplTest_findIssues method findByContentId2.

@Test
public void findByContentId2() throws Exception {
    ContentId contentId = ContentId.from("issue-item-2");
    IssueQuery query = IssueQuery.create().items(ContentIds.from(contentId)).build();
    final FindIssuesResult result = this.issueService.findIssues(query);
    assertNotNull(result);
    assertEquals(3, result.getHits());
    assertTrue(result.getIssues().stream().allMatch(issue -> issue.getPublishRequest().getItems().stream().anyMatch(item -> item.getId().equals(contentId))));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Issue(com.enonic.xp.issue.Issue) PublishRequestItem(com.enonic.xp.issue.PublishRequestItem) CreateIssueParams(com.enonic.xp.issue.CreateIssueParams) Test(org.junit.jupiter.api.Test) ContentId(com.enonic.xp.content.ContentId) ContentIds(com.enonic.xp.content.ContentIds) IssueQuery(com.enonic.xp.issue.IssueQuery) FindIssuesResult(com.enonic.xp.issue.FindIssuesResult) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PublishRequest(com.enonic.xp.issue.PublishRequest) ContentId(com.enonic.xp.content.ContentId) IssueQuery(com.enonic.xp.issue.IssueQuery) FindIssuesResult(com.enonic.xp.issue.FindIssuesResult) Test(org.junit.jupiter.api.Test)

Aggregations

IssueQuery (com.enonic.xp.issue.IssueQuery)7 FindIssuesResult (com.enonic.xp.issue.FindIssuesResult)6 Test (org.junit.jupiter.api.Test)6 ContentId (com.enonic.xp.content.ContentId)3 ContentIds (com.enonic.xp.content.ContentIds)3 CreateIssueParams (com.enonic.xp.issue.CreateIssueParams)3 Issue (com.enonic.xp.issue.Issue)3 PublishRequest (com.enonic.xp.issue.PublishRequest)3 PublishRequestItem (com.enonic.xp.issue.PublishRequestItem)3 NodeQuery (com.enonic.xp.node.NodeQuery)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 NodeIds (com.enonic.xp.node.NodeIds)2 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1