Validate response in my spring project(like Postman test scripts) - testing

Now I'm developing with spring, intellij.
I want to validate the api response body at my spring project as we do in postman 'Test' function.
I've done like below in postman
pm.test("some api test", function() {
pm.expect(pm.response.json()).eql(JSON.parse('{"success": true,"result": {"a": "value", "b": "value"}}'))
})
Postman is very good. But I want to put the above codes in my project and manage them with git.
I can't usemockMvc because I won't validate localhost:8080's data.
I have to validate with real server data. Because all dev data is not enough to validate.
Is there any good library?
If I can manage test code in my project, it is also enough(Don't need to be JVM language).
I tried restClient in intellij, but I don't know how to validate response body on this library like Postman.

Related

If graphQL uses an async concept and has http capability why does it conflict with the REST API design of Node/Express with http?

I've set up a TypeScript/Node/Express API that includes 'http' for REST and 'express-graphql'. After coding the schema, resolvers and types for TypeScript conformity I run with nodemon ts-node and everything is fine with 'http' requests. When I send a graphQL Query via Postman as a POST it just hangs. I've never seen anything like this that does not time out and it could be running for minutes. Postman shows some unusual 'read RECONNECT' error. Why is graphQL this problematic. Why doesn't it just fit in instead of suggesting the replacement of a perfectly proven process like REST?

Azure logic app API http response with excel file download using Postman

Created azure logic app HTTP request it gives response for normal JSON schema However, I want to attach SharePoint excel sheet when I trigger the request from Postman.
1.How to used content type or schema to download the attached file. when postman request sent.
2.is that possible to download when you hit API through logic app
3.Generated HTTP POST URL is working
For your requirement, I test it in my side. It seems we do not need to set any value for "Content-Type" in headers of response. Please refer to my logic app below:
Then when you request the logic app url in postman, please choose "Send and Download" instead of "Send".
After that, you can download the file when request the url in postman.

Pre request script of upload file with multipart/form-data hitting method 2 times in Postman

I'm working with API project and writing test cases with Postman for automation to check API status. Here I have one upload method in which user has to upload a file to the server and need to check if the server returns an appropriate response.
Upload method accepting the request with multipart/form-data, from Postman I'm passing as below screen:
I believe that in order to write a test case, I need to write a pre-request script.
pm.sendRequest({
url: pm.environment.get("baseURL") + '/document/upload',
method: 'POST',
header: [{
"key": "Authorization",
"value": pm.environment.get("authorization"),
"type": "text",
}],
body: {
mode: 'formdata',
formdata: [{
"key": "file",
"type": "binary",
"src": "C:\Users\Desktop\api.pdf"
}]
}
}, function(err, res) {
console.log(res);
});
However, the method is getting hit two times, any thoughts to make it correct and hit only once?
I have gone through the docs and figured it out that what is the issue. I was facing issue while running collection using Runner, after searching out a way to handle file uploading, I came to Newman finally, which seem easy for such scenarios. However, it's still unclear how to upload file while running using Runner!
As per the comments above:
Due to security reasons Postman runner doesn't support file uploading
directly. Find Github thread
here
You can add request before this one in your collection which makes the upload if you need it in the next one. Although the good practice says, that the requests should be atomic with pre-request it will be very difficult. You may achieve it using base64 string of the files and send request with formdata if you insist of doing it like that. The other option runs with Newman in a pipeline. All you have to do is export the collection, the environment and the test files and make sure you don't have absolute path in the exported json. ( Newman should be executed from the directory with the collection and env json files)

Load DB data(to Rest API) through postman

We have been using postman for our Rest API testing but to make it more of an e2e data driven tool, we have a requirement to:
- Make postman grab data from our database and feed it to the API calls
- Run some api calls based on that data
- Query DB again to check the sanity of the data after REST POST requests for example
I know postman is for client side interactions. Is there a way to make postman to talk to DB somehow? I have came across "volos-mysql" and "dreamFactory" but problem is how to load an external module inside postman script?

How to log external in .net web api 2

I'm trying to log in and register with external authentication using MVC5, web api 2 and templates from it.
I don't know how to do it. I read
asp.net web api 2: how to login with external authentication services?.
When I call
GET /api/Account/ExternalLogins?returnUrl=%2F&generateState=true
response is
{
"Name": "Facebook",
"Url": "/api/Account/ExternalLogin?provider=Facebook&
response_type=token&
client_id=self&redirect_uri=http%3A%2F%2Flocalhost%3A6685%2F&
state=Yj1...hU1",
"State": "Yj1...hU1"
}
(I don't know what is State for)
Then i can use the Url above (authentication is with cookies) and response is OK html status and some html page (i dont know why)
This call
GET /api/Account/UserInfo
response info with null loginProvider.
I want to register user with FB or Google, so i need token, but i don't know whitch access_token and how can i get it. In example (link above) is this:
POST /api/Account/RegisterExternal
Authorization: Bearer VPcd1RQ4X... (access_token from url)
Content-Type: application/json
{"UserName":"myusername"}
but what is
access_token from url ?
So, my questions are:
How can I external register / login with web api 2 templates?
What is State for? (seems like useless)
External login is Web Api is supported out of the box and can be easily plugged in using the Owin pipeline. Gettting the access token and performing all the oauth related calls are done by the Facebook Owin Provider.
You can find a sample of facebook login with a web site here