How do I add a SOAP template from XSD in soapUI when XML extension is in place? - testing

I need to make a large number of SOAP test cases to automate the testing process of an application.
Currently, the architecture requires that a single "generic" SOAP method is invoked with an object of a generic type. Each "real" operation is defined by an element in the generic object and requires an object of an extended type to be used as input.
When I create the request template with soapUI, I only get the generic object elements, but I would like to add the empty template for a specific XSD type that is defined in my current schema to be used.
If I use xsi:type then soapUI correctly says that my markup is not valid against the schema (missing required elements), but I can't manage to get a ready-to-fill XML template.
Can you help me?
Example
genericRequest is made of
<genericRequest>
<methodName>specificMethodName</methodName>
<authenticationID>ABCDEF</authenticationID>
</genericRequest>
sumReuqest (extending genericRequest) for a "sum" operation is made of
<sumRequest>
<methodName>specificMethodName</methodName>
<authenticationID>ABCDEF</authenticationID>
<addend>5</addend>
<addend>3</addend>
</sumRequest>
I would ultimately like soapUI to fill a SOAP template with empty addend item (of course I work with lots of elements, and they are structured too!!)

In this case you need to create two resources in soaupUI one for generic request and other for operation request, I know right now its pain to create each resource for each operation, but soapUI is developed like that or if you think any of the parameters listed : http://www.soapui.org/REST-Testing/understanding-rest-parameters.html could help, you could define parameters as one of the above.
you could try using QUERY or MATRIX style parameters in your resource.

Related

Why do we need to use POJO class and serialization in RestAssured, when we can directly send request body in the form of String?

What is the realtime use case for serialization in RestAssured?
Even though we can send request body(JSON) as String.
I tried googling but did not get satisfying results.
There are few advantages that come up as your code logic becames more complicated:
You might want to send the same object to different endpoint which might not support json but xml content type. So you can simply have one pojo and RestAssured would take care of all conversions.
Your object might change in runtime. So you will have to introduce changes to your string accordingly. This is quite an error-prone way. Serializer would assure that you send somewhat what is a proper json considering syntax stuff, escaping what needs to be escaped and so on.
There might be the case when you fetch object from one endpoint and send it to another. Hence you would be able to use class for deserialization and further serialization in runtime.

Getting SOAP request as POJO in Mule

In our project we expose a number of web-services that were generated from a wsdl. After generating them, I can see that the requests and responses are mapped to POJOs and when I am making the response, I just set a new POJO. This works really nice. However, I have a problem with the request. When we receive the request I expected that the payload will be a POJO mapping the parameters from the request. The payload becomes actually an array of objects. I can access the values but this is not very comfortable. You can take a look at the picture.
I can see that the under "Variables" in the method it is correctly matched to the POJO we would like to have. Is there some setting that I am missing somewhere so that we can get the payload to be mapped to correct POJO type?
Re-run the WSDL to Java codegen but this time with wrapper style disabled, see: https://cxf.apache.org/docs/wsdl-to-java.html#WSDLtoJava-wrapperstyle

Automatic serialization

I want to download xsd specifications from a web service and automatic converting (serialize) these schemas to classes (visual studio - vb.net). If the organization that is responsible for the xsd schemas alter them in a way that only my class corresponding to the xsd have to be altered (not the rest of my code) I would like to automatic update my xsd corresponding class. Is this possible? If so, can somebody tell me how to do it?
Thanks!
I use vs2010. What I want to do is: call a web service where I can send in an input parameter to the service which specifies the xsd I want to retrieve (the service is GetShemaDefenition and returns an object with the schema specification in a string property of the object). I den have to read the xsd string from the string property and convert this to a class representation of this xsd specification. Is it possible to do this automatically? I have done this manually by using xsd.exe. If the owner organization of the xsd has altered the xsd specification, I have to test if there is a new specification, and if there is I have to build a new class representation of this xsd? Is it possible to do what I want? And how would I know if it has been a big change in the xsd which also affect other parts of my code, not just the class representation of the xsd?
Tanks a lot for your reply! So what you are saying, if I understand you correct, is that there is not a good solution for automating this functionality because if the xsd change I most likely (in some occasions’) have to change my code manually? So I have to choose, either in my application or in my intermediate service? But what is the purpose for providing the xsd in a web service? What can I use the web service for? I just wondering, maybe it is clear but I am new to web services and is eager to learn more.
Update:
Thanks! But can you explain a little bit more. What I have to do is: I use one web service where one of the properties is a string. The string is an XML inside a CDATA block. The organization which provides the web service will not pares the xml inside the CDATA block but instead forward this to another organization that will use the xml data. The organization which uses the xml data specifies the xsd schem that I have to follow to generate my xml correct. This is the xsd schema I can get from another web service. I don’t really understand what I can do with this xsd file from the web service. What can I do with it and why do I want to download it from the web service, when I can’t use it automatically? Because I have to manually do the changes when the xsd changes I can easily download the xsd schema from the organization’s home page and make the new class with xsd.exe. I understand there is something I don’t understand :o), can you pleas clarify?
What visual studio version you are using?, Normally you can click on the project's references and Add Web service. In this case Visual studio creates automatically the objects required to consume the service. you can update it any time by a right click on the reference.
However if it is very likely to change often, One solution is to implement an adapter class. use create an interface that provides the same functionality and call the actual web service. In your application you use only the proxy class and not the Web Service. Later when the web service interface changes all you have to do is to change the internals of this intermediate class.
Update:
you can use this tool to create you object model in code. Then you can compile your new object model and use it in you application. There are many complications in what you want to do and the bottom line is; when the object model changes, your code will fail. There is absolutely no way to imagine how the interface will change so while you can do all that automatically there is nothing to do if the name of a function changes.
However the answer to your situation is indirection. If you can't guaranty the stability of a external service. Why not create a stable intermediate service that calls the actual one? this way in future you don't need to touch you application. All you have to do is to modify the intermediate service while keeping it's interface compatible.

MsmqIntegrationBinding Serialization with Unknown Message Body Types

I'm looking to use the MsmqIntegrationBinding to integrate with a legacy queue which has a serialized object as the message body. Has anyone come up with a way to obtain the "metadata" of the message body and create a service side class to use within the service?
For example, if I put in a serialized Product object from System A and my service needs to consume it, how do I provide MsmqMessage the type if I do not have the Product class on my side? I was thinking of reading off a message in a separate program, deserializing, and then emitting via the code dom. Ideas?
I wholeheartedly recommend against attempting to emit the deserialized type at runtime in the message destination. Either work with the XML at the destination to obtain the data you desire, or build data contracts that both the source and destination can adhere to.
Hmm... in WCF, you can define service methods which take (and optionally return) an untyped Message type. This seems to fit your bill quite nicely.
Other than with strongly typed messages, you'll have to do all the putting together of the message on the client and the taking apart on the server by means of reading the raw XML - but that seems to be what you're looking for, right?
Find more information and samples here:
WCF - Handling Generic Messages
How to pass a generic object through WCF
Untyped messages on WCF
Untyped messages have some restrictions, e.g. you can only read them once on the server, but you should be able to manage your scenario with this, I think.
Marc

Creating WCF messages with mutiple namespaces

I'm trying to create a WSTransfer implementation (I realise Roman Kiss has written one already for WCF - but it doesn't actually meet the specifications)
I've ended up abandoning data contracts on the service contacts because WSTransfer is loosely coupled; so each the create message looks like Message Create(Message request).
This works fine, and everything is lovely until it's time to fire back a response.
The problem I have is in the way a WSTransfer response is constructed. Taking create as the example the response looks like
<wxf:ResourceCreated>
<wsa:Address>....</wsa:Address>
<wsa:ReferenceProperties>
<xxx:MyID>....</xxx:MyId>
</wsa:ReferenceProperties>
</wxf:ResourceCreated>
As you can see there are 3 different XML namespaces within the response message.
Now, it's easy enough when one is involved; you can (even if you're not exposing it), create a data contract and set the values and fire it back
Message response = Message.CreateMessage(request.Version,
"http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse",
resourceCreatedMessage);
However the problem arises in setting different namespaces for the child elements within the response; it appears WCF's datacontracts don't do this. Even using
[MessageBodyMember(Namespace="....")]
on the individual elements within the response class don't appear to make any changes, everything becomes part of the namespace specified for the contract class.
So how do I apply different namespaces to individual elements in a WCF Message; either via a contract, or via some other jiggery pokery?
In a case like this when you need precise control over the XML output, you should use the the XmlSerializer instead of DataContract or MessageContract serialization. Here is more info on how to do that:
http://msdn.microsoft.com/en-us/library/ms733901.aspx
So following up jezell's answer; the problem with using XmlSerialization when creating a message by hand is that the child elements of the root get their element names mangled. This happens because despite the operation contract being marked as [XmlSerializerFormat] when you create a message by hand the DataContractSerializer is used.
You cannot pass the XmlSerializer into Message.CreateMessage() because it demands an XmlObjectSerializer, which XmlSerializer is not.
So the answer appears to be write a wrapper class for XmlSerializer, which has XmlObjectSerializer as its base class (here's an example) and pass that in; along with your message holding class.
Unfortunately it's not clever enough to setup prefixes in the XML; so you end up with messages like
<ResourceCreated xmlns="http://schemas.xmlsoap.org/ws/2004/09/transfer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Address xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing/">http://localhost:8731/Design_Time_Addresses/AddTests/WSTransfer/</Address>
<ReferenceType xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing/"></ReferenceType>
But it's all equivalent.