I have a piece of code below that checks that every value of regionId (found under region.hotels.regionId) matches its property value regionid_request.
def response = messageExchange.response.responseContent
def json = new JsonSlurper().parseText(response)
def regionid_request = messageExchange.modelItem.testStep.testCase.testSuite.getPropertyValue("regionid") as Integer
region.hotels.each { hotel ->
assert hotel.regionId == regionid_request
}
I want the code above to perform slightly differently. Instead of saying each regionid needs to match its property value, I just want any of regionid to match its property value. In other words I want to ensure when I have my response, that at least one of the regionIds matches the property value.
What needs to be changed above to match this condition?
Thank you,
Just
assert region.hotels.regionId.contains(regionid_request)
Related
I noticed that when calling values() or values_list() one a queryset returns the normal value in the field and not the display value I'd like. Is there a way to manupilate the display value of the field while creating a result that is a list of list of the queryset?
class FooBar(models.Model):
...
foo_bar = models.CharField(_("foo"), choices=[(1, 'foo'), (2, 'bar')])
def get_foo_bar_display(self):
return "something"
def get_foobar(user):
foobar = FooBar.objects.filter(user=user).values_list(.., 'foo_bar')
foobar = list(map(list, foobar))
return foobar
It always returns the foo_bar original value and not the display value.
One way out for you is to get the model instances with only some selected fields (needed for the get_x_display to work correctly) using .only() query set method.
Going from there you can call the get_x_display on the model like you'd normally do.
I have a query where I need to retrieve a column which I need only temporarily because I need to pass it in the parameter for a where clause, how can I remove this column and its value from my result set after it served that purpose. Hopefully the code will show what I mean...
def empQuery = "select id, name, address from Employee"
def retObj = [:]
def sql = new Sql(datasource)
retObj = sql.rows(empQuery.toString())
retObj.each {
def addressQuery = "select street from Address where employe_id = ${it['id']}
// at this point I want to remove 'id:n' from the result set hash map aka 'it'
}
Because later on I am displaying that result set on a page for the user, and the ID field is not relevant.
So can you please show the Groovy code to remove a column and its value from the rows data structure returned from sql.rows?
from http://docs.groovy-lang.org/latest/html/api/groovy/sql/GroovyRowResult.html
It looks like you can do something line:
retObj.each { it.remove('id')}
However I haven't tried it....
I have some geb content like this
buttonName(wait: true){$("a.btn_primary")}
I need get value from {} i.e. i need string $("a.btn_primary")
For example def value = "$("a.btn_primary")"
If your buttonName is correct, then try this:
def value = buttonName.text()
Cheers!
Try
def value = buttonName.value()
if .text() does not work.
From The Book of Geb,
"The value of input, select and textarea elements can be retrieved and set with the value method. Calling value() with no arguments will return the String value of the first element in the Navigator.
Calling value(value) will set the current value of all elements in the Navigator. The argument can be of any type and will be coerced to a String if necessary. The exceptions are that when setting a checkbox value the method expects a boolean (or, an existing checkbox value) and when setting a multiple select the method expects an array or Collection of values."
Hope it works out!
I've got a small code snippet that loops through a node and grabs all its properties.
I can get this to work if I set one variable to grab the properties values (except it has a weird [] surrounding it). But I don't want redundant code so I'm trying to set multiple properties inside the loop, except all that returns is a single value, it's not looping around all the nodes.
WORKING
String selectNodeLabel = null
selectNodeLabel = JcrUtils.getChildNodes("links").collect{
it.getProperty("label").getString()
}
SINGLE VALUE
String selectNodeLabel = null
String selectNodeMeta = null
String selectNodeFooter= null
String topicNode = null
topicNode = JcrUtils.getChildNodes("links").collect{
selectNodeLabel = it.getProperty("label").getString()
selectNodeMeta = it.getProperty("meta").getString()
selectNodeFooter = it.getProperty("footer").getString()
}
Thanks for any help!
Try:
def nodeList = JcrUtils.getChildNodes("links").collect{
[ selectNodeLabel : it.getProperty("label").getString()
selectNodeMeta : it.getProperty("meta").getString()
selectNodeFooter : it.getProperty("footer").getString() ]
}
Then, nodeList will be a list of Maps, so you could do:
println nodeList*.selectNodeLabel
To print all the selectNodeLabel values for example.
To explain the problems with your code... Collect creates a list of the elements returned by the closure. What your SINGLE VALUE code is doing is overwriting the values in the selectNode... variables, and then setting topicNode to the value returned from the closure for each element in JcrUtils.getChildNodes("links").
For this case, topicNode will contain a List of it.getProperty("footer").getString() (as it is the last line in the Closure
Is that correct:
When I query a value before validation (or if validation failed) I have to use getSubmittedValue();. Once the value is validated, even if I query it in another validation later in the page/control I have to use .getValue(); since getSubmittedValue(); returns null after successful validation?
This xsnippet makes it easier to handle this. It allows you to just call getComponentValue("inputText1") to get either value or submittedValue.
Here's the function for reference:
function getComponentValue(id){
var field = getComponent(id);
var value = field.getSubmittedValue();
if( null == value ){
// else not yet submitted
value = field.getValue();
}
return value
}
There's a slightly easier way: if you're just expecting a simple single-value String, just call:
var compare = firstField.getValueAsString();
Otherwise, call:
var compare = com.ibm.xsp.util.FacesUtil.convertValue(facesContext, firstField);
The former calls the latter anyway, but is obviously a terser syntax. This does what you're looking for and more:
If the value hasn't yet been validated, returns the submitted value
If validation has already passed, returns the value after it's already been processed by any converters and / or content filters, so particularly in cases where you're trying to compare two field values, this should ensure that both values have been properly trimmed, etc., and is therefore less likely to return a false positive than just comparing the raw submitted values.
Found the answer here. So when you want to ensure that 2 text fields have the same value (use case: please repeat your email) and the first box already has a validation that might fail, you need to use submittedValue unless it is null, then you use the value. Code in the validation expression for the second field looks like this:
var firstField = getComponent("inputText1");
var compare = firstField.getSubmittedValue() || firstField.getValue();
compare == value;
You have to love it.