Search in sources :

Example 96 with Patch

use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceIT method rollbackInstalledNonRollupPatch.

@Test
public void rollbackInstalledNonRollupPatch() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    GitPatchRepository repository = patchManagement();
    PatchManagement management = (PatchManagement) pm;
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL());
    Patch patch = management.trackPatch(patches.get(0));
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    ObjectId master1 = fork.getRepository().resolve(GitPatchRepository.HISTORY_BRANCH);
    String tx = management.beginInstallation(PatchKind.NON_ROLLUP);
    management.install(tx, patch, null);
    management.commitInstallation(tx);
    management.rollback(patch.getPatchData());
    repository.closeRepository(fork, true);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    ObjectId master2 = fork.getRepository().resolve(GitPatchRepository.HISTORY_BRANCH);
    assertThat(master1, not(equalTo(master2)));
    assertThat(fork.tagList().call().size(), equalTo(2));
    assertTrue(repository.containsTag(fork, "patch-management"));
    assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
    assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
    String binStart = FileUtils.readFileToString(new File(karafHome, "bin/start"));
    assertTrue("bin/start should be at previous version", binStart.contains("echo \"This is user's change\""));
}
Also used : Git(org.eclipse.jgit.api.Git) ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) File(java.io.File) Test(org.junit.Test)

Example 97 with Patch

use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.

the class ServiceImplTest method testCheckPrerequisitesNotInstalled.

@Test
public void testCheckPrerequisitesNotInstalled() throws IOException {
    ServiceImpl service = createMockServiceImpl(getDirectoryForResource("prereq/patch2.patch"));
    Patch patch = service.getPatch("patch2");
    assertNotNull(patch);
    try {
        service.checkPrerequisites(patch);
        fail("Patch will prerequisites that are not yet installed should not pass check");
    } catch (PatchException e) {
        assertTrue(e.getMessage().toLowerCase().contains("required patch 'prereq2' is not installed"));
    }
}
Also used : GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) PatchException(io.fabric8.patch.management.PatchException) Patch(io.fabric8.patch.management.Patch) Test(org.junit.Test)

Example 98 with Patch

use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.

the class ServiceImplTest method testLoadWithRanges.

@Test
public void testLoadWithRanges() throws IOException {
    ServiceImpl service = createMockServiceImpl();
    PatchData pd = PatchData.load(getClass().getClassLoader().getResourceAsStream("test2.patch"));
    assertEquals(2, pd.getBundles().size());
    assertEquals("[1.0.0,2.0.0)", pd.getVersionRange("mvn:io.fabric8.test/test1/1.0.0"));
    assertNull(pd.getVersionRange("mvn:io.fabric8.test/test2/1.0.0"));
    assertTrue(pd.getRequirements().isEmpty());
}
Also used : PatchData(io.fabric8.patch.management.PatchData) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) Test(org.junit.Test)

Example 99 with Patch

use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.

the class ServiceImplTest method testCheckPrerequisitesMissing.

@Test
public void testCheckPrerequisitesMissing() throws IOException {
    ServiceImpl service = createMockServiceImpl(getDirectoryForResource("prereq/patch1.patch"));
    Patch patch = service.getPatch("patch1");
    assertNotNull(patch);
    try {
        service.checkPrerequisites(patch);
        fail("Patch will missing prerequisites should not pass check");
    } catch (PatchException e) {
        assertTrue(e.getMessage().toLowerCase().contains("required patch 'prereq1' is missing"));
    }
}
Also used : GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) PatchException(io.fabric8.patch.management.PatchException) Patch(io.fabric8.patch.management.Patch) Test(org.junit.Test)

Example 100 with Patch

use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.

the class ServiceImplTest method testLoadWithoutRanges.

@Test
public void testLoadWithoutRanges() throws IOException, GitAPIException {
    BundleContext bundleContext = createMock(BundleContext.class);
    ComponentContext componentContext = createMock(ComponentContext.class);
    Bundle sysBundle = createMock(Bundle.class);
    BundleContext sysBundleContext = createMock(BundleContext.class);
    Bundle bundle = createMock(Bundle.class);
    Bundle bundle2 = createMock(Bundle.class);
    FrameworkWiring wiring = createMock(FrameworkWiring.class);
    GitPatchRepository repository = createMock(GitPatchRepository.class);
    // 
    // Create a new service, download a patch
    // 
    expect(componentContext.getBundleContext()).andReturn(bundleContext);
    expect(bundleContext.getBundle(0)).andReturn(sysBundle).anyTimes();
    expect(sysBundle.getBundleContext()).andReturn(sysBundleContext).anyTimes();
    expect(sysBundleContext.getProperty(Service.NEW_PATCH_LOCATION)).andReturn(storage.toString()).anyTimes();
    expect(repository.getManagedPatch(anyString())).andReturn(null).anyTimes();
    expect(repository.findOrCreateMainGitRepository()).andReturn(null).anyTimes();
    expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
    expect(sysBundleContext.getProperty("karaf.home")).andReturn(karaf.getCanonicalPath()).anyTimes();
    expect(sysBundleContext.getProperty("karaf.base")).andReturn(karaf.getCanonicalPath()).anyTimes();
    expect(sysBundleContext.getProperty("karaf.name")).andReturn("root").anyTimes();
    expect(sysBundleContext.getProperty("karaf.instances")).andReturn(karaf.getCanonicalPath() + "/instances").anyTimes();
    expect(sysBundleContext.getProperty("karaf.data")).andReturn(karaf.getCanonicalPath() + "/data").anyTimes();
    replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository);
    PatchManagement pm = new GitPatchManagementServiceImpl(bundleContext);
    ((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
    ServiceImpl service = new ServiceImpl();
    setField(service, "patchManagement", pm);
    service.activate(componentContext);
    PatchData pd = PatchData.load(getClass().getClassLoader().getResourceAsStream("test1.patch"));
    assertEquals(2, pd.getBundles().size());
    assertTrue(pd.getRequirements().isEmpty());
}
Also used : GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) PatchData(io.fabric8.patch.management.PatchData) ComponentContext(org.osgi.service.component.ComponentContext) Bundle(org.osgi.framework.Bundle) PatchManagement(io.fabric8.patch.management.PatchManagement) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

File (java.io.File)54 Test (org.junit.Test)43 Git (org.eclipse.jgit.api.Git)35 PatchException (io.fabric8.patch.management.PatchException)34 Patch (io.fabric8.patch.management.Patch)30 IOException (java.io.IOException)28 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)27 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)26 HashMap (java.util.HashMap)18 RevCommit (org.eclipse.jgit.revwalk.RevCommit)18 LinkedList (java.util.LinkedList)17 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)17 ObjectId (org.eclipse.jgit.lib.ObjectId)17 Bundle (org.osgi.framework.Bundle)17 Version (org.osgi.framework.Version)15 PatchResult (io.fabric8.patch.management.PatchResult)13 BundleUpdate (io.fabric8.patch.management.BundleUpdate)11 PatchData (io.fabric8.patch.management.PatchData)11 ArrayList (java.util.ArrayList)11