How to fetch and display the POST Request Body Content in Rest Assured with Junit - Serenity Report - rest-assured

I am using Serenity BDD framework with Rest assured Junit5.
While creating the post request using using 'mvn clean install' command in index file report , I am unable to see the request body. its displaying the path which I provided for the json file. but not the actual POST request body content.
Can someone please advise on how to display the POST Request Body Content in the index file Report.

Step 1: Convert json file to String.
String payload = new String(Files.readAllBytes(Paths.get("path_to_file")));
Step 2: Put it in request body
given().contentType(ContentType.JSON).body(payload)...

Related

Microsoft Graph (OneDrive) API - Resumable Upload Content-Type

I am trying to create the upload PUT request for the OneDrive API. It's the large file "resumable upload" version which requires the createUploadSession.
I have read the Microsoft docs here: As a warning the docs are VERY inaccurate and full of factual errors...
The docs simply say:
PUT
https://sn3302.up.1drv.com/up/fe6987415ace7X4e1eF866337Content-Length:
26Content-Range: bytes 0-25/128 <bytes 0-25 of the
file>
I am authenticated and have the upload session created, however when I pass the JSON body containing my binary file I receive this error:
{ "error": {
"code": "BadRequest",
"message": "Property file in payload has a value that does not match schema.", .....
Can anyone point me at the schema definition? Or explain how the JSON should be constructed?
As a side question, am I right in using "application/json" for this at all? What format should the request use?
Just to confirm, I am able to see the temp file created ready and waiting on OneDrive for the upload, so I know I'm close.
Thanks for any help!
If you're uploading the entire file in a single request then why do you use upload session when you can use the simple PUT request?
url = https://graph.microsoft.com/v1.0/{user_id}/items/{parent_folder_ref_id}:/{filename}:/content
and "Content-Type": "text/plain" header and in body simply put the file bytes.
If for some reason I don't understand you have to use single-chunk upload session then:
Create upload session (you didn't specified any problems here so i'm not elaborating)
Get uploadUrl from createUploadSession response and send PUT request with the following headers:
2.1 "Content-Length": str(file_size_in_bytes)
2.2 "Content-Range": "bytes 0-{file_size_in_bytes - 1}/{file_size_in_bytes}"
2.3 "Content-Type": "text/plain"
Pass the file bytes in body.
Note that in the PUT request the body is not json but simply bytes (as specified by the content-type header.
Also note that max chuck size is 4MB so if your file is larger than that, you will have to split into more than one chunks.
Goodlcuk

How to correctly request a geoserver WFS via POST?

I have a geoserver instance, that contains our data. Requesting this via GET works all-right and returns the expected results. But sadly it doesn't works with POST.
To be precise, here is the request for the Capabilities with GET, that returns a valid GetCapabilities-Response:
http://myserver:8080/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities
I test this with wget, so the command looks like that:
wget -O wfs 'http://myserver:8080/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities'
Now I try the Capabilities-request with POST. I create a file with the request (named request) with the following content:
<GetCapabilities
service="WFS"
xmlns="http://www.opengis.net/wfs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"/>
This I run against the Geoserver with the following wget:
wget -O wfs --post-file=request 'http://myserver:8080/geoserver/wfs'
But now I get an OWS-Exception:
<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://moa:8080/geoserver/schemas/ows/1.1.0/owsAll.xsd">
<ows:Exception exceptionCode="MissingParameterValue" locator="request">
<ows:ExceptionText>Could not determine geoserver request from http request org.geoserver.platform.AdvancedDispatchFilter$AdvancedDispatchHttpRequest#1e5c2cc</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
This looks like no POST-body has been sent or it was ignored. What do I wrong here?
EDIT: OK, I solved the problem. The problem is Geoserver expects a Content-Type-Header for Posting a XML-File. So correct request looks like the following:
wget -O wfs --header='Content-Type: text/xml' --post-file=request.xml 'http://myserver:8080/geoserver/wfs'
This returns the expected result.
I tried to investigate in your case but I don't have a server, so I used http://demo.opengeo.org/geoserver/web/
GET test: http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities
I got a full response like you did.
POST test: I used http://www.hurl.it/ because I am on a Windows computer. With the following parameters:
URL: http://demo.opengeo.org/geoserver/wfs
Parameters: add body > same as yours:
<GetCapabilities
service="WFS"
xmlns="http://www.opengis.net/wfs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"/>
And I got the same response as the GET version.
Can you try the same tests with this demo server?
UPDATE
After a few comments chatting, the OP find himself the solution. The POST call was missing the Content-Type-Header information which is mandatory.

How to make jmeter convert |(pipe) to %7C automatically?

I am getting following error whenever Jmeter gets a | (pipe) symbol in the URL since the "pipe" symbol is not allowed in URL. Is there any way to convert the |(pipes) in URL to %7C automatically?
Response code: Non HTTP response code: java.net.URISyntaxException
Assuming the pipe is in an existing parameter try the following:
Check "Encode?" box in "Send Parameters with the Request" input of HTTP Request
Wrap your variable in __urlEncode function as ${__urlencode(queryTerm)}
Use Beanshell Pre Processor as a child of HTTP Request with the following code:
vars.put("queryTerm", URLEncoder.encode(vars.get("queryTerm")));
This should convert the pipes automatically.
Got the instructions from here: Jmeter - Configure Keywords with spaces using CSV File Configuration

How to use REST assured?

I have never used JUnit or other testing frameworks. All i know is how to develop rest service. I recently saw REST assured framework to test REST api. But all the articles that i found looks like below. But i don't know how to pass request xml and how will i get response and when should i call this method.?
Do i need to use some other tool before this REST assured.? I am completely beginner in this kind of testing frameworks. Please show me some light in this world. All i know is how to send request and check values in the response in SOAPUI. I have never tried this.
expect().
statusCode(200).
body(
"user.email", equalTo("test#hascode.com"),
"user.firstName", equalTo("Tim"),
"user.lastName", equalTo("Testerman"),
"user.id", equalTo("1")).
when().
get("/service/single-user/xml");
expect() /* what u expect after sending a request to REST Service */
statusCode(200) /*you are expecting 200 as statuscode which tells request handled successfully at server */
body()
/* the conditions given in body are compare the value with expected values. "equalTo" hamcrest matcher condition (you need to have hamcrest jar in java classpath).*/
when(). /* as is name says above all will be done after sending get/post/put/delete request right so before you put these get,post,put,delete you will have this method as prefix */
get("/service/single-user/xml")
/* the actual REST API request url goes here. can be GET/POST/PUT/DELETE. the confusion for you is its only showing half part which is base path.you can give entire request url in get() method.*/
more on:
http://rest-assured.googlecode.com/svn/tags/1.8.1/apidocs/com/jayway/restassured/RestAssured.html
I hope this helps.

Rails not getting params from HTTP request

I'm trying to POST the following data to a Rails server (running on WebRick) from Android.
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<data>
<email>email.test#name.com</email>
<password>APassw0rd</password>
<remember_me>1</remember_me>
</data>
Now, the funny thing is that these data never show up in the params field in the controller.
Webrick does not output any parsing error. (And I guess it would post an error if it received a POST with no data attached:
Started POST "/users/sign_in.xml" for 192.168.1.94 at 2012-12-14 17:33:20 +0100
Processing by Users::SessionController#create as XML
Completed 500 Internal Server Error in 22643ms
I also found no trace of the data in the request.env variable. Actually, I see no HTTP_BODY in the dump fields. How can one see the raw body of the request? Would webrick really not complain if it received a POST with no attached data?
request.env would show the data as an IO object so you wouldn't be able to see your xml directly.
request.raw_post should return the raw data.
For rails to try and parse your xml into the params hash directly you need to set the content type of the request to application/xml. The 'processing as xml' stuff means that rails will try to render an xml response and doesn't necessarily have any bearing on the format of the posted data

Resources