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

svn commit: r1790830 - /jmeter/trunk/test/src/org/apache/jmeter/report/dashboard/ApdexPerTransactionTest.java

Author: sebb
Date: Mon Apr 10 13:42:46 2017
New Revision: 1790830

URL: http://svn.apache.org/viewvc?rev=1790830&view=rev
Log:
getClass().getResource() does not work as a File if the classpath contains spaces
Bugzilla Id: 60966

Modified:
    jmeter/trunk/test/src/org/apache/jmeter/report/dashboard/ApdexPerTransactionTest.java

Modified: jmeter/trunk/test/src/org/apache/jmeter/report/dashboard/ApdexPerTransactionTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/report/dashboard/ApdexPerTransactionTest.java?rev=1790830&r1=1790829&r2=1790830&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/report/dashboard/ApdexPerTransactionTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/report/dashboard/ApdexPerTransactionTest.java Mon Apr 10 13:42:46 2017
@@ -22,14 +22,7 @@ import static org.junit.Assert.assertArr
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Iterator;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Set;
 
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -39,7 +32,6 @@ import org.apache.oro.text.regex.Pattern
 import org.junit.Test;
 
 import jodd.props.Props;
-import jodd.props.PropsEntry;
 
 public class ApdexPerTransactionTest extends JMeterTestCase {
 	
@@ -48,45 +40,28 @@ public class ApdexPerTransactionTest ext
 	private static final String apdexString = "sample(\\d+):1000|2000;samples12:3000|4000;scenar01-12:5000|6000";
 	
 	@Test
-	public void testgetApdexPerTransactionProperty() {
-		final Properties merged = new Properties();
+	public void testgetApdexPerTransactionProperty() throws Exception {
 		final Props props = new Props();
 		final String REPORT_GENERATOR_KEY_PREFIX = "jmeter.reportgenerator";
 		final char KEY_DELIMITER = '.';
 		final String REPORT_GENERATOR_KEY_APDEX_PER_TRANSACTION = REPORT_GENERATOR_KEY_PREFIX
 	            + KEY_DELIMITER + "apdex_per_transaction";
 		
-		merged.putAll(loadProps(
-		        new File(this.getClass().getResource("reportgenerator_test.properties").getFile())));
-		props.load(merged);
+		props.load(this.getClass().getResourceAsStream("reportgenerator_test.properties"));
 		final String apdexPerTransaction = getOptionalProperty(props, 
         		REPORT_GENERATOR_KEY_APDEX_PER_TRANSACTION, 
         		String.class);
 		assertEquals(apdexString, apdexPerTransaction);
-		
 	}
 	
     @Test
-    public void testgetApdexPerTransactionPropertySimple() {
-        final Properties merged = new Properties();
+    public void testgetApdexPerTransactionPropertySimple() throws Exception {
         final Props props = new Props();
-        
-        merged.putAll(loadProps(
-                new File(this.getClass().getResource("reportgenerator_test.properties").getFile())));
-        props.load(merged);
+        props.load(this.getClass().getResourceAsStream("reportgenerator_test.properties"));
         final String title = getOptionalProperty(props, 
                 "jmeter.reportgenerator.graph.responseTimePercentiles.title", 
                 String.class);
-        if (title == null) {
-            Iterator<PropsEntry> it = props.iterator();
-            int i = 0;
-            while(it.hasNext()) {
-                PropsEntry pe = it.next();
-                i++;
-                System.err.println(pe);
-            }
-            fail("title should not be null; see above for entries in property collection: " + i);            
-        }
+        assertNotNull("title should not be null", title);
     }
     
 	@Test
@@ -156,16 +131,6 @@ public class ApdexPerTransactionTest ext
 		
 	}
 	
-	private static Properties loadProps(File file) {
-        final Properties props = new Properties();
-        try (FileInputStream inStream = new FileInputStream(file)) {
-            props.load(inStream);
-        } catch (IOException e) {
-            fail("Problem loading properties. " + e); // NOSONAR
-        }
-        return props;
-    }
-	
 	private static String getOptionalProperty(Props props,
             String key, Class<String> clazz) {
         String property = getProperty(props, key, null, clazz);