Conversion of byte array to a string (StepDefs#convertResponseBody(byte[]) German ISO-8859-15
See original GitHub issueHi,
I am using this awesome framework in version 0.4.3 to test a soap webservice. The webservice contains data in German language, also names which contain umlauts like ‘ü’ or ‘ö’.
My tests run into an exception:
java.lang.RuntimeException: cannot convert to map: [type: INPUT_STREAM, value: java.io.ByteArrayInputStream@6e530ccc]
I was debugging for the cause and I found a candidate, the method convertResponseBody(byte[])
in class StepDefs
. This method tries to convert a byte array. For soap data without umlauts this methods returns a raw string which works fine. But for data with umlauts it returns a ByteArrayInputStream
. Later down the execution path the method getAsMap()
of class ScriptValue
throws a runtime exception because the value type ByteArrayInputStream
is unknown.
I think the error cause is that the comparison of the byte array given by the input parameter and the byte array of the converted string is erroneous. It is this line:
if (Arrays.equals(bytes, rawString.getBytes())) {
The comparison of the byte arrays with Array#equals
is not working when the string contains umlauts.
I checked my assumption with this code:
String mueller = "Müller";
final byte[] bytes = mueller.getBytes();
final byte[] bytesUtf8 = mueller.getBytes("utf-8");
String rawString = new String(bytes, "utf-8");
System.out.println("bytes Length: " + bytes.length);
System.out.println("bytesUtf8 Length: " + bytesUtf8.length);
System.out.println("rawString.getBytes() Length: " + rawString.getBytes().length);
System.out.println();
System.out.println("Arrays.equals(bytes, rawString.getBytes()): " + Arrays.equals(bytes, rawString.getBytes()));
System.out.println("Arrays.equals(bytesUtf8, rawString.getBytes()): " + Arrays.equals(bytesUtf8, rawString.getBytes()));
System.out.println("Arrays.equals(bytes, bytesUtf8): " + Arrays.equals(bytes, bytesUtf8));
The comparison of strings with umlauts by the method Arrays#equals
is not working as expected. If the char ‘ü’ is removed then the comparison works fine.
Best regards, Georgios.
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (9 by maintainers)
Top GitHub Comments
Setting the file encoding to UTF-8 led to the desired result. The tests went green.
wow. that is great to know ! thanks @GeorgiosAndreadakis for the update.