Skip to content

Commit

Permalink
Merge pull request #499 from xlight05/test-svc1
Browse files Browse the repository at this point in the history
Reuse http records annotations
  • Loading branch information
xlight05 authored Sep 2, 2022
2 parents ce3bf6d + e2fa557 commit 1d02613
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 1,187 deletions.
69 changes: 35 additions & 34 deletions ballerina-tests/main.bal
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ballerinax/azure_functions as af;
import ballerina/http;

listener af:HTTPListener ep = new ();
listener af:HttpListener ep = new ();

public type DBEntry record {
string id;
Expand All @@ -11,7 +12,7 @@ type Person record {
int age;
};

listener af:HTTPListener ep1 = new ();
listener af:HttpListener ep1 = new ();

service /hello\- on ep1 {

Expand All @@ -25,22 +26,22 @@ service /hello on ep {
return "Hello from all";
}

resource function post optional/out(@af:Payload string greeting) returns string {
resource function post optional/out(@http:Payload string greeting) returns string {
return "Hello from optional output binding";
}

resource function post optional/payload(@af:Payload string? greeting) returns string {
resource function post optional/payload(@http:Payload string? greeting) returns string {
if (greeting is string) {
return "Hello, the payload found " + greeting;
}
return "Hello, the payload wasn't set but all good ;)";
}

resource function post .(@af:Payload string greeting) returns @af:HttpOutput string {
resource function post .(@http:Payload string greeting) returns @af:HttpOutput string {
return "Hello from . path ";
}
resource function post httpResTest1(@af:Payload string greeting) returns @af:HttpOutput af:Unauthorized {
af:Unauthorized unauth = {
resource function post httpResTest1(@http:Payload string greeting) returns @af:HttpOutput http:Unauthorized {
http:Unauthorized unauth = {
body: "Helloworld.....",
mediaType: "application/account+json",
headers: {
Expand All @@ -50,12 +51,12 @@ service /hello on ep {
return unauth;
}

resource function post httpResTest2(@af:Payload string greeting) returns @af:HttpOutput af:Ok {
af:Ok ok = {body: "Helloworld....."};
resource function post httpResTest2(@http:Payload string greeting) returns @af:HttpOutput http:Ok {
http:Ok ok = {body: "Helloworld....."};
return ok;
}
resource function post httpResTest3(@af:Payload string greeting) returns @af:HttpOutput af:InternalServerError {
af:InternalServerError err = {
resource function post httpResTest3(@http:Payload string greeting) returns @af:HttpOutput http:InternalServerError {
http:InternalServerError err = {
body: "Helloworld.....",
headers: {
"Content-Type": "application/json+id",
Expand All @@ -64,24 +65,24 @@ service /hello on ep {
};
return err;
}
resource function post httpResTest4(@af:Payload string greeting) returns @af:HttpOutput af:InternalServerError {
af:InternalServerError err = {};
resource function post httpResTest4(@http:Payload string greeting) returns @af:HttpOutput http:InternalServerError {
http:InternalServerError err = {};
return err;
}

resource function post foo(@af:Payload string greeting) returns @af:HttpOutput string {
resource function post foo(@http:Payload string greeting) returns @af:HttpOutput string {
return "Hello from foo path " + greeting;
}

resource function post foo/[string bar](@af:Payload string greeting) returns @af:HttpOutput string {
resource function post foo/[string bar](@http:Payload string greeting) returns @af:HttpOutput string {
return "Hello from foo param " + bar;
}

resource function post foo/bar(@af:Payload string greeting) returns @af:HttpOutput string {
resource function post foo/bar(@http:Payload string greeting) returns @af:HttpOutput string {
return "Hello from foo bar res";
}

resource function post db(@af:Payload string greeting, @af:CosmosDBInput {
resource function post db(@http:Payload string greeting, @af:CosmosDBInput {
connectionStringSetting: "CosmosDBConnection",
databaseName: "db1",
collectionName: "c2",
Expand All @@ -90,36 +91,36 @@ service /hello on ep {
return "Hello " + greeting + input1[0].id;
}

resource function post payload/jsonToRecord(@af:Payload Person greeting) returns @af:HttpOutput string|error {
resource function post payload/jsonToRecord(@http:Payload Person greeting) returns @af:HttpOutput string|error {
return "Hello from json to record " + greeting.name;
}

resource function post payload/jsonToJson(@af:Payload json greeting) returns @af:HttpOutput string|error {
resource function post payload/jsonToJson(@http:Payload json greeting) returns @af:HttpOutput string|error {
string name = check greeting.name;
return "Hello from json to json " + name;
}

resource function post payload/xmlToXml(@af:Payload xml greeting) returns @af:HttpOutput string|error {
resource function post payload/xmlToXml(@http:Payload xml greeting) returns @af:HttpOutput string|error {
return greeting.toJsonString();
}

resource function post payload/textToString(@af:Payload string greeting) returns @af:HttpOutput string|error {
resource function post payload/textToString(@http:Payload string greeting) returns @af:HttpOutput string|error {
return greeting;
}

resource function post payload/textToByte(@af:Payload byte[] greeting) returns @af:HttpOutput string|error {
resource function post payload/textToByte(@http:Payload byte[] greeting) returns @af:HttpOutput string|error {
return string:fromBytes(greeting);
}

resource function post payload/octaToByte(@af:Payload byte[] greeting) returns @af:HttpOutput string|error {
resource function post payload/octaToByte(@http:Payload byte[] greeting) returns @af:HttpOutput string|error {
return string:fromBytes(greeting);
}

resource function get err/empty/payload(@af:Payload string greeting) returns @af:HttpOutput string {
resource function get err/empty/payload(@http:Payload string greeting) returns @af:HttpOutput string {
return "Hello from get empty payload";
}

resource function post err/invalid/payload(@af:Payload string greeting) returns @af:HttpOutput string {
resource function post err/invalid/payload(@http:Payload string greeting) returns @af:HttpOutput string {
return "Hello from get invalid payload " + greeting;
}

Expand Down Expand Up @@ -147,8 +148,8 @@ service /hello on ep {
return "Hello from all";
}

resource function post httpResTest5() returns af:StatusCodeResponse {
af:InternalServerError err = {};
resource function post httpResTest5() returns http:StatusCodeResponse {
http:InternalServerError err = {};
return err;
}

Expand Down Expand Up @@ -224,7 +225,7 @@ service /hello on ep {

}

resource function get blobInput(@af:Payload string greeting, string name, @af:BlobInput {path: "bpath1/{Query.name}"} byte[]? blobIn) returns string|error {
resource function get blobInput(@http:Payload string greeting, string name, @af:BlobInput {path: "bpath1/{Query.name}"} byte[]? blobIn) returns string|error {
if blobIn is byte[] {
string content = check string:fromBytes(blobIn);
return "Blob from " + name + ", content is " + content;
Expand All @@ -233,7 +234,7 @@ service /hello on ep {
}
}

resource function post query(string name, @af:Payload string greeting) returns @af:HttpOutput string|error {
resource function post query(string name, @http:Payload string greeting) returns @af:HttpOutput string|error {
return "Hello from the query " + greeting + " " + name;
}

Expand Down Expand Up @@ -278,7 +279,7 @@ service /hello on ep {
queueName: "queue2"
}
service "queue" on new af:QueueListener() {
remote function onMessage(@af:Payload string inMsg) returns @af:QueueOutput {queueName: "queue3"} string|error {
remote function onMessage(string inMsg) returns @af:QueueOutput {queueName: "queue3"} string|error {
return "helloo " + inMsg;
}
}
Expand All @@ -287,7 +288,7 @@ service "queue" on new af:QueueListener() {
listener af:CosmosDBListener cosmosEp = new ();

service "cosmos" on cosmosEp {
remote function onUpdated(@af:Payload DBEntry[] inMsg) returns @af:QueueOutput {queueName: "queue3"} string|error {
remote function onUpdated(DBEntry[] inMsg) returns @af:QueueOutput {queueName: "queue3"} string|error {
string id = inMsg[0].id;
return "helloo " + id;
}
Expand All @@ -297,7 +298,7 @@ service "cosmos" on cosmosEp {
listener af:TimerListener timerListener = new af:TimerListener();

service "timer" on timerListener {
remote function onTrigger(@af:Payload af:TimerMetadata inMsg) returns @af:QueueOutput {queueName: "queue3"} string|error {
remote function onTrigger(af:TimerMetadata inMsg) returns @af:QueueOutput {queueName: "queue3"} string|error {
return "helloo " + inMsg.IsPastDue.toString();
}
}
Expand All @@ -309,7 +310,7 @@ service "timer" on timerListener {
listener af:QueueListener queueListener1 = new af:QueueListener();

service "queue-input" on queueListener1 {
remote function onMessage(@af:Payload string inMsg, @af:CosmosDBInput {
remote function onMessage(string inMsg, @af:CosmosDBInput {
connectionStringSetting: "CosmosDBConnection",
databaseName: "db1",
collectionName: "c2",
Expand All @@ -325,7 +326,7 @@ service "queue-input" on queueListener1 {
listener af:BlobListener blobListener = new af:BlobListener();

service "blob" on blobListener {
remote function onUpdated(@af:Payload byte[] blobIn, @af:BindingName {} string name) returns @af:BlobOutput {
remote function onUpdated(byte[] blobIn, @af:BindingName {} string name) returns @af:BlobOutput {
path: "bpath1/newBlob"
} byte[]|error {
return blobIn;
Expand Down
18 changes: 9 additions & 9 deletions ballerina/code.bal
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ type HttpPayload record {
};

type Identity record {
anydata? AuthenticationType?;
boolean IsAuthenticated?;
anydata? Actor?;
anydata BootstrapContext?;
anydata[] Claims?;
anydata? Label?;
anydata? Name?;
string NameClaimType?;
string RoleClaimType?;
// anydata? AuthenticationType?;
// boolean IsAuthenticated?;
// anydata? Actor?;
// anydata BootstrapContext?;
// anydata[] Claims?;
// anydata? Label?;
// anydata? Name?;
// string NameClaimType?;
// string RoleClaimType?;
};

# HTTP binding data.
Expand Down
2 changes: 1 addition & 1 deletion ballerina/http_listener.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import ballerina/io;

public class HTTPListener {
public class HttpListener {
ResourceService[] httpServices;

public isolated function init() returns error? {
Expand Down
Loading

0 comments on commit 1d02613

Please sign in to comment.