Short version: How do I do nested property expansion in an XQuery in SoapUI Pro 5, where the outer property is a reference to the ResponseAsXML of a previous test step, and the inner property comes from a properties file?
Example:
My test steps look like this:
Call AddCustomer, which also adds an email address, and returns customerId.
Use property transfer to store the customerId in a properties file called EmailProperties.
Call AddEmailToCustomer, which adds a second email to the same customer and returns a new emailId.
Call GetEmailsForCustomer, which returns both emails for the customer.
The REST endpoints for step 3 and 4 look like this:
POST/GET http://myEndpoint.com/customers/{customerId}/emails
When trying to verify step 4, I wrote an XQuery that loops through the Response (since we can't guarantee what order the emails will be in the response) to find the email added in step 3. In my XQuery, if I hardcode the customerId in the namespace like this it works fine:
for $email in //emails
where $email/id/text()='${AddEmailToCustomer#ResponseAsXml#declare namespace ns1='http://myEndpoint.com/customers/1234/emails'; //ns1:Response[1]/ns1:id[1]}'
But if I try to use the customerId from the properties file like this:
for $email in //emails
where $email/id/text()='${AddEmailToCustomer#ResponseAsXml#declare namespace ns1='http://myEndpoint.com/customers/${#EmailProperties#customerId}/emails'; //ns1:Response[1]/ns1:id[1]}'
I get an error about how it can't find the expected child nodes:
...Exception:org.custommonkey.xmlunit.Diff[different] Expected presence of child nodes to be 'true' but was 'false'...
How can I get this to work?
You can use wildcards for namespaces to greatly simplify your XPaths:
where $email/id/text()='${AddEmailToCustomer#ResponseAsXml#//*:Response[1]/*:id[1]}'
As #SiKing recommends you can use wildcards for namespaces to simplify XPath, this is enough if you don't care about check the namespace (which is the most usual behavior). However I think that you put the namespace in a property in order to check possible different namespaces due you can try declaring your XQuery Match assertion as follows:
declare namespace ns1='http://myEndpoint.com/customers/${#EmailProperties#customerId}/emails';
<XQueryResult>
{
for $email in //ns1:emails
where $email/id/text()='${AddEmailToCustomer#Response#//ns1:Response[1]/ns1:id[1]}'
return $email
}
</XQueryResult>
Please note that if EmailProperties is a property testStep then you must use ${EmailProperties#customerId} instead of ${#EmailProperties#customerId}, also in this case I prefer to use #Response instead of #ResponseAsXml.
Hope this helps,
Related
For example:
public function getField() {
return ucfirst($this->field);
}
Given that an entity has getters that do some changes on the database value before returning it, how can those changes also be applied when using the getArrayResult() method ?
For example, Laravel has accessors (http://laravel.com/docs/5.0/eloquent#accessors-and-mutators). The entity getter can be used in the same way.
When using getArrayResult(), the value for the "field" will not have the first character capitalized.
Thank you!
Well, it's the same behaviour as laravel almost :)
Take a look at Hydrators
.
Hydrators are the processors that bind your raw db output to various data types in doctrine. Thus you have Doctrine_Core::HYDRATE_RECORD which is the standard hydrator(aka the thing called when you use $query->getResult()).
If you use $query->getArrayResult(), it uses the Doctrine_Core::HYDRATE_ARRAY Hydrator.
If you need a more detailed description, please let me know.
i just want to make a class that inherited from Attribute class to put attribute tags in every method in my project to write the method name , Class name that have this method , date and time of calling , parameters and method's return ( if it's return something ).
i create a table in SQL Server that will receive all log information and sign it ..
i have done all the methods & query that interact with my database ( except Date & Time method) , the only problem is i don't know how to use it with Attribute way to get the information i have mention.
If you want logging with attributes, you may use PostSharp that modifies IL during compilation of your code and puts your logging codes before/after the method that you put your custom attribute derived from PostSharp's attributes (aspects)(AOP).
I think you can not do this only by use of custom attributes, because as I know custom attributes are instantiated only when Type.GetCustomAttributes() is called. So you may have to do some reflection business for sending your logs through your attributes that I don't recommend.
Instead of attributes, you can simply use AOP through a third party tool. You can use Castle Dynamic Proxy 's interceptor.
You can also log with attributes by using Interception in Castle Windsor.
To do this, you create a class that inherits from IInterceptor, register it with your container, then you can add an attribute to any class or method you want to add the logging behaviour to.
I've written an explanation here:
http://www.paulsodimu.co.uk/Post/Aspect-Oriented-Programming-Using-Castle-Windsor
And I've created a sample on GitHub to show how its done:
https://github.com/PaulSodimu/LoggingAopCastle
In my Symfony2 project I am retrieving an ordered set of entity IDs from an Elasticsearch index. I'm then passing this list to Doctrine2 to retrieve the actual entities, by way of a WHERE IN() call.
This doesn't return them in the correct order, so I think I need to use the MySQL-specific FIELD() function. I've created a custom DQL function to allow the functionality.
So now I'm using the following code to build a Doctrine query object, but the parameters aren't being parsed into the select() method:
$itemIds = array(4,8,2,1);
$this->getRepository()
->createQueryBuilder('i')
->select('i, FIELD(i.id, :ids_string) AS HIDDEN fixed_order')
->where('i.id IN (:ids)')
->setParameters(array(
'ids_string' => implode(',', $itemIds),
'ids' => $itemIds))
->orderBy('fixed_order', 'ASC')
->getQuery()
;
This fails with the error "Invalid parameter number: number of bound variables does not match number of tokens", so apparently it's not "seeing" the :ids_string in the select() method.
I initially tried putting the FIELD() function in the orderBy() call, but it doesn't look like this is getting parsed for custom DQL function calls, and I imagine I'd run into the same problem as above.
EDIT 1 I'm aware I could put the base data directly into the select() call.
EDIT 2 I've given up and put the bare data into the select() call (which I wanted to avoid). This worked, but then it became necessary to implement Koc's suggestion of using the HIDDEN keyword to prevent Doctrine returning array(Object i, array(fixed_order)) instead of just Object i
From Doctrine 2.2 you can use HIDDEN keyword for avability field in order by without hydration them.
Try:
->select('i, FIELD(i.id, :ids_string) AS HIDDEN fixed_order')
You're going to kick yourself when you notice the problem...
Try re-reading your sentence: "so apparently it's not "seeing" the :ids_string in the select() method".
And then take a close look at your code: 'id_string' => implode(',', $itemIds)
I'm using this guide to call stored procedure in my projet which using EF4 EDMX through WCFDataservice.
I have mapped a complex type to return items from the stored procedure. If I call the method by http, the XML'result is perfect, but when I call with this code:
public void Test()
{
Uri methodUri = new Uri(entities.BaseUri + "/GetCase");
List<CaseFiltered> result = entities.Execute<CaseFiltered>(methodUri).ToList();
}
I get this exception The closed type CaseFiltered does not have a corresponding element settable property.
I had try this solution but it doesn't work for me.
Have you a solution?
Thank you!
Ok I find the solution according this article
Actually, you did everything
right...However, our client library
does not support materialization of a
collection of complex types directly
(yet). If you look at the output of
the service op, you would see a list
of tag, rather than an Atom
Feed.
My workaround: I'm using Case entities, not the CaseFiltered complex type
Flex3 + Cairngorm. I have my service in Servicis.mxml:
<mx:HTTPService id="docIndex" url="{URL_PREFIX}/jobs/{???}/docs" resultFormat="e4x"/>
And I call it from my generic restful delegate like this:
public function index(params:Object):void {
var call:AsyncToken = services.getHTTPService(resourceName+"Index").send(params);
call.addResponder(responder);
}
I want to know how I can use the params Object I pass inside the url definition (the ??? above). And please tell me how you would go about searching an answer to this in the documentation, I'd like to be a little more independet on these problems...
EDIT: I'll explain myself if you didn't understand my problem:
I have a restful api written in rails to which I'm connecting. Doc is a child resource of Job. If I want to get all docs I have to supply a job_id too. Therefore in the service the url must be changed for each .send() call, with the proper job_id (the ??? part above). I'd like to call it like myDelegate.index({job_id:34}) and insert that job_id field in the Service URL.
Write a class that extends HTTPService and allows you to set parameters into the url. Then, in your index function you can fetch it with services.getHTTPService, and call a function you create that sets the url values for you.
In your service locator create an instance of your class rather than a flat HTTPService.