You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2017/07/15 12:05:49 UTC

svn commit: r1802020 - /jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionTest.java

Author: fschumacher
Date: Sat Jul 15 12:05:49 2017
New Revision: 1802020

URL: http://svn.apache.org/viewvc?rev=1802020&view=rev
Log:
Unit tests for MD5HexAssertion

Modified:
    jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionTest.java

Modified: jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionTest.java?rev=1802020&r1=1802019&r2=1802020&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionTest.java Sat Jul 15 12:05:49 2017
@@ -18,14 +18,72 @@
 
 package org.apache.jmeter.assertions;
 
+import java.nio.charset.StandardCharsets;
+
+import org.apache.jmeter.samplers.SampleResult;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
 public class MD5HexAssertionTest {
+    
+    private MD5HexAssertion assertion;
+
+    @Before
+    public void setUp() {
+        assertion = new MD5HexAssertion();
+    }
+
+    @Test
+    public void testEmptyResponse() throws Exception {
+        AssertionResult result = assertion.getResult(sampleResult(""));
+        Assert.assertTrue(result.isFailure());
+        Assert.assertNotEquals(result.getFailureMessage(), "");
+    }
+
+    @Test
+    public void testEmptyMD5() throws Exception {
+        assertion.setAllowedMD5Hex("");
+        AssertionResult result = assertion.getResult(sampleResult("anything"));
+        Assert.assertTrue(result.isFailure());
+        Assert.assertNotEquals(result.getFailureMessage(), "");
+    }
+
+    @Test
+    public void testWrongMD5() throws Exception {
+        assertion.setAllowedMD5Hex("a");
+        AssertionResult result = assertion.getResult(sampleResult("anything"));
+        Assert.assertTrue(result.isFailure());
+        Assert.assertNotEquals(result.getFailureMessage(), "");
+    }
+
+    @Test
+    public void testCorrectMD5LowerCase() throws Exception {
+        assertion.setAllowedMD5Hex("f0e166dc34d14d6c228ffac576c9a43c");
+        AssertionResult result = assertion.getResult(sampleResult("anything"));
+        Assert.assertFalse(result.isFailure());
+        Assert.assertFalse(result.isError());
+        Assert.assertNull(result.getFailureMessage());
+    }
+
+    @Test
+    public void testCorrectMD5MixedCase() throws Exception {
+        assertion.setAllowedMD5Hex("F0e166Dc34D14d6c228ffac576c9a43c");
+        AssertionResult result = assertion.getResult(sampleResult("anything"));
+        Assert.assertFalse(result.isFailure());
+        Assert.assertFalse(result.isError());
+        Assert.assertNull(result.getFailureMessage());
+    }
 
     @Test
     public void testMD5() throws Exception {
         Assert.assertEquals("D41D8CD98F00B204E9800998ECF8427E", MD5HexAssertion.baMD5Hex(new byte[] {}).toUpperCase(java.util.Locale.ENGLISH));
     }
 
+    private SampleResult sampleResult(String data) {
+        SampleResult response = new SampleResult();
+        response.setResponseData(data.getBytes(StandardCharsets.UTF_8));
+        return response;
+    }
+
 }