You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/03/04 20:13:07 UTC

svn commit: r1785519 - /jmeter/trunk/test/src/org/apache/jmeter/functions/TestSimpleFunctions.java

Author: pmouawad
Date: Sat Mar  4 20:13:07 2017
New Revision: 1785519

URL: http://svn.apache.org/viewvc?rev=1785519&view=rev
Log:
Add tests for UUID, EscapeHtml, ThreadNumber

Added:
    jmeter/trunk/test/src/org/apache/jmeter/functions/TestSimpleFunctions.java   (with props)

Added: jmeter/trunk/test/src/org/apache/jmeter/functions/TestSimpleFunctions.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/TestSimpleFunctions.java?rev=1785519&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/TestSimpleFunctions.java (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/TestSimpleFunctions.java Sat Mar  4 20:13:07 2017
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ */
+
+package org.apache.jmeter.functions;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.UUID;
+
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestSimpleFunctions extends JMeterTestCase {
+    private SampleResult result;
+
+    private Collection<CompoundVariable> params;
+    private JMeterVariables vars;
+    private JMeterContext jmctx;
+
+    @Before
+    public void setUp() {
+        result = new SampleResult();
+        jmctx = JMeterContextService.getContext();
+        String data = "The quick brown fox";
+        result.setResponseData(data, null);
+        vars = new JMeterVariables();
+        jmctx.setVariables(vars);
+        jmctx.setPreviousResult(result);
+        params = new LinkedList<>();
+        Thread.currentThread().setName("ThreadGroup-1");
+    }
+
+    @Test
+    public void testUUIDParameterCount() throws Exception {
+        AbstractFunction function = new Uuid();
+        checkInvalidParameterCounts(function, 0, 0);
+    }
+    
+    @Test
+    public void testThreadNumberParameterCount() throws Exception {
+        AbstractFunction function = new ThreadNumber();
+        checkInvalidParameterCounts(function, 0, 0);
+    }
+    
+    @Test
+    public void testEscapeHtmlParameterCount() throws Exception {
+        AbstractFunction function = new EscapeHtml();
+        checkInvalidParameterCounts(function, 1, 1);
+    }
+    
+    @Test
+    public void testThreadNumber() throws Exception {
+        AbstractFunction function = new ThreadNumber();
+        function.setParameters(params);
+        String ret = function.execute(result, null);
+        assertEquals("1", ret);
+    }
+    
+    
+    @Test
+    public void testUuid() throws Exception {
+        AbstractFunction function = new Uuid();
+        function.setParameters(params);
+        String ret = function.execute(result, null);
+        UUID.fromString(ret);
+    }
+    
+    @Test
+    public void testEscapeHtml() throws Exception {
+        AbstractFunction function = new EscapeHtml();
+        params.add(new CompoundVariable("\"bread\" & \"butter\""));
+        function.setParameters(params);
+        String ret = function.execute(result, null);
+        assertEquals("&quot;bread&quot; &amp; &quot;butter&quot;", ret);
+    }
+}

Propchange: jmeter/trunk/test/src/org/apache/jmeter/functions/TestSimpleFunctions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jmeter/trunk/test/src/org/apache/jmeter/functions/TestSimpleFunctions.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain