Skip to content

Commit 6707871

Browse files
committed
attempt to make even java method refs work in callSingle #1558 #1633
1 parent a383a00 commit 6707871

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

karate-core/src/main/java/com/intuit/karate/core/ScenarioEngine.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1175,8 +1175,7 @@ private Object recurseAndAttachAndDeepClone(String name, Object o, Set<Object> s
11751175
}
11761176
if (o instanceof Class) {
11771177
Class clazz = (Class) o;
1178-
Value value = JS.evalForValue("Java.type('" + clazz.getCanonicalName() + "')");
1179-
return value;
1178+
return JS.evalForValue("Java.type('" + clazz.getCanonicalName() + "')");
11801179
} else if (o instanceof JsFunction) {
11811180
JsFunction jf = (JsFunction) o;
11821181
try {
@@ -1233,7 +1232,7 @@ private Object recurseAndDetachAndDeepClone(String name, Object o, Set<Object> s
12331232
}
12341233
} catch (Exception e) {
12351234
logger.warn("[*** detach deep ***] ignoring non-json value in callonce / callSingle: '{}' - {}", name, e.getMessage());
1236-
return null;
1235+
return value; // re-attempt on attach
12371236
}
12381237
}
12391238
if (o instanceof List) {

karate-core/src/main/java/com/intuit/karate/graal/JsExecutable.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,22 @@ public JsExecutable(Value value) {
4242
this.value = value;
4343
}
4444

45+
private static final Object LOCK = new Object();
46+
4547
@Override
4648
public Object execute(Value... arguments) {
47-
return value.execute(arguments);
49+
Object[] args = new Object[arguments.length];
50+
for (int i = 0; i < args.length; i++) {
51+
args[i] = arguments[i].as(Object.class);
52+
}
53+
try {
54+
return value.execute(args);
55+
} catch (Exception e) {
56+
logger.warn("[*** execute ***] java method reference (from callSingle() ?) invocation failed: {}", e.getMessage());
57+
synchronized (LOCK) {
58+
return value.execute(args);
59+
}
60+
}
4861
}
4962

5063
}

karate-core/src/test/java/com/intuit/karate/core/parallel/parallel-outline-1.feature

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Background:
66
* url serverUrl
77
* def data = [ { name: 'value1' }, { name: 'value2' }, { name: 'value3' }, { name: 'value4' } ]
88
# java object that comes from a callSingle in the config
9-
* def helloClass = HelloConfigSingle
9+
* def HelloBg = HelloConfigSingle
1010
* callonce read('call-once-from-feature.feature')
1111

1212
Scenario Outline:
@@ -16,9 +16,10 @@ Scenario Outline:
1616
* method get
1717
* status 200
1818
* match response == { message: 'from feature' }
19-
# use java object from background, callSingle, config
20-
* match helloClass.sayHello('from the other side') == 'hello from the other side'
21-
* match helloClass.sayHello(name) == 'hello ' + name
19+
20+
* match HelloBg.sayHello('world') == 'hello world'
21+
* match HelloOnce.sayHello('world') == 'hello world'
22+
* match sayHello('world') == 'hello world'
2223

2324
Examples:
2425
| data |

karate-core/src/test/java/com/intuit/karate/core/parallel/parallel.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Scenario: one
1818

1919
* match HelloConfigSingle.sayHello('world') == 'hello world'
2020
* match HelloOnce.sayHello('world') == 'hello world'
21-
# * match sayHello('world') == 'hello world'
21+
* match sayHello('world') == 'hello world'
2222

2323
Scenario: two
2424
* path 'two'
@@ -30,7 +30,7 @@ Scenario: two
3030

3131
* match HelloConfigSingle.sayHello('world') == 'hello world'
3232
* match HelloOnce.sayHello('world') == 'hello world'
33-
# * match sayHello('world') == 'hello world'
33+
* match sayHello('world') == 'hello world'
3434

3535
Scenario: three
3636
* path 'three'
@@ -42,4 +42,4 @@ Scenario: three
4242

4343
* match HelloConfigSingle.sayHello('world') == 'hello world'
4444
* match HelloOnce.sayHello('world') == 'hello world'
45-
# * match sayHello('world') == 'hello world'
45+
* match sayHello('world') == 'hello world'

0 commit comments

Comments
 (0)