Forum Discussion
Hey rao
Ok -I don't know if my rubbish explanations have confused you - I need to think about your code a bit cos just when I think I can read your code, you introduce new stuff that I can't!
Anyway - (in the meantime whilst I work out exactly how your code snippet works to see if it does what I need) I've tried to clarify the requirement I'm trying to test is to actually copy in the requirement statement below - I've copied this straight from the JIRA user story:
Registration From Date = If Geographical Indication Status is 'Registered' then '29 Mar 2019' else Null;
Aah! - hold it - my brain's catching up - so using your example I can use two assertion as follows to cover the 29 Mar 2019 and null scenario like as follows:
def json = new groovy.json.JsonSlurper().parseText(context.response) assert 1 == json.data.findAll{it.'GeographicalIndicationStatusId_Name' == 'Registered'}.collect {it.'RegistrationFromDate'}.unique().size() assert 1 == json.data.findAll{it.'GeographicalIndicationStatusId_Name' != 'Registered'}.collect {it.'RegistrationFromDate'}.unique().size()
Just trying this to see if the second assertion works for nulls......
I hope I've been clear!
thanks!
richie
Actually there was a bit of confusion for me from below statements of yours.
[Statement 1]
So if attribute1 = valueX, assert attribute2 = valueY, if attribute1 = valueZ, assert attribute2 = valueA - so I think the basic if/then/else isn't a problem - but it's getting it to work on repeating attributes.
[Statement 2]
I want to assert that every instance of 'RegistrationFromDate' is 29th March when 'GeographyIndicationStatusId_Name' is 'Registered' and 'RegistrationFromDate' is null for all other scenarios
So, I thought date can be possible to change between responses and that's why I gave that "equals to one". But, that holds still true (irrespective of expected value i.e., null or a date)
If you still want to verify along with values as well, then use below snippet of code and pass the values.
Here there another advantage is that you change sibling property names / attributes or keys and their values i.e., works generic.
//assumes json object is defined already def areAllSiblingValuesMatching = { key, value, condition -> def actalValues = json.data.findAll(condition).collect {it."$key"}.unique() (1 == actalValues.size() && value == actalValues.first() ) ? true : false } //verify date value and status name is Registered assert areAllSiblingValuesMatching('RegistrationFromDate', '2019-03-29 00:00:00.000'){ it.GeographicalIndicationStatusId_Name == 'Registered'} //verify date value and status name is not Registered assert areAllSiblingValuesMatching('RegistrationFromDate', null){ it.GeographicalIndicationStatusId_Name != 'Registered'}
- richie6 years agoCommunity Hero
Hey nmrao
again my attempt at the code looked completely different to yours!
Thanks man - it works great - but I have a question - regarding the second assertion below
//Code courtesy of Rao
//assumes json object is defined already def areAllSiblingValuesMatching = { key, value, condition -> def actalValues = json.data.findAll(condition).collect {it."$key"}.unique() (1 == actalValues.size() && value == actalValues.first() ) ? true : false } //verify date value and status name is Registered assert areAllSiblingValuesMatching('RegistrationFromDate', '2019-03-29 00:00:00.000'){ it.GeographicalIndicationStatusId_Name == 'Registered'} //verify date value and status name is not Registered - THIS IS THE SECOND ASSERTION assert areAllSiblingValuesMatching('RegistrationFromDate', null){ it.GeographicalIndicationStatusId_Name != 'Registered'}If there are no records in the dataset where GeographicalIndicationStatusId_Name != 'Registered - I get an assertion failure on this.
When I execute the step when the resultset DOES have >=1 row where GeographicalIndicationStatusId_Name != 'Registered' - the step PASSES
Is there something I can do to tweak this for scenarios where the resultset does NOT contain records where GeographicalIndicationStatusId_Name != 'Registered' ???
Thanks man - do you fancy a job? I need some help at my place! :)
cheers,
richie
- nmrao6 years agoChampion Level 3
What is expected in below case? Is the response expected to meet that condition?
If there are no records in the dataset where GeographicalIndicationStatusId_Name != 'Registered - I get an assertion failure on this.
Otherwise, it is ok not to have additional assertions which are not expected.
Related Content
- 2 years ago
- 6 months ago
- 6 years ago
- 6 years ago
- 6 years ago
Recent Discussions
- 7 hours ago