use of com.enonic.xp.export.NodeExportResult in project xp by enonic.
the class ExportHandlerTest method testExample.
@Test
public void testExample() {
final NodeExportResult result = NodeExportResult.create().addNodePath(NodePath.create("/content").build()).addBinary(NodePath.create("binaryPath").build(), BinaryReference.from("ref")).addError(new ExportError("some error")).build();
when(exportService.exportNodes(any())).thenReturn(result);
runScript("/lib/xp/examples/export/exportNodes.js");
}
use of com.enonic.xp.export.NodeExportResult in project xp by enonic.
the class ExportHandler method execute.
public NodeExportResultMapper execute() {
final ExportNodesParams.Builder paramsBuilder = ExportNodesParams.create().sourceNodePath(NodePath.create(sourceNodePath).build()).exportName(exportName).nodeExportListener(new FunctionBasedNodeExportListener(nodeExported, nodeResolved));
if (includeNodeIds != null) {
paramsBuilder.includeNodeIds(includeNodeIds);
}
if (includeVersions != null) {
paramsBuilder.includeVersions(includeVersions);
}
final NodeExportResult nodeImportResult = this.context.getService(ExportService.class).get().exportNodes(paramsBuilder.build());
return new NodeExportResultMapper(nodeImportResult);
}
use of com.enonic.xp.export.NodeExportResult in project xp by enonic.
the class ExportRunnableTaskTest method exportNodes.
@Test
public void exportNodes() {
final NodeExportResult nodeExportResult = NodeExportResult.create().addNodePath(NodePath.create().addElement("node").addElement("path").build()).addBinary(NodePath.create().elements("binary").build(), BinaryReference.from("binaryRef")).build();
Mockito.when(this.exportService.exportNodes(isA(ExportNodesParams.class))).thenReturn(nodeExportResult);
final ExportRunnableTask task = createAndRunTask(new ExportNodesRequestJson("a:b:c", "export", true, true, true));
task.createTaskResult();
Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("export"));
final String result = contentQueryArgumentCaptor.getAllValues().get(0);
jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("exportNodes_result.json"), jsonTestHelper.stringToJson(result));
}
use of com.enonic.xp.export.NodeExportResult in project xp by enonic.
the class ExportRunnableTask method run.
@Override
public void run(final TaskId id, final ProgressReporter progressReporter) {
final NodeExportResult result = getContext(params.getSourceRepoPath()).callWith(() -> this.exportService.exportNodes(ExportNodesParams.create().sourceNodePath(params.getSourceRepoPath().getNodePath()).exportName(params.getExportName()).dryRun(params.isDryRun()).includeNodeIds(params.isExportWithIds()).includeVersions(params.isIncludeVersions()).nodeExportListener(new ExportListenerImpl(progressReporter)).build()));
progressReporter.info(NodeExportResultJson.from(result).toString());
}
use of com.enonic.xp.export.NodeExportResult in project xp by enonic.
the class NodeExportIntegrationTest method one_node_error.
@Test
public void one_node_error() throws Exception {
createNode("mynode", NodePath.ROOT);
final ExportWriter exportWriter = Mockito.mock(ExportWriter.class);
Mockito.doThrow(new RuntimeException("exception message")).when(exportWriter).writeElement(Mockito.isA(Path.class), Mockito.anyString());
final NodeExportResult result = NodeExporter.create().nodeService(this.nodeService).nodeExportWriter(exportWriter).sourceNodePath(NodePath.ROOT).targetDirectory(this.temporaryFolder.resolve("myExport")).build().execute();
assertEquals(1, result.getExportErrors().size());
assertEquals("java.lang.RuntimeException: exception message", result.getExportErrors().get(0).toString());
}
Aggregations