use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.
the class DumpServiceImplTest method version_ids_should_stay_the_same_if_no_changes.
@Test
public void version_ids_should_stay_the_same_if_no_changes() throws Exception {
final Node node = createNode(NodePath.ROOT, "myNode");
RenameNodeCommand.create().searchService(this.searchService).storageService(this.storageService).indexServiceInternal(this.indexServiceInternal).params(RenameNodeParams.create().nodeId(node.id()).nodeName(NodeName.from("renamed")).build()).build().execute();
this.nodeService.push(NodeIds.from(node.id()), WS_OTHER);
updateNode(node);
refresh();
final NodeVersionQueryResult versionsBeforeLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
refresh();
final NodeVersionQueryResult versionsAfterLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
final NodeVersionIds versionIdsBeforeLoad = versionsBeforeLoad.getNodeVersionsMetadata().getAllVersionIds();
final NodeVersionIds versionIdsAfterLoad = versionsAfterLoad.getNodeVersionsMetadata().getAllVersionIds();
assertEquals(versionIdsBeforeLoad, versionIdsAfterLoad);
}
use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.
the class DumpServiceImplTest method limit_number_of_versions.
@Test
public void limit_number_of_versions() throws Exception {
final Node node = createNode(NodePath.ROOT, "myNode");
for (int i = 0; i < 10; i++) {
updateNode(node);
}
NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true, SystemDumpParams.create().dumpName("myTestDump").maxVersions(5).build()));
final NodeVersionQueryResult versionsAfterLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).size(-1).build());
assertEquals(6, versionsAfterLoad.getHits());
}
use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.
the class NodeVersionQueryResultFactory method create.
public static NodeVersionQueryResult create(final NodeVersionQuery query, final SearchResult searchResult) {
final NodeVersionQueryResult.Builder findNodeVersionsResult = NodeVersionQueryResult.create();
findNodeVersionsResult.hits(searchResult.getHits().getSize());
findNodeVersionsResult.totalHits(searchResult.getTotalHits());
findNodeVersionsResult.from(query.getFrom());
findNodeVersionsResult.to(query.getSize());
final NodeVersionsMetadata nodeVersionsMetadata = buildEntityVersions(query, searchResult);
findNodeVersionsResult.entityVersions(nodeVersionsMetadata);
return findNodeVersionsResult.build();
}
use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.
the class FindNodeVersionsCommandTest method get_multiple_version.
@Test
void get_multiple_version() {
PropertyTree data = new PropertyTree();
final Node node = createNode(CreateNodeParams.create().data(data).name("my-node").parent(NodePath.ROOT).build());
final int updateCount = 4;
updateNode(node.id(), updateCount);
refresh();
final NodeVersionQuery query = NodeVersionQuery.create().size(100).from(0).nodeId(node.id()).addOrderBy(FieldOrderExpr.create(VersionIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).build();
final NodeVersionQueryResult result = FindNodeVersionsCommand.create().query(query).searchService(this.searchService).build().execute();
assertEquals(updateCount + 1, result.getHits());
final NodeVersionsMetadata nodeVersionsMetadata = result.getNodeVersionsMetadata();
Instant previousTimestamp = null;
for (final NodeVersionMetadata nodeVersionMetadata : nodeVersionsMetadata) {
final Instant currentNodeTimestamp = nodeVersionMetadata.getTimestamp();
if (previousTimestamp != null) {
if (currentNodeTimestamp.isAfter(previousTimestamp)) {
fail(String.format("expected timestamp of current item to be before or equal to previous. Previous: [%s], current: [%s]", previousTimestamp, currentNodeTimestamp));
}
}
previousTimestamp = currentNodeTimestamp;
}
}
use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.
the class VersionTableVacuumTaskTest method assertVersions.
private void assertVersions(final NodeId nodeId, final int versions) {
final NodeVersionQueryResult result = this.nodeService.findVersions(NodeVersionQuery.create().nodeId(nodeId).size(0).build());
assertEquals(versions, result.getTotalHits(), "Wrong number of versions found");
}
Aggregations