Shanmuganathan(Shan) Srinivasan

Thursday, May 15, 2014

MD5 checksum comparison of two files looking for changes

Environment:
  Java et. al.

Issue:
  We are in process of migrating from one framework to another, so we had to keep two copies of same file conforming two different frameworks until we complete the whole migration. but there is active development going on in the same code base. We need to make sure if the change made in one file belonging to one framework is also made in similar file when applicable.

Solution:
Write a testcase that checks if any one of the files is changed, indicate user to make sure both are synced and update the latest checksum in the Enum file for the testcase to pass.

Below is the Enum for the list of dependent files and Test case 


//Enum that has master list of dependent files and corresponding checksums
 public enum Fmwk1Fmwk2FilesEnum {

    /**
     * This has to be manually updated after making sure the Fmwk1 and Fmwk2 files are synced if changed.
     */
    HEADER_TILE("src\\main\\webapp\\common\\tiles\\header_tile_fmwk1.jsp",
"src\\main\\webapp\\common\\tiles\\header_tile.jsp",
"375b53df14a8c0170ee2baa51408338a","dc31d9355a5a74333a146ee1541e53c1"),
    LAYOUT_SIMPLE("src\\main\\webapp\\common\\layouts\\layout_simple_fmwk1.jsp",
"src\\main\\webapp\\common\\layouts\\layout_simple.jsp",
"8cc127cf58db6ecfc57c275eef4fc76e","cd6396dca9abbb9243402f222f8c98b8"),


/***
* TEST CASE to check if the files have been changed
***/
/**
 *
 * The purpose of this test to keep the new Fmwk1 files to be in sync with Older Fmwk2 files.
 * This test need to be deleted once we move to 100% Fmwk1 and we should not have any older
 * Fmwk2 files until then every time any of the associated file is modified it is expected that both
 * the files are synced in other words if any change is done in one file it should be done in other as well and
 * corresponding checksum needs to be updated.
* Respective enums also need to be updated once we delete the files while we migrate to new framework
 *
 */
                final String fmwk1MD5 = DigestUtils.md5Hex(new FileInputStream(fmwk1File));

                assertFalse("Fmwk1 File " + fmwk1Fmwk2FilesEnum.getFmwk1File() + " has been changed, make sure the changes are synced in " + fmwk1Fmwk2FilesEnum.getFmwk2File() +
                                ". If synced fine, update the checksum in the Enum Fmwk1Fmwk2FilesEnum. Updated MD5 " + fmwk1MD5,
                        !fmwk1MD5.equals(fmwk1Fmwk2FilesEnum.getFmwk1CheckSum())
                );

0 Comments:

Post a Comment

<< Home