@Test public void testOneOffPatch() throws Exception { // build a one-off patch for the base installation // with 1 added module String patchID = randomString(); String layerPatchID = randomString(); File patchDir = mkdir(tempDir, patchID); String moduleName = randomString(); ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName); InstalledIdentity installedIdentity = loadInstalledIdentity(); final PatchBuilder builder = PatchBuilder.create(); builder .setPatchId(patchID) .setPatchId(patchID) .setDescription(randomString()) .oneOffPatchIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion()) .getParent() .oneOffPatchElement(layerPatchID, BASE, false) .addContentModification(moduleAdded); Patch patch = builder.build(); checkApplyPatchAndRollbackRestoresBackupConfiguration(patchDir, patch); }
private void checkApplyPatchAndRollbackRestoresBackupConfiguration(File patchDir, Patch patch) throws Exception { createPatchXMLFile(patchDir, patch); File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId()); Identity identityBeforePatch = loadInstalledIdentity().getIdentity(); PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, patch); // check the AS7 config files have been backed up File backupAppclientXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "appclient", "appclient.xml"); assertFileContent(originalAppClientHash, backupAppclientXmlFile); File backupStandaloneXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "standalone", "standalone.xml"); assertFileContent(originalStandaloneHash, backupStandaloneXmlFile); File backupDomainXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "domain", "domain.xml"); assertFileContent(originalDomainHash, backupDomainXmlFile); // let's change the standalone.xml file dump(standaloneXmlFile, "<updated standalone configuration with changes from the added module>"); byte[] updatedStandaloneXmlFile = hashFile(standaloneXmlFile); tree(tempDir); PatchingResult rollbackResult = rollback(patch.getPatchId()); assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch); File rolledBackStandaloneXmlFile = assertFileExists(env.getInstalledImage().getStandaloneDir(), "configuration", "standalone.xml"); assertEquals("updated content was " + bytesToHexString(updatedStandaloneXmlFile), bytesToHexString(originalStandaloneHash), bytesToHexString(hashFile(rolledBackStandaloneXmlFile))); }
@Test public void testCumulativePatch() throws Exception { // build a cumulative patch for the base installation // with 1 added module String patchID = randomString(); String layerPatchID = randomString(); File patchDir = mkdir(tempDir, patchID); String moduleName = randomString(); ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName); InstalledIdentity installedIdentity = loadInstalledIdentity(); final PatchBuilder builder = PatchBuilder.create(); builder .setPatchId(patchID) .setDescription(randomString()) .upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-CP1") .getParent() .upgradeElement(layerPatchID, BASE, false) .addContentModification(moduleAdded); Patch patch = builder.build(); checkApplyPatchAndRollbackRestoresBackupConfiguration(patchDir, patch); }