Skip to content

Commit

Permalink
Merge pull request #396 from chamil321/target-fix
Browse files Browse the repository at this point in the history
Add contextually expected type inference support for client methods
  • Loading branch information
shafreenAnfar authored May 17, 2021
2 parents 5bb56a7 + 0f0ef0c commit ac0c4ee
Show file tree
Hide file tree
Showing 114 changed files with 834 additions and 831 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [1.1.0-beta.1] - 2021-05-06

### Added
- [Add contextually expected type inference support for client remote methods](https://github.com/ballerina-platform/ballerina-standard-library/issues/1371)

### Changed
- [Change configuration parameters of listeners and clients to included record parameters](https://github.com/ballerina-platform/ballerina-standard-library/issues/1325)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ service /baz on authListener {
}

@test:Config {}
function testNoAuthServiceResourceSuccess() {
isolated function testNoAuthServiceResourceSuccess() {
assertSuccess(sendBearerTokenRequest("/baz/foo", JWT1));
assertSuccess(sendJwtRequest("/baz/foo"));
}

@test:Config {}
function testNoAuthServiceResourceWithRequestSuccess() {
isolated function testNoAuthServiceResourceWithRequestSuccess() {
assertSuccess(sendBearerTokenRequest("/baz/bar", JWT2));
}

@test:Config {}
function testNoAuthServiceResourceWithRequestAndCallerSuccess() {
isolated function testNoAuthServiceResourceWithRequestAndCallerSuccess() {
assertSuccess(sendBearerTokenRequest("/baz/baz", JWT3));
}

Expand All @@ -89,17 +89,17 @@ service /basicAuth on authListener {
}

@test:Config {}
function testBasicAuthServiceAuthSuccess() {
isolated function testBasicAuthServiceAuthSuccess() {
assertSuccess(sendBasicTokenRequest("/basicAuth", "alice", "xxx"));
}

@test:Config {}
function testBasicAuthServiceAuthzFailure() {
isolated function testBasicAuthServiceAuthzFailure() {
assertForbidden(sendBasicTokenRequest("/basicAuth", "bob", "yyy"));
}

@test:Config {}
function testBasicAuthServiceAuthnFailure() {
isolated function testBasicAuthServiceAuthnFailure() {
assertUnauthorized(sendBasicTokenRequest("/basicAuth", "peter", "123"));
assertUnauthorized(sendNoTokenRequest("/basicAuth"));
}
Expand Down
10 changes: 5 additions & 5 deletions http-ballerina-tests/tests/auth_test_commons.bal
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ isolated function createSecureRequest(string headerValue) returns http:Request {
return request;
}

function sendNoTokenRequest(string path) returns http:Response|http:ClientError {
isolated function sendNoTokenRequest(string path) returns http:Response|http:ClientError {
http:Client clientEP = checkpanic new("https://localhost:" + securedListenerPort.toString(), {
secureSocket: {
cert: {
Expand All @@ -111,7 +111,7 @@ function sendNoTokenRequest(string path) returns http:Response|http:ClientError
return <@untainted> clientEP->get(path);
}

function sendBasicTokenRequest(string path, string username, string password) returns http:Response|http:ClientError {
isolated function sendBasicTokenRequest(string path, string username, string password) returns http:Response|http:ClientError {
http:Client clientEP = checkpanic new("https://localhost:" + securedListenerPort.toString(), {
auth: {
username: username,
Expand All @@ -127,7 +127,7 @@ function sendBasicTokenRequest(string path, string username, string password) re
return <@untainted> clientEP->get(path);
}

function sendBearerTokenRequest(string path, string token) returns http:Response|http:ClientError {
isolated function sendBearerTokenRequest(string path, string token) returns http:Response|http:ClientError {
http:Client clientEP = checkpanic new("https://localhost:" + securedListenerPort.toString(), {
auth: {
token: token
Expand All @@ -142,7 +142,7 @@ function sendBearerTokenRequest(string path, string token) returns http:Response
return <@untainted> clientEP->get(path);
}

function sendJwtRequest(string path) returns http:Response|http:ClientError {
isolated function sendJwtRequest(string path) returns http:Response|http:ClientError {
http:Client clientEP = checkpanic new("https://localhost:" + securedListenerPort.toString(), {
auth: {
username: "admin",
Expand Down Expand Up @@ -172,7 +172,7 @@ function sendJwtRequest(string path) returns http:Response|http:ClientError {
return <@untainted> clientEP->get(path);
}

function sendOAuth2TokenRequest(string path) returns http:Response|http:ClientError {
isolated function sendOAuth2TokenRequest(string path) returns http:Response|http:ClientError {
http:Client clientEP = checkpanic new("https://localhost:" + securedListenerPort.toString(), {
auth: {
tokenUrl: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/token",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ service /hello on acceptEncodingListenerEP {
function testAcceptEncodingEnabled() {
http:Request req = new;
req.setTextPayload("accept encoding test");
var response = acceptEncodingEnableEP->post("/", req);
http:Response|error response = acceptEncodingEnableEP->post("/", req);
if (response is http:Response) {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
assertJsonValue(response.getJsonPayload(), "acceptEncoding", "deflate, gzip");
Expand All @@ -67,7 +67,7 @@ function testAcceptEncodingEnabled() {
function testAcceptEncodingDisabled() {
http:Request req = new;
req.setTextPayload("accept encoding test");
var response = acceptEncodingDisableEP->post("/", req);
http:Response|error response = acceptEncodingDisableEP->post("/", req);
if (response is http:Response) {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
assertJsonValue(response.getJsonPayload(), "acceptEncoding", "Accept-Encoding header not present.");
Expand All @@ -81,7 +81,7 @@ function testAcceptEncodingDisabled() {
function testAcceptEncodingAuto() {
http:Request req = new;
req.setTextPayload("accept encoding test");
var response = acceptEncodingAutoEP->post("/", req);
http:Response|error response = acceptEncodingAutoEP->post("/", req);
if (response is http:Response) {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
assertJsonValue(response.getJsonPayload(), "acceptEncoding", "Accept-Encoding header not present.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ service /requestPayloadLimit on lowPayloadLimitEP {
@test:Config {}
function testValidUrlLength() {
http:Client limitClient = checkpanic new("http://localhost:" + requestLimitsTestPort1.toString());
var response = limitClient->get("/requestUriLimit/validUrl");
http:Response|error response = limitClient->get("/requestUriLimit/validUrl");
if (response is http:Response) {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
assertHeaderValue(checkpanic response.getHeader(mime:CONTENT_TYPE), TEXT_PLAIN);
Expand All @@ -122,7 +122,7 @@ function testValidUrlLength() {
@test:Config {}
function testInvalidUrlLength() {
http:Client limitClient = checkpanic new("http://localhost:" + requestLimitsTestPort2.toString());
var response = limitClient->get("/lowRequestUriLimit/invalidUrl");
http:Response|error response = limitClient->get("/lowRequestUriLimit/invalidUrl");
if (response is http:Response) {
//414 Request-URI Too Long
test:assertEquals(response.statusCode, 414, msg = "Found unexpected output");
Expand All @@ -135,7 +135,7 @@ function testInvalidUrlLength() {
@test:Config {}
function testValidHeaderLength() {
http:Client limitClient = checkpanic new("http://localhost:" + requestLimitsTestPort4.toString());
var response = limitClient->get("/requestHeaderLimit/validHeaderSize");
http:Response|error response = limitClient->get("/requestHeaderLimit/validHeaderSize");
if (response is http:Response) {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
assertHeaderValue(checkpanic response.getHeader(mime:CONTENT_TYPE), TEXT_PLAIN);
Expand All @@ -149,7 +149,7 @@ function testValidHeaderLength() {
@test:Config {}
function testInvalidHeaderLength() {
http:Client limitClient = checkpanic new("http://localhost:" + requestLimitsTestPort3.toString());
var response = limitClient->get("/lowRequestHeaderLimit/invalidHeaderSize", {"X-Test":getLargeHeader()});
http:Response|error response = limitClient->get("/lowRequestHeaderLimit/invalidHeaderSize", {"X-Test":getLargeHeader()});
if (response is http:Response) {
//431 Request Header Fields Too Large
test:assertEquals(response.statusCode, 431, msg = "Found unexpected output");
Expand All @@ -172,7 +172,7 @@ function getLargeHeader() returns string {
@test:Config {}
function testHttp2ServiceInvalidHeaderLength() {
http:Client limitClient = checkpanic new("http://localhost:" + requestLimitsTestPort5.toString());
var response = limitClient->get("/http2service/invalidHeaderSize", {"X-Test":getLargeHeader()});
http:Response|error response = limitClient->get("/http2service/invalidHeaderSize", {"X-Test":getLargeHeader()});
if (response is http:Response) {
test:assertEquals(response.statusCode, 431, msg = "Found unexpected output");
} else {
Expand All @@ -186,7 +186,7 @@ function testInvalidPayloadSize() {
http:Request req = new;
req.setTextPayload("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
http:Client limitClient = checkpanic new("http://localhost:" + requestLimitsTestPort6.toString());
var response = limitClient->post("/requestPayloadLimit/test", req);
http:Response|error response = limitClient->post("/requestPayloadLimit/test", req);
if (response is http:Response) {
//413 Payload Too Large
test:assertEquals(response.statusCode, 413, msg = "Found unexpected output");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ service /responseLimit on statusLineEP {
clientEP = http2headerLimitClient;
}

var clientResponse = clientEP->forward("/", <@untainted>req);
http:Response|error clientResponse = clientEP->forward("/", <@untainted>req);
if (clientResponse is http:Response) {
error? result = caller->respond(<@untainted>clientResponse);
if (result is error) {
Expand Down Expand Up @@ -169,7 +169,7 @@ function sendResponse(http:Caller caller, http:Response res) {
//Test when status line length is less than the configured maxStatusLineLength threshold
@test:Config {}
function testValidStatusLineLength() {
var response = limitTestClient->get("/responseLimit/statusline", {[X_TEST_TYPE]:[SUCCESS]});
http:Response|error response = limitTestClient->get("/responseLimit/statusline", {[X_TEST_TYPE]:[SUCCESS]});
if (response is http:Response) {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
test:assertEquals(response.reasonPhrase, "HELLO", msg = "Found unexpected output");
Expand All @@ -182,7 +182,7 @@ function testValidStatusLineLength() {
//Test when status line length is greater than the configured maxStatusLineLength threshold
@test:Config {}
function testInvalidStatusLineLength() {
var response = limitTestClient->get("/responseLimit/statusline", {[X_TEST_TYPE]:[ERROR]});
http:Response|error response = limitTestClient->get("/responseLimit/statusline", {[X_TEST_TYPE]:[ERROR]});
if (response is http:Response) {
test:assertEquals(response.statusCode, 500, msg = "Found unexpected output");
assertTextPayload(response.getTextPayload(), "error ClientError (\"Response max " +
Expand All @@ -195,7 +195,7 @@ function testInvalidStatusLineLength() {
//Test when header size is less than the configured maxHeaderSize threshold
@test:Config {}
function testValidHeaderLengthOfResponse() {
var response = limitTestClient->get("/responseLimit/header", {[X_TEST_TYPE]:[SUCCESS]});
http:Response|error response = limitTestClient->get("/responseLimit/header", {[X_TEST_TYPE]:[SUCCESS]});
if (response is http:Response) {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
assertHeaderValue(checkpanic response.getHeader(X_HEADER), "Validated");
Expand All @@ -208,7 +208,7 @@ function testValidHeaderLengthOfResponse() {
//Test when header size is greater than the configured maxHeaderSize threshold
@test:Config {}
function testInvalidHeaderLengthOfResponse() {
var response = limitTestClient->get("/responseLimit/header", {[X_TEST_TYPE]:[ERROR]});
http:Response|error response = limitTestClient->get("/responseLimit/header", {[X_TEST_TYPE]:[ERROR]});
if (response is http:Response) {
test:assertEquals(response.statusCode, 500, msg = "Found unexpected output");
assertTextPayload(response.getTextPayload(), "error ClientError (\"Response max " +
Expand All @@ -227,7 +227,7 @@ function testInvalidHeaderLengthOfResponse() {
//Test when entityBody size is less than the configured maxEntityBodySize threshold
@test:Config {}
function testValidEntityBodyLength() {
var response = limitTestClient->get("/responseLimit/entitybody", {[X_TEST_TYPE]:[SUCCESS]});
http:Response|error response = limitTestClient->get("/responseLimit/entitybody", {[X_TEST_TYPE]:[SUCCESS]});
if (response is http:Response) {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
assertTextPayload(response.getTextPayload(), "Small payload");
Expand All @@ -239,7 +239,7 @@ function testValidEntityBodyLength() {
//Test when entityBody size is greater than the configured maxEntityBodySize threshold
@test:Config {}
function testInvalidEntityBodyLength() {
var response = limitTestClient->get("/responseLimit/statusline", {[X_TEST_TYPE]:[ERROR]});
http:Response|error response = limitTestClient->get("/responseLimit/statusline", {[X_TEST_TYPE]:[ERROR]});
if (response is http:Response) {
test:assertEquals(response.statusCode, 500, msg = "Found unexpected output");
assertTextPayload(response.getTextPayload(), "error ClientError (\"Response max " +
Expand All @@ -252,7 +252,7 @@ function testInvalidEntityBodyLength() {
//Test when header size is less than the configured maxHeaderSize threshold in http2 client but the backend sends http 1.1 response
@test:Config {}
function testValidHeaderLengthWithHttp2Client() {
var response = limitTestClient->get("/responseLimit/http2", {[X_TEST_TYPE]:[SUCCESS]});
http:Response|error response = limitTestClient->get("/responseLimit/http2", {[X_TEST_TYPE]:[SUCCESS]});
if (response is http:Response) {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
assertHeaderValue(checkpanic response.getHeader(X_HEADER), "Validated");
Expand All @@ -265,7 +265,7 @@ function testValidHeaderLengthWithHttp2Client() {
//Test when header size is greater than the configured maxHeaderSize threshold in http2 client but the backend sends http 1.1 response
@test:Config {}
function testInvalidHeaderLengthWithHttp2Client() {
var response = limitTestClient->get("/responseLimit/header", {[X_TEST_TYPE]:[ERROR]});
http:Response|error response = limitTestClient->get("/responseLimit/header", {[X_TEST_TYPE]:[ERROR]});
if (response is http:Response) {
test:assertEquals(response.statusCode, 500, msg = "Found unexpected output");
assertTextPayload(response.getTextPayload(), "error ClientError (\"Response max " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function jsonTest() {
http:Request request = new;
request.setHeader("content-type", "application/json");
request.setPayload({test: "菜鸟驿站"});
var response = entityClient->post(path, request);
http:Response|error response = entityClient->post(path, request);
if (response is http:Response) {
assertJsonPayload(response.getJsonPayload(), {test: "菜鸟驿站"});
} else {
Expand Down
2 changes: 1 addition & 1 deletion http-ballerina-tests/tests/entity_mime_with_http.bal
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function testAccessingPayloadFromEntity() {
string jsonString = "{\"" + key + "\":\"" + value + "\"}";
http:Request req = new;
req.setTextPayload(jsonString);
var response = mimeClient->post(path, req);
http:Response|error response = mimeClient->post(path, req);
if (response is http:Response) {
assertJsonPayload(response.getJsonPayload(), {"payload":{"lang":"ballerina"}, "header":"text/plain"});
} else {
Expand Down
4 changes: 2 additions & 2 deletions http-ballerina-tests/tests/http2_100_continue_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ service /continueService on new http:Listener(9128, {httpVersion: "2.0"}) {

resource function get initial(http:Caller caller, http:Request req) {
io:println("test100ContinueResource");
var response = h2Client->post("/helloWorld/abnormalResource", "100 continue response should be ignored by this client");
http:Response|error response = h2Client->post("/helloWorld/abnormalResource", "100 continue response should be ignored by this client");
if (response is http:Response) {
checkpanic caller->respond(<@untainted>response);
} else {
Expand All @@ -70,7 +70,7 @@ function handleRespError(error? result) {
@test:Config {}
public function testUnexpected100ContinueResponse() {
http:Client clientEP = checkpanic new("http://localhost:9128");
var resp = clientEP->get("/continueService/initial");
http:Response|error resp = clientEP->get("/continueService/initial");
if (resp is http:Response) {
var payload = resp.getTextPayload();
if (payload is string) {
Expand Down
Loading

0 comments on commit ac0c4ee

Please sign in to comment.