use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.
the class PatchBundleUnitTestCase method testSkipInstalled.
@Test
public void testSkipInstalled() throws Exception {
final PatchingTestBuilder builder = createDefaultBuilder("layer-2", "layer-1", "base");
final byte[] moduleHashOne = new byte[20];
final byte[] moduleHashTwo = new byte[20];
final byte[] moduleHashThree = new byte[20];
final PatchingTestStepBuilder cp1 = builder.createStepBuilder();
cp1.setPatchId("CP1").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP1", "base", false).addModuleWithRandomContent("org.jboss.test", moduleHashOne);
final PatchingTestStepBuilder cp2 = builder.createStepBuilder();
cp2.setPatchId("CP2").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("layer-1-CP1", "layer-1", false).addModuleWithRandomContent("org.jboss.test.two", moduleHashTwo);
final PatchingTestStepBuilder cp3 = builder.createStepBuilder();
cp3.setPatchId("CP3").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("layer-2-CP1", "layer-2", false).removeModule("org.jboss.test.three", "main", moduleHashThree);
apply(cp1);
apply(cp2);
// Prepare multi patch
final File multiPatch = prepare(builder.getRoot(), cp1, cp2, cp3);
// Create the patch tool and apply the patch
// Get installation manager instance for the unit test
InstallationManager mgr = updateInstallationManager();
final PatchTool patchTool = PatchTool.Factory.create(mgr);
final PatchingResult result = patchTool.applyPatch(multiPatch, ContentVerificationPolicy.STRICT);
result.commit();
try {
PatchStepAssertions.APPLY.after(builder.getFile(JBOSS_INSTALLATION), cp3.build(), mgr);
} catch (IOException e) {
throw new PatchingException(e);
}
}
use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.
the class PatchBundleUnitTestCase method prepare.
/**
* Prepare the multi patch bundle.
*
* @param root the temp dir root
* @param steps the individual steps
* @return the prepared content
* @throws PatchingException
*/
protected File prepare(File root, PatchingTestStepBuilder... steps) throws PatchingException {
final File tempDir = new File(root, randomString());
tempDir.mkdir();
final List<BundledPatch.BundledPatchEntry> entries = new ArrayList<BundledPatch.BundledPatchEntry>();
for (final PatchingTestStepBuilder step : steps) {
// Prepare the patches.
final Patch patch = step.build();
writePatch(step.getPatchDir(), patch);
final String patchId = patch.getPatchId();
final String path = patchId + ".zip";
final File patchOutput = new File(tempDir, path);
ZipUtils.zip(step.getPatchDir(), patchOutput);
entries.add(new BundledPatch.BundledPatchEntry(patchId, path));
}
final File multiPatchXml = new File(tempDir, PatchBundleXml.MULTI_PATCH_XML);
try {
final OutputStream os = new FileOutputStream(multiPatchXml);
try {
PatchBundleXml.marshal(os, new BundledPatch() {
@Override
public List<BundledPatchEntry> getPatches() {
return entries;
}
});
} finally {
safeClose(os);
}
} catch (Exception e) {
throw new PatchingException(e);
}
final File result = new File(root, "multi-step-contents.zip");
ZipUtils.zip(tempDir, result);
return result;
}
use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.
the class PatchStepAssertions method assertApplied.
static void assertApplied(final Patch patch, InstallationManager manager) throws IOException {
final String patchID = patch.getPatchId();
InstalledIdentity installedIdentity = null;
try {
installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null);
} catch (PatchingException e) {
Assert.fail(e.getLocalizedMessage());
}
final PatchableTarget target = installedIdentity.getIdentity();
final PatchableTarget.TargetInfo identity = target.loadTargetInfo();
assertIsApplied(patch.getIdentity().getPatchType(), patchID, identity);
assertExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patchID));
assertContentItems(patchID, target, patch.getModifications());
for (final PatchElement element : patch.getElements()) {
final PatchElementProvider provider = element.getProvider();
final PatchableTarget targetElement = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName());
assertIsApplied(provider.getPatchType(), element.getId(), targetElement.loadTargetInfo());
assertContentItems(element.getId(), targetElement, element.getModifications());
}
}
use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.
the class PatchUndoTestCase method testWrongMiscContent.
@Test
public void testWrongMiscContent() throws Exception {
final PatchingTestBuilder builder = createDefaultBuilder();
ContentModificationUtils.addMisc(builder.getRoot(), "oo2", "test-content", "wrong-content");
final MiscContentItem item = new MiscContentItem("wrong-content", new String[0], WRONG_HASH);
final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
final PatchingTestStepBuilder step1 = builder.createStepBuilder();
step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo2").oneOffPatchElement("base-patch-002", "base", false).addModuleWithRandomContent("other.test", null).getParent().addFileWithRandomContent(null, "test", "content").addContentModification(wrongModification);
//
try {
apply(step1);
Assert.fail("should have failed");
} catch (PatchingException e) {
Assert.assertFalse(builder.hasFile("test", "content"));
Assert.assertFalse(builder.hasFile("wrong-content"));
final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity();
final PatchableTarget base = identity.getLayer("base");
Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-002").exists());
Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo2").exists());
}
}
use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.
the class PatchUndoTestCase method testInvalidPatch.
@Test
public void testInvalidPatch() throws Exception {
final PatchingTestBuilder builder = createDefaultBuilder();
ContentModificationUtils.addMisc(builder.getRoot(), "oo2", "test-content", "wrong-content");
final MiscContentItem item = new MiscContentItem("wrong-content", new String[0], WRONG_HASH);
final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
final PatchingTestStepBuilder step1 = builder.createStepBuilder();
step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo2").oneOffPatchElement("base-patch-002", "base", false).addModuleWithRandomContent("other.test", null).getParent().addFileWithRandomContent(null, "test", "content");
apply(step1);
Assert.assertTrue(builder.hasFile("test", "content"));
//
final PatchingTestStepBuilder step2 = builder.createStepBuilder();
step2.upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).setPatchId("cp2").upgradeElement("base-patch-cp2", "base", false).getParent().addContentModification(wrongModification);
try {
apply(step2);
Assert.fail("should have failed");
} catch (PatchingException e) {
Assert.assertTrue(builder.hasFile("test", "content"));
}
}
Aggregations