I want to make an API negative test scenario with Rest-Assured Library. I'm creating a get request for a data that doesn't exist. When I print this response to the console, I want to see the text 'not found' Because postman says this is the request body. But my test failed on get method. I am getting that error
io.restassured.internal.http.HttpResponseException: status code: 404, reason phrase: Not Found
Actually I know the status code is 404. But I can not test about it. How can i write that negative scenario
Response response = given().
when().
get("https://restful-booker.herokuapp.com/booking/1001");
Related
When searching for a keyword ("Test email"), using Outlook API, and the keyword exist in my mailbox, I retrived a result within a second. However, if the keyword ("blablabla") does not exist in the mailbox I do not get a reply. Almost after 2 minutes I get a runtime error.
http get on: https://outlook.office365.com:443/api/v2.0/users/user#sub.onmicrosoft.com/messages?$search=blablablablabla&$top=100&$select=Sender,ToRecipients,CcRecipients,Weblink,Subject,ReceivedDateTime,BodyPreview
http headers:
Authorization: bearer theToken
x-AnchorMailbox: theEmailAddress
I expected to get an HTTP Response that says something like "Could not find any result"
Instead I get no reply upto two minutes and than a runtime error with that yellow background that instructs to turn on
<customError mode="Off" />
Though the http staus code is 200.
I think as an API consumer I should not get such replies.
I'm working with a really strange (and nasty) API that I have no control over, and unfortunately when an invalid request is made, instead of responding with a 4xx status, it responds with a 200 status instead.
With this response, it also changes the response body from the usual XML response to plain text, but does not change the content type header. You can imagine how annoying this is!
I've got Siesta working with the API and the fact that it is no actually RESTful in the slightest, but I'm unsure how to get the next part working - handling the unsuccessful requests.
How do I go about transforming a technically valid and successful 200 response, into an error response? Right now I have the following setup:
configure("/endpoint") {
$0.mutateRequests { req in
... perform some mutation to request ...
}
$0.pipeline[.parsing].add(self.XMLTransformer)
}
configureTransformer("/endpoint") {
($0.content as APIResponse)
.data()
.map(Resource.init)
}
This is working just fine when the response actually is XML, however in the scenario where the response is an error, I receive the following:
bad api request: invalid api key
or something similar to this. The XMLParser class is already handling this, and in turn marks itself as having come across an error, however I don't know how to make Siesta realise that there is an error, and to not call my transformer but instead mark the request as failed to I can handle the error elsewhere.
How can I achieve what I'm after?
configureTransformer is just a common-case shortcut for the full-featured (but more verbose) arbitrary transformers Siesta’s pipeline supports. Full transformers can arbitrarily convert any response to any other, including success → failure and failure → success. The user guide discusses this a bit.
You can see this in action in the example project, which has a customer transformer that does something very similar to what you want, turning a 404 failure into a success with the content false. It is configured here and defined here. That example does a failure → success transformation, but you should find the code adaptable for your success → failure purposes.
I'm trying to set up a test where I make a POST request but getting a 500 Server Error (Response Body that I'm seeing is Unexpected 'T' [JSON]; Tests reporting "There was an error in evaluating the test script: SyntaxError: Unexpected token T in JSON at position 0") and so Tests should show Failed for all 5 of my tests. What can i do?
One of my tests isn't even run it looks like:
tests["Status code is 201 Created"] = responseCode.code === 201;
Thanks in advance for your help.
Tien.
You can check that HTTP code is not 500 with following:
tests["Status code is not 500"] = responseCode.code != 500;
Is this what you're looking for?
Error 500 means either you are sending some invalid JSON in your request body or some issue with your server.
Could tell more by looking at the request and response body.
Do you have your test under any if condition? I don't any reason why the test didn't run except if you have any syntax error in test section.
If you create a web service which receives an processes some data like XML/JSON and the parsing of the data fails because it's incorrect, what do you do?
Send a HTTP 400 error code: After all it was the client who messed up the data (XML/JSON)
Send a HTTP 500 error code: It's the server who wasn't able to complete its task
If data in the request is malformed, then you'll want to return a 400 level error. Generally 500-level errors mean that something is wrong on the server that has nothing to do with the client or the client's request.
422 code.
422 Unprocessable Entity
The 422 (Unprocessable Entity) status code means the server
understands the content type of the request entity (hence a
415(Unsupported Media Type) status code is inappropriate), and the
syntax of the request entity is correct (thus a 400 (Bad Request)
status code is inappropriate) but was unable to process the contained
instructions. For example, this error condition may occur if an XML
request body contains well-formed (i.e., syntactically correct), but
semantically erroneous, XML instructions
https://www.rfc-editor.org/rfc/rfc4918#section-11
I am working on a flex application which communicates with a Rails backened.
When i request for some data, It sends back xml feed.
In some cases, if given parameters are not valid, then rails return an error feed with status code = 422 as following
email is wrong
But I dont get this feed in FaultEvent of Flex, How could i read error feed?
Thanks
Are you getting the result in ResultEvent in such cases? I am not sure for what all HTTP error codes FaultEvent will get invoke(I know only it goes for 404 and 500). May be its still going to ResultEvent as a valid result!
You can use HTTPService instead of URLLoader.
Flex HTTP results will not include the actual underlying HTTP response codes. It just doesn't work. (TM)