Search in sources :

Example 6 with FeaturesProcessing

use of org.apache.karaf.features.internal.model.processing.FeaturesProcessing in project fuse-karaf by jboss-fuse.

the class FeatureProcessingTest method readProcessingWithPlaceholders.

@Test
public void readProcessingWithPlaceholders() {
    FeaturesProcessing fp1 = InternalUtils.loadFeatureProcessing(new File("src/test/resources/processing/oakf.1.xml"), null);
    FeaturesProcessing fp2 = InternalUtils.loadFeatureProcessing(new File("src/test/resources/processing/oakf.1.xml"), new File("src/test/resources/processing/oakf.1.properties"));
    assertThat(fp1.getBundleReplacements().getOverrideBundles().get(1).getReplacement()).isEqualTo("mvn:org.jboss.fuse.test/test-2/${version.test2}");
    assertThat(fp2.getBundleReplacements().getOverrideBundles().get(1).getReplacement()).isEqualTo("mvn:org.jboss.fuse.test/test-2/1.3");
}
Also used : File(java.io.File) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) Test(org.junit.Test)

Example 7 with FeaturesProcessing

use of org.apache.karaf.features.internal.model.processing.FeaturesProcessing in project fuse-karaf by jboss-fuse.

the class GitPatchManagementServiceIT method installThreeNonRollupPatchesWithExternalizedVersionsProperties.

@Test
public void installThreeNonRollupPatchesWithExternalizedVersionsProperties() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInSystem();
    try (FileOutputStream fos = new FileOutputStream(new File(karafHome, "etc/org.apache.karaf.features.xml"))) {
        FileUtils.copyFile(new File("src/test/resources/processing/oakf.2.xml"), fos);
    }
    FileUtils.write(new File(karafHome, "etc/versions.properties"), "version.zen = 1.1.9\n", "UTF-8");
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch5", "target/karaf/patches/source/patch-5.zip", false);
    preparePatchZip("src/test/resources/content/patch6", "target/karaf/patches/source/patch-6.zip", false);
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
    Patch patch1 = service.trackPatch(patchData1);
    PatchData patchData5 = service.fetchPatches(new File("target/karaf/patches/source/patch-5.zip").toURI().toURL()).get(0);
    Patch patch5 = service.trackPatch(patchData5);
    PatchData patchData6 = service.fetchPatches(new File("target/karaf/patches/source/patch-6.zip").toURI().toURL()).get(0);
    Patch patch6 = service.trackPatch(patchData6);
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertTrue(FileUtils.readFileToString(new File(karafHome, "etc/versions.properties"), "UTF-8").contains("version.zen = 1.1.9"));
    String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    List<BundleUpdate> patch1Updates = new LinkedList<>();
    patch1Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-tranquility/1.2.0").to("mvn:org.jboss.fuse/fuse-tranquility/1.2.3"));
    service.install(tx, patch1, patch1Updates);
    List<BundleUpdate> patch5Updates = new LinkedList<>();
    patch5Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-zen/1.1.44/war").to("mvn:org.jboss.fuse/fuse-zen/1.2.0/war"));
    service.install(tx, patch5, patch5Updates);
    List<BundleUpdate> patch6Updates = new LinkedList<>();
    patch6Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-zen/1.2.4/war").to("mvn:org.jboss.fuse/fuse-zen/1.3.0/war"));
    service.install(tx, patch6, patch6Updates);
    service.commitInstallation(tx);
    String binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
    assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
    String etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
    // version from patch-5 should be chosen, because there's 1.1.44->1.2.0
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
    assertFalse(new File(karafHome, "etc/overrides.properties").exists());
    FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(3));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-tranquility/[1.2.0,1.3.0)".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-tranquility/1.2.3".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.2)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/${version.zen}/war".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
    assertTrue(FileUtils.readFileToString(new File(karafHome, "etc/versions.properties"), "UTF-8").contains("version.zen = 1.2.0"));
    /* rollback time! */
    Patch p5 = service.loadPatch(new PatchDetailsRequest("my-patch-5"));
    service.rollback(p5.getPatchData());
    binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
    assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
    etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
    // rollback wasn't successful
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
    assertFalse(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.1.44/war = 42"));
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
    fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(3));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-tranquility/[1.2.0,1.3.0)".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-tranquility/1.2.3".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.2)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/${version.zen}/war".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
    assertTrue(FileUtils.readFileToString(new File(karafHome, "etc/versions.properties"), "UTF-8").contains("version.zen = 1.2.0"));
    Patch p6 = service.loadPatch(new PatchDetailsRequest("my-patch-6"));
    service.rollback(p6.getPatchData());
    binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
    assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
    etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
    fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(2));
    assertTrue(bundles.stream().noneMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
    // after rolling back patch 6 we can rollback patch 5
    p5 = service.loadPatch(new PatchDetailsRequest("my-patch-5"));
    service.rollback(p5.getPatchData());
    fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    bundles = fp.getBundleReplacements().getOverrideBundles();
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.1.9)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/${version.zen}/war".equals(b.getReplacement())));
    assertTrue(FileUtils.readFileToString(new File(karafHome, "etc/versions.properties"), "UTF-8").contains("version.zen = 1.1.9"));
    repository.closeRepository(fork, true);
}
Also used : Arrays(java.util.Arrays) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) BundleReplacements(org.apache.karaf.features.internal.model.processing.BundleReplacements) RevWalk(org.eclipse.jgit.revwalk.RevWalk) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Map(java.util.Map) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) InternalUtils(org.jboss.fuse.patch.management.impl.InternalUtils) LinkedList(java.util.LinkedList) Before(org.junit.Before) Properties(java.util.Properties) Iterator(java.util.Iterator) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) SystemUtils(org.apache.commons.lang3.SystemUtils) FeatureReplacements(org.apache.karaf.features.internal.model.processing.FeatureReplacements) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) File(java.io.File) ObjectId(org.eclipse.jgit.lib.ObjectId) BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) Mockito(org.mockito.Mockito) List(java.util.List) Ref(org.eclipse.jgit.lib.Ref) GitPatchManagementService(org.jboss.fuse.patch.management.impl.GitPatchManagementService) FileReader(java.io.FileReader) Git(org.eclipse.jgit.api.Git) ListBranchCommand(org.eclipse.jgit.api.ListBranchCommand) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Assert(org.junit.Assert) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) LinkedList(java.util.LinkedList) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.Test)

Example 8 with FeaturesProcessing

use of org.apache.karaf.features.internal.model.processing.FeaturesProcessing in project fuse-karaf by jboss-fuse.

the class GitPatchManagementServiceIT method installPPatchAndThenRPatch.

@Test
public void installPPatchAndThenRPatch() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInSystem();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
    // simulation of P patch installed using old patching mechanism
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    FileUtils.write(new File(karafHome, "etc/overrides.properties"), "mvn:org.jboss.fuse/fuse-oceans/1.4.2\n", "UTF-8");
    // non-conflicting
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    repository.closeRepository(fork, true);
    // overrides.properties as after installing P patch with old mechanism
    String etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"), "UTF-8");
    assertThat(etcOverridesProperties, equalTo("mvn:org.jboss.fuse/fuse-oceans/1.4.2\n"));
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
    Patch patch1 = service.trackPatch(patchData1);
    PatchData patchData4 = service.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL()).get(0);
    Patch patch4 = service.trackPatch(patchData4);
    String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    service.install(tx, patch1, null);
    service.commitInstallation(tx);
    assertTrue("There should be no changes to etc/overrides.properties after installing non-rollup patch", new File(karafHome, "etc/overrides.properties").exists());
    // overrides.properties as after installing P patch with new mechanism
    etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"), "UTF-8");
    assertThat(etcOverridesProperties, equalTo("mvn:org.jboss.fuse/fuse-oceans/1.4.2\n"));
    // override from P-Patch should go to etc/org.apache.karaf.features.xml
    FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(1));
    assertThat(bundles.get(0).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-tranquility/1.2.3"));
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
    assertFalse(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
    repository.closeRepository(fork, true);
    tx = service.beginInstallation(PatchKind.ROLLUP);
    service.install(tx, patch4, null);
    service.commitInstallation(tx);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
    assertTrue(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
    assertFalse("There should be no etc/overrides.properties after installing rollup patch", new File(karafHome, "etc/overrides.properties").exists());
    repository.closeRepository(fork, true);
}
Also used : GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) File(java.io.File) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) Test(org.junit.Test)

Example 9 with FeaturesProcessing

use of org.apache.karaf.features.internal.model.processing.FeaturesProcessing in project fuse-karaf by jboss-fuse.

the class GitPatchManagementServiceIT method installPPatchHotFixPPatchAndThenRPatch.

/**
 * Installation of R patch <strong>may</strong> leave P patches installed when they provide <strong>only</strong>
 * bundles and the bundles are at higher version
 * @throws IOException
 * @throws GitAPIException
 */
@Test
public void installPPatchHotFixPPatchAndThenRPatch() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    preparePatchZip("src/test/resources/baselines/baseline5", "target/karaf/system/org/jboss/fuse/fuse-karaf/7.0.0/fuse-karaf-7.0.0-baseline.zip", true);
    validateInitialGitRepository();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch2", "target/karaf/patches/source/patch-2.zip", false);
    preparePatchZip("src/test/resources/content/patch9", "target/karaf/patches/source/patch-9.zip", false);
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
    Patch patch1 = service.trackPatch(patchData1);
    PatchData patchData2 = service.fetchPatches(new File("target/karaf/patches/source/patch-2.zip").toURI().toURL()).get(0);
    Patch patch2 = service.trackPatch(patchData2);
    PatchData patchData9 = service.fetchPatches(new File("target/karaf/patches/source/patch-9.zip").toURI().toURL()).get(0);
    Patch patch9 = service.trackPatch(patchData9);
    String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    service.install(tx, patch1, null);
    service.commitInstallation(tx);
    tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    service.install(tx, patch2, null);
    service.commitInstallation(tx);
    assertFalse("There should be no etc/overrides.properties after installing non-rollup patches", new File(karafHome, "etc/overrides.properties").exists());
    FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(3));
    assertThat(bundles.get(0).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-observations/3.2"));
    assertThat(bundles.get(1).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-temporary-workaround/2.2.1"));
    assertThat(bundles.get(2).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-tranquility/1.2.5"));
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
    assertTrue(repository.containsTag(fork, "patch-my-patch-2"));
    assertFalse(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
    repository.closeRepository(fork, true);
    tx = service.beginInstallation(PatchKind.ROLLUP);
    service.install(tx, patch9, null);
    service.commitInstallation(tx);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
    assertFalse(repository.containsTag(fork, "patch-my-patch-2"));
    assertTrue(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
    assertFalse("There still should be no etc/overrides.properties after installing rollup patch", new File(karafHome, "etc/overrides.properties").exists());
    // features processing should be conflict-resolved (R-patch version and P-patch version).
    // newer version of fuse-tranquility (from P-Patch) should win
    fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(2));
    assertThat(bundles.get(1).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-tranquility/1.2.5"));
    repository.closeRepository(fork, true);
}
Also used : GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) File(java.io.File) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) Test(org.junit.Test)

Example 10 with FeaturesProcessing

use of org.apache.karaf.features.internal.model.processing.FeaturesProcessing in project fuse-karaf by jboss-fuse.

the class GitPatchManagementServiceIT method installThreeNonRollupPatches.

@Test
public void installThreeNonRollupPatches() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInSystem();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch5", "target/karaf/patches/source/patch-5.zip", false);
    preparePatchZip("src/test/resources/content/patch6", "target/karaf/patches/source/patch-6.zip", false);
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
    Patch patch1 = service.trackPatch(patchData1);
    PatchData patchData5 = service.fetchPatches(new File("target/karaf/patches/source/patch-5.zip").toURI().toURL()).get(0);
    Patch patch5 = service.trackPatch(patchData5);
    PatchData patchData6 = service.fetchPatches(new File("target/karaf/patches/source/patch-6.zip").toURI().toURL()).get(0);
    Patch patch6 = service.trackPatch(patchData6);
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    List<BundleUpdate> patch1Updates = new LinkedList<>();
    patch1Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-tranquility/1.2.0").to("mvn:org.jboss.fuse/fuse-tranquility/1.2.3"));
    service.install(tx, patch1, patch1Updates);
    List<BundleUpdate> patch5Updates = new LinkedList<>();
    patch5Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-zen/1.1.44/war").to("mvn:org.jboss.fuse/fuse-zen/1.2.0/war"));
    service.install(tx, patch5, patch5Updates);
    List<BundleUpdate> patch6Updates = new LinkedList<>();
    patch5Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-zen/1.2.4/war").to("mvn:org.jboss.fuse/fuse-zen/1.3.0/war"));
    service.install(tx, patch6, patch6Updates);
    service.commitInstallation(tx);
    String binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
    assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
    String etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
    // version from patch-5 should be chosen, because there's 1.1.44->1.2.0
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
    assertFalse(new File(karafHome, "etc/overrides.properties").exists());
    FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(karafHome);
    List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(3));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-tranquility/[1.2.0,1.3.0)".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-tranquility/1.2.3".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.2)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.2.0/war".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
    /* rollback time! */
    Patch p5 = service.loadPatch(new PatchDetailsRequest("my-patch-5"));
    service.rollback(p5.getPatchData());
    binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
    assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
    etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
    // rollback wasn't successful
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
    assertFalse(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.1.44/war = 42"));
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
    fp = InternalUtils.loadFeatureProcessing(karafHome);
    bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(3));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-tranquility/[1.2.0,1.3.0)".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-tranquility/1.2.3".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.2)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.2.0/war".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
    Patch p6 = service.loadPatch(new PatchDetailsRequest("my-patch-6"));
    service.rollback(p6.getPatchData());
    binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
    assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
    etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
    fp = InternalUtils.loadFeatureProcessing(karafHome);
    bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(2));
    assertTrue(bundles.stream().noneMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
    repository.closeRepository(fork, true);
}
Also used : Arrays(java.util.Arrays) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) BundleReplacements(org.apache.karaf.features.internal.model.processing.BundleReplacements) RevWalk(org.eclipse.jgit.revwalk.RevWalk) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Map(java.util.Map) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) InternalUtils(org.jboss.fuse.patch.management.impl.InternalUtils) LinkedList(java.util.LinkedList) Before(org.junit.Before) Properties(java.util.Properties) Iterator(java.util.Iterator) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) SystemUtils(org.apache.commons.lang3.SystemUtils) FeatureReplacements(org.apache.karaf.features.internal.model.processing.FeatureReplacements) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) File(java.io.File) ObjectId(org.eclipse.jgit.lib.ObjectId) BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) Mockito(org.mockito.Mockito) List(java.util.List) Ref(org.eclipse.jgit.lib.Ref) GitPatchManagementService(org.jboss.fuse.patch.management.impl.GitPatchManagementService) FileReader(java.io.FileReader) Git(org.eclipse.jgit.api.Git) ListBranchCommand(org.eclipse.jgit.api.ListBranchCommand) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Assert(org.junit.Assert) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) LinkedList(java.util.LinkedList) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) File(java.io.File) Test(org.junit.Test)

Aggregations

FeaturesProcessing (org.apache.karaf.features.internal.model.processing.FeaturesProcessing)14 Test (org.junit.Test)11 File (java.io.File)9 BundleReplacements (org.apache.karaf.features.internal.model.processing.BundleReplacements)5 LinkedList (java.util.LinkedList)4 FeatureReplacements (org.apache.karaf.features.internal.model.processing.FeatureReplacements)4 Git (org.eclipse.jgit.api.Git)4 GitPatchManagementServiceImpl (org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl)4 GitPatchRepository (org.jboss.fuse.patch.management.impl.GitPatchRepository)4 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 Properties (java.util.Properties)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 FileReader (java.io.FileReader)2 Arrays (java.util.Arrays)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)2 FileUtils (org.apache.commons.io.FileUtils)2