Search in sources :

Example 1 with SystemLoadParams

use of com.enonic.xp.dump.SystemLoadParams in project xp by enonic.

the class LoadRunnableTaskTest method load_system.

@Test
public void load_system() throws Exception {
    Files.createDirectory(dumpDir.resolve("name"));
    SystemLoadParams params = SystemLoadParams.create().dumpName("name").includeVersions(true).build();
    SystemLoadResult systemLoadResult = SystemLoadResult.create().add(RepoLoadResult.create(RepositoryId.from("my-repo")).add(BranchLoadResult.create(Branch.create().value("branch-value").build()).error(LoadError.error("error-message")).successful(2L).build()).versions(VersionsLoadResult.create().error(LoadError.error("version-load-error-message")).successful(1L).build()).build()).build();
    Mockito.when(this.dumpService.load(Mockito.isA(SystemLoadParams.class))).thenReturn(systemLoadResult);
    final LoadRunnableTask task = createAndRunTask(new SystemLoadRequestJson(params.getDumpName(), params.isUpgrade(), params.isArchive()));
    task.createTaskResult();
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("dump"));
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("load_system_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : SystemLoadResult(com.enonic.xp.dump.SystemLoadResult) SystemLoadRequestJson(com.enonic.xp.impl.server.rest.model.SystemLoadRequestJson) SystemLoadParams(com.enonic.xp.dump.SystemLoadParams) RunnableTask(com.enonic.xp.task.RunnableTask) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Example 2 with SystemLoadParams

use of com.enonic.xp.dump.SystemLoadParams in project xp by enonic.

the class LoadRunnableTaskTest method load.

@Test
public void load() throws Exception {
    Path nameDir = Files.createDirectory(dumpDir.resolve("name"));
    final NodeImportResult importResult = NodeImportResult.create().added(NodePath.create("/path/to/node1").build()).updated(NodePath.create("/path/to/node2").build()).dryRun(true).build();
    final PropertyTree repoData = new PropertyTree();
    repoData.addString("key", "value");
    Mockito.when(this.exportService.importNodes(Mockito.isA(ImportNodesParams.class))).thenReturn(importResult);
    Mockito.when(this.repositoryService.list()).thenReturn(Repositories.from(Repository.create().branches(Branch.from("master")).id(RepositoryId.from("my-repo")).data(repoData).build()));
    Files.writeString(nameDir.resolve("export.properties"), "a=b");
    SystemLoadParams params = SystemLoadParams.create().dumpName("name").includeVersions(true).build();
    SystemLoadResult systemLoadResult = SystemLoadResult.create().add(RepoLoadResult.create(RepositoryId.from("my-repo")).add(BranchLoadResult.create(Branch.create().value("branch-value").build()).error(LoadError.error("error-message")).successful(2L).build()).versions(VersionsLoadResult.create().error(LoadError.error("version-load-error-message")).successful(1L).build()).build()).build();
    Mockito.when(this.dumpService.load(Mockito.isA(SystemLoadParams.class))).thenReturn(systemLoadResult);
    final LoadRunnableTask task = createAndRunTask(new SystemLoadRequestJson(params.getDumpName(), params.isUpgrade(), params.isArchive()));
    task.createTaskResult();
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("dump"));
    Mockito.verify(nodeRepositoryService, Mockito.times(1)).create(CreateRepositoryParams.create().repositoryId(RepositoryId.from("my-repo")).data(repoData).repositorySettings(RepositorySettings.create().build()).build());
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("load_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : Path(java.nio.file.Path) NodePath(com.enonic.xp.node.NodePath) ImportNodesParams(com.enonic.xp.export.ImportNodesParams) SystemLoadResult(com.enonic.xp.dump.SystemLoadResult) SystemLoadRequestJson(com.enonic.xp.impl.server.rest.model.SystemLoadRequestJson) PropertyTree(com.enonic.xp.data.PropertyTree) SystemLoadParams(com.enonic.xp.dump.SystemLoadParams) 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

SystemLoadParams (com.enonic.xp.dump.SystemLoadParams)2 SystemLoadResult (com.enonic.xp.dump.SystemLoadResult)2 SystemLoadRequestJson (com.enonic.xp.impl.server.rest.model.SystemLoadRequestJson)2 AbstractRunnableTaskTest (com.enonic.xp.task.AbstractRunnableTaskTest)2 RunnableTask (com.enonic.xp.task.RunnableTask)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 NodePath (com.enonic.xp.node.NodePath)1 Path (java.nio.file.Path)1