Search in sources :

Example 31 with PatchException

use of io.fabric8.patch.management.PatchException 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 32 with PatchException

use of io.fabric8.patch.management.PatchException 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 33 with PatchException

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

the class PatchServiceImplTest method testCheckRequirementsMissingPatches.

@Test
public void testCheckRequirementsMissingPatches() throws IOException {
    PatchServiceImpl.PatchDescriptor descriptor = getPatchDescriptor("test4.patch");
    Version version = buildVersion("1.1").withProfiles("karaf", "default", "patch-prereq4a", "patch-somethingelse").done();
    try {
        PatchServiceImpl.checkRequirements(version, descriptor);
        fail("Patch should not have passed requirements check - required patch is missing");
    } catch (PatchException e) {
        assertTrue(e.getMessage().toLowerCase().contains("required patch 'prereq4b' is missing"));
    }
}
Also used : Version(io.fabric8.api.Version) PatchException(io.fabric8.api.PatchException) Test(org.junit.Test)

Example 34 with PatchException

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

the class PatchServiceImplTest method testFailOnCorruptedZip.

@Test
public void testFailOnCorruptedZip() throws URISyntaxException, MalformedURLException {
    FabricService mockFabricService = Mockito.mock(FabricService.class);
    when(mockFabricService.getMavenRepoUploadURI()).thenReturn(new URI("http://dummy"));
    PatchServiceImpl patchService = new PatchServiceImpl(mockFabricService);
    Version version = Mockito.mock(Version.class);
    URL url = getClass().getClassLoader().getResource("corrupted_archive.zip");
    try {
        patchService.applyPatch(version, url, "not_relevant", "not_relevant");
        fail("Expected PatchException has not been triggered.");
    } catch (PatchException e) {
        assertNotNull(e);
        e.printStackTrace();
    } catch (Exception e) {
        fail("Note the expected exception: " + e);
        e.printStackTrace();
    }
}
Also used : Version(io.fabric8.api.Version) FabricService(io.fabric8.api.FabricService) PatchException(io.fabric8.api.PatchException) URI(java.net.URI) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) PatchException(io.fabric8.api.PatchException) Test(org.junit.Test)

Example 35 with PatchException

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

the class FabricInstallAction method doExecute.

@Override
protected void doExecute(Service service) throws Exception {
    Patch patch = service.getPatch(patchId);
    if (patch == null) {
        throw new PatchException("Patch '" + patchId + "' not found");
    }
    ProfileUpdateStrategy strategy = ProfileUpdateStrategy.GIT;
    if ((mergeOverwrite && (mergeSelectNew || mergeKeepExisting)) || (mergeSelectNew && (mergeOverwrite || mergeKeepExisting)) || (mergeKeepExisting && (mergeOverwrite || mergeSelectNew))) {
        throw new UnsupportedOperationException("Please select single merge strategy");
    }
    if (mergeKeepExisting) {
        strategy = ProfileUpdateStrategy.PROPERTIES_PREFER_EXISTING;
    } else if (mergeSelectNew) {
        strategy = ProfileUpdateStrategy.PROPERTIES_PREFER_NEW;
    }
    PatchResult result = fabricPatchService.install(patch, simulation, versionId, upload, username, password, strategy);
}
Also used : PatchResult(io.fabric8.patch.management.PatchResult) PatchException(io.fabric8.patch.management.PatchException) ProfileUpdateStrategy(io.fabric8.patch.management.ProfileUpdateStrategy) Patch(io.fabric8.patch.management.Patch)

Aggregations

PatchException (io.fabric8.patch.management.PatchException)30 IOException (java.io.IOException)19 File (java.io.File)15 Patch (io.fabric8.patch.management.Patch)14 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)11 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)10 Git (org.eclipse.jgit.api.Git)10 LinkedList (java.util.LinkedList)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)7 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)6 URISyntaxException (java.net.URISyntaxException)6 HashMap (java.util.HashMap)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 PatchResult (io.fabric8.patch.management.PatchResult)5 FileInputStream (java.io.FileInputStream)5 FileNotFoundException (java.io.FileNotFoundException)5 BundleException (org.osgi.framework.BundleException)5 ManagedPatch (io.fabric8.patch.management.ManagedPatch)4 URL (java.net.URL)4