use of org.jboss.as.patching.metadata.MiscContentItem in project wildfly-core by wildfly.
the class PatchStepAssertions method assertContentModification.
static void assertContentModification(final String patchID, final PatchableTarget target, final ContentModification modification) {
final ContentItem item = modification.getItem();
final ContentType contentType = item.getContentType();
switch(contentType) {
case MODULE:
assertModule(patchID, target, (ModuleItem) item);
break;
case BUNDLE:
break;
case MISC:
final File home = target.getDirectoryStructure().getInstalledImage().getJbossHome();
final ModificationCondition condition = modification.getCondition();
if (condition != null) {
if (condition instanceof ModificationCondition.ExistsCondition) {
final ContentItem requiredItem = ((ModificationCondition.ExistsCondition) condition).getContentItem();
File requiredFile;
switch(requiredItem.getContentType()) {
case MISC:
requiredFile = PatchContentLoader.getMiscPath(home, (MiscContentItem) requiredItem);
break;
case MODULE:
case BUNDLE:
default:
throw new IllegalStateException("Unsupported content type");
}
if (!requiredFile.exists()) {
final File file = PatchContentLoader.getMiscPath(home, (MiscContentItem) item);
Assert.assertFalse(file.exists());
return;
}
}
}
assertMisc(home, modification.getType(), (MiscContentItem) item);
break;
default:
Assert.fail();
}
}
use of org.jboss.as.patching.metadata.MiscContentItem 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.metadata.MiscContentItem 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"));
}
}
use of org.jboss.as.patching.metadata.MiscContentItem in project wildfly-core by wildfly.
the class ContentModificationUtils method modifyMisc.
public static ContentModification modifyMisc(File patchDir, String patchElementID, String modifiedContent, byte[] existingHash, String[] fileSegments, String[] requiredSegments) throws IOException {
File miscDir = newFile(patchDir, patchElementID, MISC);
File modifiedFile = touch(miscDir, fileSegments);
dump(modifiedFile, modifiedContent);
byte[] modifiedHash = hashFile(modifiedFile);
String[] subdir = new String[0];
if (fileSegments.length > 0) {
subdir = new String[fileSegments.length - 1];
System.arraycopy(fileSegments, 0, subdir, 0, fileSegments.length - 1);
}
final MiscContentItem item = new MiscContentItem(modifiedFile.getName(), subdir, modifiedHash);
ModificationCondition condition = null;
if (requiredSegments != null && requiredSegments.length > 0) {
subdir = new String[requiredSegments.length - 1];
System.arraycopy(requiredSegments, 0, subdir, 0, requiredSegments.length - 1);
condition = ModificationCondition.Factory.exists(new MiscContentItem(requiredSegments[requiredSegments.length - 1], subdir, null));
}
return new ContentModification(item, existingHash, MODIFY, condition);
}
use of org.jboss.as.patching.metadata.MiscContentItem in project wildfly-core by wildfly.
the class ContentModificationUtils method removeMisc.
public static ContentModification removeMisc(File existingFile, String... fileSegments) throws IOException {
byte[] existingHash = hashFile(existingFile);
String[] subdir = new String[0];
if (fileSegments.length > 0) {
subdir = new String[fileSegments.length - 1];
System.arraycopy(fileSegments, 0, subdir, 0, fileSegments.length - 1);
}
ContentModification fileRemoved = new ContentModification(new MiscContentItem(existingFile.getName(), subdir, NO_CONTENT), existingHash, REMOVE);
return fileRemoved;
}
Aggregations