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

Enable salesforce listener tests #366

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Changes from 1 commit
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
130 changes: 66 additions & 64 deletions ballerina/tests/listener_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,79 +17,81 @@
import ballerina/lang.runtime;
import ballerina/log;
import ballerina/test;
import ballerina/os;
import ballerina/io;
aashikam marked this conversation as resolved.
Show resolved Hide resolved

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

// ListenerConfig listenerConfig = {
// auth: {
// username: username,
// password: password
// }
// };
// listener Listener eventListener = new (listenerConfig);
ListenerConfig listenerConfig = {
auth: {
username: username,
password: password
aashikam marked this conversation as resolved.
Show resolved Hide resolved
}
};
listener Listener eventListener = new (listenerConfig);

isolated boolean isUpdated = false;
isolated boolean isCreated = false;
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") {
// lock {
// isCreated = true;
// }
// io:println("Created " + payload.toString());
// } else {
// io:println(payload.toString());
// }
// }

// remote isolated function onUpdate(EventData payload) {
// json accountName = payload.changedData.get("Name");
// if (accountName.toString() == "WSO2 Inc") {
// lock {
// isUpdated = true;
// }
// io:println("Updated " + payload.toString());
// } else {
// io:println(payload.toString());
// }
// }

// remote function onDelete(EventData payload) {
// string? eventType = payload.metadata?.changeType;
// if (eventType is string && eventType == "DELETE") {
// lock {
// isDeleted = true;
// }
// io:println("Deleted " + payload.toString());
// } else {
// io:println(payload.toString());
// }
// }

// remote function onRestore(EventData payload) {
// string? eventType = payload.metadata?.changeType;
// if (eventType is string && eventType == "UNDELETE") {
// lock {
// isRestored = true;
// }
// io:println("Restored " + payload.toString());
// } else {
// io:println(payload.toString());
// }
// }
// }
service "/data/ChangeEvents" on eventListener {
remote function onCreate(EventData payload) {
aashikam marked this conversation as resolved.
Show resolved Hide resolved
string? eventType = payload.metadata?.changeType;
if (eventType is string && eventType == "CREATE") {
aashikam marked this conversation as resolved.
Show resolved Hide resolved
lock {
isCreated = true;
}
io:println("Created " + payload.toString());
} else {
io:println(payload.toString());
}
}

remote isolated function onUpdate(EventData payload) {
json accountName = payload.changedData.get("Name");
aashikam marked this conversation as resolved.
Show resolved Hide resolved
if (accountName.toString() == "WSO2 Inc") {
aashikam marked this conversation as resolved.
Show resolved Hide resolved
lock {
isUpdated = true;
}
io:println("Updated " + payload.toString());
} else {
io:println(payload.toString());
}
}

remote function onDelete(EventData payload) {
string? eventType = payload.metadata?.changeType;
if (eventType is string && eventType == "DELETE") {
aashikam marked this conversation as resolved.
Show resolved Hide resolved
lock {
isDeleted = true;
}
io:println("Deleted " + payload.toString());
} else {
io:println(payload.toString());
}
}

remote function onRestore(EventData payload) {
string? eventType = payload.metadata?.changeType;
if (eventType is string && eventType == "UNDELETE") {
aashikam marked this conversation as resolved.
Show resolved Hide resolved
lock {
isRestored = true;
}
io:println("Restored " + payload.toString());
} else {
io:println(payload.toString());
}
}
}

// Using direct-token config for client configuration
Client lisbaseClient = check new (sfConfigRefreshCodeFlow);
string testRecordId = "";

@test:Config {
enable: false
enable: true
aashikam marked this conversation as resolved.
Show resolved Hide resolved
}
function testCreateRecord() {
log:printInfo("lisbaseClient -> createRecord()");
Expand All @@ -108,7 +110,7 @@ function testCreateRecord() {
}

@test:Config {
enable: false,
enable: true,
aashikam marked this conversation as resolved.
Show resolved Hide resolved
dependsOn: [testCreateRecord]
}
function testUpdateRecord() {
Expand All @@ -126,7 +128,7 @@ function testUpdateRecord() {
}

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

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

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

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