I am writing test cases in RestAssured to test rest webservices using spring mvc.
rest response is
{
"links": [
{
"rel": "self",
"href": "http://www.localhost.com:8080/v1/communities?offset=0&limit=10"
},
{
"rel": "next",
"href": "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"
}
],
"content": [
{
.....
and my test case is
when().
get("/communities").
then().
root("links").
body("href", new ResponseAwareMatcher() {
public Matcher<? extends Object> matcher(ResponseBody response) {
return equalTo(new String[] {"http://www.localhost.com:8080/v1/communities?offset=0&limit=10", "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"});
}
});
The test case fails with error
java.lang.AssertionError: 1 expectation failed.
JSON path links.href doesn't match.
Expected: ["http://www.localhost.com:8080/v1/communities?offset=0&limit=10", "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"]
Actual: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]
I even tried
equalTo("[http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10");
which would error out as
java.lang.AssertionError: 1 expectation failed.
JSON path links.href doesn't match.
Expected: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]]
Actual: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]
I am using Rest Assured 3.0.1. Thanks for your help in advance.
Try this
assertEquals("http://www.localhost.com:8080/v1/communities?offset=0&limit=10", given().when().get("/communities").body().jsonPath().get("links[0].href"));
Related
It seems that the scdf folks decided that this should be forbidden functionality as this returns an error:
curl -X DELETE 'http://localhost:9393/streams/deployments/test' && \
curl -X POST 'http://localhost:9393/streams/deployments/test'
{
"_embedded": {
"errors": [{
"message": "Statemachine is not in state ready to do DELETE",
"logref": "SkipperException",
"_links": {
"self": {
"href": "/"
}
}
}]
}
}
{
"_embedded": {
"errors": [{
"message": "Stream 'test' is already being deployed",
"logref": "StreamAlreadyDeployingException",
"_links": {
"self": {
"href": "/"
}
}
}]
}
}
are there any known ways to do this (or workarounds)?
the use case is that as soon as i ran the above commands, i realized that I coded an error in one of the spring cloud stream apps defined in that stream, and now I needed to change it. the bug caused one of the apps to hang. now i have to recreate my definition.
I'm currently configuring a Swagger file to utilize OAuth to retrieve tokens from a site. For brevity, I have removed my schemes and most of my paths as those are fine.
{
"openapi": "3.0.2",
"info": {
"title": "swagger",
"version": "1.0.0",
"description": ""
},
"servers": [
{
"url": "url"
}
],
"paths": {
"/oauth_token.do": {
"post": {
"requestBody": {
"required": true,
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"components": {
"securitySchemes": {
"OAuth": {
"type": "oauth2",
"flows": {
"password": {
"tokenUrl": "/oauth_token.do",
"refreshUrl": "/oauth_token.do",
"scopes": {
"useraccount": "utilize user account"
}
}
}
}
}
}
"security": [
{
"OAuth": ["useraccount"]
}
]
}
The endpoint for this API specifies that I should use x-www-form-urlencoded in the header as the Content-Type. When executing this request in Postman, it returns 200 with the desired response.
However, with https://editor.swagger.io I input the same postman request to get the fetch failed error with my Authorize button. To test for this, I created a custom path that specifies that the content should be x-www-form-urlencoded and this also fails.
So, what am I missing in this case? Any help would be appreciated.
I believe the issue was I did not fill out some portions I added on the response for path. Instead I opted to only leave description for the 200 response.
The main error I'm getting now is CORS related which is unrelated to the original question. I'll mark this answered for now.
Got a small problem (I guess). I created c# rest web API on docker swarm environment. Rest API is working properly - tested via the postman. Then I tried to compose Hasura service on the same docker swarm environment. The console is working properly also. The problem is with query action.
Code:
Action definition:
type Query {
getWeatherForecast : [WeatherForecastResonse]
}
New types definition:
type WeatherForecastResonse {
date : String
temperatureC : Int
temperature : Int
summary : String
}
Handler:
http://{api ip}:{api port}/WeatherForecast
While trying to execute query:
query MyQuery {
getWeatherForecast {
temperature
summary
date
temperatureC
}
}
All I got from response is error with json:
{
"errors": [
{
"extensions": {
"internal": {
"error": "invalid json: Error in $: not enough input",
"response": {
"status": 405,
"body": "",
"headers": [
{
"value": "Mon, 14 Jun 2021 13:54:00 GMT",
"name": "Date"
},
{
"value": "Kestrel",
"name": "Server"
},
{
"value": "0",
"name": "Content-Length"
},
{
"value": "GET",
"name": "Allow"
}
]
},
"request": {
"body": {
"session_variables": {
"x-hasura-role": "admin"
},
"input": {},
"action": {
"name": "getWeatherForecast"
}
},
"url": "http://{api ip}:{api port}/WeatherForecast",
"headers": []
}
},
"path": "$",
"code": "unexpected"
},
"message": "not a valid json response from webhook"
}
]
}
I got desired response by using postman white calling: http://{api ip}:{api port}/WeatherForecast (GET method)
Where should I improve, to finally get desired result from rest api?
P.S. hasura version: v2.0.0-alpha.4 (tried also with v1.3.3)
UPDATE:
Released a new version of web API. Inside WeatherForecastController included a new method with POST attribute. Query remained the same, but now graphql query returns what I want.
So the question is: Is it possible to call/access web api methods with GET attribute with Hasura action query?
From the version v2.1.0 and above we can do this using the REST Connectors.Hasura Actions RESTConnectors Methods
Go to the Actions tab on the console and create or modify an action. Scroll down to Configure REST Connectors.
In the Configure REST Connectors section, click on Add Request Options Transform
Along with this you can do a lot of other configurations.
No, currently it's not possible, Hasura always makes POST requests to the action handler:
When the action is executed i.e. when the query or the mutation is called, Hasura makes a POST request to the handler with the action arguments and the session variables.
Source: https://hasura.io/docs/latest/graphql/core/actions/action-handlers.html#http-handler
I'm trying to create an invoice record from Postman and Salesforce and from both the places I'm getting error.
To me it looks like a syntax error, but couldn't find it
In Postman Invoice Create, I'm passing below body:
{
"Line": [
{
"Amount": 100.00,
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"ItemRef": {
"value": "1",
"name": "Services"
}
}
}
],
"CustomerRef": {
"value": "58"
}
}
But I'm getting this error:
{"Fault":{"Error":[{"Message":"Error parsing
query","Detail":"QueryParserError:
null","code":"4000","element":"Query"}],"type":"ValidationFault"},"time":"2021-05-01T09:07:03.252-07:00"}
In Salesforce I'm using below code to create invoice:
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://sandbox-quickbooks.api.intuit.com/v3/company/462081dsfdsfsfds550/query?minorversion=56');
request.setMethod('POST');
request.setHeader('Accept', 'application/json');
request.setHeader('Content-Type', 'application/text');
request.setHeader('Authorization', authorization);
request.setHeader('Authorization', 'Bearer sessionId');
string body = '{"Line": [{"DetailType": "SalesItemLineDetail","Amount": 100.0,"SalesItemLineDetail": {"ItemRef": {"name": "Services", "value": "1"}}}], "CustomerRef": {"value": "58"}}';
request.setBody(body);
HttpResponse response = http.send(request);
I'm getting below error for this:
{"Fault":{"Error":[{"Message":"Error parsing query","Detail":"QueryParserError: Invalid content. Lexical error at line 1, column 1. Encountered: \"{\" (123), after : \"\"","code":"4000"}],"type":"ValidationFault"},"time":"2021-05-01T09:10:23.563-07:00"}
To me it looks like some syntax error, but not sure where it is
I found the issue, it was because of URL
I was using this:
https://sandbox-quickbooks.api.intuit.com/v3/company/462081dsfdsfsfds550/query?minorversion=56
instead of
https://sandbox-quickbooks.api.intuit.com/v3/company/462081dsfdsfsfds550/invoice?minorversion=56
When using the Graph API I can successfully create a task, I then wish to update the task details, specifically the description and to add some references.
I'm following the documentation here https://graph.microsoft.io/en-us/docs/api-reference/beta/api/taskdetails_update
I add the request headers, Authentication Bearer, If-Match using the eTag from when I created the task. The URL is:
https://graph.microsoft.com/beta/tasks/6oqAlz30WE66F915zUcSepYAM2ki/details
Http method used is PATCH
Body is:
{
"description": "My Task Title description",
"references": {
"https://tenant.sharepoint.com/teams/teamsite/_layouts/15/WopiFrame.aspx?sourcedoc={521F1D0F-397D-4163-BB16-7C9EF436650B}&file=Release Notes.one&action=view&DefaultItemOpen=1": {
"alias": "OneNote",
"type": "OneNote"
}
}
}
Http response is:
StatusCode: 400, ReasonPhrase: 'Bad Request'
Response Content is:
{
"error": {
"code": "",
"message": "The request is invalid.",
"innerError": {
"request-id": "4e2eae7d-9587-4a69-8c9d-40c5d571190a",
"date": "2016-06-24T10:57:33"
}
}
}
Any ideas as to what I may be doing wrong here?
Coding in C# .Net using HttpClient, HttpRequestMessage.
The URL in the references object needs to be encoded, that's it. i.e.
{
"description": "My Task Title description",
"references": {
"https%3A%2F%2Ftenant.sharepoint.com%2Fteams%2Fteamsite%2F_layouts%2F15%2FWopiFrame.aspx%3Fsourcedoc%3D%7B521F1D0F-397D-4163-BB16-7C9EF436650B%7D%26file%3DRelease+Notes.one%26action%3Dview%26DefaultItemOpen%3D1": {
"alias": "OneNote",
"type": "OneNote"
}
}
}