Search in sources :

Example 1 with ImportNodesRequestJson

use of com.enonic.xp.impl.server.rest.model.ImportNodesRequestJson in project xp by enonic.

the class RepositoryResourceTest method importNodes.

@Test
public void importNodes() throws Exception {
    Mockito.when(taskService.submitTask(Mockito.isA(ImportRunnableTask.class), eq("import"))).thenReturn(TaskId.from("task-id"));
    final ImportNodesRequestJson json = Mockito.mock(ImportNodesRequestJson.class);
    final TaskResultJson result = resource.importNodes(json);
    assertEquals("task-id", result.getTaskId());
}
Also used : ImportNodesRequestJson(com.enonic.xp.impl.server.rest.model.ImportNodesRequestJson) ImportRunnableTask(com.enonic.xp.impl.server.rest.task.ImportRunnableTask) TaskResultJson(com.enonic.xp.task.TaskResultJson) Test(org.junit.jupiter.api.Test)

Example 2 with ImportNodesRequestJson

use of com.enonic.xp.impl.server.rest.model.ImportNodesRequestJson in project xp by enonic.

the class ImportRunnableTaskTest method importNodes.

@Test
public void importNodes() {
    NodeImportResult nodeImportResult = NodeImportResult.create().added(NodePath.create().addElement("node").addElement("path").build()).addBinary("binary", BinaryReference.from("binaryRef")).updated(NodePath.create().addElement("node2").addElement("path2").build()).build();
    Mockito.when(this.exportService.importNodes(isA(ImportNodesParams.class))).thenReturn(nodeImportResult);
    final PropertyTree repoData = new PropertyTree();
    repoData.addString("key", "value");
    Mockito.when(this.repositoryService.list()).thenReturn(Repositories.from(Repository.create().branches(Branch.from("master")).id(RepositoryId.from("system-repo")).data(repoData).build()));
    final ImportRunnableTask task = createAndRunTask(new ImportNodesRequestJson("export", "system-repo:master:a", true, true, true, "", null));
    task.createTaskResult();
    Mockito.verify(repositoryService, Mockito.times(1)).invalidateAll();
    Mockito.verify(nodeRepositoryService, Mockito.times(1)).isInitialized(RepositoryId.from("system-repo"));
    Mockito.verify(nodeRepositoryService, Mockito.times(1)).create(CreateRepositoryParams.create().repositoryId(RepositoryId.from("system-repo")).data(repoData).repositorySettings(RepositorySettings.create().build()).build());
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("import"));
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("importNodes_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : ImportNodesParams(com.enonic.xp.export.ImportNodesParams) ImportNodesRequestJson(com.enonic.xp.impl.server.rest.model.ImportNodesRequestJson) PropertyTree(com.enonic.xp.data.PropertyTree) RunnableTask(com.enonic.xp.task.RunnableTask) NodeImportResult(com.enonic.xp.export.NodeImportResult) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Aggregations

ImportNodesRequestJson (com.enonic.xp.impl.server.rest.model.ImportNodesRequestJson)2 Test (org.junit.jupiter.api.Test)2 PropertyTree (com.enonic.xp.data.PropertyTree)1 ImportNodesParams (com.enonic.xp.export.ImportNodesParams)1 NodeImportResult (com.enonic.xp.export.NodeImportResult)1 ImportRunnableTask (com.enonic.xp.impl.server.rest.task.ImportRunnableTask)1 AbstractRunnableTaskTest (com.enonic.xp.task.AbstractRunnableTaskTest)1 RunnableTask (com.enonic.xp.task.RunnableTask)1 TaskResultJson (com.enonic.xp.task.TaskResultJson)1