Skip to content

Commit

Permalink
fixing bug introduced with step-defs csv support for http key-vals, a…
Browse files Browse the repository at this point in the history
…nd demo test added
  • Loading branch information
ptrthomas committed May 2, 2017
1 parent d1f0a90 commit aa6cd7d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions karate-core/src/main/java/com/intuit/karate/ScriptValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import com.intuit.karate.cucumber.FeatureWrapper;
import com.jayway.jsonpath.DocumentContext;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
Expand Down Expand Up @@ -122,6 +125,8 @@ public boolean isListLike() {
public List getAsList() {
switch (type) {
case JS_ARRAY:
Collection coll = getValue(ScriptObjectMirror.class).values();
return new ArrayList(coll);
case LIST:
return getValue(List.class);
default:
Expand Down
16 changes: 13 additions & 3 deletions karate-core/src/main/java/com/intuit/karate/StepDefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,19 @@ public void path(List<String> paths) {

private List<String> evalList(List<String> values) {
List<String> list = new ArrayList(values.size());
for (String value : values) {
ScriptValue temp = Script.eval(value, context);
list.add(temp.getAsString());
try {
for (String value : values) {
ScriptValue temp = Script.eval(value, context);
list.add(temp.getAsString());
}
} catch (Exception e) { // hack. for e.g. json with commas would land here
String joined = StringUtils.join(values, ", ");
ScriptValue temp = Script.eval(joined, context);
if (temp.isListLike()) {
return temp.getAsList();
} else {
return Collections.singletonList(temp.getAsString());
}
}
return list;
}
Expand Down
10 changes: 10 additions & 0 deletions karate-demo/src/test/java/demo/headers/headers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,15 @@ Scenario: set multi-value headers using json
When method get
Then status 200

Scenario: set multi-value headers using function call

# this is a test case for an edge case where commas in json confuse cucumber
* def fun = function(arg){ return [arg.first, arg.second] }
* header Authorization = call fun { first: 'dummy', second: '#(token + time + demoBaseUrl)' }

Given path 'headers', token
And param url = demoBaseUrl
When method get
Then status 200


0 comments on commit aa6cd7d

Please sign in to comment.