public static void assertFileContent(String message, byte[] expected, File f) throws Exception { assertEquals(message, bytesToHexString(expected), bytesToHexString(hashFile(f))); }
protected void assertRestoredConfig(File baseDir, String xmlName, byte[] updatedHash, byte[] originalHash) throws IOException { File rolledBackXmlFile = assertFileExists(baseDir, "configuration", xmlName); assertEquals(bytesToHexString(updatedHash), bytesToHexString(hashFile(rolledBackXmlFile))); File restoredXmlFile = assertFileExists(baseDir, "configuration", "restored-configuration", xmlName); assertEquals(bytesToHexString(originalHash), bytesToHexString(hashFile(restoredXmlFile))); }
private static void writeModuleItem(final XMLExtendedStreamWriter writer, final DistributionModuleItem item, final Element element) throws XMLStreamException { writer.writeEmptyElement(element.name); writer.writeAttribute(Attribute.NAME.name, item.getName()); writer.writeAttribute(Attribute.SLOT.name, item.getSlot()); writer.writeAttribute(Attribute.COMPARISON_HASH.name, HashUtils.bytesToHexString(item.getComparisonHash())); writer.writeAttribute(Attribute.METADATA_HASH.name, HashUtils.bytesToHexString(item.getMetadataHash())); }
protected static void writeSlottedItem(final XMLExtendedStreamWriter writer, Element element, ContentModification modification) throws XMLStreamException { writer.writeEmptyElement(element.name); final ModuleItem item = (ModuleItem) modification.getItem(); final ModificationType type = modification.getType(); writer.writeAttribute(Attribute.NAME.name, item.getName()); if (!MAIN_SLOT.equals(item.getSlot())) { writer.writeAttribute(Attribute.SLOT.name, item.getSlot()); } byte[] hash = item.getContentHash(); if (hash.length > 0 && type != ModificationType.REMOVE) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); } if(type == ModificationType.REMOVE) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); } } else if(type == ModificationType.MODIFY) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.NEW_HASH.name, bytesToHexString(existingHash)); } } }
private static void writeChildren(final XMLExtendedStreamWriter writer, final Collection<DistributionContentItem> items) throws XMLStreamException { if (items == null || items.size() == 0) { return; } for (final DistributionContentItem item : items) { writer.writeStartElement(Element.NODE.name); writer.writeAttribute(Attribute.NAME.name, item.getName()); if (item.isLeaf()) { writer.writeAttribute(Attribute.COMPARISON_HASH.name, HashUtils.bytesToHexString(item.getComparisonHash())); writer.writeAttribute(Attribute.METADATA_HASH.name, HashUtils.bytesToHexString(item.getMetadataHash())); } writer.writeAttribute(Attribute.DIRECTORY.name, String.valueOf(!item.isLeaf())); // Recurse final Collection<DistributionContentItem> children = item.getChildren(); writeChildren(writer, children); writer.writeEndElement(); } }
protected static void writeSlottedItem(final XMLExtendedStreamWriter writer, Element element, ContentModification modification) throws XMLStreamException { writer.writeEmptyElement(element.name); final ModuleItem item = (ModuleItem) modification.getItem(); final ModificationType type = modification.getType(); writer.writeAttribute(Attribute.NAME.name, item.getName()); if (!MAIN_SLOT.equals(item.getSlot())) { writer.writeAttribute(Attribute.SLOT.name, item.getSlot()); } byte[] hash = item.getContentHash(); if (hash.length > 0 && type != ModificationType.REMOVE) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); } if(type == ModificationType.REMOVE) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); } } else if(type == ModificationType.MODIFY) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.NEW_HASH.name, bytesToHexString(existingHash)); } } }
final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); byte[] hash = item.getContentHash(); if(hash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); writer.writeAttribute(Attribute.NEW_HASH.name, bytesToHexString(modification.getTargetHash())); if (item.isAffectsRuntime()) { writer.writeAttribute(Attribute.IN_RUNTIME_USE.name, "true");
final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); byte[] hash = item.getContentHash(); if(hash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); writer.writeAttribute(Attribute.NEW_HASH.name, bytesToHexString(modification.getTargetHash())); if (item.isAffectsRuntime()) { writer.writeAttribute(Attribute.IN_RUNTIME_USE.name, "true");
assertNotEquals(bytesToHexString(originalStandaloneHash), bytesToHexString(updatedStandaloneXmlFile)); assertNotEquals(bytesToHexString(originalAppClientHash), bytesToHexString(updatedAppClientXmlHash)); assertNotEquals(bytesToHexString(originalDomainHash), bytesToHexString(updatedDomainXmlHash)); assertEquals(bytesToHexString(originalStandaloneHash), bytesToHexString(hashFile(rolledBackStandaloneXmlFile))); assertEquals(bytesToHexString(originalAppClientHash), bytesToHexString(hashFile(rolledBackAppClientXmlFile))); assertEquals(bytesToHexString(originalDomainHash), bytesToHexString(hashFile(rolledBackDomainXmlFile)));
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))); }