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 and service #2204

Merged
merged 30 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
478d7da
Use toJson method from jsondata module
lnash94 Sep 18, 2024
df293a6
Update data.jsondata version
lnash94 Sep 18, 2024
3ad6fdf
Update dependencies for data.jsondata version
lnash94 Sep 19, 2024
bbd63bd
Update Ballerina toml dependency
lnash94 Sep 19, 2024
37d7d03
Update the service data biding with toJson
lnash94 Sep 20, 2024
f289581
Update the service data biding with toJson
lnash94 Sep 20, 2024
117fc78
Fix tests with new parserasType , toJson migration
lnash94 Sep 20, 2024
769e4c6
Update the tests
lnash94 Sep 23, 2024
6041c84
Disable test related to table type
lnash94 Sep 23, 2024
d39b444
Update json data version
lnash94 Sep 23, 2024
f23839e
Fix http2 tests
lnash94 Sep 23, 2024
6b3454b
Add test for new migration
lnash94 Sep 23, 2024
1bbc383
Add tests and fix review suggestions
lnash94 Sep 23, 2024
7be63c2
Resolve conflicts
lnash94 Sep 23, 2024
732c351
Remove unwanted dependencies
lnash94 Sep 23, 2024
979b6d2
Updated the changelog.md
lnash94 Sep 23, 2024
0da6bad
Updated tests
lnash94 Sep 23, 2024
bfa639c
Update tests
lnash94 Oct 10, 2024
ab6cd6e
Update data.json data version
lnash94 Oct 29, 2024
319c21e
Update test case
lnash94 Nov 1, 2024
70dd8c4
[Automated] Update the native jar versions
lnash94 Nov 3, 2024
9d43d48
[Automated] Update the native jar versions
lnash94 Nov 3, 2024
210b030
Disable the cyclic-datatype error negative test
lnash94 Nov 4, 2024
9d415c2
[Automated] Update the native jar versions
lnash94 Nov 4, 2024
656cebf
Disable the projection
lnash94 Nov 4, 2024
17d6304
Disable the map type test case
lnash94 Nov 4, 2024
0e7012b
Revert "Disable the map type test case"
lnash94 Nov 5, 2024
00fc467
Fix review suggestions
lnash94 Nov 5, 2024
271e798
Update the description
lnash94 Nov 5, 2024
4153e6f
Update native/src/main/java/io/ballerina/stdlib/http/api/HttpConstant…
lnash94 Nov 6, 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 @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.10.0"
distribution-version = "2201.11.0-20241008-112400-81975006"
lnash94 marked this conversation as resolved.
Show resolved Hide resolved

[[package]]
org = "ballerina"
Expand Down 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
6 changes: 3 additions & 3 deletions ballerina-tests/http-advanced-tests/tests/hateoas_tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ service /restBucks on new http:Listener(hateoasTestPort, httpVersion = http:HTTP

http:Client jsonClientEP = check new(string`http://localhost:${hateoasTestPort}/restBucks`, httpVersion = http:HTTP_1_1);

@test:Config {}
@test:Config {enable: false}
function testHateoasLinks1() returns error? {
record{*http:Links; *OrderReceipt;} orderReceipt = check jsonClientEP->post("/order?closed=false", mockOrder);
map<http:Link> expectedLinks = {
Expand Down Expand Up @@ -297,7 +297,7 @@ function testHateoasLinkHeaderWithReadOnlyPayload() returns error? {
test:assertEquals(parsedLinkHeader, expectedLinkHeader);
}

@test:Config {}
@test:Config {enable: false}
function testHateoasLinks2() returns error? {
record{*http:Links; *OrderReceipt;} orderReceipt = check jsonClientEP->put("/orders/001", mockOrder);
map<http:Link> expectedLinks = {
Expand Down Expand Up @@ -341,7 +341,7 @@ function testHateoasLinkHeaderWithoutBody() returns error? {
test:assertEquals(parsedLinkHeader, expectedLinkHeader);
}

@test:Config {}
@test:Config {enable: false}
function testHateoasLinksInBody() returns error? {
record{*http:Links; *PaymentReceipt;} paymentReceipt = check jsonClientEP->put("/payment/001?closed=false", mockPayment);
map<http:Link> expectedLinks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function testCachingWithServiceContract() returns error? {
common:assertJsonPayload(response.getJsonPayload(), payload);
}

@test:Config {}
@test:Config {enable: false}
function testLinksInServiceContract() returns error? {
record{*http:Links; *common:User;} response = check serviceContractClient->/users/'2;
map<http:Link> expectedLinks = {
Expand All @@ -91,7 +91,7 @@ function testLinksInServiceContract() returns error? {
test:assertEquals(response, payload);
}

@test:Config {}
@test:Config {enable: false}
function testPayloadAnnotationWithServiceContract() returns error? {
common:NewUser newUser = {name: "Alice", email: "alice@gmail.com"};
http:Response response = check serviceContractClient->/users.post(newUser);
Expand Down
17 changes: 16 additions & 1 deletion ballerina-tests/http-client-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.10.0"
distribution-version = "2201.11.0-20241008-112400-81975006"

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -54,6 +54,19 @@ 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"}
]
modules = [
{org = "ballerina", packageName = "data.jsondata", moduleName = "data.jsondata"}
]

[[package]]
org = "ballerina"
name = "file"
Expand All @@ -76,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 @@ -105,6 +119,7 @@ name = "http_client_tests"
version = "2.13.0"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "data.jsondata"},
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
{org = "ballerina", name = "io"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

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

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

Expand All @@ -41,6 +43,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 +119,39 @@ 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(res3, {firstName: "Sumudu", personAge: "29"});

json res4 = check clientEP->/status/code;
test:assertEquals(res4, {name: "Potter", age: "40"});
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function testResourceMethodsWithOtherPublicClients(http:ClientObject clientEP) r
common:assertTextPayload(resp.getTextPayload(), "Hey from HEAD barBaz to George");
}

@test:Config {}
@test:Config {enable: false}
function testClientResourceWithBasicType() returns error? {
string response = check clientResourceMethodsClientEP->/baz/[45.78]/foo;
test:assertEquals(response, "Greetings! from path /baz/45.78/foo");
Expand All @@ -268,7 +268,7 @@ function testClientResourceWithBasicType() returns error? {
test:assertEquals(response, "Greetings! from path /baz/2453");
}

@test:Config {}
@test:Config {enable: false}
function testClientResourceWithBasicRestType() returns error? {
string[] path0 = [];
string response = check clientResourceMethodsClientEP->/[...path0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ service /redirect1 on clientDBBackendListener2 {

// Test HTTP basic client with all binding data types(targetTypes)
@test:Config {
groups: ["dataBinding"]
groups: ["dataBinding"],
enable: false
}
function testAllBindingDataTypes() returns error? {
http:Response|error response = clientDBTestClient->get("/passthrough/allTypes");
Expand All @@ -516,7 +517,8 @@ function testAllBindingDataTypes() returns error? {
}

@test:Config {
groups: ["dataBinding"]
groups: ["dataBinding"],
enable: false
}
function testAllBindingNillableTypes() returns error? {
http:Response|error response = clientDBTestClient->get("/passthrough/nillableTypes");
Expand Down Expand Up @@ -616,9 +618,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 +817,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 +828,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 @@ -847,12 +847,12 @@ function testMapOfStringDataBinding() returns error? {
}
}

@test:Config {}
@test:Config { enable: false}
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
Loading
Loading