| career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

// $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/assertions/,v 1.2 2004/02/13 01:27:26 sebb Exp $
 * Copyright 2004 The Apache Software Foundation.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

 * MD5HexAssertion class creates an MD5 checksum from the response 
* and matches it with the MD5 hex provided. * The assertion will fail when the expected hex is different from the
* one calculated from the response OR when the expected hex is left empty. * * @author Jorg Heymans * @version $Revision: 1.2 $ last updated $Date: 2004/02/13 01:27:26 $ */ package org.apache.jmeter.assertions; import; import; import; import java.text.MessageFormat; import junit.framework.TestCase; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.testelement.AbstractTestElement; import; import org.apache.jmeter.util.JMeterUtils; public class MD5HexAssertion extends AbstractTestElement implements Serializable, Assertion { /** Key for storing assertion-informations in the jmx-file. */ private static final String MD5HEX_KEY = "MD5HexAssertion.size"; /* * @param response * @return */ public AssertionResult getResult(SampleResult response) { AssertionResult result = new AssertionResult(); result.setFailure(false); byte[] resultData = response.getResponseData(); if (resultData == null) { result.setError(false); result.setFailure(true); result.setFailureMessage("Response was null"); return result; } //no point in checking if we don't have anything to compare against if (getAllowedMD5Hex().equals("")) { result.setError(false); result.setFailure(true); result.setFailureMessage("MD5Hex to test against is empty"); return result; } String md5Result=baMD5Hex(resultData); //String md5Result = DigestUtils.md5Hex(resultData); if (!md5Result.equalsIgnoreCase(getAllowedMD5Hex())) { result.setFailure(true); Object[] arguments = { md5Result, getAllowedMD5Hex()}; String message = MessageFormat.format( JMeterUtils.getResString("md5hex_assertion_failure"), arguments); result.setFailureMessage(message); } return result; } public void setAllowedMD5Hex(String hex) { setProperty(new StringProperty(MD5HexAssertion.MD5HEX_KEY, hex)); } public String getAllowedMD5Hex() { return getPropertyAsString(MD5HexAssertion.MD5HEX_KEY); } private static String baToHex(byte ba []) { StringBuffer sb = new StringBuffer(32); for (int i = 0; i
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.