Search in sources :

Example 1 with SystemLoadRequestJson

use of com.enonic.xp.impl.server.rest.model.SystemLoadRequestJson 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 SystemLoadRequestJson

use of com.enonic.xp.impl.server.rest.model.SystemLoadRequestJson 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)

Example 3 with SystemLoadRequestJson

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

the class SystemResourceTest method load.

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

Aggregations

SystemLoadRequestJson (com.enonic.xp.impl.server.rest.model.SystemLoadRequestJson)3 Test (org.junit.jupiter.api.Test)3 SystemLoadParams (com.enonic.xp.dump.SystemLoadParams)2 SystemLoadResult (com.enonic.xp.dump.SystemLoadResult)2 AbstractRunnableTaskTest (com.enonic.xp.task.AbstractRunnableTaskTest)2 RunnableTask (com.enonic.xp.task.RunnableTask)2 PropertyTree (com.enonic.xp.data.PropertyTree)1 ImportNodesParams (com.enonic.xp.export.ImportNodesParams)1 NodeImportResult (com.enonic.xp.export.NodeImportResult)1 LoadRunnableTask (com.enonic.xp.impl.server.rest.task.LoadRunnableTask)1 NodePath (com.enonic.xp.node.NodePath)1 TaskResultJson (com.enonic.xp.task.TaskResultJson)1 Path (java.nio.file.Path)1