soapui context properties in script assertion - web-services

I've two test case A and B under one test suite
I am setting the context property in script assertion of one of the test step of B
def holder = new XmlHolder( messageExchange.responseContentAsXml )
context.setProperty("xmlHolder", holder)
I am getting the context property in script assertion of one of the test step of A
def Holder=context.getProperty("xmlHolder")
log.info(Holder)
but the value of "Holder" is printed null
I just want to set it in one TC and get it in the other one.
EDIT
Found this , and I was trying to set property like this. I already had a Runner created in script assertion.
Runner.getTestCase().setPropertyValue("xmlHolder", holder)
But receiving a null error
I could do
Runner.getTestCase().setPropertyValue("xmlHolder", "A")
Just wondering , if TC properties can hold an Object compare to string. So, my original question remains as it is.

Based on above comments, got this working
setting property in script assertion of B
context.testCase.testSuite.setPropertyValue('xmlHolder', messageExchange.responseContentAsXml)
getting property in script assertion of B and converting it to XmlHolder object
def HolderContent=context.testCase.testSuite.getPropertyValue('xmlHolder')
def Holder = new XmlHolder ( HolderContent)

Related

Understanding legacy grails code?

The following is a chunk of code in setUp method of controller unit test class in grails. I am trying to understand the purpose of the following setup code. The application has a TimeService which is responsible for doing time operations. I appreciate any help!
def customPropertyEditor = new CustomPropertyEditorRegistrar(timeService: new TimeService())
def map = (Map<String, PropertyEditorRegistrar>) servletContext.getAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS)
if (!map) servletContext.setAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS, [customPropertyEditor: customPropertyEditor])
else map.put('customPropertyEditor', customPropertyEditor)
Create this TimeService object that is customPropertyEditor
def customPropertyEditor = new CustomPropertyEditorRegistrar(timeService: new TimeService())
Make a map out of servletContext.getAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS
def map = (Map<String, PropertyEditorRegistrar>) servletContext.getAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS)
if (!map) = If no map found = as in null due to no results
Then set servletContext.setAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS to be the object at the top customPropertyEditor
servletContext.setAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS, [customPropertyEditor: customPropertyEditor])
If there was a map put in the map customPropertyEditor this value
else map.put('customPropertyEditor', customPropertyEditor)
As for what GrailsDataBinder is doing as Servlet Attribute have a search for it in the code base to see what other things are interacting
ok i found that this chunk of code is responsible for making it so that date binds well. Apparently, there is no clean method to bind date in grails 2.2.

Relationship property not persisted in graph

Context
SDN 3.3.0.RELEASE / 3.4.0.M1
Neo4j 2.1.7 in distant server mode.
Use case
I have an existing Person in database which can have multiple PersonTranslatedContent that can be in several languages.
So basicaly, my modelisation is like :
(:Person)-[:TRANSLATION {lang:"fr}]->(:PersonTranslatedContent)
Problem
When I create a PersonTranslatedContent node and a TRANSLATION relation to link with my Person, the 'lang' property is not persisted on the relationship.
The nodes are corecctly created, but when I query the database from the Neo4j browser, my relationship has only one property : _type__ : PersonToPersonTranslatedContent
Analysis
When logging the HTTP request received by Neo4j, the requets performed are in this order :
1. MATCH (n) WHERE id(n) = {id_n} MATCH (m) WHERE id(m) = {id_m} CREATE (n)-[r:`TRANSLATION`]->(m) SET r={props} RETURN id(r) as id, type(r) as type, r as properties, id(startNode(r)) as start, id(endNode(r)) as end
2. START r=rel({id}) SET r.`_ _type_ _` = {value}
3. START r=rel({id}) RETURN id(r) as id, type(r) as type, r as properties, id(startNode(r)) as start, id(endNode(r)) as end
4. **START r=rel({id}) SET r.`lang` = {value}** <-- here the lang property seems to be correctly set !
5. START r=rel({id}) SET r = {props} <- here, props = {"_ _type_ _" : PersonToPersonTranslatedContent"}
All those REST calls are done within a simple call to personToPersonTranslatedContentRepository.save(). I followed the white rabit in debug mode and here is the shortened call stack :
Neo4jEntityConverterImpl.write() --> entityStateHandler.useOrCreateState() --> RestAPICypherImpl.createRelationship() (correspond to bullet 1)
Neo4jEntityConverterImpl.write() --> typeMapper.writeType() --> RestAPICypherImpl.setPropertyOnEntity() (correspond to bullet 2)
Neo4jEntityConverterImpl.write() --> sourceStateTransmitter.copyPropertiesTo() --> persistentEntity.doWithProperties() --> RestAPICypherImpl.setPropertyOnEntity() (correspond to bullet 4)
Neo4jEntityConverterImpl.write() --> sourceStateTransmitter.copyPropertiesTo() --> ((UpdateableState)target).flush() --> RestAPICypherImpl.setPropertiesOnEntity() (correspond to bullet 5)
So, in my opinion considering what I know and what I saw during debug, the problem seems to be around the "propertyData" attribute of class RestEntity which is used in the ((UpdateableState)target).flush() ! It always hold the value {"_ type _" : PersonToPersonTranslatedContent"} but never contains my "lang" property.
Note : my problem is the same as the one explain here 3.3.0.M1 : Properties on RelationShipEntity not saved when using CypherRestGraphDatabase?. His post has no satisfying answer.
Can you help me (and him I guess) ?
Thx :)
13/07/15 : Updated
I finally manage to resolve my problem by using :
Map<String, Object> properties = new HashMap<>();
properties.put("lang", lang);
properties.put("__type__", "UserToUserTranslatedContent");
neo4jOperations.createRelationshipBetween(neo4jOperations.getNode(user.getId()), neo4jOperations.getNode(translatedContent.getId()), RelationNames.TRANSLATION, properties);
But it is still strange that simple save() operation do not work as expected
For people looking for a fix, I made a report concerning this problem (https://jira.spring.io/browse/DATAGRAPH-699) and a quick way to use SDN like before (< 3.3.x) is doing like this:
remove "spring-data-neo4j" and "spring-data-neo4j-rest" from your build.gradle and add these lines:
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'org.springframework:spring-orm:4.1.7.RELEASE'
compile 'org.springframework:spring-aspects:4.1.7.RELEASE'
compile 'com.github.nousmotards:spring-data-neo4j:3.3.1.NM1'
}
Hope this will help in the mean time of having a real fix ;)

Reset id sequence or update id on Grails Test

In Grails 1.3.7, I have a code that filters objects by ID and I need to test that
The domain class has a sequence
static mapping = {
id generator: 'sequence', params[sequence: 'seq_shipping_service']
}
In the test, the object is created several times and I need the identifier to be 11 in all the tests and even though, it deletes the whole database between every test, it doesn't reset the sequence. So I would get a superior ID
foo = createFoo()
foo.id = 11l
foo.save () //This gets error
My ideas are
1) Reset somehow the id sequence so it's everytime the same number between tests
2) Set somehow the id
I don't know if I make myself clear
Personally, if I need to do something like this I:
create an object mother to spawn all required objects (i.e. foo.id == 11)
use Groovy SQL to insert data into database. In your case:
public class BlahBlahTest extends Specification {
DataSource dataSource
def setup () {
new Sql(dataSource).exec ("insert into blablah (11, ...)")
}
...
Obviously you could do anything else there - for example recreate the sequence to start with 11.

Grails Test Domain Model - Mocks

I am trying to test some methods within a Domain object, the code seems to execute (based on log) but the assertions fail.
The code being tested (extendDates), is working, I am just adding the unit tests now.
I assume I am doing something wrong in the mocking.The following is a simplified version of my code. Based on the log output, the assertion should pass.
class EventDate{
Date startDate
Date endDate
belongsTo = [Appointments owner]
static constraints = {
endDate(nullable:true, blank:false)
startDate(nullable:false, blank:false)
}
}
class Appointments {
hasMany = [ eventDates: EventDate]
belongsTo = [ customer: Customer ]
def extendDates(start,end){
//some logic on eventDates...
EventDate(startDate:start,endDate:end, owner:this).save(flush:true,failOnError:true);
}
}
#TestFor(Appointments)
#Mock([EventDate])
class AppointmentsTests {
void testDateExtend(){
assertTrue domain != null
assertTrue domain instanceof Appointments
//Log indicates the correct execution and creation of event
domain.extendDates(new Date(),null)
//following returns NullPointerException
assertTrue domain.eventDates.size() == 1
}
}
In your example you test for
if (create_new)
The variable "create_new" is never set and would therefore test false using groovy truth logic, thus never executing the if statement.
The if statement never adds anything to the "eventDates" property of Appointments, this would also mean that the assertion would fail.
I'm thinking your example is incomplete and therefore cannot help you until you expand it.
Yes, you will get NullPointerException in the assert condition. The reason being that, you are creating instance of EventDate in the extendDates method but you are not really adding it to the eventDates list in Appointments domain.
So, you have to modify your that method something like:
// Initialize with empty array to avoid NPE
List<EventDate> eventDates = []
static hasMany = [ eventDates: EventDate]
def extendDates(start, end) {
EventDate instance = EventDate(start, end).save()
// And add it to the list of events
this.addToEventDates(instance)
this.save(flush: true)
}
Now, your test case should work your assert condition.
(Also, looks like you have not added nullable constraint in end but passing the null value while creating instance of EventDate, may be not included in sample code)

Issue overriding method using mockFor and MockDomain

I'm trying to unit test a service and I would like to use a mock to override a method on domain object which retrieves a file from a DB.
def mockElem = mockFor(DataElement, false)
mockElem.demand.getFile(){return tempFile}
def dataElem = mockElem.createMock()
dataElem.orderId = "123"
dataElem.id = tempFileName
dataElem.dataType = "cnv"
dataElem.dataStatus = DataStatus.TRANSFERED
mockDomain(DataElement, [dataElem])
When I call a dynamic finder on the data element I want this Mock Domain to be returned with the mockFor demand functionality for getFile. An Assertion error is thrown when the MockDomain line is reached
junit.framework.AssertionFailedError: No call to 'getClass' expected
at this point. Still 1 call(s) to 'getFile' expected. at
groovy.mock.interceptor.StrictExpectation.match(StrictExpectation.groovy:56)
at grails.test.GrailsMock.createMock_closure1(GrailsMock.groovy:136)
at
grails.test.MockUtils.updateMetaClassForClass_closure95(MockUtils.groovy:1297)
at groovy.lang.Closure.call(Closure.java:412) at
groovy.lang.Closure.call(Closure.java:425) at
grails.test.MockUtils.updateMetaClassForClass(MockUtils.groovy:1294)
at grails.test.MockUtils.mockDomain(MockUtils.groovy:470) at
grails.plugin.spock.UnitSpec.mockDomain(UnitSpec.groovy:141) at
com.genospace.inbound.pg.HemeCNVPipelineTestSpec.test processing Heme
file(HemeCNVPipelineTestSpec.groovy:66)
Not sure what is the question.
You got this error because you are mocking an object twice :
with mockFor/createMock
with mockDomain
mockDomain need to know some information about objects being passedas arguments (here it verifies the class is correct) but mockFor did not allow that getClass() was called : you did not add a demand for such call.
Do you really need to mock with demand ?
I think the simple case should work :
def dataElem = new DataElement()
dataElem.orderId = "123"
dataElem.id = tempFileName
dataElem.dataType = "cnv"
dataElem.dataStatus = DataStatus.TRANSFERED
dataElem.file = tempFile
mockDomain(DataElement, [dataElem])