use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.
the class FindVersionsHandler method execute.
@Override
public Object execute() {
final NodeVersionQueryResult result;
NodeId nodeId = getNodeId(key);
if (nodeId == null) {
result = NodeVersionQueryResult.empty(0);
} else {
GetNodeVersionsParams params = GetNodeVersionsParams.create().nodeId(nodeId).from(from).size(size).build();
result = nodeService.findVersions(params);
}
return new NodeVersionsQueryResultMapper(result);
}
use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.
the class FindVersionsHandlerTest method testFindVersionsHandler.
@Test
public void testFindVersionsHandler() {
final NodeVersionMetadata newNodeVersionMeta = NodeVersionMetadata.create().nodeId(NodeId.from("nodeId1")).nodeVersionId(NodeVersionId.from("nodeVersionNew")).nodePath(NodePath.ROOT).timestamp(Instant.ofEpochSecond(1000)).build();
final NodeVersionMetadata oldNodeVersionMeta = NodeVersionMetadata.create().nodeId(NodeId.from("nodeId1")).nodeVersionId(NodeVersionId.from("nodeVersionOld")).nodePath(NodePath.ROOT).timestamp(Instant.ofEpochSecond(500)).build();
final NodeVersionsMetadata nodeVersionsMetadata = NodeVersionsMetadata.create(NodeId.from("nodeId1")).add(newNodeVersionMeta).add(oldNodeVersionMeta).build();
final NodeVersionQueryResult result = NodeVersionQueryResult.create().entityVersions(nodeVersionsMetadata).from(0).to(2).hits(2).totalHits(40).build();
final ArgumentCaptor<GetNodeVersionsParams> getNodeVersionsParamsCaptor = ArgumentCaptor.forClass(GetNodeVersionsParams.class);
Mockito.when(nodeService.findVersions(Mockito.any(GetNodeVersionsParams.class))).thenReturn(result);
runScript("/lib/xp/examples/node/findVersions.js");
Mockito.verify(nodeService).findVersions(getNodeVersionsParamsCaptor.capture());
assertEquals("nodeId", getNodeVersionsParamsCaptor.getValue().getNodeId().toString());
assertEquals(0, getNodeVersionsParamsCaptor.getValue().getFrom());
assertEquals(2, getNodeVersionsParamsCaptor.getValue().getSize());
}
Aggregations