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/11 20:50:39 UTC

svn commit: r1786531 - /jmeter/trunk/test/src/org/apache/jmeter/config/TestRandomVariableConfig.java

Author: pmouawad
Date: Sat Mar 11 20:50:39 2017
New Revision: 1786531

URL: http://svn.apache.org/viewvc?rev=1786531&view=rev
Log:
Add test for Random Variable

Added:
    jmeter/trunk/test/src/org/apache/jmeter/config/TestRandomVariableConfig.java   (with props)

Added: jmeter/trunk/test/src/org/apache/jmeter/config/TestRandomVariableConfig.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/config/TestRandomVariableConfig.java?rev=1786531&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/config/TestRandomVariableConfig.java (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/config/TestRandomVariableConfig.java Sat Mar 11 20:50:39 2017
@@ -0,0 +1,92 @@
+/*
+ * 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 to test FileServer methods 
+ */
+     
+package org.apache.jmeter.config;
+
+import java.io.IOException;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestRandomVariableConfig extends JMeterTestCase {
+
+    private JMeterVariables threadVars;
+    
+    private static final String MIN_VALUE = "0";
+    private static final String MAX_VALUE = "10";
+    RandomVariableConfig config = new RandomVariableConfig();
+
+    @Before
+    public void setUp(){
+        JMeterContext jmcx = JMeterContextService.getContext();
+        jmcx.setVariables(new JMeterVariables());
+        threadVars = jmcx.getVariables();        
+        config.setRandomSeed("abcd");
+        config.setVariableName("randomVar");
+
+    }
+
+    @After
+    public void tearDown() throws IOException{
+    }
+    
+    @Test
+    public void testRandom() throws Exception {
+        config.setMinimumValue(MIN_VALUE);
+        config.setMaximumValue(MAX_VALUE);
+        for (int i = 0; i < 100;i++) {
+            config.iterationStart(null);
+            String value = threadVars.get("randomVar");
+            Assert.assertNotNull(threadVars.get("randomVar"));
+            int numericValue = Integer.parseInt(value);
+            Assert.assertTrue("value:"+numericValue+" is not in range ["+MIN_VALUE+","+MAX_VALUE+"]", 
+                    numericValue >=0 && numericValue <=10);            
+        }
+    }
+    
+    @Test
+    public void testRandomWithFormat() throws Exception {
+        config.setMinimumValue(MAX_VALUE);
+        config.setMaximumValue(MAX_VALUE);
+        config.setOutputFormat("000.00");
+        config.iterationStart(null);
+        String value = threadVars.get("randomVar");
+        Assert.assertNotNull(threadVars.get("randomVar"));
+        Assert.assertEquals("010.00", value);
+
+    }
+    
+    @Test
+    public void testInvalidRange() throws Exception {
+        config.setMinimumValue(MAX_VALUE);
+        config.setMaximumValue(MIN_VALUE);
+        config.iterationStart(null);
+        Assert.assertNull(threadVars.get("randomVar"));
+    }
+
+}

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

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