Search in sources :

Example 26 with GitPatchRepository

use of io.fabric8.patch.management.impl.GitPatchRepository 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 27 with GitPatchRepository

use of io.fabric8.patch.management.impl.GitPatchRepository 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

GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)26 Test (org.junit.Test)23 Git (org.eclipse.jgit.api.Git)22 File (java.io.File)21 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)20 ObjectId (org.eclipse.jgit.lib.ObjectId)13 RevCommit (org.eclipse.jgit.revwalk.RevCommit)7 Map (java.util.Map)5 Ref (org.eclipse.jgit.lib.Ref)5 PatchManagement (io.fabric8.patch.management.PatchManagement)4 Bundle (org.osgi.framework.Bundle)4 BundleContext (org.osgi.framework.BundleContext)4 ComponentContext (org.osgi.service.component.ComponentContext)4 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 Version (org.osgi.framework.Version)3 FrameworkWiring (org.osgi.framework.wiring.FrameworkWiring)3 Patch (io.fabric8.patch.management.Patch)2 PatchResult (io.fabric8.patch.management.PatchResult)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2