I have a web service with a post method that will get two parameters, JobNumber and AssociateID, from the query string. It is also looking to get an XML Document as a parameter for the Post method [public HttpResponseMessage Post(XMLDocument NobXML)].
How would I write something to test this Post method?
Related
I'm trying to leverage Postman's mock server feature to mock an API that my application calls.
This is a Post request. I have gone through the documentation and as advised I have saved the responses as examples.
When I try hit the mock URL I get the postman error response
Here is my setup -
My Collection with saved examples
MY mock server
After going through your query, I can see that you're trying to match an example based on the body passed with the request.
To match an example based on the request body, you can leverage the body matching feature of mock servers by:
Enabling the body matching feature from the mock edit page (Reference: https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/setting-up-mock/#matching-request-body-and-headers).
OR
Passing an additional x-mock-match-request-body header with value as true along with your mock request to get the desired results.
You can find more information on how to use body matching feature with mock servers here: https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/matching-algorithm/#6-check-for-header-and-body-matching.
Do let me know if this doesn't solve your issue. In that case, it would be helpful if you can share the mock request that you're sending to get the response.
I have two scenarios for the following API URL.
POST http://{{ip_port}}/oauth/token
When I put the user name and password correctly, it should return
200 and mock json response.
When I put user name and password incorrectly, it should return 401 and mocked json(error).
In Postman Mock server, I noticed that there is no matching algorithm logic for request param.
I want to filter by request param and return related mock responses. I don't want to add two URLs(/token and /failedtoken) for above scenarios.
Currently Postman only support three logic for matching algorithm logic.
Properly formatted responses
HTTP method
Filter by URL
Is there any way to add only one URL for many scenarios in Postman Mock Server?
Postman Mock Server now supports matching by request body. You can use it by specifying a custom header (x-mock-match-request-body to true).
You can also check out an example that demonstrates how this feature works by going to New->Templates and searching for Request Body Matching.
I am using Django, Neo4j, and pentaho. In Pentaho Data Integration, we can use the javascript for any transaction. My question is that can we call ajax from the PDI javasticpt to django server method. Actually i want to send success msg to server after the ETL process done by the PDI. Following is the javascript I am trying.
var xhReq = new XMLHttpRequest();
xhReq.open("GET", "http://127.0.0.1/url_name/?parameter=value", false);
xhReq.send();
Don't re-invent the wheel my friend!, use the "REST Client" step as the last step of your flow, and use the parameters in the step to specify the GET Method and URL with GET parameters to send. After executing the "REST Client" you will get the expected response as you specified in the parameters (maybe a JSON if your server answers it).
You don't need to code with javascript (actually is possible with User Defined Java Class with coding, but it's a more complex process).
I am trying to write a test case for a jersey resource using InMemory container provided by Jersey.
As my service method contains many multivalued parameters as filters, I opted to send all of those values as single JSON parameter, so that it will be easy to send a list of values for each filter.
When i send the JSON string using target("path").queryParam("filters", jsonString).request().get(); the call fails die to Jersey clients internal query builder, which is parsing the url and checking for path param templates in the url. Since the url contains my JSON with "{" in it, they are interpreted as path param.
If I try to encode the JSON using URLEncode.encode(jsonStr, "UTF-8"), the path param template issue is solved but white spaces in JSON are received by server as "+" as jersey client encoding URL one more time, but server decoding it only once.
If I make the Queryparam as post param test is working, but i don't want to use POST for just to retrieve data.
I can't post original code due to company policies.
My question is, is there any way to disable path template check in jersey clieny by setting custom builder.
A simpler solution would be to replace the '+' by '%20' as suggested here and here:
URLEncode.encode(jsonStr, "UTF-8").replaceAll("\\+", "%20");
I am working on a Restful Web Service, which get request from client, then strip some information and insert it into the database.
When it insert to the database, it has two parts of information needed: Uri and HttpRequest.
Now I have my method like this:
public void insertDb (#Context UriInfo uriInfo, #Context HttpServletRequest request)
I am trying to do some unit testing, create a client then WebResouce.
I wonder how can I pass in the parameters in unit testing? Or should I change the params in the insertDb function?
Have you heard about Jersey Test Framework? http://jersey.java.net/nonav/documentation/latest/test-framework.html
You don't need to change signature of your method, you need to start Jersey somehow (Test Framework can help you with that) and make request to that Resource. Simple sample of this can be seen in helloworld sample, see http://search.maven.org/remotecontent?filepath=com/sun/jersey/samples/helloworld/1.10/helloworld-1.10-project.zip.