Forum Discussion
JHunt
Community Hero
import com.eviware.soapui.impl.actions.RestServiceBuilder import com.eviware.soapui.impl.wsdl.WsdlProject import com.eviware.soapui.impl.wsdl.WsdlSubmitContext import com.eviware.soapui.impl.rest.support.RestURIParserImpl f = new File('myexamplefile.txt') f.text = "This is an example file" encodedFile = f.bytes.encodeBase64() f.delete() service = new RestURIParserImpl("http://jsonplaceholder.typicode.com/posts") project = new WsdlProject() new RestServiceBuilder() .createRestService(project, service.endpoint + service.resourcePath) project .getInterfaceByName(service.endpoint) .getOperationByName(service.resourceName) .addNewMethod("Add New Post") .with { setMethod (com.eviware.soapui.impl.rest.RestRequestInterface.HttpMethod.POST) addNewRequest("Request 1") .with { requestHeaders << ["Content-Type":"application/json"] requestHeaders << ["Accept":"application/json"] requestContent = """ { "content":"Hi, this is my new post.", "attachment":"$encodedFile" } """ submit(new WsdlSubmitContext(), false).response .with { assert statusCode == 201 // Created assert statusCode == javax.servlet.http.HttpServletResponse.SC_CREATED new groovy.json.JsonSlurper().parseText(contentAsString) .with { assert id in Integer assert id == 101 assert content == "Hi, this is my new post." assert attachment == 'VGhpcyBpcyBhbiBleGFtcGxlIGZpbGU=' assert new String(attachment.decodeBase64()) == "This is an example file" } } } }
dsathishupm
7 years agoOccasional Contributor
really thanks for the sample, will try with this reference...
Related Content
- 2 years ago
- 4 years ago
- 5 years ago
- 7 years ago
Recent Discussions
- 15 years ago