Search in sources :

Example 1 with Version

use of com.enonic.xp.util.Version in project xp by enonic.

the class DumpServiceImplTest method upgrade.

@Test
public void upgrade() throws Exception {
    final String dumpName = "testDump";
    createIncompatibleDump(dumpName);
    NodeHelper.runAsAdmin(() -> {
        final UpgradeListener upgradeListener = mock(UpgradeListener.class);
        final SystemDumpUpgradeParams params = SystemDumpUpgradeParams.create().dumpName(dumpName).upgradeListener(upgradeListener).build();
        final DumpUpgradeResult result = this.dumpService.upgrade(params);
        assertEquals(new Version(0, 0, 0), result.getInitialVersion());
        assertEquals(DumpConstants.MODEL_VERSION, result.getUpgradedVersion());
        Mockito.verify(upgradeListener, Mockito.times(8)).upgraded();
        Mockito.verify(upgradeListener, Mockito.times(1)).total(8);
        FileDumpReader reader = FileDumpReader.create(null, temporaryFolder, dumpName);
        final DumpMeta updatedMeta = reader.getDumpMeta();
        assertEquals(DumpConstants.MODEL_VERSION, updatedMeta.getModelVersion());
    });
}
Also used : DumpMeta(com.enonic.xp.repo.impl.dump.model.DumpMeta) UpgradeListener(com.enonic.xp.upgrade.UpgradeListener) Version(com.enonic.xp.util.Version) NodeVersion(com.enonic.xp.node.NodeVersion) SystemDumpUpgradeParams(com.enonic.xp.dump.SystemDumpUpgradeParams) DumpUpgradeResult(com.enonic.xp.dump.DumpUpgradeResult) FileDumpReader(com.enonic.xp.repo.impl.dump.reader.FileDumpReader) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 2 with Version

use of com.enonic.xp.util.Version in project xp by enonic.

the class DumpMetaJson method fromJson.

public static DumpMeta fromJson(final DumpMetaJson dumpMetaJson) {
    final DumpMeta.Builder dumpMeta = DumpMeta.create().xpVersion(dumpMetaJson.getXpVersion()).timestamp(Instant.parse(dumpMetaJson.getTimestamp()));
    if (dumpMetaJson.getResult() != null) {
        SystemDumpResult.Builder systemDumpResult = SystemDumpResult.create();
        dumpMetaJson.getResult().forEach((key, value) -> systemDumpResult.add(RepoDumpResultJson.fromJson(key, value)));
        dumpMeta.systemDumpResult(systemDumpResult.build());
    }
    if (!isNullOrEmpty(dumpMetaJson.getModelVersion())) {
        final Version modelVersion = Version.valueOf(dumpMetaJson.getModelVersion());
        dumpMeta.modelVersion(modelVersion);
    }
    return dumpMeta.build();
}
Also used : DumpMeta(com.enonic.xp.repo.impl.dump.model.DumpMeta) Version(com.enonic.xp.util.Version) SystemDumpResult(com.enonic.xp.dump.SystemDumpResult)

Example 3 with Version

use of com.enonic.xp.util.Version in project xp by enonic.

the class CommitDumpUpgrader method upgradeVersionEntry.

@Override
protected byte[] upgradeVersionEntry(final RepositoryId repositoryId, final String entryContent) {
    final Pre6VersionsDumpEntryJson sourceEntry = deserializeValue(entryContent, Pre6VersionsDumpEntryJson.class);
    final VersionsDumpEntryJson.Builder upgradedEntry = VersionsDumpEntryJson.create().nodeId(sourceEntry.getNodeId());
    sourceEntry.getVersions().stream().map(version -> {
        final boolean commit = commitedVersionIds.contains(version.getVersion());
        return upgradeVersionDumpEntry(version, commit);
    }).forEach(upgradedEntry::version);
    return serialize(upgradedEntry.build());
}
Also used : AbstractMetaDumpUpgrader(com.enonic.xp.repo.impl.dump.upgrade.AbstractMetaDumpUpgrader) BranchDumpEntryJson(com.enonic.xp.repo.impl.dump.serializer.json.BranchDumpEntryJson) VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.serializer.json.VersionsDumpEntryJson) Files(java.nio.file.Files) Version(com.enonic.xp.util.Version) Pre6VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6VersionsDumpEntryJson) NodeCommitId(com.enonic.xp.node.NodeCommitId) VersionDumpEntryJson(com.enonic.xp.repo.impl.dump.serializer.json.VersionDumpEntryJson) Pre6BranchDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6BranchDumpEntryJson) HashSet(java.util.HashSet) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) RepositoryId(com.enonic.xp.repository.RepositoryId) Pre6VersionDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6VersionDumpEntryJson) CommitDumpEntryJson(com.enonic.xp.repo.impl.dump.serializer.json.CommitDumpEntryJson) Path(java.nio.file.Path) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.serializer.json.VersionsDumpEntryJson) Pre6VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6VersionsDumpEntryJson) Pre6VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6VersionsDumpEntryJson)

Example 4 with Version

use of com.enonic.xp.util.Version in project xp by enonic.

the class UpgradeRunnableTaskTest method upgrade.

@Test
public void upgrade() {
    final DumpUpgradeResult upgradeResult = DumpUpgradeResult.create().initialVersion(Version.emptyVersion).upgradedVersion(new Version(1)).stepResult(DumpUpgradeStepResult.create().stepName("Step1").initialVersion(Version.emptyVersion).upgradedVersion(new Version(1)).build()).build();
    Mockito.when(this.dumpService.upgrade(Mockito.isA(SystemDumpUpgradeParams.class))).thenReturn(upgradeResult);
    final UpgradeRunnableTask task = createAndRunTask(new SystemDumpUpgradeRequestJson("dump-name"));
    task.createTaskResult();
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("upgrade"));
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("upgrade_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : SystemDumpUpgradeRequestJson(com.enonic.xp.impl.server.rest.model.SystemDumpUpgradeRequestJson) Version(com.enonic.xp.util.Version) RunnableTask(com.enonic.xp.task.RunnableTask) SystemDumpUpgradeParams(com.enonic.xp.dump.SystemDumpUpgradeParams) DumpUpgradeResult(com.enonic.xp.dump.DumpUpgradeResult) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Aggregations

Version (com.enonic.xp.util.Version)4 DumpUpgradeResult (com.enonic.xp.dump.DumpUpgradeResult)2 SystemDumpUpgradeParams (com.enonic.xp.dump.SystemDumpUpgradeParams)2 DumpMeta (com.enonic.xp.repo.impl.dump.model.DumpMeta)2 Test (org.junit.jupiter.api.Test)2 SystemDumpResult (com.enonic.xp.dump.SystemDumpResult)1 SystemDumpUpgradeRequestJson (com.enonic.xp.impl.server.rest.model.SystemDumpUpgradeRequestJson)1 NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)1 NodeCommitId (com.enonic.xp.node.NodeCommitId)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 FileDumpReader (com.enonic.xp.repo.impl.dump.reader.FileDumpReader)1 BranchDumpEntryJson (com.enonic.xp.repo.impl.dump.serializer.json.BranchDumpEntryJson)1 CommitDumpEntryJson (com.enonic.xp.repo.impl.dump.serializer.json.CommitDumpEntryJson)1 VersionDumpEntryJson (com.enonic.xp.repo.impl.dump.serializer.json.VersionDumpEntryJson)1 VersionsDumpEntryJson (com.enonic.xp.repo.impl.dump.serializer.json.VersionsDumpEntryJson)1 AbstractMetaDumpUpgrader (com.enonic.xp.repo.impl.dump.upgrade.AbstractMetaDumpUpgrader)1 Pre6BranchDumpEntryJson (com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6BranchDumpEntryJson)1 Pre6VersionDumpEntryJson (com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6VersionDumpEntryJson)1 Pre6VersionsDumpEntryJson (com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre6.Pre6VersionsDumpEntryJson)1 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)1