Search in sources :

Example 1 with SystemLoadResult

use of com.enonic.xp.dump.SystemLoadResult 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 SystemLoadResult

use of com.enonic.xp.dump.SystemLoadResult 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 SystemLoadResult

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

the class DumpServiceImplTest method dumpDeleteAndLoad.

private SystemLoadResult dumpDeleteAndLoad(final boolean clearBlobStore, final SystemDumpParams params) {
    doDump(params);
    doListRepositories().stream().map(Repository::getId).filter(Predicate.isEqual(SystemConstants.SYSTEM_REPO_ID).or(Predicate.isEqual(AUDIT_LOG_REPO_ID)).or(Predicate.isEqual(SCHEDULER_REPO_ID)).negate()).forEach(this::doDeleteRepository);
    // Then delete all system repositories
    doDeleteRepository(AUDIT_LOG_REPO_ID);
    doDeleteRepository(SCHEDULER_REPO_ID);
    // system-repo must be deleted last
    doDeleteRepository(SystemConstants.SYSTEM_REPO_ID);
    if (clearBlobStore) {
        this.blobStore.clear();
    }
    bootstrap();
    final SystemLoadResult result = doLoad();
    refresh();
    return result;
}
Also used : Repository(com.enonic.xp.repository.Repository) SystemLoadResult(com.enonic.xp.dump.SystemLoadResult)

Example 4 with SystemLoadResult

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

the class DumpServiceImplTest method number_of_versions_in_other_repo.

@Test
public void number_of_versions_in_other_repo() {
    final Repository myRepo = NodeHelper.runAsAdmin(() -> doCreateRepository(RepositoryId.from("myrepo"), AccessControlList.create().add(AccessControlEntry.create().principal(ctxDefault().getAuthInfo().getUser().getKey()).allowAll().build()).build(), null));
    final Context myRepoContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(myRepo.getId()).branch(RepositoryConstants.MASTER_BRANCH).build();
    final Node myNode = myRepoContext.callWith(() -> createNode(NodePath.ROOT, "myNode"));
    myRepoContext.runWith(() -> updateNode(myNode));
    myRepoContext.runWith(() -> updateNode(myNode));
    myRepoContext.runWith(() -> updateNode(myNode));
    final SystemLoadResult dumpResult = NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true, SystemDumpParams.create().dumpName("myTestDump").build()));
    final RepoLoadResult repoLoadResult = getRepoLoadResult(dumpResult, myRepo.getId());
    final VersionsLoadResult versionsLoadResult = repoLoadResult.getVersionsLoadResult();
    assertNotNull(versionsLoadResult);
    // One for root, 4 for myNode
    assertEquals(5, versionsLoadResult.getSuccessful());
}
Also used : BundleContext(org.osgi.framework.BundleContext) Context(com.enonic.xp.context.Context) InternalContext(com.enonic.xp.repo.impl.InternalContext) Repository(com.enonic.xp.repository.Repository) SystemLoadResult(com.enonic.xp.dump.SystemLoadResult) Node(com.enonic.xp.node.Node) VersionsLoadResult(com.enonic.xp.dump.VersionsLoadResult) RepoLoadResult(com.enonic.xp.dump.RepoLoadResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 5 with SystemLoadResult

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

the class SystemRepoLoadResultJsonTest method create.

@Test
public void create() throws Exception {
    final SystemLoadResult results = SystemLoadResult.create().add(RepoLoadResult.create(RepositoryId.from("my-repo")).add(BranchLoadResult.create(Branch.from("myBranch")).successful(100L).build()).add(BranchLoadResult.create(Branch.from("myOtherBranch")).successful(100L).build()).build()).add(RepoLoadResult.create(RepositoryId.from("my-other-repo")).add(BranchLoadResult.create(Branch.from("myBranch2")).successful(100L).error(LoadError.error("this is an error")).error(LoadError.error("this is another error")).build()).versions(VersionsLoadResult.create().successful(10L).error(LoadError.error("fisk")).build()).build()).build();
    final SystemLoadResultJson json = SystemLoadResultJson.from(results);
    assertEquals(2, json.getRepositories().size());
    assertEquals(2, json.getRepositories().get(0).getBranches().size());
}
Also used : SystemLoadResult(com.enonic.xp.dump.SystemLoadResult) Test(org.junit.jupiter.api.Test)

Aggregations

SystemLoadResult (com.enonic.xp.dump.SystemLoadResult)5 Test (org.junit.jupiter.api.Test)4 SystemLoadParams (com.enonic.xp.dump.SystemLoadParams)2 SystemLoadRequestJson (com.enonic.xp.impl.server.rest.model.SystemLoadRequestJson)2 Repository (com.enonic.xp.repository.Repository)2 AbstractRunnableTaskTest (com.enonic.xp.task.AbstractRunnableTaskTest)2 RunnableTask (com.enonic.xp.task.RunnableTask)2 Context (com.enonic.xp.context.Context)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 RepoLoadResult (com.enonic.xp.dump.RepoLoadResult)1 VersionsLoadResult (com.enonic.xp.dump.VersionsLoadResult)1 ImportNodesParams (com.enonic.xp.export.ImportNodesParams)1 NodeImportResult (com.enonic.xp.export.NodeImportResult)1 Node (com.enonic.xp.node.Node)1 NodePath (com.enonic.xp.node.NodePath)1 InternalContext (com.enonic.xp.repo.impl.InternalContext)1 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)1 Path (java.nio.file.Path)1 BundleContext (org.osgi.framework.BundleContext)1