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 anydata support for setPayload methods #2135

Merged
merged 14 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
6 changes: 3 additions & 3 deletions ballerina-tests/http-advanced-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_advanced_tests"
version = "2.12.0"
version = "2.12.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.12.0"
version = "2.12.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-advanced-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -105,7 +105,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_advanced_tests"
version = "2.12.0"
version = "2.12.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "file"},
Expand All @@ -125,7 +125,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-client-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_client_tests"
version = "2.12.0"
version = "2.12.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.12.0"
version = "2.12.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-client-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -102,7 +102,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_client_tests"
version = "2.12.0"
version = "2.12.1"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "http"},
Expand All @@ -121,7 +121,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-dispatching-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_dispatching_tests"
version = "2.12.0"
version = "2.12.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.12.0"
version = "2.12.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-dispatching-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -102,7 +102,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_dispatching_tests"
version = "2.12.0"
version = "2.12.1"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "http"},
Expand All @@ -124,7 +124,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-interceptor-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_interceptor_tests"
version = "2.12.0"
version = "2.12.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.12.0"
version = "2.12.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-interceptor-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -99,7 +99,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_interceptor_tests"
version = "2.12.0"
version = "2.12.1"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
Expand All @@ -115,7 +115,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-misc-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_misc_tests"
version = "2.12.0"
version = "2.12.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.12.0"
version = "2.12.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-misc-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -99,7 +99,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_misc_tests"
version = "2.12.0"
version = "2.12.1"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
Expand All @@ -118,7 +118,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ service /entityService on generalListener {
}
check caller->respond(response);
}

resource function post anydataTest(AnydataRecord rec) returns http:Response {
http:Response response = new;
response.setPayload(rec);
return response;
}
}

final http:Client entityClient = check new ("http://localhost:" + generalPort.toString());
Expand All @@ -334,3 +340,31 @@ function jsonTest() {
test:assertFail(msg = "Test Failed! " + <string>response.message());
}
}

@test:Config {}
function setPayloadWithAnydata() {
string path = "/entityService/anydataTest";
http:Request request = new;
AnydataRecord rec = {a: "ballerina", b: 1};
request.setPayload(rec);
http:Response|error response = entityClient->post(path, request);
if response is http:Response {
common:assertJsonPayload(response.getJsonPayload(), rec.toJson());
} else {
test:assertFail(msg = "Test Failed! " + response.message());
}
}

@test:Config {}
function setPayloadWithAnydataDataBinding() {
string path = "/entityService/anydataTest";
http:Request request = new;
AnydataRecord rec = {a: "ballerina", b: 1};
request.setPayload(rec);
AnydataRecord|error response = entityClient->post(path, request);
if response is AnydataRecord {
test:assertEquals(response, rec);
} else {
test:assertFail(msg = "Test Failed! " + response.message());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,18 @@ function testRequestSetBinaryPayload() returns error? {
test:assertEquals(req.getContentType(), "binary/test2", msg = "Found unexpected headerValue");
return;
}

type AnydataRecord record {
string a;
int b;
};

@test:Config {}
function testRequestSetAnydataPayload() returns error? {
http:Request req = new;
AnydataRecord testValue = {a: "ballerina", b: 1};
req.setPayload(testValue);
test:assertEquals(req.getContentType(), "application/json", msg = "Found unexpected headerValue");
json payload = check req.getJsonPayload();
test:assertEquals(payload, testValue.toJson(), msg = "Found unexpected payload");
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,13 @@ function testResponseSetByteStream() returns error? {
test:assertEquals(res.getContentType(), "stream/test2", msg = "Found unexpected headerValue");
return;
}

@test:Config {}
function testResponseSetAnydataPayload() returns error? {
http:Response res = new;
AnydataRecord testValue = {a: "ballerina", b: 1};
res.setPayload(testValue);
test:assertEquals(res.getContentType(), "application/json", msg = "Found unexpected headerValue");
json payload = check res.getJsonPayload();
test:assertEquals(payload, testValue.toJson(), msg = "Found unexpected payload");
}
6 changes: 3 additions & 3 deletions ballerina-tests/http-resiliency-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_resiliency_tests"
version = "2.12.0"
version = "2.12.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.12.0"
version = "2.12.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-resiliency-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -99,7 +99,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_resiliency_tests"
version = "2.12.0"
version = "2.12.1"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
Expand All @@ -116,7 +116,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.12.0"
version = "2.12.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-security-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_security_tests"
version = "2.12.0"
version = "2.12.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.12.0"
version = "2.12.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar"
Loading
Loading