package pt.fccn.mobile.arquivo.tests.print;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.io.IOUtils;
import org.junit.Test;

import pt.fccn.arquivo.selenium.Retry;
import pt.fccn.arquivo.util.AppendableErrorsBaseTest;

/**
 *
 * @author Ivo Branco <ivo.branco@fccn.pt>
 *
 */
public class PrintTest extends AppendableErrorsBaseTest {

	private String testURL;

	public PrintTest() {
		this.testURL = System.getProperty("test.url");
	}

	@Test
	@Retry
	public void printTest() {
		String screenshotUrlStr = this.testURL + "/print/?url=" + this.testURL
				+ "/noFrame/replay/19961013145650/http://www.fccn.pt/";

		byte[] bytes = print(screenshotUrlStr);

		String md5 = getMd5(bytes);

		assertEquals("Verify print md5sum", "d034de355125a3a89470caf03b73ed97", md5);
	}

	private byte[] print(String screenshotUrlStr) {
		URL url;
		try {
			url = new URL(screenshotUrlStr);
		} catch (MalformedURLException e) {
			throw new RuntimeException(
					"Error generating URL to a screenshot of a page verify if you have passed correct test url parameter",
					e);
		}

		byte[] bytes;
		try {
			InputStream is = url.openStream();
			bytes = IOUtils.toByteArray(is);
		} catch (IOException e) {
			throw new RuntimeException("Error downloading a screenshot", e);
		}
		return bytes;
	}

	public static String getMd5(byte[] input) {
		try {

			// Static getInstance method is called with hashing MD5
			MessageDigest md = MessageDigest.getInstance("MD5");

			// digest() method is called to calculate message digest
			// of an input digest() return array of byte
			byte[] messageDigest = md.digest(input);

			// Convert byte array into signum representation
			BigInteger no = new BigInteger(1, messageDigest);

			// Convert message digest into hex value
			String hashtext = no.toString(16);
			while (hashtext.length() < 32) {
				hashtext = "0" + hashtext;
			}
			return hashtext;
		}

		// For specifying wrong message digest algorithms
		catch (NoSuchAlgorithmException e) {
			throw new RuntimeException(e);
		}
	}

}

package pt.fccn.mobile.arquivo.tests.print;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.io.IOUtils;
import org.junit.Test;

import pt.fccn.arquivo.selenium.Retry;
import pt.fccn.arquivo.util.AppendableErrorsBaseTest;

/**
 *
 * @author Ivo Branco <ivo.branco@fccn.pt>
 *
 */
public class PrintTest extends AppendableErrorsBaseTest {

	private String testURL;

	public PrintTest() {
		this.testURL = System.getProperty("test.url");
	}

	@Test
	@Retry
	public void printTest() {
		String screenshotUrlStr = this.testURL + "/screenshot?url=" + this.testURL
				+ "/noFrame/replay/19961013145650/http://www.fccn.pt/&download=false";

		byte[] bytes = print(screenshotUrlStr);

		String md5 = getMd5(bytes);
		
		assertEquals("Verify print md5sum", "5eebe9f78862a65a2150606be3678deb", md5);
	}

	private byte[] print(String screenshotUrlStr) {
		URL url;
		try {
			url = new URL(screenshotUrlStr);
		} catch (MalformedURLException e) {
			throw new RuntimeException(
					"Error generating URL to a screenshot of a page verify if you have passed correct test url parameter",
					e);
		}

		byte[] bytes;
		try {
			InputStream is = url.openStream();
			bytes = IOUtils.toByteArray(is);
		} catch (IOException e) {
			throw new RuntimeException("Error downloading a screenshot", e);
		}
		return bytes;
	}

	public static String getMd5(byte[] input) {
		try {

			// Static getInstance method is called with hashing MD5
			MessageDigest md = MessageDigest.getInstance("MD5");

			// digest() method is called to calculate message digest
			// of an input digest() return array of byte
			byte[] messageDigest = md.digest(input);

			// Convert byte array into signum representation
			BigInteger no = new BigInteger(1, messageDigest);

			// Convert message digest into hex value
			String hashtext = no.toString(16);
			while (hashtext.length() < 32) {
				hashtext = "0" + hashtext;
			}
			return hashtext;
		}

		// For specifying wrong message digest algorithms
		catch (NoSuchAlgorithmException e) {
			throw new RuntimeException(e);
		}
	}

}

Fix print