Class ImageCompareTest

  • All Implemented Interfaces:
    Test

    public class ImageCompareTest
    extends AbstractTest
    This test does a pixel comparison of two images and passes if the two images are identical. It fails otherwise, producing a report describing why the two images are different.
    Version:
    $Id: ImageCompareTest.java 1808001 2017-09-11 09:51:29Z ssteiner $
    • Field Detail

      • ERROR_COULD_NOT_OPEN_IMAGE

        public static final java.lang.String ERROR_COULD_NOT_OPEN_IMAGE
        See Also:
        Constant Field Values
      • ERROR_COULD_NOT_LOAD_IMAGE

        public static final java.lang.String ERROR_COULD_NOT_LOAD_IMAGE
        See Also:
        Constant Field Values
      • ERROR_DIFFERENCES

        public static final java.lang.String ERROR_DIFFERENCES
        See Also:
        Constant Field Values
      • ERROR_WHILE_COMPARING_FILES

        public static final java.lang.String ERROR_WHILE_COMPARING_FILES
        See Also:
        Constant Field Values
      • ENTRY_KEY_FIRST_IMAGE

        public static final java.lang.String ENTRY_KEY_FIRST_IMAGE
        See Also:
        Constant Field Values
      • ENTRY_KEY_SECOND_IMAGE

        public static final java.lang.String ENTRY_KEY_SECOND_IMAGE
        See Also:
        Constant Field Values
      • ENTRY_KEY_COMPARISON

        public static final java.lang.String ENTRY_KEY_COMPARISON
        See Also:
        Constant Field Values
      • ENTRY_KEY_DIFFERENCE

        public static final java.lang.String ENTRY_KEY_DIFFERENCE
        See Also:
        Constant Field Values
      • ENTRY_KEY_IMAGE_URL

        public static final java.lang.String ENTRY_KEY_IMAGE_URL
        See Also:
        Constant Field Values
      • IMAGE_TYPE_DIFFERENCE

        public static final java.lang.String IMAGE_TYPE_DIFFERENCE
        See Also:
        Constant Field Values
      • IMAGE_TYPE_COMPARISON

        public static final java.lang.String IMAGE_TYPE_COMPARISON
        See Also:
        Constant Field Values
      • TEMP_FILE_PREFIX

        public static final java.lang.String TEMP_FILE_PREFIX
        Prefix for the temporary files created by Tests of this class
        See Also:
        Constant Field Values
      • TEMP_FILE_SUFFIX

        public static final java.lang.String TEMP_FILE_SUFFIX
        Suffix for the temporary files created by Tests of this class
        See Also:
        Constant Field Values
      • urlAStr

        protected java.lang.String urlAStr
        URL for the first image to be compared.
      • urlA

        protected java.net.URL urlA
      • urlBStr

        protected java.lang.String urlBStr
        URL for the second image to be compared
      • urlB

        protected java.net.URL urlB
    • Constructor Detail

      • ImageCompareTest

        public ImageCompareTest​(java.lang.String urlA,
                                java.lang.String urlB)
        This test makes a binary comparison of the two images (and not a pixel comparison). If the images are different, the test generates a report containing the two images and a delta images to help the user visualize the difference.
        Parameters:
        urlA - first image
        urlB - second image
    • Method Detail

      • resolveURL

        protected java.net.URL resolveURL​(java.lang.String url)
        Resolves the input string as follows. + First, the string is interpreted as a file description. If the file exists, then the file name is turned into a URL. + Otherwise, the string is supposed to be a URL. If it is an invalid URL, an IllegalArgumentException is thrown.
      • initURLs

        protected void initURLs()
      • rumImpl

        public TestReport rumImpl()
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • buildCompareImage

        protected java.awt.image.BufferedImage buildCompareImage​(java.awt.image.BufferedImage ref,
                                                                 java.awt.image.BufferedImage gen)
      • imageToFile

        protected java.io.File imageToFile​(java.awt.image.BufferedImage img,
                                           java.lang.String imageType)
                                    throws java.io.IOException
        Creates a temporary File into which the input image is saved.
        Throws:
        java.io.IOException
      • makeRandomFileName

        protected java.io.File makeRandomFileName​(java.lang.String imageType)
                                           throws java.io.IOException
        Creates a temporary File into which the input image is saved.
        Throws:
        java.io.IOException
      • buildDiffImage

        public static java.awt.image.BufferedImage buildDiffImage​(java.awt.image.BufferedImage ref,
                                                                  java.awt.image.BufferedImage gen)
        Builds a new BufferedImage that is the difference between the two input images
      • compare

        public static boolean compare​(java.io.InputStream refStream,
                                      java.io.InputStream newStream)
                               throws java.io.IOException
        Compare the two input streams
        Throws:
        java.io.IOException
      • getImage

        protected java.awt.image.BufferedImage getImage​(java.net.URL url)
        Loads an image from a URL