Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple output binding support #603

Merged
merged 17 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions ballerina-tests/tests/http_validation.bal
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,23 @@ function httpValidationTest(string jsonPath, json expectedResp) returns error? {

function httpValidationDataProvider() returns map<[string, json]>|error {
map<[string, json]> dataSet = {
"httpPathValid": ["path/valid.json", {"Outputs":{"resp":{"statusCode":200, "headers":{"Content-Type":"text/plain"}, "body":"Hello, 2!"}}, "Logs":[], "ReturnValue":null}],
"httpPathInvalidPayload": ["path/invalid-payload.json", {"Outputs":{"resp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"{ballerina/lang.int}NumberParsingError"}}, "Logs":[], "ReturnValue":null}],
"httpPathValid": ["path/valid.json", {"Outputs":{"outResp":{"statusCode":200, "headers":{"Content-Type":"text/plain"}, "body":"Hello, 2!"}}, "Logs":[], "ReturnValue":null}],
"httpPathInvalidPayload": ["path/invalid-payload.json", {"Outputs":{"outResp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"{ballerina/lang.int}NumberParsingError"}}, "Logs":[], "ReturnValue":null}],

"httpPayloadInvalidPayload": ["payload/invalid-payload.json", {"Outputs":{"resp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"{ballerina/lang.value}ConversionError"}}, "Logs":[], "ReturnValue":null}],
"httpPayloadOptionalInvalid": ["payload/optional-invalid.json", {"Outputs":{"resp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"{ballerina/lang.value}ConversionError"}}, "Logs":[], "ReturnValue":null}],
"httpPayloadOptionalNegative": ["payload/optional-negative.json", {"Outputs":{"resp":{"statusCode":201, "headers":{"Content-Type":"text/plain"}, "body":"payload not specified"}}, "Logs":[], "ReturnValue":null}],
"httpPayloadOptionalPositive": ["payload/optional-positive.json", {"Outputs":{"resp":{"statusCode":201, "headers":{"Content-Type":"text/plain"}, "body":"Hello from the query {\"test1\":\"Test 1\",\"test2\":\"Test 2\"}"}}, "Logs":[], "ReturnValue":null}],
"httpPayloadInvalidPayload": ["payload/invalid-payload.json", {"Outputs":{"outResp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"{ballerina/lang.value}ConversionError"}}, "Logs":[], "ReturnValue":null}],
"httpPayloadOptionalInvalid": ["payload/optional-invalid.json", {"Outputs":{"outResp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"{ballerina/lang.value}ConversionError"}}, "Logs":[], "ReturnValue":null}],
"httpPayloadOptionalNegative": ["payload/optional-negative.json", {"Outputs":{"outResp":{"statusCode":201, "headers":{"Content-Type":"text/plain"}, "body":"payload not specified"}}, "Logs":[], "ReturnValue":null}],
"httpPayloadOptionalPositive": ["payload/optional-positive.json", {"Outputs":{"outResp":{"statusCode":201, "headers":{"Content-Type":"text/plain"}, "body":"Hello from the query {\"test1\":\"Test 1\",\"test2\":\"Test 2\"}"}}, "Logs":[], "ReturnValue":null}],

"httpQueryInvalid": ["query/invalid-payload.json", {"Outputs":{"resp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"{ballerina/lang.int}NumberParsingError"}}, "Logs":[], "ReturnValue":null}],
"httpQueryOptionalInvalid": ["query/optional-invalid.json", {"Outputs":{"resp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"{ballerina/lang.int}NumberParsingError"}}, "Logs":[], "ReturnValue":null}],
"httpQueryOptionalNegative": ["query/optional-negative.json", {"Outputs":{"resp":{"statusCode":200, "headers":{"Content-Type":"text/plain"}, "body":"age not specified"}}, "Logs":[], "ReturnValue":null}],
"httpQueryOptionalPositive": ["query/optional-positive.json", {"Outputs":{"resp":{"statusCode":200, "headers":{"Content-Type":"text/plain"}, "body":"Hello from the query 23"}}, "Logs":[], "ReturnValue":null}],
"httpQueryInvalid": ["query/invalid-payload.json", {"Outputs":{"outResp":{"statusCode":400,
"headers":{"Content-Type":"text/plain"}, "body":"Query param value parsing failed for 'name'"}}, "Logs":[], "ReturnValue":null}],
"httpQueryOptionalInvalid": ["query/optional-invalid.json", {"Outputs":{"outResp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"Query param value parsing failed for 'age'"}}, "Logs":[], "ReturnValue":null}],
"httpQueryOptionalNegative": ["query/optional-negative.json", {"Outputs":{"outResp":{"statusCode":200, "headers":{"Content-Type":"text/plain"}, "body":"age not specified"}}, "Logs":[], "ReturnValue":null}],
"httpQueryOptionalPositive": ["query/optional-positive.json", {"Outputs":{"outResp":{"statusCode":200, "headers":{"Content-Type":"text/plain"}, "body":"Hello from the query 23"}}, "Logs":[], "ReturnValue":null}],

"httpInputCosmosEmpty": ["input/cosmos/empty.json", {"Outputs":{"resp":{"statusCode":200, "headers":{"Content-Type":"application/json"}, "body":[]}}, "Logs":[], "ReturnValue":null}],
"httpInputCosmosInvalid": ["input/cosmos/invalid.json", {"Outputs":{"resp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"{ballerina/lang.value}ConversionError"}}, "Logs":[], "ReturnValue":null}],
"httpInputCosmosValid": ["input/cosmos/valid.json", {"Outputs":{"resp":{"statusCode":200, "headers":{"Content-Type":"application/json"}, "body": [{"test1":"Test 1","test2":"Test 2","_attachments":"attachments/","_rid":"YcIcALZZoCSChB4AAAAAAA==","id":"123","_self":"dbs/YcIcAA==/colls/YcIcALZZoCQ=/docs/YcIcALZZoCSChB4AAAAAAA==/","_etag":"\"0601def4-0000-0700-0000-63d0cc740000\"","_ts":1674628212},{"test1":"Test 11","test2":"Test 22","_attachments":"attachments/","_rid":"YcIcALZZoCSDhB4AAAAAAA==","id":"124","_self":"dbs/YcIcAA==/colls/YcIcALZZoCQ=/docs/YcIcALZZoCSDhB4AAAAAAA==/","_etag":"\"06019cf8-0000-0700-0000-63d0cc8c0000\"","_ts":1674628236}]}}, "Logs":[], "ReturnValue":null}]
"httpInputCosmosEmpty": ["input/cosmos/empty.json", {"Outputs":{"outResp":{"statusCode":200, "headers":{"Content-Type":"application/json"}, "body":[]}}, "Logs":[], "ReturnValue":null}],
"httpInputCosmosInvalid": ["input/cosmos/invalid.json", {"Outputs":{"outResp":{"statusCode":400, "headers":{"Content-Type":"text/plain"}, "body":"{ballerina/lang.value}ConversionError"}}, "Logs":[], "ReturnValue":null}],
"httpInputCosmosValid": ["input/cosmos/valid.json", {"Outputs":{"outResp":{"statusCode":200, "headers":{"Content-Type":"application/json"}, "body": [{"test1":"Test 1","test2":"Test 2","_attachments":"attachments/","_rid":"YcIcALZZoCSChB4AAAAAAA==","id":"123","_self":"dbs/YcIcAA==/colls/YcIcALZZoCQ=/docs/YcIcALZZoCSChB4AAAAAAA==/","_etag":"\"0601def4-0000-0700-0000-63d0cc740000\"","_ts":1674628212},{"test1":"Test 11","test2":"Test 22","_attachments":"attachments/","_rid":"YcIcALZZoCSDhB4AAAAAAA==","id":"124","_self":"dbs/YcIcAA==/colls/YcIcALZZoCQ=/docs/YcIcALZZoCSDhB4AAAAAAA==/","_etag":"\"06019cf8-0000-0700-0000-63d0cc8c0000\"","_ts":1674628236}]}}, "Logs":[], "ReturnValue":null}]

};
return dataSet;
Expand Down
27 changes: 27 additions & 0 deletions ballerina-tests/tests/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public type NoHeaderVal record {|
string Content\-Type1;
|};

public type AzureReturn [@af:HttpOutput string,@af:QueueOutput{queueName: "queue3"} string];

listener af:HttpListener ep1 = new ();

service /hello\- on ep1 {
Expand Down Expand Up @@ -417,6 +419,31 @@ service /hello on ep {
byte[] byteArray = check bodyPart.getByteArray();
return byteArray.length();
}

resource function get products(map<json> name) returns string|error {
return (check name.name).toString() + (check name.value).toString();
}

resource function get catalog(int[] name) returns string|error {
return name.toString();
}

resource function get multiout() returns [@af:HttpOutput string, @af:QueueOutput{queueName: "queue3"} string] {
return ["hello", "world"];
}

resource function get multiout/ref() returns AzureReturn {
return ["hello1", "world1"];
}

resource function get singleout() returns [@af:HttpOutput string] {
return ["hello"];
}

resource function get threeout() returns [@af:HttpOutput string, @af:QueueOutput{queueName: "queue3"} string,
@af:BlobOutput {path: "bpath1/newBlob"} byte[]] {
return ["hello", "world", "anjana".toBytes()];
}
}

@af:QueueTrigger {
Expand Down
98 changes: 98 additions & 0 deletions ballerina-tests/tests/resources/multi-out-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"Data": {
"httpPayload": {
"Url": "http://localhost:7071/hello/emptytuple",
"Method": "GET",
"Query": {
},
"Headers": {
"Accept": [
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
],
"Connection": [
"keep-alive"
],
"Host": [
"localhost:7071"
],
"User-Agent": [
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
],
"Accept-Encoding": [
"gzip, deflate, br"
],
"Accept-Language": [
"en-US,en;q=0.9"
],
"Cookie": [
"_ga=GA1.1.720190479.1641539348; Idea-2474b141=7a691445-10e4-435d-b306-2b36a77b1d2e; Webstorm-fe5cf5e6=379eafe5-e706-45c1-92e8-6e424ab655f0"
],
"Upgrade-Insecure-Requests": [
"1"
],
"sec-ch-ua": [
"\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Google Chrome\";v=\"108\""
],
"sec-ch-ua-mobile": [
"?0"
],
"sec-ch-ua-platform": [
"\"Linux\""
],
"Sec-Fetch-Site": [
"none"
],
"Sec-Fetch-Mode": [
"navigate"
],
"Sec-Fetch-User": [
"?1"
],
"Sec-Fetch-Dest": [
"document"
]
},
"Params": {},
"Identities": [
{
"AuthenticationType": null,
"IsAuthenticated": false,
"Actor": null,
"BootstrapContext": null,
"Claims": [],
"Label": null,
"Name": null,
"NameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
"RoleClaimType": "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
}
]
}
},
"Metadata": {
"name": "\"meow\"",
"Query": {
},
"Headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Connection": "keep-alive",
"Host": "localhost:7071",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"Cookie": "_ga=GA1.1.720190479.1641539348; Idea-2474b141=7a691445-10e4-435d-b306-2b36a77b1d2e; Webstorm-fe5cf5e6=379eafe5-e706-45c1-92e8-6e424ab655f0",
"Upgrade-Insecure-Requests": "1",
"sec-ch-ua": "\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Google Chrome\";v=\"108\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Linux\"",
"Sec-Fetch-Site": "none",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-User": "?1",
"Sec-Fetch-Dest": "document"
},
"sys": {
"MethodName": "get-hello-emptytuple",
"UtcNow": "2023-01-11T09:38:31.8085731Z",
"RandGuid": "21516b2a-f417-4230-b8cc-d237149e436d"
}
}
}
98 changes: 98 additions & 0 deletions ballerina-tests/tests/resources/multi-out-ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"Data": {
"httpPayload": {
"Url": "http://localhost:7071/hello/multiout/ref",
"Method": "GET",
"Query": {
},
"Headers": {
"Accept": [
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
],
"Connection": [
"keep-alive"
],
"Host": [
"localhost:7071"
],
"User-Agent": [
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
],
"Accept-Encoding": [
"gzip, deflate, br"
],
"Accept-Language": [
"en-US,en;q=0.9"
],
"Cookie": [
"_ga=GA1.1.720190479.1641539348; Idea-2474b141=7a691445-10e4-435d-b306-2b36a77b1d2e; Webstorm-fe5cf5e6=379eafe5-e706-45c1-92e8-6e424ab655f0"
],
"Upgrade-Insecure-Requests": [
"1"
],
"sec-ch-ua": [
"\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Google Chrome\";v=\"108\""
],
"sec-ch-ua-mobile": [
"?0"
],
"sec-ch-ua-platform": [
"\"Linux\""
],
"Sec-Fetch-Site": [
"none"
],
"Sec-Fetch-Mode": [
"navigate"
],
"Sec-Fetch-User": [
"?1"
],
"Sec-Fetch-Dest": [
"document"
]
},
"Params": {},
"Identities": [
{
"AuthenticationType": null,
"IsAuthenticated": false,
"Actor": null,
"BootstrapContext": null,
"Claims": [],
"Label": null,
"Name": null,
"NameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
"RoleClaimType": "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
}
]
}
},
"Metadata": {
"name": "\"meow\"",
"Query": {
},
"Headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Connection": "keep-alive",
"Host": "localhost:7071",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"Cookie": "_ga=GA1.1.720190479.1641539348; Idea-2474b141=7a691445-10e4-435d-b306-2b36a77b1d2e; Webstorm-fe5cf5e6=379eafe5-e706-45c1-92e8-6e424ab655f0",
"Upgrade-Insecure-Requests": "1",
"sec-ch-ua": "\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Google Chrome\";v=\"108\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Linux\"",
"Sec-Fetch-Site": "none",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-User": "?1",
"Sec-Fetch-Dest": "document"
},
"sys": {
"MethodName": "get-hello-multiout-ref",
"UtcNow": "2023-01-11T09:38:31.8085731Z",
"RandGuid": "21516b2a-f417-4230-b8cc-d237149e436d"
}
}
}
98 changes: 98 additions & 0 deletions ballerina-tests/tests/resources/multi-out-single.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"Data": {
"httpPayload": {
"Url": "http://localhost:7071/hello/singleout",
"Method": "GET",
"Query": {
},
"Headers": {
"Accept": [
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
],
"Connection": [
"keep-alive"
],
"Host": [
"localhost:7071"
],
"User-Agent": [
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
],
"Accept-Encoding": [
"gzip, deflate, br"
],
"Accept-Language": [
"en-US,en;q=0.9"
],
"Cookie": [
"_ga=GA1.1.720190479.1641539348; Idea-2474b141=7a691445-10e4-435d-b306-2b36a77b1d2e; Webstorm-fe5cf5e6=379eafe5-e706-45c1-92e8-6e424ab655f0"
],
"Upgrade-Insecure-Requests": [
"1"
],
"sec-ch-ua": [
"\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Google Chrome\";v=\"108\""
],
"sec-ch-ua-mobile": [
"?0"
],
"sec-ch-ua-platform": [
"\"Linux\""
],
"Sec-Fetch-Site": [
"none"
],
"Sec-Fetch-Mode": [
"navigate"
],
"Sec-Fetch-User": [
"?1"
],
"Sec-Fetch-Dest": [
"document"
]
},
"Params": {},
"Identities": [
{
"AuthenticationType": null,
"IsAuthenticated": false,
"Actor": null,
"BootstrapContext": null,
"Claims": [],
"Label": null,
"Name": null,
"NameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
"RoleClaimType": "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
}
]
}
},
"Metadata": {
"name": "\"meow\"",
"Query": {
},
"Headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Connection": "keep-alive",
"Host": "localhost:7071",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"Cookie": "_ga=GA1.1.720190479.1641539348; Idea-2474b141=7a691445-10e4-435d-b306-2b36a77b1d2e; Webstorm-fe5cf5e6=379eafe5-e706-45c1-92e8-6e424ab655f0",
"Upgrade-Insecure-Requests": "1",
"sec-ch-ua": "\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Google Chrome\";v=\"108\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Linux\"",
"Sec-Fetch-Site": "none",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-User": "?1",
"Sec-Fetch-Dest": "document"
},
"sys": {
"MethodName": "get-hello-singleout",
"UtcNow": "2023-01-11T09:38:31.8085731Z",
"RandGuid": "21516b2a-f417-4230-b8cc-d237149e436d"
}
}
}
Loading