jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1816908 - in /jmeter/trunk: src/jorphan/org/apache/jorphan/io/ src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/ src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ test/src/org/apache/jmeter/protocol/jms/sampler/render/...
Date Fri, 01 Dec 2017 21:04:37 GMT
Author: pmouawad
Date: Fri Dec  1 21:04:37 2017
New Revision: 1816908

URL: http://svn.apache.org/viewvc?rev=1816908&view=rev
Log:
Bug 61827 - [JMSPublisher] Don't add new line at the end of the file
Contributed by Graham Russell
This closes #346
Bugzilla Id: 61827

Added:
    jmeter/trunk/test/src/org/apache/jorphan/io/
    jmeter/trunk/test/src/org/apache/jorphan/io/TextFileSpec.groovy
Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/io/TextFile.java
    jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
    jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/TextMessageRenderer.java
    jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/BinaryMessageRendererTest.java
    jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/MessageRendererTest.java
    jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRendererTest.java
    jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/TextMessageRendererTest.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/io/TextFile.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/io/TextFile.java?rev=1816908&r1=1816907&r2=1816908&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/io/TextFile.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/io/TextFile.java Fri Dec  1 21:04:37 2017
@@ -18,18 +18,11 @@
 
 package org.apache.jorphan.io;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
 
-import org.apache.jorphan.util.JOrphanUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -38,26 +31,21 @@ import org.slf4j.LoggerFactory;
  * <p>
  * Note this is just as memory-inefficient as handling a text file can be. Use
  * with restraint.
- *
  */
 public class TextFile extends File {
     private static final long serialVersionUID = 240L;
 
     private static final Logger log = LoggerFactory.getLogger(TextFile.class);
 
-    /**
-     * File encoding. null means use the platform's default.
-     */
+    /** File encoding. null means use the platform's default. */
     private String encoding = null;
 
     /**
      * Create a TextFile object to handle the named file with the given
      * encoding.
      *
-     * @param filename
-     *            File to be read and written through this object.
-     * @param encoding
-     *            Encoding to be used when reading and writing this file.
+     * @param filename File to be read and written through this object.
+     * @param encoding Encoding to be used when reading and writing this file.
      */
     public TextFile(File filename, String encoding) {
         super(filename.toString());
@@ -68,8 +56,7 @@ public class TextFile extends File {
      * Create a TextFile object to handle the named file with the platform
      * default encoding.
      *
-     * @param filename
-     *            File to be read and written through this object.
+     * @param filename File to be read and written through this object.
      */
     public TextFile(File filename) {
         super(filename.toString());
@@ -79,8 +66,7 @@ public class TextFile extends File {
      * Create a TextFile object to handle the named file with the platform
      * default encoding.
      *
-     * @param filename
-     *            Name of the file to be read and written through this object.
+     * @param filename Name of the file to be read and written through this object.
      */
     public TextFile(String filename) {
         super(filename);
@@ -90,10 +76,8 @@ public class TextFile extends File {
      * Create a TextFile object to handle the named file with the given
      * encoding.
      *
-     * @param filename
-     *            Name of the file to be read and written through this object.
-     * @param encoding
-     *            Encoding to be used when reading and writing this file.
+     * @param filename Name of the file to be read and written through this object.
+     * @param encoding Encoding to be used when reading and writing this file.
      */
     public TextFile(String filename, String encoding) {
         super(filename);
@@ -101,29 +85,16 @@ public class TextFile extends File {
     }
 
     /**
-     * Create the file with the given string as content -- or replace it's
+     * Create the file with the given string as content -- or replace its
      * content with the given string if the file already existed.
      *
-     * @param body
-     *            New content for the file.
+     * @param body New content for the file.
      */
     public void setText(String body) {
-        Writer writer = null;
-        OutputStream outputStream = null;
         try {
-            outputStream = new FileOutputStream(this);
-            if (encoding == null) {
-                writer = new OutputStreamWriter(outputStream);
-            } else {
-                writer = new OutputStreamWriter(outputStream, encoding);
-            }
-            writer.write(body);
-            writer.flush();
+            Files.write(this.toPath(), body.getBytes(getCharset()));
         } catch (IOException ioe) {
             log.error("", ioe);
-        } finally {
-            JOrphanUtils.closeQuietly(writer);
-            JOrphanUtils.closeQuietly(outputStream);
         }
     }
 
@@ -133,35 +104,19 @@ public class TextFile extends File {
      * @return the content of the file
      */
     public String getText() {
-        String lineEnd = System.getProperty("line.separator"); //$NON-NLS-1$
-        StringBuilder sb = new StringBuilder();
-        Reader reader = null;
-        BufferedReader br = null;
-        FileInputStream fileInputStream = null;
         try {
-            fileInputStream = new FileInputStream(this);
-            if (encoding == null) {
-                reader = new InputStreamReader(fileInputStream);                
-            } else {
-                reader = new InputStreamReader(fileInputStream, encoding);
-            }
-            br = new BufferedReader(reader);
-            String line = "NOTNULL"; //$NON-NLS-1$
-            while (line != null) {
-                line = br.readLine();
-                if (line != null) {
-                    sb.append(line + lineEnd);
-                }
-            }
+            byte[] encoded = Files.readAllBytes(this.toPath());
+            return new String(encoded, getCharset());
         } catch (IOException ioe) {
-            log.error("", ioe); //$NON-NLS-1$
-        } finally {
-            JOrphanUtils.closeQuietly(br);
-            JOrphanUtils.closeQuietly(reader); 
-            JOrphanUtils.closeQuietly(fileInputStream); 
+            log.error("Failed to getText", ioe);
+            return "";
         }
+    }
 
-        return sb.toString();
+    private Charset getCharset() {
+        return encoding != null
+                    ? Charset.forName(encoding)
+                    : Charset.defaultCharset();
     }
 
     /**
@@ -172,8 +127,7 @@ public class TextFile extends File {
     }
 
     /**
-     * @param string
-     *            Encoding to be used to read and write this file.
+     * @param string Encoding to be used to read and write this file.
      */
     public void setEncoding(String string) {
         encoding = string;
@@ -208,7 +162,7 @@ public class TextFile extends File {
         TextFile other = (TextFile) obj;
         if (encoding == null) {
             return other.encoding == null;
-        } 
+        }
         return encoding.equals(other.encoding);
     }
 }

Modified: jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java?rev=1816908&r1=1816907&r2=1816908&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
(original)
+++ jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
Fri Dec  1 21:04:37 2017
@@ -79,9 +79,11 @@ public class PublisherSampler extends Ba
      */
     public static String[] getSupportedEncodings() {
         // Only get JVM standard charsets
-        return Stream.concat(NO_ENCODING.stream(),
+        return Stream.concat(
+                NO_ENCODING.stream(),
                 Arrays.stream(StandardCharsets.class.getDeclaredFields())
-                        .filter(f -> Modifier.isStatic(f.getModifiers()) && Modifier.isPublic(f.getModifiers())
+                        .filter(f -> Modifier.isStatic(f.getModifiers())
+                                && Modifier.isPublic(f.getModifiers())
                                 && f.getType() == Charset.class)
                         .map(f -> {
                             try {
@@ -89,8 +91,10 @@ public class PublisherSampler extends Ba
                             } catch (IllegalArgumentException | IllegalAccessException e)
{
                                 throw new RuntimeException(e);
                             }
-                        }).map(Charset::displayName).sorted())
-                .toArray(size -> new String[size]);
+                        })
+                        .map(Charset::displayName)
+                        .sorted())
+                .toArray(String[]::new);
     }
 
     private static final long serialVersionUID = 233L;
@@ -119,9 +123,9 @@ public class PublisherSampler extends Ba
     private static final String JMS_FILE_ENCODING = "jms.file_encoding"; // $NON-NLS-1$
 
     /** File extensions for text files **/
-    private static final String[] EXT_FILE_TEXT = { ".txt", ".obj" };
+    private static final String[] TEXT_FILE_EXTS = { ".txt", ".obj" };
     /** File extensions for binary files **/
-    private static final String[] EXT_FILE_BIN = { ".dat" };
+    private static final String[] BIN_FILE_EXTS = { ".dat" };
 
     // --
 
@@ -193,8 +197,7 @@ public class PublisherSampler extends Ba
     public SampleResult sample() {
         String configChoice = getConfigChoice();
         if (fileCache == null) {
-            Cache<Object, Object> newCache = buildCache(configChoice);
-            fileCache = newCache;
+            fileCache = buildCache(configChoice);
         }
 
         SampleResult result = new SampleResult();
@@ -224,19 +227,18 @@ public class PublisherSampler extends Ba
             for (int idx = 0; idx < loop; idx++) {
                 Message msg;
                 if (JMSPublisherGui.TEXT_MSG_RSC.equals(type)) {
-                    String tmsg = getRenderedContent(String.class, EXT_FILE_TEXT);
+                    String tmsg = getRenderedContent(String.class, TEXT_FILE_EXTS);
                     msg = publisher.publish(tmsg, getDestination(), msgProperties, deliveryMode,
priority, expiration);
                     buffer.append(tmsg);
                 } else if (JMSPublisherGui.MAP_MSG_RSC.equals(type)) {
                     @SuppressWarnings("unchecked")
-                    Map<String, Object> map = getRenderedContent(Map.class, EXT_FILE_TEXT);
-                    Map<String, Object> m = map;
-                    msg = publisher.publish(m, getDestination(), msgProperties, deliveryMode,
priority, expiration);
+                    Map<String, Object> map = getRenderedContent(Map.class, TEXT_FILE_EXTS);
+                    msg = publisher.publish(map, getDestination(), msgProperties, deliveryMode,
priority, expiration);
                 } else if (JMSPublisherGui.OBJECT_MSG_RSC.equals(type)) {
-                    Serializable omsg = getRenderedContent(Serializable.class, EXT_FILE_TEXT);
+                    Serializable omsg = getRenderedContent(Serializable.class, TEXT_FILE_EXTS);
                     msg = publisher.publish(omsg, getDestination(), msgProperties, deliveryMode,
priority, expiration);
                 } else if (JMSPublisherGui.BYTES_MSG_RSC.equals(type)) {
-                    byte[] bmsg = getRenderedContent(byte[].class, EXT_FILE_BIN);
+                    byte[] bmsg = getRenderedContent(byte[].class, BIN_FILE_EXTS);
                     msg = publisher.publish(bmsg, getDestination(), msgProperties, deliveryMode,
priority, expiration);
                 } else {
                     throw new JMSException(type + " is not recognised");
@@ -311,8 +313,7 @@ public class PublisherSampler extends Ba
         case JMSPublisherGui.USE_FILE_RSC:
             return getInputFile();
         case JMSPublisherGui.USE_RANDOM_RSC:
-            String fname = FSERVER.getRandomFile(getRandomPath(), ext).getAbsolutePath();
-            return fname;
+            return FSERVER.getRandomFile(getRandomPath(), ext).getAbsolutePath();
         default:
             throw new IllegalArgumentException("Type of input not handled:" + getConfigChoice());
         }

Modified: jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/TextMessageRenderer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/TextMessageRenderer.java?rev=1816908&r1=1816907&r2=1816908&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/TextMessageRenderer.java
(original)
+++ jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/TextMessageRenderer.java
Fri Dec  1 21:04:37 2017
@@ -42,6 +42,4 @@ class TextMessageRenderer implements Mes
     String getContent(FileKey key) {
         return new TextFile(key.getFilename(), key.getEncoding()).getText();
     }
-
-
 }

Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/BinaryMessageRendererTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/BinaryMessageRendererTest.java?rev=1816908&r1=1816907&r2=1816908&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/BinaryMessageRendererTest.java
(original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/BinaryMessageRendererTest.java
Fri Dec  1 21:04:37 2017
@@ -17,7 +17,6 @@
 
 package org.apache.jmeter.protocol.jms.sampler.render;
 
-import static java.lang.String.format;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -25,6 +24,7 @@ import static org.junit.Assert.assertEqu
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
+import java.nio.charset.UnsupportedCharsetException;
 
 import org.junit.Rule;
 import org.junit.Test;
@@ -76,27 +76,22 @@ public class BinaryMessageRendererTest e
 
     @Test
     public void getValueFromFile_withNoVar() {
-        String text = format("éè€%n");
+        String text = "éè€";
         assertValueFromFile(text, "utf8.txt", true);
         assertCacheContentInString(text);
-
     }
 
     @Test
     public void getValueFromFile_withOneVar() {
         String value = "éè€";
         jmeterCtxService.get().getVariables().put("oneVar", value);
-        assertValueFromFile(format("%s%n", value), "oneVar.txt", true);
-        assertCacheContentInString(format("${oneVar}%n"));
+        assertValueFromFile(value, "oneVar.txt", true);
+        assertCacheContentInString("${oneVar}");
     }
 
-
-
     @Test
     public void getValueFromFile_withInvalidEncoding() {
-        error.expect(RuntimeException.class);
-        error.expectCause(instanceOf(UnsupportedEncodingException.class));
-
+        error.expect(UnsupportedCharsetException.class);
         render.getValueFromFile(getResourceFile("utf8.txt"), "banana", true, cache);
     }
 

Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/MessageRendererTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/MessageRendererTest.java?rev=1816908&r1=1816907&r2=1816908&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/MessageRendererTest.java
(original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/MessageRendererTest.java
Fri Dec  1 21:04:37 2017
@@ -28,9 +28,6 @@ import org.junit.Rule;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.github.benmanes.caffeine.cache.Caffeine;
 
-/**
- *
- */
 public abstract class MessageRendererTest<T> {
 
     protected Cache<Object,Object> cache = Caffeine.newBuilder().build();

Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRendererTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRendererTest.java?rev=1816908&r1=1816907&r2=1816908&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRendererTest.java
(original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRendererTest.java
Fri Dec  1 21:04:37 2017
@@ -27,9 +27,6 @@ import java.io.Serializable;
 import org.apache.jmeter.protocol.jms.sampler.PublisherSampler;
 import org.junit.Test;
 
-/**
- *
- */
 public class ObjectMessageRendererTest extends MessageRendererTest<Serializable> {
 
     private ObjectMessageRenderer render = RendererFactory.getInstance().getObject();
@@ -65,7 +62,7 @@ public class ObjectMessageRendererTest e
         String filename = getResourceFile("object_cp1252.xml");
         Serializable object = getRenderer().getValueFromFile(filename, "Cp1252", true, cache);
         assertObject(object, "eéè€");
-        assertEquals("cache", format("%s%n", getUnicodeContent()), getFirstCachedValue());
+        assertEquals("cache", getUnicodeContent(), getFirstCachedValue());
 
     }
 
@@ -74,7 +71,7 @@ public class ObjectMessageRendererTest e
         String filename = getResourceFile("object_utf8.xml");
         Serializable object = getRenderer().getValueFromFile(filename, PublisherSampler.DEFAULT_ENCODING,
true, cache);
         assertObject(object, "eéè€");
-        assertEquals("cache", format("%s%n", getUnicodeContent()), getFirstCachedValue());
+        assertEquals("cache", getUnicodeContent(), getFirstCachedValue());
 
     }
 
@@ -85,7 +82,7 @@ public class ObjectMessageRendererTest e
         assertObject(object, "eéè€");
         Person p = (Person) object;
         assertEquals("object.name", "eéè€", p.getName());
-        assertEquals("cache", format("<?xml version=\"1.0\" encoding=\"Windows-1252\"?>%n%s%n",
getUnicodeContent()), getFirstCachedValue());
+        assertEquals("cache", format("<?xml version=\"1.0\" encoding=\"Windows-1252\"?>%n%s",
getUnicodeContent()), getFirstCachedValue());
 
     }
 

Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/TextMessageRendererTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/TextMessageRendererTest.java?rev=1816908&r1=1816907&r2=1816908&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/TextMessageRendererTest.java
(original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/jms/sampler/render/TextMessageRendererTest.java
Fri Dec  1 21:04:37 2017
@@ -17,7 +17,6 @@
 
 package org.apache.jmeter.protocol.jms.sampler.render;
 
-import static java.lang.String.format;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
 
@@ -25,9 +24,6 @@ import java.util.Arrays;
 
 import org.junit.Test;
 
-/**
- *
- */
 public class TextMessageRendererTest extends MessageRendererTest<String> {
 
     private TextMessageRenderer render = RendererFactory.getInstance().getText();
@@ -49,36 +45,35 @@ public class TextMessageRendererTest ext
     private void assertContent(String resource, String encoding) {
         String filename = getResourceFile(resource);
         String actual = render.getContent(new FileKey(filename, encoding));
-        assertEquals(format("éè€%n"), actual);
+        assertEquals("éè€", actual);
     }
 
-
     @Test
     public void getValueFromFileWithNoVar() {
-        assertValueFromFile(format("noVar%n"), "noVar.txt", true);
+        assertValueFromFile("noVar", "noVar.txt", true);
     }
 
     @Test
     public void getValueFromFileWithOneVar() {
         jmeterCtxService.get().getVariables().put("oneVar", "foobar");
-        assertValueFromFile(format("foobar%n"), "oneVar.txt", true);
+        assertValueFromFile("foobar", "oneVar.txt", true);
     }
 
     @Test
     public void checkCache() {
         jmeterCtxService.get().getVariables().put("oneVar", "foo");
-        assertValueFromFile(format("foo%n"), "oneVar.txt", true);
-        assertEquals(format("${oneVar}%n"), getFirstCachedValue());
+        assertValueFromFile("foo", "oneVar.txt", true);
+        assertEquals("${oneVar}", getFirstCachedValue());
 
         jmeterCtxService.get().getVariables().put("oneVar", "bar");
-        assertValueFromFile(format("bar%n"), "oneVar.txt", true);
-        assertEquals(format("${oneVar}%n"), getFirstCachedValue());
+        assertValueFromFile("bar", "oneVar.txt", true);
+        assertEquals("${oneVar}", getFirstCachedValue());
     }
 
     @Test
     public void checkNoVariable() {
         jmeterCtxService.get().getVariables().put("oneVar", "RAW");
-        assertValueFromFile(format("${oneVar}%n"), "oneVar.txt", false);
+        assertValueFromFile("${oneVar}", "oneVar.txt", false);
     }
 
     @Test

Added: jmeter/trunk/test/src/org/apache/jorphan/io/TextFileSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jorphan/io/TextFileSpec.groovy?rev=1816908&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jorphan/io/TextFileSpec.groovy (added)
+++ jmeter/trunk/test/src/org/apache/jorphan/io/TextFileSpec.groovy Fri Dec  1 21:04:37 2017
@@ -0,0 +1,87 @@
+package org.apache.jorphan.io
+
+import org.apache.commons.io.FileUtils
+import spock.lang.Specification
+import spock.lang.Unroll
+
+import java.nio.charset.Charset
+import java.nio.charset.StandardCharsets
+
+@Unroll
+class TextFileSpec extends Specification {
+
+    def tmpFile = File.createTempFile("TextFile", ".unittest")
+    def tmpPath = tmpFile.getAbsolutePath()
+
+    def setup() {
+        tmpFile.deleteOnExit()
+    }
+
+    def "getText of empty file is empty string"() {
+        given:
+            def sut = new TextFile(tmpPath)
+        expect:
+            sut.getText() == ""
+    }
+
+    def "getText returns exact content of file"() {
+        given:
+            def sut = new TextFile(tmpPath)
+            FileUtils.write(tmpFile, content, Charset.defaultCharset())
+        expect:
+            sut.getText() == content
+        where:
+            content << ["a\nb\nc", "\"a\nb\nc\n"]
+    }
+
+    def "getText returns exact content of file with specific charset"() {
+        given:
+            def sut = new TextFile(tmpPath, encoding)
+            FileUtils.write(tmpFile, content, charset)
+        expect:
+            sut.getText() == content
+        where:
+            content     | charset                     | encoding
+            "a\nb\nc"   | StandardCharsets.UTF_16     | "UTF_16"
+            "a\nb\nc\n" | StandardCharsets.UTF_16     | "UTF_16"
+            "a\nb\nc"   | StandardCharsets.ISO_8859_1 | "ISO_8859_1"
+            "a\nb\nc\n" | StandardCharsets.ISO_8859_1 | "ISO_8859_1"
+    }
+
+    def "setText sets exact content of file"() {
+        given:
+            def sut = new TextFile(tmpPath)
+        when:
+            sut.setText(content)
+        then:
+            sut.getText() == content
+        where:
+            content << ["a\nb\nc", "\"a\nb\nc\n"]
+    }
+
+    def "setText sets exact content of file other charset"() {
+        given:
+            def sut = new TextFile(tmpPath, encoding)
+        when:
+            sut.setText(content, encoding)
+        then:
+            sut.getText(encoding) == content
+        where:
+            content     | encoding
+            "a\nb\nc"   | "UTF_16"
+            "a\nb\nc\n" | "UTF_16"
+            "a\nb\nc"   | "ISO_8859_1"
+            "a\nb\nc\n" | "ISO_8859_1"
+    }
+
+    def "getText throws exception with invalid encoding"() {
+        given:
+            def sut = new TextFile(tmpPath, invalidEncoding)
+        when:
+            sut.getText()
+        then:
+            thrown(IllegalArgumentException)
+        where:
+            invalidEncoding << ["", "invalid", "invalid encoding"]
+    }
+}

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1816908&r1=1816907&r2=1816908&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Fri Dec  1 21:04:37 2017
@@ -211,6 +211,7 @@ Summary
 <ul>
     <li><bug>61698</bug>Test Action: It stop is selected, samplers following
Test Action can run</li>
     <li><bug>61707</bug>Test Action: Target is ignored when pause is selected,
so it should be disabled</li>
+    <li><bug>61827</bug>JMSPublisher: Don't add new line at the end of
the file. Contributed by Graham Russell (graham at ham1.co.uk)</li>
 </ul>
 
 <h3>Controllers</h3>



Mime
View raw message