I am new to REST and i am making test cases for server client application. where server is made in php using symphony framework and clients are available both in android and ios. Server implements Rest instead of Soap. Now i have to make a test case in soapui to add a group in which nested JSON parameter is going but i am failed to send parameter as nested. I can show you the request from the log on server side.
[2014-09-24 11:14:36] las_api.INFO:
{
"request": {
"url": "http:\/\/192.168.1.134\/las_web\/web\/app_dev.php\/api\/users\/2\/groups.json",
"attributes": {
"_controller": "Las\\ApiBundle\\Controller\\User\\GroupController::cpostAction",
"_format": "json",
"userId": "2",
"_route": "api_post_user_groups",
"_route_params": {
"_format": "json",
"userId": "2"
}
},
"post": {
"group": {
"name": "Seniors"
},
"token": "{81A9B0D9-CA0E-E70F-ADFF-116EE7A1A980}"
},
"get": [
]
},
"ip": "192.168.1.134"
}
Below is the parameter request parameter. where in group there are two parameters first is name of the group and second is the token generated by server on login time.
{
"group": {
"name": "Seniors"
},
"token": "{81A9B0D9-CA0E-E70F-ADFF-116EE7A1A980}"
}
I have successfully made test case for login. I can show you the request from server log while logging.
[2014-09-24 10:11:37] las_api.INFO:
{
"request": {
"url": "http:\/\/192.168.1.134\/las_web\/web\/app_dev.php\/api\/tokens",
"attributes": {
"_controller": "Las\\ApiBundle\\Controller\\TokenController::cpostAction",
"_format": "json",
"_route": "api_post_tokens",
"_route_params": {
"_format": "json"
}
},
"post": {
"password": "abc123",
"username": "abc#gmail.com"
},
"get": [
]
},
"ip": "192.168.1.134"
}
Related
I am trying to run a test suit in post man by json file upload, and executing test cases by .xl file upload.
my test.json file look like below,
{
"info": {
"_postman_id": "af0ea50c-4264-41a6-ac2c-bcacbf966394",
"name": "CCAPI TEST",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "API TEST",
"event": [
{
"listen": "test",
"script": {
"id": "c195d434-6bb6-4c00-ae21-3d71552b86f0",
"exec": [
"let expected_response = pm.variables.get(\"expected_response\");\r",
"\r",
"console.log(\"expected_response:\"+expected_response + \" ->responseBody:\"+responseBody);\r",
"pm.test(\"Body matches string\", function () {\r",
" pm.expect(responseBody).to.include(expected_response);\r",
"}); "
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
"Accept":"application/json",
"Content-Type":"application/json"
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{ip_port}}/CCAPI/subscription",
"host": [
"{{ip_port}}"
],
"path": [
"CCAPI",
"subscription"
],
}
},
"response": []
}
]
}
In postman I am passing below data in body,
{
"name":"abc",
"number":"919876567876",
"value":"ENABLE"
}
POSTMAN RESPONSE:
{
"description":"successfully added",
"status":"success"
}
I want to pass the same to the json file, I am not getting where should I add this,
for result once the test is created after uploading the file, I click on run , there I will upload the .xl file, from there It has to check for the output of the api is matching or not
.xl file contents :
name number value expected_response
abc 988988999 ENABLE {"description":"successfully
added","status":"success"}
I am not getting where to add the body of the json REQ in the .json file
If anyone tried running test suite in postman tool who knows this reply
I am using authorize.net's sandbox API to test their gateway in my wix (corvid/code) environment. Funny thing is that when i send JSON to the sandbox API i get a valid JSON response approving the (fake) transaction. however when i set it up thru wix i get data errors in my console. I have built on existing files that i have been able to run basic API responses, and more advanced auths with token responses. so the code works, just not with authorize.net. given my level of expertise, i think it might be something im doing wrong. i've done my due diligence, and there are no questions on this topic. here is my code:
///front end, from the corvid page's code
import {buyIt} from 'backend/authorizeNet';
export function button1_click(event) {
buyIt();
}
pretty basic, just calling code from my backend onClick. the filepath is correct. here is the module on the backend:
//// backend/authorizeNet.jsw
import {fetch} from 'wix-fetch';
export function buyIt() {
let data = {
"createTransactionRequest": {
"merchantAuthentication": {
"name": "***************",
"transactionKey": "****************"
},
"refId": "123456",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "5",
"payment": {
"creditCard": {
"cardNumber": "5424000000000015",
"expirationDate": "2020-12",
"cardCode": "999"
}
},
"lineItems": {
"lineItem": {
"itemId": "1",
"name": "vase",
"description": "Cannes logo",
"quantity": "18",
"unitPrice": "45.00"
}
},
"tax": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"duty": {
"amount": "8.55",
"name": "duty name",
"description": "duty description"
},
"shipping": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"poNumber": "456654",
"customer": {
"id": "99999456654"
},
"billTo": {
"firstName": "Ellen",
"lastName": "Johnson",
"company": "Souveniropolis",
"address": "14 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"shipTo": {
"firstName": "China",
"lastName": "Bayles",
"company": "Thyme for Tea",
"address": "12 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"customerIP": "192.168.1.1",
"transactionSettings": {
"setting": {
"settingName": "testRequest",
"settingValue": "false"
}
},
"userFields": {
"userField": [
{
"name": "MerchantDefinedFieldName1",
"value": "MerchantDefinedFieldValue1"
},
{
"name": "favorite_color",
"value": "blue"
}
]
}
}
}
}
return fetch("https://test.authorize.net/xml/v1/request.api", {
"method": "post",
"headers": {"Content-Type": "application/json"},
"body": data
})
.then(response => {console.log(response.json())});///if response.text is used, it gives details
}
note at the end of the backend code, calling response.json give me a json error, due to the return code contains HTML saying that i've requested invalid data. if i change it to response.text i get this in my console:
//console response with response.text
{...}
isFulfilled:
true
isRejected:
false
fulfillmentValue:
"<HTML><HEAD>\n<TITLE>Bad Request</TITLE>\n</HEAD><BODY>\n<H1>Bad Request</H1>\nYour browser sent a request that this server could not understand.<P>\nReference #7.1d60fea5.1557756725.387c74\n</BODY>\n</HTML>\n"
how do i get a good response from the API? like ive done with the same code in postman?
thanks in advance
return fetch(url, {
method: "post",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(data)
})
.then(response => console.log(response.text())
)
this got me the result i was looking for
stringify() converted my object to a JSON string. i still cannot get it to read the incoming JSON, might have to use parse...but if i read as text i get the info i want and my API is showing a successful transaction.
I have the following pipeline:
A file is uploaded to S3, it triggers a Lambda (Let's call it L1) which runs and does some processing.
So at the moment, my entry point looks like this:
public Response handleRequest(S3Event event, Context context) {
....
}
Now, a S3Event JSON looks like this:
{
"Records": [
{
"awsRegion": "xxxxx",
"eventName": "ObjectCreated:Put",
"eventSource": "aws:s3",
"eventTime": "2017-09-12T09:27:59.471Z",
"eventVersion": "2.0",
"requestParameters": {
"sourceIPAddress": "xxxxxx"
},
"responseElements": {
"x-amz-id-2": "xxxxxx",
"x-amz-request-id": "xxxx"
},
"s3": {
"configurationId": "xxxxxx1",
"bucket": {
"name": "xxxxx",
"ownerIdentity": {
"principalId": "xxxxx"
},
"arn": "xxx"
},
"object": {
"key": "xxx",
"size": xxx,
"eTag": "xxxx",
"versionId": null,
"sequencer": "xxx",
"urlDecodedKey": "xxx"
},
"s3SchemaVersion": "1.0"
},
"userIdentity": {
"principalId": "xxxx"
}
}
],
}
If you pass this JSON in the "Test" section, it will succeed.
Now, to the point: I wish to add information to this JSON, something that would look like this:
{
"Records": [
{
"awsRegion": "xxxxx",
"eventName": "ObjectCreated:Put",
"eventSource": "aws:s3",
"eventTime": "2017-09-12T09:27:59.471Z",
"eventVersion": "2.0",
"requestParameters": {
"sourceIPAddress": "xxxxxx"
},
"responseElements": {
"x-amz-id-2": "xxxxxx",
"x-amz-request-id": "xxxx"
},
"s3": {
"configurationId": "xxxxxx1",
"bucket": {
"name": "xxxxx",
"ownerIdentity": {
"principalId": "xxxxx"
},
"arn": "xxx"
},
"object": {
"key": "xxx",
"size": xxx,
"eTag": "xxxx",
"versionId": null,
"sequencer": "xxx",
"urlDecodedKey": "xxx"
},
"s3SchemaVersion": "1.0"
},
"userIdentity": {
"principalId": "xxxx"
}
}
],
"MyErrorMessage":
{
"EnvelopeErrors": [
{
"EnvelopeErrorTrace": "stackTrace",
"EnvelopeErrorPositions": 1,
"EnvelopeErrorLength": 2
},
{
"EnvelopeErrorTrace": "SecondTrace",
"EnvelopeErrorPositions": 3,
"EnvelopeErrorLength": 4
}
],
}
}
Notice is the S3Event JSon but with a bit more data.
My question problem is the following: I want to have a custom input that also works when a pure S3Event is called.
public Response handleRequest(MyS3Event event, Context context) {
....
}
However, I have not been able to achieve this.
I have tried a custom POJO but it does not work when I upload to S3 a file.
I tried to extend the S3EventNotification class (from which S3Event extends), but again with no success.
Is it possible what I am trying to do?
What you can do is to have your Lambda (L1) call itself (asynchronously) by sending it the new, modified event similar to how recursive functions work.
Just be very careful though. You have to put a limit as to how deep you want to keep recursing. You don't want to end up with infinite calls. I am not sure if AWS guards against this.
In the AWS SDK Lambda has an invoke method:
Invokes a specific Lambda function. For an example, see Create the Lambda Function and Test It Manually.
If you are using the versioning feature, you can invoke the specific
function version by providing function version or alias name that is
pointing to the function version using the Qualifier parameter in the
request. If you don't provide the Qualifier parameter, the $LATEST
version of the Lambda function is invoked. Invocations occur at least
once in response to an event and functions must be idempotent to
handle this. For information about the versioning feature, see AWS Lambda Function Versioning and Aliases.
This operation requires permission for the lambda:InvokeFunction
action.
var params = {
FunctionName: 'STRING_VALUE', /* required */
ClientContext: 'STRING_VALUE',
InvocationType: Event | RequestResponse | DryRun,
LogType: None | Tail,
Payload: new Buffer('...') || 'STRING_VALUE',
Qualifier: 'STRING_VALUE'
};
lambda.invoke(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
One of the params you send a Payload which is the event the invoked function receives so you can send your MyErrorMessage in/as this payload to get the desired result.
I'm using solr 6.5.1. I have json data in Rest url;
For example:
POST : http://localhost:8484/api/cloud/list-users
is_user: xxx
is_key : pqxqxaweqweqx14123
I can able to fetch data via postman rest client. Is there anyway to post data to solr collection via above rest post url? Please tell me how do i implement this feature in solr.
Try this:
POST /api/cloud/list-users/update/json/docs?commit=true HTTP/1.1
Host: localhost:8484
Content-Type: application/json
{
"is_user": "xxx",
"is_key": "pqxqxaweqweqx14123"
}
And if you want to import it into Postman, here's a json (save it to a .json and then import it as a collection into Postman)
{
"variables": [],
"info": {
"name": "Solr Post New Document",
"_postman_id": "291f6b0e-6aad-7778-c29d-f194ce45c5de",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "Solr Post New Document",
"request": {
"url": "http://localhost:8983/solr/test/update/json/docs?commit=true",
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": "{\n\"is_user\": \"xxx\",\n\"is_key\": \"pqxqxaweqweqx14123\"\n}\n"
},
"description": ""
},
"response": []
}
]}
For more details, see the solr documentation:
https://cwiki.apache.org/confluence/display/solr/Uploading+Data+with+Index+Handlers#UploadingDatawithIndexHandlers-JSONFormattedIndexUpdates
I am trying to configure Wiremock mappings to return a JSON response with a value from the request.
The request is simply
{ "clientTag": "123" }
And the mapping for it is:
{
"priority": 4,
"request": {
"method": "POST",
"urlPattern": "/test"
},
"response": {
"status": 200,
"body": "{ \"loginId\": \"${loginId}\" }",
"headers": {
"Content-Type": "application/json"
}
},
"captures" : [ {
"source" : "BODY",
"target" : "loginId",
"pattern" : "$..clientTag",
"captureGroup" : 1
} ]
}
I receive the response:
{ "loginId": "" }
while the expected one is:
{ "loginId": "123" }
If I switch to XML requests, everything works fine with the pattern <clientTag>(.*?)</clientTag>, but I would like to stick to JSON.
Unfortunately Wiremock documentation is scarce hence the question. Any ideas?
UPDATE: If someone is reading this later, you'd do best to use the transforms in the code, which are available in the later Wiremock versions.
This seems like a perfect use-case for OpenTable's Wiremock Body Transformer.
It can be easily integrated with the Standalone Server like this:
java -cp "wiremock-body-transformer-1.1.6.jar:wiremock-2.3.1-standalone.jar" com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --verbose --extensions com.opentable.extension.BodyTransformer
This extension allows you to easily specify a variable in the request that you would want to match in the response.
{
"request": {
"method": "POST",
"urlPath": "/transform",
"bodyPatterns": [
{
"matchesJsonPath": "$.name"
}
]
},
"response": {
"status": 200,
"body": "{\"responseName\": \"$(name)\"}",
"headers": {
"Content-Type": "application/json"
},
"transformers": ["body-transformer"]
}
}
It also easily allows you to generate a random integer in the response as seen here:
{
"request": {
"method": "POST",
"urlPath": "/transform",
},
"response": {
"status": 200,
"body": "{\"randomInteger\": \"$(!RandomInteger)\"}",
"headers": {
"Content-Type": "application/json"
},
"transformers": ["body-transformer"]
}
}
Unless you've added an extension you haven't mentioned, this can't work - there's no "captures" element in the JSON API, and no way (without extensions) to do variable substitution in responses.
WireMock.Net does support this now.
When sending a request like:
{
"username": "stef"
}
And using mapping like:
{
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/test"
}
]
},
"Methods": [
"post"
]
},
"Response": {
"StatusCode": 200,
"BodyAsJson": {
"path": "{{request.path}}",
"result": "{{JsonPath.SelectToken request.bodyAsJson \"username\"}}"
},
"UseTransformer": true,
"Headers": {
"Content-Type": "application/json"
}
}
}
The response will be like:
{
"path": "/test",
"result": "stef"
}
Note that this functionality is currently in preview mode, see NuGet package version 1.0.4.8-preview-01.
If you have any questions, just create an issue on this github project.