Forum Discussion
It’s ok Rup. Yes I need to generate the whole project from command line and execute as part of the CI process. If you can get me the code it will be very useful…
Ok, no problem.
I will put this on my list of things to do. I did wonder about it some time back, but didn't know how useful it would be. When I crack it I'll share the script with you so you can test it, I might even do a quick blog on it.
Let me know if you crack it first please.
Cheers,
Rup
- rupert_anderson10 years agoValued Contributor
Hi,
I managed to get a chance to work a little on what we discussed... here is my first quick shot and results, please let me know what you think:
Create a Groovy script with the following content (note if you do this in Eclipse, you'll need to reference all the SoapUI libs):
import com.eviware.soapui.impl.actions.RestServiceBuilder
import com.eviware.soapui.impl.rest.RestRequest
import com.eviware.soapui.impl.wsdl.WsdlProject
import com.eviware.soapui.impl.wsdl.WsdlSubmitContext
import com.eviware.soapui.model.iface.Response
import com.eviware.soapui.model.iface.Submit
def uri = "http://jsonplaceholder.typicode.com/posts/1"
WsdlProject project = new WsdlProject()
RestServiceBuilder serviceBuilder = new RestServiceBuilder()
serviceBuilder.createRestService(project, uri)
println "service name: "+project.getInterfaceList()[0].name
println "Resource: "+project.getInterfaceList()[0].getOperationList()[0]
RestRequest request = project.getInterfaceList()[0].getOperationList()[0].getRequestList()[0]
Submit submit = (Submit) request.submit( new WsdlSubmitContext(), false );
Response response = submit.getResponse();
String responseContent = response.getContentAsString();
println( responseContent );
Running this gives:
2015-05-15 14:01:13,769 [main] WARN com.eviware.soapui.SoapUI - Could not find jfxrt.jar. Internal browser will be disabled.
14:01:14,606 WARN [SoapUI] Missing folder [/Users/bearsoftware/Documents/workspace-sts-soapui-testarea/TestSoapUIScripts/ext] for external libraries
14:01:15,565 INFO [DefaultSoapUICore] initialized soapui-settings from [/Users/bearsoftware/soapui-settings.xml]
14:01:15,755 INFO [HttpClientSupport$Helper] Initializing KeyStore
service name: http://jsonplaceholder.typicode.com
Resource: RestResource: /posts/1
14:01:19,242 DEBUG [HttpClientSupport$SoapUIHttpClient] Attempt 1 to execute request
14:01:19,242 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Sending request: GET /posts/1 HTTP/1.1
14:01:19,635 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Receiving response: HTTP/1.1 200 OK
14:01:19,640 DEBUG [HttpClientSupport$SoapUIHttpClient] Connection can be kept alive indefinitely
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et **bleep**\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
14:01:51,851 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Connection closed
The script:
- Creates a new REST Project based on the highlighted URI (a public test REST API)
- A GET request to the resource /posts/1 is automatically created.
- The request is dispatched and the response JSON content printed out.
When creating the project on-the-fly like this there is no need to persist anything or use a TestRunner script - is this allong the lines you need?
Cheers,
Rup
- BalamuruganRavi10 years agoOccasional Contributor
Sure Rup. Thank you so much
- streamerd7 years agoOccasional Contributor
Hi Rupert,
Is it also possible saving the project to an output file like in wsdl project.saveIn()?
Related Content
- 6 years ago
- 9 years ago
Recent Discussions
- 15 hours ago