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\""));
}
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"));
}
}
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());
}
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"));
}
}
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());
}
Aggregations