SOAPUI : use operation with properties in Expected result - xpath

i'm using SOAPUI for my webservices' test, and i'm searching to make an multiplication with a property, to compare it to my result.
ex:
testStep1(IMPORT) :
request => <hour>1</hour> (Import of the value)
testStep2 (JDBCrequest : EXPORT):
query : select * from myTable
result : <hour>3600</hour>(the value is stored in seconds in my DB)
What i'm trying to do = Xpath match (Assertion into my JDBC Request) :
"Xpath expression" : //Result/hour
"Expected result" : ${testStep1#Request#//hour}*3600
But it seems that "expected result" doesn't take this form of result.
Can someone help me?
Thanks in advance

In your expected result you can use Groovy one-liner like so:
${= ${testStep1#Request#//*:hour} * 60 * 60 }

Related

Laravel - WhereExists returning "Invalid parameter number: parameter was not defined"

I'm trying to use whereExists() on an existing Eloquent query builder (called $trips):
$trips = $trips->whereExists(function ($query) use ($filterValue) {
$query->from(DB::raw("jsonb_array_elements(passengers->'adults'->'persons') as p(person)"))
->whereRaw("p.person->>'name' LIKE '?%'", $filterValue);
});
The query I'm trying to create in raw postgres format is the following (this query works fine using pgAdmin):
SELECT *
from trips
WHERE exists (select *
from jsonb_array_elements(passengers -> 'adults' -> 'persons') as p(person)
where p.person ->> 'name' LIKE 'Prof%');
And I'm receiving this error:
Invalid parameter number: parameter was not defined
I think the problem is small, but I can't see it myself.
The parameter definition in your whereRaw() statement is not quite correct. Parameterized queries are not just string replacements. Your query as written doesn't have a parameter in it, it has a string literal of '?%'. You need to change this to a query parameter, and append the % wildcard to the string you pass in.
Try this:
->whereRaw("p.person->>'name' LIKE ?", $filterValue.'%')

Elasticsearch custom scoring function test null date values

I can't find anywhere examples of how to test null values in ES custom scoring functions.
According to the doc the scripts are in groovy, according to the log the script is evaluated in painless, but even with that I'm left puzzled by some errors
"script":"doc['response_rate'].value ? (doc['response_rate'].value + 1) : 0",
"lang":"painless",
"caused_by":{
"type":"wrong_method_type_exception",
"reason":"cannot convert MethodHandle(Doubles)double to (Object)boolean"}}}]
This seems to say I'm trying to cas a double to boolean and raises, but I need to test for non-null values.
How should I write my scoring script ?
EDIT : I have understood that in painless I cannot use the ternary ? : operator, so I must write explicitely doc['xx'].value != null. However, this seems to produce weird results for dates that were indexed with null values. It would seem that in painless the value is NOT null (although it is indeed null in the json when I GET /_search it) and the following does not work
"script":"(doc['unavailable_until'].value != null) ? 1 : 0"
and always seem to return 0 (as if the null date was actually not null). I have seen some people reporting something some weird default date, in this case how can I compare this date to something like Date.now ?
I wonder why I couldn't find this page before...
Basically, one can just call .empty to check for null values. Works with dates too
"script":"doc['unavailable_until'].empty ? 1 : 0",

laravel return '?' instead of '1' in WHERE clause

$datas=Elan::orderBy('created_at','desc')->where('status', 1)->take(4)->toSql();
dd($datas);
I wrote query in "laravel 5.2". I displayed it as sql query with function toSql()
and the result is:
"select * from `els` where `status` = ? order by `created_at` desc limit 4"
you can see that there is ? mark. this is why my query doesn't work. why does it return me ? instead of one. I also tried it like this '1' same result.
You may want to read about bindings if you want to understand what does ? mean.
https://laravel.com/docs/5.3/database#running-queries
If you want to debug and watch queries, you can install this debugbar: https://github.com/barryvdh/laravel-debugbar
? is used for Parameter binding which prevent against SQL injection.
If you want to see the raw SQL query which is executed with parameters values, try the below code:
DB::enableQueryLog();
$datas=Elan::orderBy('created_at','desc')->where('status', 1)->take(4)->get();
dd(DB::getQueryLog());
Hope this helps!

jmeter jdbc request parameter type

I am constructing a jmeter jdbc Prepared Select statement request.
I have the query as,
select * from tableName where c=?
Parameter Value: ${columnId}
Parameter Type: LONGVARCHAR
When I run I get a: type mismatch error UNSIGNED_LONG and CHAR for c='1234'
I need to pass a long value here. Also, how would I pass a binary array?
You should use User defined variables as reference. This way you can avid using Parameter fields.
Reference: http://jmeter.apache.org/usermanual/functions.html
select * from tableName where c='${columnId}'

How to write a query with two ? placeholders in sequence?

I am using a NamedParameterJdbcTemplate, but found that this problem is in the underlying JdbcTemplate class, so I will show the problem as it occurs with the JdbcTemplate (so let's not worry about the safety of the SQL query here).
Here's what I am trying to achieve:
String sql = "SELECT * FROM clients ORDER BY ? ?";
return jdbcTemplate.query(sql,
new Object[] { "name", "ASC" },
new ClientResultSetExtractor());
I expected the first place-holder to be replaced with "name" and the second with "ASC", which would create the valid SQL query:
SELECT * FROM clients ORDER BY name ASC
But unfortunately, running that jdbc query does not work:
ERROR: syntax error at or near "$2" at character 35
STATEMENT: SELECT * FROM clients ORDER BY $1 $2
What am I doing wrong?
EDIT
I had assumed the problem was the two placeholders in sequence, but even when I remove the first one, it still won't accept just the last one, which should tell the query whether to sort in ASC or DESC order. Is this a bug, and if not, why the heck is this not acceptable????
You're trying to use parameters incorrectly.
Parameters are not column names or SQL statement keywords. They're data content (eg., WHERE LastName = ? is a valid parameterized statement, WHERE ? = 'Smith' is not).

Resources