jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1854264 - in /jmeter/trunk: src/components/org/apache/jmeter/extractor/json/render/ test/src/org/apache/jmeter/extractor/json/ test/src/org/apache/jmeter/extractor/json/render/
Date Sun, 24 Feb 2019 14:44:00 GMT
Author: pmouawad
Date: Sun Feb 24 14:44:00 2019
New Revision: 1854264

URL: http://svn.apache.org/viewvc?rev=1854264&view=rev
Log:
Improve methods/variables naming
Make instance variable local
Increase coverage

Added:
    jmeter/trunk/test/src/org/apache/jmeter/extractor/json/
    jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/
    jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/RenderAsJsonRendererSpec.groovy
Modified:
    jmeter/trunk/src/components/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java

Modified: jmeter/trunk/src/components/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java?rev=1854264&r1=1854263&r2=1854264&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java
(original)
+++ jmeter/trunk/src/components/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java
Sun Feb 24 14:44:00 2019
@@ -75,9 +75,6 @@ public class RenderAsJsonRenderer implem
 
     private SampleResult sampleResult;
 
-    private JScrollPane jsonDataPane;
-
-
     /** {@inheritDoc} */
     @Override
     public void clearData() {
@@ -104,7 +101,7 @@ public class RenderAsJsonRenderer implem
         String command = e.getActionCommand();
         if ((sampleResult != null) && (JSONPATH_TESTER_COMMAND.equals(command)))
{
             String response = jsonDataField.getText();
-            executeAndShowXPathTester(response);
+            executeAndJSonPathTester(response);
         }
     }
 
@@ -112,7 +109,7 @@ public class RenderAsJsonRenderer implem
      * Launch json path engine to parse a input text
      * @param textToParse
      */
-    private void executeAndShowXPathTester(String textToParse) {
+    private void executeAndJSonPathTester(String textToParse) {
         if (textToParse != null && textToParse.length() > 0
                 && this.jsonPathExpressionField.getText().length() > 0) {
             this.jsonPathResultField.setText(process(textToParse));
@@ -194,7 +191,7 @@ public class RenderAsJsonRenderer implem
         jsonDataField.setWrapStyleWord(true);
         
 
-        this.jsonDataPane = JTextScrollPane.getInstance(jsonDataField, true);
+        JScrollPane jsonDataPane = JTextScrollPane.getInstance(jsonDataField, true);
         jsonDataPane.setPreferredSize(new Dimension(100, 200));
 
         JPanel panel = new JPanel(new BorderLayout(0, 5));
@@ -220,10 +217,10 @@ public class RenderAsJsonRenderer implem
         jsonPathExpressionField = new JLabeledTextField(JMeterUtils.getResString("jsonpath_tester_field"));
// $NON-NLS-1$
         jsonPathActionPanel.add(jsonPathExpressionField, BorderLayout.WEST);
 
-        JButton xpathTester = new JButton(JMeterUtils.getResString("jsonpath_tester_button_test"));
// $NON-NLS-1$
-        xpathTester.setActionCommand(JSONPATH_TESTER_COMMAND);
-        xpathTester.addActionListener(this);
-        jsonPathActionPanel.add(xpathTester, BorderLayout.EAST);
+        JButton jsonPathTester = new JButton(JMeterUtils.getResString("jsonpath_tester_button_test"));
// $NON-NLS-1$
+        jsonPathTester.setActionCommand(JSONPATH_TESTER_COMMAND);
+        jsonPathTester.addActionListener(this);
+        jsonPathActionPanel.add(jsonPathTester, BorderLayout.EAST);
 
         jsonPathResultField = new JTextArea();
         jsonPathResultField.setEditable(false);
@@ -231,11 +228,11 @@ public class RenderAsJsonRenderer implem
         jsonPathResultField.setWrapStyleWord(true);
         jsonPathResultField.setMinimumSize(new Dimension(100, 150));
 
-        JPanel xpathTasksPanel = new JPanel(new BorderLayout(0, 5));
-        xpathTasksPanel.add(jsonPathActionPanel, BorderLayout.NORTH);
-        xpathTasksPanel.add(GuiUtils.makeScrollPane(jsonPathResultField), BorderLayout.CENTER);
+        JPanel jsonPathTasksPanel = new JPanel(new BorderLayout(0, 5));
+        jsonPathTasksPanel.add(jsonPathActionPanel, BorderLayout.NORTH);
+        jsonPathTasksPanel.add(GuiUtils.makeScrollPane(jsonPathResultField), BorderLayout.CENTER);
 
-        return xpathTasksPanel;
+        return jsonPathTasksPanel;
     }
 
     /** {@inheritDoc} */

Added: jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/RenderAsJsonRendererSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/RenderAsJsonRendererSpec.groovy?rev=1854264&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/RenderAsJsonRendererSpec.groovy
(added)
+++ jmeter/trunk/test/src/org/apache/jmeter/extractor/json/render/RenderAsJsonRendererSpec.groovy
Sun Feb 24 14:44:00 2019
@@ -0,0 +1,109 @@
+/*
+ * 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.extractor.json.render
+
+import org.apache.jmeter.samplers.SampleResult
+import org.apache.jmeter.extractor.json.render.RenderAsJsonRenderer
+import org.apache.jmeter.junit.spock.JMeterSpec
+import org.apache.jmeter.util.JMeterUtils
+import javax.swing.JTabbedPane
+
+class RenderAsJsonRendererSpec extends JMeterSpec {
+
+    def sut = new RenderAsJsonRenderer()
+
+    def "init of component doesn't fail"() {
+        when:
+            sut.init()
+        then:
+            noExceptionThrown()
+            sut.jsonWithJSonPathPanel != null;
+    }
+    
+    def "render image"() {
+        given:
+            sut.init()
+            def sampleResult = new SampleResult();
+        when:
+            sut.renderImage(sampleResult)
+        then:
+            sut.jsonDataField.getText() == JMeterUtils.getResString("jsonpath_render_no_text")
+    }
+
+    def "render null Response"() {
+        given:
+            sut.init()
+            def sampleResult = new SampleResult();
+        when:
+            sut.renderResult(sampleResult)
+        then:
+            sut.jsonDataField.getText() == ""
+    }
+    
+    def "render JSON Response"() {
+        given:
+            sut.init();
+            def sampleResult = new SampleResult();
+            sampleResult.setResponseData("{name:\"Ludwig\",age: 23,city: \"Bonn\"}");
+        when:
+            sut.renderResult(sampleResult)
+        then:
+            sut.jsonDataField.getText() == '''{
+    "city": "Bonn",
+    "name": "Ludwig",
+    "age": 23
+}'''
+    }
+    
+    def "clearData clears expected fields"() {
+        given:
+            sut.init()
+            sut.jsonDataField.setText("blabla")
+            sut.jsonPathResultField.setText("blabla")
+        when:
+            sut.clearData()
+        then:
+            sut.jsonDataField.getText() == ""
+            sut.jsonPathResultField.getText() == ""
+    }
+
+    def "setupTabPane adds the tab to rightSide"() {
+        given:
+            sut.init()
+            def rightSideTabbedPane = new JTabbedPane();
+            sut.setRightSide(rightSideTabbedPane)
+        when:
+            sut.setupTabPane()
+        then:
+            sut.rightSide.getTabCount() == 1
+            // Investigate why it's failing
+            // sut.rightSide.getTabComponentAt(0) == sut.jsonWithJSonPathPanel
+    }
+    
+    def "setupTabPane called twice does not add twice the tab"() {
+        given:
+            sut.init()
+            def rightSideTabbedPane = new JTabbedPane();
+            sut.setRightSide(rightSideTabbedPane)
+            sut.setupTabPane()
+        when:
+            sut.setupTabPane()
+        then:
+            sut.rightSide.getTabCount() == 1
+    }
+}



Mime
View raw message