Skip to content

Commit

Permalink
Add changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
aashikam committed Sep 3, 2024
1 parent 91772e1 commit 33fc565
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions ballerina/tests/listener_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
// specific language governing permissions and limitations
// under the License.

import ballerina/io;
import ballerina/lang.runtime;
import ballerina/log;
import ballerina/test;
import ballerina/os;
import ballerina/io;
import ballerina/test;

configurable string username = os:getEnv("LISTENER_USERNAME");
configurable string password = os:getEnv("LISTENER_PASSWORD");

ListenerConfig listenerConfig = {
auth: {
username: username,
password: password
username,
password
}
};
listener Listener eventListener = new (listenerConfig);
Expand All @@ -37,9 +37,10 @@ isolated boolean isDeleted = false;
isolated boolean isRestored = false;

service "/data/ChangeEvents" on eventListener {

remote function onCreate(EventData payload) {
string? eventType = payload.metadata?.changeType;
if (eventType is string && eventType == "CREATE") {
if eventType is "CREATE" {
lock {
isCreated = true;
}
Expand All @@ -49,9 +50,9 @@ service "/data/ChangeEvents" on eventListener {
}
}

remote isolated function onUpdate(EventData payload) {
json accountName = payload.changedData.get("Name");
if (accountName.toString() == "WSO2 Inc") {
remote isolated function onUpdate(EventData payload) returns error? {
string accountName = check payload.changedData.get("Name").ensureType();
if accountName is "WSO2 Inc" {
lock {
isUpdated = true;
}
Expand All @@ -63,7 +64,7 @@ service "/data/ChangeEvents" on eventListener {

remote function onDelete(EventData payload) {
string? eventType = payload.metadata?.changeType;
if (eventType is string && eventType == "DELETE") {
if eventType is "DELETE" {
lock {
isDeleted = true;
}
Expand All @@ -75,7 +76,7 @@ service "/data/ChangeEvents" on eventListener {

remote function onRestore(EventData payload) {
string? eventType = payload.metadata?.changeType;
if (eventType is string && eventType == "UNDELETE") {
if eventType is "UNDELETE" {
lock {
isRestored = true;
}
Expand All @@ -90,9 +91,7 @@ service "/data/ChangeEvents" on eventListener {
Client lisbaseClient = check new (sfConfigRefreshCodeFlow);
string testRecordId = "";

@test:Config {
enable: true
}
@test:Config {}
function testCreateRecord() {
log:printInfo("lisbaseClient -> createRecord()");
Account account = {
Expand All @@ -110,7 +109,6 @@ function testCreateRecord() {
}

@test:Config {
enable: true,
dependsOn: [testCreateRecord]
}
function testUpdateRecord() {
Expand All @@ -128,7 +126,6 @@ function testUpdateRecord() {
}

@test:Config {
enable: true,
dependsOn: [testUpdateRecord]
}
function testDeleteRecord() {
Expand All @@ -142,7 +139,6 @@ function testDeleteRecord() {
}

@test:Config {
enable: true,
dependsOn: [testCreateRecord]
}
function testCreatedEventTrigger() {
Expand All @@ -154,7 +150,6 @@ function testCreatedEventTrigger() {
}

@test:Config {
enable: true,
dependsOn: [testUpdateRecord]
}
function testUpdatedEventTrigger() {
Expand All @@ -166,7 +161,6 @@ function testUpdatedEventTrigger() {
}

@test:Config {
enable: true,
dependsOn: [testDeleteRecord]
}
function testDeletedEventTrigger() {
Expand Down

0 comments on commit 33fc565

Please sign in to comment.