Skip to content

Commit

Permalink
attempt to make even java method refs work in callSingle #1558 #1633
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Jun 29, 2021
1 parent a383a00 commit 6707871
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,7 @@ private Object recurseAndAttachAndDeepClone(String name, Object o, Set<Object> s
}
if (o instanceof Class) {
Class clazz = (Class) o;
Value value = JS.evalForValue("Java.type('" + clazz.getCanonicalName() + "')");
return value;
return JS.evalForValue("Java.type('" + clazz.getCanonicalName() + "')");
} else if (o instanceof JsFunction) {
JsFunction jf = (JsFunction) o;
try {
Expand Down Expand Up @@ -1233,7 +1232,7 @@ private Object recurseAndDetachAndDeepClone(String name, Object o, Set<Object> s
}
} catch (Exception e) {
logger.warn("[*** detach deep ***] ignoring non-json value in callonce / callSingle: '{}' - {}", name, e.getMessage());
return null;
return value; // re-attempt on attach
}
}
if (o instanceof List) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,22 @@ public JsExecutable(Value value) {
this.value = value;
}

private static final Object LOCK = new Object();

@Override
public Object execute(Value... arguments) {
return value.execute(arguments);
Object[] args = new Object[arguments.length];
for (int i = 0; i < args.length; i++) {
args[i] = arguments[i].as(Object.class);
}
try {
return value.execute(args);
} catch (Exception e) {
logger.warn("[*** execute ***] java method reference (from callSingle() ?) invocation failed: {}", e.getMessage());
synchronized (LOCK) {
return value.execute(args);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Background:
* url serverUrl
* def data = [ { name: 'value1' }, { name: 'value2' }, { name: 'value3' }, { name: 'value4' } ]
# java object that comes from a callSingle in the config
* def helloClass = HelloConfigSingle
* def HelloBg = HelloConfigSingle
* callonce read('call-once-from-feature.feature')

Scenario Outline:
Expand All @@ -16,9 +16,10 @@ Scenario Outline:
* method get
* status 200
* match response == { message: 'from feature' }
# use java object from background, callSingle, config
* match helloClass.sayHello('from the other side') == 'hello from the other side'
* match helloClass.sayHello(name) == 'hello ' + name

* match HelloBg.sayHello('world') == 'hello world'
* match HelloOnce.sayHello('world') == 'hello world'
* match sayHello('world') == 'hello world'

Examples:
| data |
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Scenario: one

* match HelloConfigSingle.sayHello('world') == 'hello world'
* match HelloOnce.sayHello('world') == 'hello world'
# * match sayHello('world') == 'hello world'
* match sayHello('world') == 'hello world'

Scenario: two
* path 'two'
Expand All @@ -30,7 +30,7 @@ Scenario: two

* match HelloConfigSingle.sayHello('world') == 'hello world'
* match HelloOnce.sayHello('world') == 'hello world'
# * match sayHello('world') == 'hello world'
* match sayHello('world') == 'hello world'

Scenario: three
* path 'three'
Expand All @@ -42,4 +42,4 @@ Scenario: three

* match HelloConfigSingle.sayHello('world') == 'hello world'
* match HelloOnce.sayHello('world') == 'hello world'
# * match sayHello('world') == 'hello world'
* match sayHello('world') == 'hello world'

0 comments on commit 6707871

Please sign in to comment.