use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class MergingPatchMetadataTestCase method testModifyModify.
@Test
public void testModifyModify() throws Exception {
final Patch cp1 = generateCP("base", "cp1", ModificationType.MODIFY);
final Patch cp2 = generateCP("cp1", "cp2", ModificationType.MODIFY);
final Patch merged = PatchMerger.merge(cp1, cp2);
assertEquals("cp2", merged.getPatchId());
assertEquals("cp2" + " description", merged.getDescription());
final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
assertEquals("base", identity.getVersion());
assertEquals("cp2", identity.getResultingVersion());
assertEquals(PatchType.CUMULATIVE, identity.getPatchType());
final List<PatchElement> elements = merged.getElements();
assertEquals(1, elements.size());
final PatchElement e = elements.get(0);
assertEquals("base-" + "cp2", e.getId());
final PatchElementProvider provider = e.getProvider();
assertEquals("base", provider.getName());
assertEquals(PatchType.CUMULATIVE, provider.getPatchType());
assertEquals(LayerType.Layer, provider.getLayerType());
assertEquals(3, e.getModifications().size());
for (ContentModification mod : e.getModifications()) {
assertEquals(ModificationType.MODIFY, mod.getType());
final ContentItem item = mod.getItem();
if (ContentType.MODULE.equals(item.getContentType())) {
Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash());
Assert.assertArrayEquals(moduleHash("cp2"), item.getContentHash());
} else if (ContentType.MISC.equals(item.getContentType())) {
Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash());
Assert.assertArrayEquals(miscHash("cp2"), item.getContentHash());
} else {
Assert.assertArrayEquals(bundleHash("base"), mod.getTargetHash());
Assert.assertArrayEquals(bundleHash("cp2"), item.getContentHash());
}
}
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class MergingPatchMetadataTestCase method testModifyRemove.
@Test
public void testModifyRemove() throws Exception {
final Patch cp1 = generateCP("base", "cp1", ModificationType.MODIFY);
final Patch cp2 = generateCP("cp1", "cp2", ModificationType.REMOVE);
final Patch merged = PatchMerger.merge(cp1, cp2);
assertEquals("cp2", merged.getPatchId());
assertEquals("cp2" + " description", merged.getDescription());
final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
assertEquals("base", identity.getVersion());
assertEquals("cp2", identity.getResultingVersion());
assertEquals(PatchType.CUMULATIVE, identity.getPatchType());
final List<PatchElement> elements = merged.getElements();
assertEquals(1, elements.size());
final PatchElement e = elements.get(0);
assertEquals("base-" + "cp2", e.getId());
final PatchElementProvider provider = e.getProvider();
assertEquals("base", provider.getName());
assertEquals(PatchType.CUMULATIVE, provider.getPatchType());
assertEquals(LayerType.Layer, provider.getLayerType());
assertEquals(3, e.getModifications().size());
for (ContentModification mod : e.getModifications()) {
assertEquals(ModificationType.REMOVE, mod.getType());
final ContentItem item = mod.getItem();
assertEquals(0, item.getContentHash().length);
if (ContentType.MODULE.equals(item.getContentType())) {
Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash());
} else if (ContentType.MISC.equals(item.getContentType())) {
Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash());
} else {
Assert.assertArrayEquals(bundleHash("base"), mod.getTargetHash());
}
}
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class MergingPatchMetadataTestCase method testRemoveAdd.
@Test
public void testRemoveAdd() throws Exception {
final Patch cp1 = generateCP("base", "cp1", ModificationType.REMOVE);
final Patch cp2 = generateCP("cp1", "cp2", ModificationType.ADD);
final Patch merged = PatchMerger.merge(cp1, cp2);
assertEquals("cp2", merged.getPatchId());
assertEquals("cp2" + " description", merged.getDescription());
final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
assertEquals("base", identity.getVersion());
assertEquals("cp2", identity.getResultingVersion());
assertEquals(PatchType.CUMULATIVE, identity.getPatchType());
final List<PatchElement> elements = merged.getElements();
assertEquals(1, elements.size());
final PatchElement e = elements.get(0);
assertEquals("base-" + "cp2", e.getId());
final PatchElementProvider provider = e.getProvider();
assertEquals("base", provider.getName());
assertEquals(PatchType.CUMULATIVE, provider.getPatchType());
assertEquals(LayerType.Layer, provider.getLayerType());
assertEquals(3, e.getModifications().size());
for (ContentModification mod : e.getModifications()) {
assertEquals(ModificationType.MODIFY, mod.getType());
final ContentItem item = mod.getItem();
if (ContentType.MODULE.equals(item.getContentType())) {
Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash());
Assert.assertArrayEquals(moduleHash("cp2"), item.getContentHash());
} else if (ContentType.MISC.equals(item.getContentType())) {
Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash());
Assert.assertArrayEquals(miscHash("cp2"), item.getContentHash());
} else {
Assert.assertArrayEquals(bundleHash("base"), mod.getTargetHash());
Assert.assertArrayEquals(bundleHash("cp2"), item.getContentHash());
}
}
}
use of org.jboss.as.patching.metadata.ContentModification 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.ContentModification 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