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

[master] Use toJson method from data.jsondata module in http client #2151

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d07f5fd
Use toJson method from jsondata module
lnash94 Sep 18, 2024
5514b62
Merge branch 'master' of https://github.com/ballerina-platform/module…
lnash94 Sep 18, 2024
3b8c267
Update data.jsondata version
lnash94 Sep 18, 2024
f373e02
[Automated] Update the native jar versions
lnash94 Sep 18, 2024
9ad1b3b
Update dependencies for data.jsondata version
lnash94 Sep 19, 2024
daf51fe
[Automated] Update the native jar versions
lnash94 Sep 19, 2024
73c58e7
[Automated] Update the native jar versions
lnash94 Sep 19, 2024
a8f7a5a
[Automated] Update the native jar versions
lnash94 Sep 19, 2024
a23dcca
[Automated] Update the native jar versions
lnash94 Sep 19, 2024
b48db72
Update Ballerina toml dependency
lnash94 Sep 19, 2024
adbff7e
Update the service data biding with toJson
lnash94 Sep 20, 2024
932492b
[Automated] Update the native jar versions
lnash94 Sep 20, 2024
21cf933
Fix tests with new parserasType , toJson migration
lnash94 Sep 20, 2024
cf81568
Update the tests
lnash94 Sep 23, 2024
a017d4a
Disable test related to table type
lnash94 Sep 23, 2024
1addfb2
Merge branch 'master' into integrate-data.json
lnash94 Sep 23, 2024
2470d52
Update json data version
lnash94 Sep 23, 2024
14d017f
Merge branch 'integrate-data.json' of https://github.com/lnash94/modu…
lnash94 Sep 23, 2024
5e10d38
Fix http2 tests
lnash94 Sep 23, 2024
65646c2
Add test for new migration
lnash94 Sep 23, 2024
a639dee
Merge branch 'master' into integrate-data.json
lnash94 Sep 23, 2024
e76835a
Add tests and fix review suggestions
lnash94 Sep 23, 2024
a261992
Merge branch 'integrate-data.json' of https://github.com/lnash94/modu…
lnash94 Sep 23, 2024
6419f30
Resolve conflicts
lnash94 Sep 23, 2024
73d91ab
[Automated] Update the native jar versions
lnash94 Sep 23, 2024
d2f70ee
Remove unwanted dependencies
lnash94 Sep 23, 2024
e65a1ad
Updated the changelog.md
lnash94 Sep 23, 2024
6f4fe95
Updated tests
lnash94 Sep 23, 2024
665c8e9
Merge branch 'master' into integrate-data.json
lnash94 Sep 25, 2024
df75b5c
Add workaround for the test failure
lnash94 Sep 27, 2024
12988be
Merge branch 'integrate-data.json' of https://github.com/lnash94/modu…
lnash94 Sep 27, 2024
cb80e0b
Merge branch 'master' into integrate-data.json
lnash94 Sep 27, 2024
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
13 changes: 12 additions & 1 deletion ballerina-tests/http-advanced-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ modules = [
{org = "ballerina", packageName = "crypto", moduleName = "crypto"}
]

[[package]]
org = "ballerina"
name = "data.jsondata"
version = "0.3.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "file"
Expand All @@ -79,6 +89,7 @@ dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "data.jsondata"},
{org = "ballerina", name = "file"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -360,7 +371,7 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.4.0"
version = "2.5.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
Expand Down
13 changes: 12 additions & 1 deletion ballerina-tests/http-client-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ dependencies = [
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "data.jsondata"
version = "0.3.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "file"
Expand All @@ -76,6 +86,7 @@ dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "data.jsondata"},
{org = "ballerina", name = "file"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -356,7 +367,7 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.4.0"
version = "2.5.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// import ballerina/data.jsondata;
import ballerina/http;
import ballerina/mime;
import ballerina/test;
import ballerina/data.jsondata;

service /api on new http:Listener(resBindingAdvancedPort) {

Expand All @@ -41,6 +44,22 @@ service /api on new http:Listener(resBindingAdvancedPort) {
resource function get byteArray() returns byte[] {
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
}

resource function get overwriteNames/jsont(boolean y) returns json|TPerson {
if y {
return {"name": "John", "age": "23"};
}
TPerson t = {firstName: "Potter", personAge: "30"};
return t;
}

resource function post overwriteNames/jsont(TPerson payload) returns TPerson {
return payload;
}

resource function get status/code() returns OKPerson {
return {body: {firstName: "Potter", personAge: "40"}};
}
}

final http:Client clientEP = check new (string `localhost:${resBindingAdvancedPort}/api`);
Expand Down Expand Up @@ -101,3 +120,38 @@ function testResponseWithAnydataResBinding() returns error? {
test:assertFail("Invalid response type");
}
}

public type TPerson record {
@jsondata:Name {
value: "name"
}
string firstName;
@jsondata:Name {
value: "age"
}
string personAge;
};
public type OKPerson record {|
*http:Ok;
TPerson body;
|};

@test:Config {}
function clientoverwriteResponseJsonName() returns error? {
TPerson res1 = check clientEP->/overwriteNames/jsont(y=true);
test:assertEquals(res1, "{\"firstName\":\"John\",\"personAge\":\"23\"}");

json res2 = check clientEP->/overwriteNames/jsont(y=false);
test:assertEquals(res2, "{\"name\":\"Potter\",\"age\":\"30\"}");

json j = {
name: "Sumudu",
age: "29"
};

TPerson res3 = check clientEP->/overwriteNames/jsont.post(j);
test:assertEquals("{\"firstName\":\"Sumudu\",\"personAge\":\"29\"}");

// TPerson re4 = check clientEP->/status/code;
// io:print(re4);
}
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,9 @@ function testAllBindingErrorsWithNillableTypes() returns error? {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
common:assertHeaderValue(check response.getHeader(common:CONTENT_TYPE), common:TEXT_PLAIN);
common:assertTextPayload(response.getTextPayload(),
"Payload binding failed: 'map<json>' value cannot be converted to " +
"'xml<(lang.xml:Element|lang.xml:Comment|lang.xml:ProcessingInstruction|lang.xml:Text)>?'|" +
"incompatible typedesc int? found for 'text/plain' mime type");
"Payload binding failed: incompatible expected type 'xml<(lang.xml:Element|lang.xml:Comment|" +
"lang.xml:ProcessingInstruction|lang.xml:Text)>?' for value " +
"'{\"id\":\"chamil\",\"values\":{\"a\":2,\"b\":45,\"c\":{\"x\":\"mnb\",\"y\":\"uio\"}}}'|incompatible typedesc int? found for 'text/plain' mime type");
} else {
test:assertFail(msg = "Found unexpected output type: " + response.message());
}
Expand Down Expand Up @@ -815,9 +815,7 @@ function testDBRecordErrorNegative() {
ClientDBErrorPerson|error response = clientDBBackendClient->post("/backend/getRecord", "want record");
if (response is error) {
common:assertTrueTextPayload(response.message(),
"Payload binding failed: 'map<json>' value cannot be converted to 'http_client_tests:ClientDBErrorPerson'");
common:assertTrueTextPayload(response.message(),
"missing required field 'weight' of type 'float' in record 'http_client_tests:ClientDBErrorPerson'");
"Payload binding failed: required field 'weight' not present in JSON");
} else {
test:assertFail(msg = "Found unexpected output type: ClientDBErrorPerson");
}
Expand All @@ -828,7 +826,7 @@ function testDBRecordArrayNegative() {
ClientDBErrorPerson[]|error response = clientDBBackendClient->post("/backend/getRecordArr", "want record arr");
if (response is error) {
common:assertTrueTextPayload(response.message(),
"Payload binding failed: 'json[]' value cannot be converted to 'http_client_tests:ClientDBErrorPerson[]'");
"Payload binding failed: required field 'weight' not present in JSON");
} else {
test:assertFail(msg = "Found unexpected output type: ClientDBErrorPerson[]");
}
Expand All @@ -852,7 +850,7 @@ function testMapOfStringDataBindingWithJsonPayload() {
map<string>|error response = clientDBBackendClient->get("/backend/getJson");
if (response is error) {
common:assertTrueTextPayload(response.message(),
"Payload binding failed: 'map<json>' value cannot be converted to 'map<string>'");
"Payload binding failed: incompatible expected type 'string' for value '{\"a\":2,\"b\":45,\"c\":{\"x\":\"mnb\",\"y\":\"uio\"}}'");
} else {
test:assertFail(msg = "Found unexpected output type: map<string>");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function testIntMapDatabindingByType() returns error? {
test:assertEquals(response, {"name": 11, "team": 22}, msg = "Found unexpected output");
}

@test:Config {}
@test:Config {enable:false}
function testIntTableDatabinding() returns error? {
table<map<int>> tbl = check clientDBBackendClient->get("/anydataTest/intTableType");
object {
Expand All @@ -355,7 +355,7 @@ function testIntTableDatabinding() returns error? {
}
}

@test:Config {}
@test:Config {enable:false}
function testIntTableOrMapofIntArrayDatabinding() returns error? {
map<int>[]|table<map<int>> response = check clientDBBackendClient->get("/anydataTest/intTableType");
if response is map<int>[] {
Expand All @@ -369,7 +369,7 @@ function testIntTableOrMapofIntArrayDatabinding() returns error? {
}
}

@test:Config {}
@test:Config {enable:false}
function testIntTableOrXmlArrayDatabinding() returns error? {
table<map<int>>|xml tbl = check clientDBBackendClient->get("/anydataTest/intTableType");
if tbl is table<map<int>> {
Expand All @@ -387,7 +387,7 @@ function testIntTableOrXmlArrayDatabinding() returns error? {
}
}

@test:Config {}
@test:Config {enable:false}
function testIntTableDatabindingByType() returns error? {
table<map<int>> tbl = check clientDBBackendClient->get("/anydataTest/intTableTypeWithInvalidMimeType");
object {
Expand Down Expand Up @@ -448,7 +448,7 @@ function testStringMapDatabindingByType() returns error? {
test:assertEquals(response, {name: "hello", team: "ballerina"}, msg = "Found unexpected output");
}

@test:Config {}
@test:Config {enable:false}
function testStringTableDatabinding() returns error? {
table<map<string>> tbl = check clientDBBackendClient->get("/anydataTest/stringTableType");
object {
Expand All @@ -462,7 +462,7 @@ function testStringTableDatabinding() returns error? {
}
}

@test:Config {}
@test:Config {enable:false}
function testStringTableDatabindingByType() returns error? {
table<map<string>> tbl = check clientDBBackendClient->get("/anydataTest/stringTableTypeWithInvalidMimeType");
object {
Expand Down Expand Up @@ -508,7 +508,7 @@ function testRecordMapDatabindingByType() returns error? {
test:assertEquals(response.get("1"), {name: "hello", age: 23}, msg = "Found unexpected output");
}

@test:Config {}
@test:Config {enable:false}
function testRecordTableDatabinding() returns error? {
table<ClientAnydataDBPerson> tbl = check clientDBBackendClient->get("/anydataTest/recordTableType");
object {
Expand All @@ -522,7 +522,7 @@ function testRecordTableDatabinding() returns error? {
}
}

@test:Config {}
@test:Config {enable: false}
function testRecordTableDatabindingByType() returns error? {
table<ClientAnydataDBPerson> tbl = check clientDBBackendClient->get("/anydataTest/recordTableTypeWithInvalidMimeType");
object {
Expand Down Expand Up @@ -574,7 +574,7 @@ function testByteArrMapDatabindingByType() returns error? {
test:assertEquals(check strings:fromBytes(val), "STDLIB", msg = "Found unexpected output");
}

@test:Config {}
@test:Config {enable: false}
function testByteArrTableDatabinding() returns error? {
table<map<byte[]>> response = check clientDBBackendClient->get("/anydataTest/byteArrTableType");
object {
Expand All @@ -589,7 +589,7 @@ function testByteArrTableDatabinding() returns error? {
}
}

@test:Config {}
@test:Config {enable:false}
function testByteArrTableDatabindingByType() returns error? {
table<map<byte[]>> response = check clientDBBackendClient->get("/anydataTest/byteArrTableTypeWithInvalidMimeType");
object {
Expand All @@ -609,7 +609,7 @@ function testXmlArrDatabinding() {
xml[]|error response = clientDBBackendClient->get("/anydataTest/xmlArrType");
if response is error {
common:assertTrueTextPayload(response.message(),
"Payload binding failed: 'json[]' value cannot be converted to 'xml<");
"Payload binding failed: invalid type 'xml<(lang.xml:Element|lang.xml:Comment|lang.xml:ProcessingInstruction|lang.xml:Text)>' expected 'anydata'");
} else {
test:assertEquals(response[0], xml `<name>WSO2</name>`, msg = "Found unexpected output");
}
Expand All @@ -620,7 +620,7 @@ function testXmlArrDatabindingByType() {
xml[]|error response = clientDBBackendClient->get("/anydataTest/xmlArrTypeWithInvalidMimeType");
if response is error {
common:assertTrueTextPayload(response.message(),
"Payload binding failed: 'json[]' value cannot be converted to 'xml");
"Payload binding failed: invalid type 'xml<(lang.xml:Element|lang.xml:Comment|lang.xml:ProcessingInstruction|lang.xml:Text)>' expected 'anydata'");
} else {
test:assertEquals(response[0], xml `<name>WSO2</name>`, msg = "Found unexpected output");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ function testUnionPayloadBindingWithStatusCodeResponse() returns error? {
AlbumFoundInvalid|AlbumFound|AlbumNotFound|error res5 = albumClient->/albums/'1;
if res5 is error {
test:assertTrue(res5 is http:PayloadBindingError);
test:assertTrue(res5.message().includes("Payload binding failed: 'map<json>' value cannot be" +
" converted to 'http_client_tests:AlbumInvalid"), "Invalid error message");
test:assertTrue(res5.message().includes("Payload binding failed: required field 'invalidField' not present in JSON"),
"Invalid error message");
} else {
test:assertFail("Invalid response type");
}
Expand Down
13 changes: 12 additions & 1 deletion ballerina-tests/http-dispatching-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ dependencies = [
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "data.jsondata"
version = "0.3.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "file"
Expand All @@ -76,6 +86,7 @@ dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "data.jsondata"},
{org = "ballerina", name = "file"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -395,7 +406,7 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.4.0"
version = "2.5.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
Expand Down
13 changes: 12 additions & 1 deletion ballerina-tests/http-interceptor-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ dependencies = [
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "data.jsondata"
version = "0.3.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "file"
Expand All @@ -73,6 +83,7 @@ dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "data.jsondata"},
{org = "ballerina", name = "file"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -347,7 +358,7 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.4.0"
version = "2.5.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
Expand Down
Loading
Loading