Search in sources :

Example 6 with ContextConfigurationUpgrader

use of com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader in project cobigen by devonfw.

the class ContextConfigurationUpgraderTest method testCorrectUpgrade_v2_0_TO_LATEST.

/**
 * Tests the valid upgrade of a context configuration from version v2.0 to latest version. Please make sure that
 * .../ContextConfigurationUpgraderTest/valid-latest_version exists
 *
 * @throws Exception test fails
 */
@Test
public void testCorrectUpgrade_v2_0_TO_LATEST() throws Exception {
    // preparation
    File tmpTargetConfig = this.tempFolder.newFile(ConfigurationConstants.CONTEXT_CONFIG_FILENAME);
    File sourceTestdata = new File(testFileRootPath + "valid-v2.0/" + ConfigurationConstants.CONTEXT_CONFIG_FILENAME);
    Files.copy(sourceTestdata, tmpTargetConfig);
    ContextConfigurationUpgrader sut = new ContextConfigurationUpgrader();
    ContextConfigurationVersion version = sut.resolveLatestCompatibleSchemaVersion(this.tempFolder.getRoot().toPath());
    assertThat(version).as("Source Version").isEqualTo(ContextConfigurationVersion.v2_0);
    sut.upgradeConfigurationToLatestVersion(this.tempFolder.getRoot().toPath(), BackupPolicy.ENFORCE_BACKUP);
    assertThat(tmpTargetConfig.toPath().resolveSibling("context.bak.xml").toFile()).exists().hasSameContentAs(sourceTestdata);
    version = sut.resolveLatestCompatibleSchemaVersion(this.tempFolder.getRoot().toPath());
    assertThat(version).as("Target version").isEqualTo(ContextConfigurationVersion.getLatest());
    XMLUnit.setIgnoreWhitespace(true);
    new XMLTestCase() {
    }.assertXMLEqual(new FileReader(testFileRootPath + "valid-" + ContextConfigurationVersion.getLatest() + "/" + ConfigurationConstants.CONTEXT_CONFIG_FILENAME), new FileReader(tmpTargetConfig));
}
Also used : ContextConfigurationUpgrader(com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader) XMLTestCase(org.custommonkey.xmlunit.XMLTestCase) FileReader(java.io.FileReader) File(java.io.File) ContextConfigurationVersion(com.devonfw.cobigen.impl.config.constant.ContextConfigurationVersion) Test(org.junit.Test) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)

Example 7 with ContextConfigurationUpgrader

use of com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader in project cobigen by devonfw.

the class ContextConfigurationUpgraderTest method testCorrectLatestSchemaDetection.

/**
 * Tests if latest context configuration is compatible to latest schema version.
 *
 * @throws Exception test fails
 */
@Test
public void testCorrectLatestSchemaDetection() throws Exception {
    // preparation
    File targetConfig = new File(testFileRootPath + "valid-" + ContextConfigurationVersion.getLatest());
    ContextConfigurationVersion version = new ContextConfigurationUpgrader().resolveLatestCompatibleSchemaVersion(targetConfig.toPath());
    assertThat(version).isEqualTo(ContextConfigurationVersion.getLatest());
}
Also used : ContextConfigurationUpgrader(com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader) File(java.io.File) ContextConfigurationVersion(com.devonfw.cobigen.impl.config.constant.ContextConfigurationVersion) Test(org.junit.Test) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)

Aggregations

ContextConfigurationUpgrader (com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader)7 File (java.io.File)6 Test (org.junit.Test)5 ContextConfigurationVersion (com.devonfw.cobigen.impl.config.constant.ContextConfigurationVersion)3 TemplateConfigurationUpgrader (com.devonfw.cobigen.impl.config.upgrade.TemplateConfigurationUpgrader)3 Ignore (org.junit.Ignore)3 AbstractUnitTest (com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)2 ConfigurationConflictException (com.devonfw.cobigen.api.exception.ConfigurationConflictException)1 InvalidConfigurationException (com.devonfw.cobigen.api.exception.InvalidConfigurationException)1 GeneratorProjectNotExistentException (com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException)1 FileReader (java.io.FileReader)1 Path (java.nio.file.Path)1 XMLTestCase (org.custommonkey.xmlunit.XMLTestCase)1 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1