From 1e37ef13cebd06f4272a563de8bda944c34f4f5c Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Wed, 15 Nov 2023 10:32:43 +0530 Subject: [PATCH 01/23] [Automated] Update native jar versions in toml files --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 33c4697..43f4a33 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerinax" name = "persist.sql" -version = "1.2.0" +version = "1.2.1" authors = ["Ballerina"] keywords = ["persist", "sql", "mysql", "mssql", "sql-server"] repository = "https://github.com/ballerina-platform/module-ballerinas-persist.sql" @@ -15,8 +15,8 @@ graalvmCompatible = true [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "persist.sql-native" -version = "1.2.0" -path = "../native/build/libs/persist.sql-native-1.2.0.jar" +version = "1.2.1" +path = "../native/build/libs/persist.sql-native-1.2.1-SNAPSHOT.jar" [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 5aeadcf..185af12 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,7 +3,7 @@ id = "persist.sql-compiler-plugin" class = "io.ballerina.stdlib.persist.sql.compiler.PersistSqlCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/persist.sql-compiler-plugin-1.2.0.jar" +path = "../compiler-plugin/build/libs/persist.sql-compiler-plugin-1.2.1-SNAPSHOT.jar" [[dependency]] path = "./lib/persist-native-1.2.0.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 93a23f3..5df665b 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -66,7 +66,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.10.0" +version = "2.10.3" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -294,7 +294,7 @@ modules = [ [[package]] org = "ballerina" name = "sql" -version = "1.11.0" +version = "1.11.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -434,7 +434,7 @@ modules = [ [[package]] org = "ballerinax" name = "persist.sql" -version = "1.2.0" +version = "1.2.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"}, From 78fbd331cfda24aa68376131ea4d9036a6ea7a77 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Fri, 26 Jan 2024 13:36:05 +0530 Subject: [PATCH 02/23] [Automated] Update native jar versions in toml files --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 5df665b..52a4f87 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -294,7 +294,7 @@ modules = [ [[package]] org = "ballerina" name = "sql" -version = "1.11.1" +version = "1.11.0" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, From 56e455eb5ca75dcdf6b1a1f86322b328c345ce07 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Fri, 26 Jan 2024 14:05:13 +0530 Subject: [PATCH 03/23] [Automated] Update native jar versions in toml files --- ballerina/Ballerina.toml | 2 +- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 4a691d6..eac06ea 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -22,7 +22,7 @@ path = "../native/build/libs/persist.sql-native-1.2.2-SNAPSHOT.jar" groupId = "io.ballerina.stdlib" artifactId = "persist-native" version = "1.2.1" -path = "./lib/persist-native-1.2.1-20231129-200000-11c71ca.jar" +path = "./lib/persist-native-1.2.1-20231130-100000-cca5690.jar" [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 0a146e9..a372cb9 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -6,4 +6,4 @@ class = "io.ballerina.stdlib.persist.sql.compiler.PersistSqlCompilerPlugin" path = "../compiler-plugin/build/libs/persist.sql-compiler-plugin-1.2.2-SNAPSHOT.jar" [[dependency]] -path = "./lib/persist-native-1.2.1-20231129-200000-11c71ca.jar" +path = "./lib/persist-native-1.2.1-20231130-100000-cca5690.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 677681f..d1434dc 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -66,7 +66,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.10.0" +version = "2.10.3" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -100,9 +100,6 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} ] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] [[package]] org = "ballerina" @@ -439,7 +436,6 @@ org = "ballerinax" name = "persist.sql" version = "1.2.2" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"}, {org = "ballerina", name = "persist"}, From aa77cd1e7f243bb2a9b2e90d4c0036aa345bc62a Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sun, 4 Feb 2024 12:54:54 +0530 Subject: [PATCH 04/23] [Automated] Update native jar versions in toml files --- ballerina/Dependencies.toml | 481 ------------------------------------ 1 file changed, 481 deletions(-) delete mode 100644 ballerina/Dependencies.toml diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml deleted file mode 100644 index d1434dc..0000000 --- a/ballerina/Dependencies.toml +++ /dev/null @@ -1,481 +0,0 @@ -# AUTO-GENERATED FILE. DO NOT MODIFY. - -# This file is auto-generated by Ballerina for managing dependency versions. -# It should not be modified by hand. - -[ballerina] -dependencies-toml-version = "2" -distribution-version = "2201.8.0" - -[[package]] -org = "ballerina" -name = "auth" -version = "2.10.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "log"} -] - -[[package]] -org = "ballerina" -name = "cache" -version = "3.7.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "constraint"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "task"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "constraint" -version = "1.4.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "crypto" -version = "2.5.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "file" -version = "1.9.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "os"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "http" -version = "2.10.3" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "auth"}, - {org = "ballerina", name = "cache"}, - {org = "ballerina", name = "constraint"}, - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "file"}, - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "jwt"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.decimal"}, - {org = "ballerina", name = "lang.int"}, - {org = "ballerina", name = "lang.regexp"}, - {org = "ballerina", name = "lang.runtime"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "lang.value"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "mime"}, - {org = "ballerina", name = "oauth2"}, - {org = "ballerina", name = "observe"}, - {org = "ballerina", name = "time"}, - {org = "ballerina", name = "url"} -] - -[[package]] -org = "ballerina" -name = "io" -version = "1.6.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] - -[[package]] -org = "ballerina" -name = "jballerina.java" -version = "0.0.0" -modules = [ - {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "jwt" -version = "2.10.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "cache"}, - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.int"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.decimal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.int" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" - -[[package]] -org = "ballerina" -name = "lang.regexp" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.runtime" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.string" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.regexp"} -] - -[[package]] -org = "ballerina" -name = "lang.transaction" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "log" -version = "2.9.0" -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"}, - {org = "ballerina", name = "observe"} -] -modules = [ - {org = "ballerina", packageName = "log", moduleName = "log"} -] - -[[package]] -org = "ballerina" -name = "mime" -version = "2.9.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.int"} -] - -[[package]] -org = "ballerina" -name = "oauth2" -version = "2.10.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "cache"}, - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "time"}, - {org = "ballerina", name = "url"} -] - -[[package]] -org = "ballerina" -name = "observe" -version = "1.2.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "os" -version = "1.8.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "persist" -version = "1.2.1" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] -modules = [ - {org = "ballerina", packageName = "persist", moduleName = "persist"} -] - -[[package]] -org = "ballerina" -name = "sql" -version = "1.11.0" -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"}, - {org = "ballerina", name = "time"} -] -modules = [ - {org = "ballerina", packageName = "sql", moduleName = "sql"} -] - -[[package]] -org = "ballerina" -name = "task" -version = "2.5.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - -[[package]] -org = "ballerina" -name = "time" -version = "2.4.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] -modules = [ - {org = "ballerina", packageName = "time", moduleName = "time"} -] - -[[package]] -org = "ballerina" -name = "url" -version = "2.4.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "uuid" -version = "1.7.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.int"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerinai" -name = "transaction" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "cache"}, - {org = "ballerina", name = "http"}, - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.runtime"}, - {org = "ballerina", name = "lang.transaction"}, - {org = "ballerina", name = "lang.value"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "task"}, - {org = "ballerina", name = "time"}, - {org = "ballerina", name = "uuid"} -] -modules = [ - {org = "ballerinai", packageName = "transaction", moduleName = "transaction"} -] - -[[package]] -org = "ballerinax" -name = "mssql" -version = "1.11.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "sql"}, - {org = "ballerina", name = "time"} -] -modules = [ - {org = "ballerinax", packageName = "mssql", moduleName = "mssql"} -] - -[[package]] -org = "ballerinax" -name = "mssql.driver" -version = "1.5.0" -scope = "testOnly" -modules = [ - {org = "ballerinax", packageName = "mssql.driver", moduleName = "mssql.driver"} -] - -[[package]] -org = "ballerinax" -name = "mysql" -version = "1.11.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "sql"}, - {org = "ballerina", name = "time"} -] -modules = [ - {org = "ballerinax", packageName = "mysql", moduleName = "mysql"} -] - -[[package]] -org = "ballerinax" -name = "mysql.driver" -version = "1.5.0" -scope = "testOnly" -modules = [ - {org = "ballerinax", packageName = "mysql.driver", moduleName = "mysql.driver"} -] - -[[package]] -org = "ballerinax" -name = "persist.sql" -version = "1.2.2" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "persist"}, - {org = "ballerina", name = "sql"}, - {org = "ballerina", name = "test"}, - {org = "ballerina", name = "time"}, - {org = "ballerinai", name = "transaction"}, - {org = "ballerinax", name = "mssql"}, - {org = "ballerinax", name = "mssql.driver"}, - {org = "ballerinax", name = "mysql"}, - {org = "ballerinax", name = "mysql.driver"}, - {org = "ballerinax", name = "postgresql"}, - {org = "ballerinax", name = "postgresql.driver"} -] -modules = [ - {org = "ballerinax", packageName = "persist.sql", moduleName = "persist.sql"} -] - -[[package]] -org = "ballerinax" -name = "postgresql" -version = "1.11.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "sql"}, - {org = "ballerina", name = "time"} -] -modules = [ - {org = "ballerinax", packageName = "postgresql", moduleName = "postgresql"} -] - -[[package]] -org = "ballerinax" -name = "postgresql.driver" -version = "1.5.0" -scope = "testOnly" -modules = [ - {org = "ballerinax", packageName = "postgresql.driver", moduleName = "postgresql.driver"} -] - From a78aebd708f209bf1fb05c50a39480d7e8c78bfc Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 8 Feb 2024 14:09:27 +0530 Subject: [PATCH 05/23] Add H2 database support for the persist SQL --- ballerina/Dependencies.toml | 509 ++++++++++++++++++ ballerina/Module.md | 5 +- ballerina/build.gradle | 124 ++--- ballerina/constants.bal | 9 + ballerina/tests/Config.toml | 9 + ballerina/tests/h2-all-types-tests.bal | 228 ++++++++ ballerina/tests/h2-associations-tests.bal | 288 ++++++++++ ballerina/tests/h2-building-tests.bal | 226 ++++++++ ballerina/tests/h2-composite-key-tests.bal | 196 +++++++ ballerina/tests/h2-department-tests.bal | 217 ++++++++ ballerina/tests/h2-employee-tests.bal | 260 +++++++++ ballerina/tests/h2-id-fields-tests.bal | 476 ++++++++++++++++ ballerina/tests/h2-native-tests.bal | 303 +++++++++++ ballerina/tests/h2-transaction-tests.bal | 75 +++ ballerina/tests/h2-workspace-tests.bal | 252 +++++++++ .../tests/h2_rainier_generated_client.bal | 363 +++++++++++++ .../h2_test_entities_generated_client.bal | 502 +++++++++++++++++ ballerina/tests/init-tests.bal | 196 ++++++- build.gradle | 2 + changelog.md | 1 + gradle.properties | 3 +- .../persist/sql/datastore/H2Processor.java | 49 ++ 22 files changed, 4222 insertions(+), 71 deletions(-) create mode 100644 ballerina/Dependencies.toml create mode 100644 ballerina/tests/h2-all-types-tests.bal create mode 100644 ballerina/tests/h2-associations-tests.bal create mode 100644 ballerina/tests/h2-building-tests.bal create mode 100644 ballerina/tests/h2-composite-key-tests.bal create mode 100644 ballerina/tests/h2-department-tests.bal create mode 100644 ballerina/tests/h2-employee-tests.bal create mode 100644 ballerina/tests/h2-id-fields-tests.bal create mode 100644 ballerina/tests/h2-native-tests.bal create mode 100644 ballerina/tests/h2-transaction-tests.bal create mode 100644 ballerina/tests/h2-workspace-tests.bal create mode 100644 ballerina/tests/h2_rainier_generated_client.bal create mode 100644 ballerina/tests/h2_test_entities_generated_client.bal create mode 100644 native/src/main/java/io/ballerina/stdlib/persist/sql/datastore/H2Processor.java diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml new file mode 100644 index 0000000..3dbc4b3 --- /dev/null +++ b/ballerina/Dependencies.toml @@ -0,0 +1,509 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.8.0" + +[[package]] +org = "ballerina" +name = "auth" +version = "2.10.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "log"} +] + +[[package]] +org = "ballerina" +name = "cache" +version = "3.7.1" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "task"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "constraint" +version = "1.5.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "crypto" +version = "2.6.2" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "file" +version = "1.9.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "os"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "http" +version = "2.10.5" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "auth"}, + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "file"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "jwt"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.decimal"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "lang.regexp"}, + {org = "ballerina", name = "lang.runtime"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "mime"}, + {org = "ballerina", name = "oauth2"}, + {org = "ballerina", name = "observe"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "url"} +] + +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +modules = [ + {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "jwt" +version = "2.10.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.decimal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.int" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "lang.regexp" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.runtime" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.string" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.regexp"} +] + +[[package]] +org = "ballerina" +name = "lang.transaction" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "log" +version = "2.9.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerina", packageName = "log", moduleName = "log"} +] + +[[package]] +org = "ballerina" +name = "mime" +version = "2.9.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.int"} +] + +[[package]] +org = "ballerina" +name = "oauth2" +version = "2.10.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "url"} +] + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.2" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "os" +version = "1.8.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "persist" +version = "1.2.1" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "persist", moduleName = "persist"} +] + +[[package]] +org = "ballerina" +name = "sql" +version = "1.11.1" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"}, + {org = "ballerina", name = "time"} +] +modules = [ + {org = "ballerina", packageName = "sql", moduleName = "sql"} +] + +[[package]] +org = "ballerina" +name = "task" +version = "2.5.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + +[[package]] +org = "ballerina" +name = "time" +version = "2.4.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "time", moduleName = "time"} +] + +[[package]] +org = "ballerina" +name = "url" +version = "2.4.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "uuid" +version = "1.7.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerinai" +name = "transaction" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "http"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.runtime"}, + {org = "ballerina", name = "lang.transaction"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "task"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "uuid"} +] +modules = [ + {org = "ballerinai", packageName = "transaction", moduleName = "transaction"} +] + +[[package]] +org = "ballerinax" +name = "h2.driver" +version = "1.1.0" +scope = "testOnly" +modules = [ + {org = "ballerinax", packageName = "h2.driver", moduleName = "h2.driver"} +] + +[[package]] +org = "ballerinax" +name = "java.jdbc" +version = "1.11.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "sql"}, + {org = "ballerina", name = "time"} +] +modules = [ + {org = "ballerinax", packageName = "java.jdbc", moduleName = "java.jdbc"} +] + +[[package]] +org = "ballerinax" +name = "mssql" +version = "1.11.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "sql"}, + {org = "ballerina", name = "time"} +] +modules = [ + {org = "ballerinax", packageName = "mssql", moduleName = "mssql"} +] + +[[package]] +org = "ballerinax" +name = "mssql.driver" +version = "1.5.0" +scope = "testOnly" +modules = [ + {org = "ballerinax", packageName = "mssql.driver", moduleName = "mssql.driver"} +] + +[[package]] +org = "ballerinax" +name = "mysql" +version = "1.11.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "sql"}, + {org = "ballerina", name = "time"} +] +modules = [ + {org = "ballerinax", packageName = "mysql", moduleName = "mysql"} +] + +[[package]] +org = "ballerinax" +name = "mysql.driver" +version = "1.5.0" +scope = "testOnly" +modules = [ + {org = "ballerinax", packageName = "mysql.driver", moduleName = "mysql.driver"} +] + +[[package]] +org = "ballerinax" +name = "persist.sql" +version = "1.2.2" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "persist"}, + {org = "ballerina", name = "sql"}, + {org = "ballerina", name = "test"}, + {org = "ballerina", name = "time"}, + {org = "ballerinai", name = "transaction"}, + {org = "ballerinax", name = "h2.driver"}, + {org = "ballerinax", name = "java.jdbc"}, + {org = "ballerinax", name = "mssql"}, + {org = "ballerinax", name = "mssql.driver"}, + {org = "ballerinax", name = "mysql"}, + {org = "ballerinax", name = "mysql.driver"}, + {org = "ballerinax", name = "postgresql"}, + {org = "ballerinax", name = "postgresql.driver"} +] +modules = [ + {org = "ballerinax", packageName = "persist.sql", moduleName = "persist.sql"} +] + +[[package]] +org = "ballerinax" +name = "postgresql" +version = "1.11.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "sql"}, + {org = "ballerina", name = "time"} +] +modules = [ + {org = "ballerinax", packageName = "postgresql", moduleName = "postgresql"} +] + +[[package]] +org = "ballerinax" +name = "postgresql.driver" +version = "1.5.0" +scope = "testOnly" +modules = [ + {org = "ballerinax", packageName = "postgresql.driver", moduleName = "postgresql.driver"} +] + diff --git a/ballerina/Module.md b/ballerina/Module.md index b36a4cd..789245f 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -2,14 +2,15 @@ This module provides relation database support for the `bal persist` feature, which provides functionality to store and query data from a relational database conveniently through a data model instead of using SQL query language. -Currently, this package supports MySQL, MSSQL, PostgreSQL as the relational database. However, we are also planning to add support for other relational databases such as Oracle. +Currently, this package supports MySQL, MSSQL, PostgreSQL, H2 as the relational database. However, we are also planning to add support for other relational databases such as Oracle. -The MySQL, MSSQL, PostgreSQL data stores are relational database management systems that stores data in tables. None of these data stores is the default data store for the `bal persist` feature. Therefore, you need to explicitly specify the data store when initializing `bal persist` in your application. as follows, +The MySQL, MSSQL, PostgreSQL, H2 data stores are relational database management systems that stores data in tables. None of these data stores is the default data store for the `bal persist` feature. Therefore, you need to explicitly specify the data store when initializing `bal persist` in your application. as follows, ``` $ bal persist init --datastore mysql $ bal persist init --datastore mssql $ bal persist init --datastore postgresql +$ bal persist init --datastore h2 ``` ## Supported Ballerina Types diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 5096aa4..2838bf4 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -142,7 +142,7 @@ static def checkExecResult(executionResult, failText, standardOutput) { task createMySQLTestDockerImage(type: Exec) { if (!Os.isFamily(Os.FAMILY_WINDOWS)) { def standardOutput = new ByteArrayOutputStream() - commandLine 'sh', '-c', "docker build --platform linux/amd64 -f $project.projectDir/tests/resources/mysql/Dockerfile -t ballerina-persist-mysql" + + commandLine 'sh', '-c', "docker build --platform linux/x86_64/v8 -f $project.projectDir/tests/resources/mysql/Dockerfile -t ballerina-persist-mysql" + " -q $project.projectDir/tests/resources/mysql/" doLast { checkExecResult(executionResult, 'Error', standardOutput) @@ -200,67 +200,67 @@ task stopMySQLTestDockerContainer() { } } -task createMSSQLTestDockerImage(type: Exec) { - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { - def standardOutput = new ByteArrayOutputStream() - commandLine 'sh', '-c', "docker build -f $project.projectDir/tests/resources/mssql/Dockerfile -t ballerina-persist-mssql" + - " -q $project.projectDir/tests/resources/mssql/" - doLast { - checkExecResult(executionResult, 'Error', standardOutput) - sleep(10 * 1000) - } - } -} +//task createMSSQLTestDockerImage(type: Exec) { +// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { +// def standardOutput = new ByteArrayOutputStream() +// commandLine 'sh', '-c', "docker build -f $project.projectDir/tests/resources/mssql/Dockerfile -t ballerina-persist-mssql" + +// " -q $project.projectDir/tests/resources/mssql/" +// doLast { +// checkExecResult(executionResult, 'Error', standardOutput) +// sleep(10 * 1000) +// } +// } +//} -def checkMSSQLTestDockerContainerStatus(containerName) { - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { - try { - return exec { - commandLine 'sh', '-c', - "docker exec ${containerName} /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Test123#" - }.exitValue - } catch (all) { - return 1; - } - } -} +//def checkMSSQLTestDockerContainerStatus(containerName) { +// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { +// try { +// return exec { +// commandLine 'sh', '-c', +// "docker exec ${containerName} /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Test123#" +// }.exitValue +// } catch (all) { +// return 1; +// } +// } +//} -task startMSSQLTestDockerContainer(type: Exec) { - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { - def standardOutput = new ByteArrayOutputStream() - commandLine 'sh', '-c', - "docker run --rm -d --name ballerina-persist-mssql -e ACCEPT_EULA=1 -e SA_PASSWORD=Test123# -p 1433:1433 -d ballerina-persist-mssql" - def healthCheck = 1; - def counter = 0; - doLast { - checkExecResult(executionResult, 'Error', standardOutput) - while (healthCheck != 0 && counter < 12) { - sleep(5 * 1000) - healthCheck = checkMSSQLTestDockerContainerStatus("ballerina-persist-mssql") - counter = counter + 1; - } - if (healthCheck != 0) { - throw new GradleException("Docker container 'ballerina-persist-mssql' health test exceeded timeout!") - } - } - } -} +//task startMSSQLTestDockerContainer(type: Exec) { +// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { +// def standardOutput = new ByteArrayOutputStream() +// commandLine 'sh', '-c', +// "docker run --rm -d --name ballerina-persist-mssql -e ACCEPT_EULA=1 -e SA_PASSWORD=Test123# -p 1433:1433 -d ballerina-persist-mssql" +// def healthCheck = 1; +// def counter = 0; +// doLast { +// checkExecResult(executionResult, 'Error', standardOutput) +// while (healthCheck != 0 && counter < 12) { +// sleep(5 * 1000) +// healthCheck = checkMSSQLTestDockerContainerStatus("ballerina-persist-mssql") +// counter = counter + 1; +// } +// if (healthCheck != 0) { +// throw new GradleException("Docker container 'ballerina-persist-mssql' health test exceeded timeout!") +// } +// } +// } +//} -task stopMSSQLTestDockerContainer() { - doLast { - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { - try { - def stdOut = new ByteArrayOutputStream() - exec { - commandLine 'sh', '-c', "docker stop ballerina-persist-mssql" - standardOutput = stdOut - } - } catch (all) { - println("Process can safely ignore stopTestDockerContainer task") - } - } - } -} +//task stopMSSQLTestDockerContainer() { +// doLast { +// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { +// try { +// def stdOut = new ByteArrayOutputStream() +// exec { +// commandLine 'sh', '-c', "docker stop ballerina-persist-mssql" +// standardOutput = stdOut +// } +// } catch (all) { +// println("Process can safely ignore stopTestDockerContainer task") +// } +// } +// } +//} task createPostgreSQLTestDockerImage(type: Exec) { if (!Os.isFamily(Os.FAMILY_WINDOWS)) { @@ -325,18 +325,18 @@ task stopPostgreSQLTestDockerContainer() { updateTomlFiles.dependsOn copyStdlibs startMySQLTestDockerContainer.dependsOn createMySQLTestDockerImage -startMSSQLTestDockerContainer.dependsOn createMSSQLTestDockerImage +//startMSSQLTestDockerContainer.dependsOn createMSSQLTestDockerImage startPostgreSQLTestDockerContainer.dependsOn createPostgreSQLTestDockerImage build.dependsOn "generatePomFileForMavenPublication" build.dependsOn ":${packageName}-compiler-plugin:build" build.dependsOn ":${packageName}-native:build" build.finalizedBy stopMySQLTestDockerContainer -build.finalizedBy stopMSSQLTestDockerContainer +//build.finalizedBy stopMSSQLTestDockerContainer build.finalizedBy stopPostgreSQLTestDockerContainer test.dependsOn ":${packageName}-compiler-plugin:build" test.dependsOn ":${packageName}-native:build" test.dependsOn startMySQLTestDockerContainer -test.dependsOn startMSSQLTestDockerContainer +//test.dependsOn startMSSQLTestDockerContainer test.dependsOn startPostgreSQLTestDockerContainer diff --git a/ballerina/constants.bal b/ballerina/constants.bal index 755693a..b09b8c2 100644 --- a/ballerina/constants.bal +++ b/ballerina/constants.bal @@ -40,3 +40,12 @@ public final DataSourceSpecifics & readonly POSTGRESQL_SPECIFICS = { duplicateKeyStartIndicator: "Detail: Key ", duplicateKeyEndIndicator: " already exists." }; + +public final DataSourceSpecifics & readonly H2_SPECIFICS = { + quoteOpen: "\"", + quoteClose: "\"", + constraintViolationErrorMessage: "Referential integrity constraint violation", + duplicateEntryErrorMessage: "Unique index or primary key violation", + duplicateKeyStartIndicator: "Unique index or primary key violation: \"", + duplicateKeyEndIndicator: " ON " +}; diff --git a/ballerina/tests/Config.toml b/ballerina/tests/Config.toml index 15feb58..b3130f8 100644 --- a/ballerina/tests/Config.toml +++ b/ballerina/tests/Config.toml @@ -1,3 +1,7 @@ +h2Url="jdbc:h2:./build/test" +h2User="sa" +h2Password="" + [mysql] user="root" password="Test123#" @@ -22,3 +26,8 @@ password="postgres" host="localhost" port=5432 database="test" + +[h2] +url="jdbc:h2:./build/test" +user="sa" +password="" diff --git a/ballerina/tests/h2-all-types-tests.bal b/ballerina/tests/h2-all-types-tests.bal new file mode 100644 index 0000000..7a3fc04 --- /dev/null +++ b/ballerina/tests/h2-all-types-tests.bal @@ -0,0 +1,228 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; +import ballerina/persist; + +@test:Config { + groups: ["all-types", "h2"] +} +function h2AllTypesCreateTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + + int[] ids = check testEntitiesClient->/alltypes.post([allTypes1, allTypes2]); + test:assertEquals(ids, [allTypes1.id, allTypes2.id]); + + AllTypes allTypesRetrieved = check testEntitiesClient->/alltypes/[allTypes1.id].get(); + test:assertEquals(allTypesRetrieved, allTypes1Expected); + + allTypesRetrieved = check testEntitiesClient->/alltypes/[allTypes2.id].get(); + test:assertEquals(allTypesRetrieved, allTypes2Expected); + + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["all-types", "h2"] +} +function h2AllTypesCreateOptionalTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + + int[] ids = check testEntitiesClient->/alltypes.post([allTypes3]); + test:assertEquals(ids, [allTypes3.id]); + + AllTypes allTypesRetrieved = check testEntitiesClient->/alltypes/[allTypes3.id].get(); + test:assertEquals(allTypesRetrieved, allTypes3Expected); + + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["all-types", "h2"], + dependsOn: [h2AllTypesCreateTest, h2AllTypesCreateOptionalTest] +} +function h2AllTypesReadTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + + stream allTypesStream = testEntitiesClient->/alltypes.get(); + AllTypes[] allTypes = check from AllTypes allTypesRecord in allTypesStream + select allTypesRecord; + + test:assertEquals(allTypes, [allTypes1Expected, allTypes2Expected, allTypes3Expected]); + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["all-types", "h2", "dependent"], + dependsOn: [h2AllTypesCreateTest, h2AllTypesCreateOptionalTest] +} +function h2AllTypesReadDependentTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + + stream allTypesStream = testEntitiesClient->/alltypes.get(); + AllTypesDependent[] allTypes = check from AllTypesDependent allTypesRecord in allTypesStream + select allTypesRecord; + + test:assertEquals(allTypes, [ + { + booleanType: allTypes1Expected.booleanType, + intType: allTypes1Expected.intType, + floatType: allTypes1Expected.floatType, + decimalType: allTypes1Expected.decimalType, + stringType: allTypes1Expected.stringType, + byteArrayType: allTypes1Expected.byteArrayType, + dateType: allTypes1Expected.dateType, + timeOfDayType: allTypes1Expected.timeOfDayType, + civilType: allTypes1Expected.civilType, + booleanTypeOptional: allTypes1Expected.booleanTypeOptional, + intTypeOptional: allTypes1Expected.intTypeOptional, + floatTypeOptional: allTypes1Expected.floatTypeOptional, + decimalTypeOptional: allTypes1Expected.decimalTypeOptional, + stringTypeOptional: allTypes1Expected.stringTypeOptional, + dateTypeOptional: allTypes1Expected.dateTypeOptional, + timeOfDayTypeOptional: allTypes1Expected.timeOfDayTypeOptional, + civilTypeOptional: allTypes1Expected.civilTypeOptional + }, + { + booleanType: allTypes2Expected.booleanType, + intType: allTypes2Expected.intType, + floatType: allTypes2Expected.floatType, + decimalType: allTypes2Expected.decimalType, + stringType: allTypes2Expected.stringType, + byteArrayType: allTypes2Expected.byteArrayType, + dateType: allTypes2Expected.dateType, + timeOfDayType: allTypes2Expected.timeOfDayType, + civilType: allTypes2Expected.civilType, + booleanTypeOptional: allTypes2Expected.booleanTypeOptional, + intTypeOptional: allTypes2Expected.intTypeOptional, + floatTypeOptional: allTypes2Expected.floatTypeOptional, + decimalTypeOptional: allTypes2Expected.decimalTypeOptional, + stringTypeOptional: allTypes2Expected.stringTypeOptional, + dateTypeOptional: allTypes2Expected.dateTypeOptional, + timeOfDayTypeOptional: allTypes2Expected.timeOfDayTypeOptional, + civilTypeOptional: allTypes2Expected.civilTypeOptional + }, + { + booleanType: allTypes3Expected.booleanType, + intType: allTypes3Expected.intType, + floatType: allTypes3Expected.floatType, + decimalType: allTypes3Expected.decimalType, + stringType: allTypes3Expected.stringType, + byteArrayType: allTypes3Expected.byteArrayType, + dateType: allTypes3Expected.dateType, + timeOfDayType: allTypes3Expected.timeOfDayType, + civilType: allTypes3Expected.civilType, + booleanTypeOptional: allTypes3Expected.booleanTypeOptional, + intTypeOptional: allTypes3Expected.intTypeOptional, + floatTypeOptional: allTypes3Expected.floatTypeOptional, + decimalTypeOptional: allTypes3Expected.decimalTypeOptional, + stringTypeOptional: allTypes3Expected.stringTypeOptional, + dateTypeOptional: allTypes3Expected.dateTypeOptional, + timeOfDayTypeOptional: allTypes3Expected.timeOfDayTypeOptional, + civilTypeOptional: allTypes3Expected.civilTypeOptional + } + ]); + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["all-types", "h2"], + dependsOn: [h2AllTypesCreateTest, h2AllTypesCreateOptionalTest] +} +function h2AllTypesReadOneTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + + AllTypes allTypesRetrieved = check testEntitiesClient->/alltypes/[allTypes1.id].get(); + test:assertEquals(allTypesRetrieved, allTypes1Expected); + + allTypesRetrieved = check testEntitiesClient->/alltypes/[allTypes2.id].get(); + test:assertEquals(allTypesRetrieved, allTypes2Expected); + + allTypesRetrieved = check testEntitiesClient->/alltypes/[allTypes3.id].get(); + test:assertEquals(allTypesRetrieved, allTypes3Expected); + + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["all-types", "h2"] +} +function h2AllTypesReadOneTestNegative() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + + AllTypes|persist:Error allTypesRetrieved = testEntitiesClient->/alltypes/[4].get(); + if allTypesRetrieved is persist:NotFoundError { + test:assertEquals(allTypesRetrieved.message(), "A record with the key '4' does not exist for the entity 'AllTypes'."); + } + else { + test:assertFail("persist:NotFoundError expected."); + } + + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["all-types", "h2"], + dependsOn: [h2AllTypesReadOneTest, h2AllTypesReadTest, h2AllTypesReadDependentTest] +} +function h2AllTypesUpdateTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + + AllTypes allTypes = check testEntitiesClient->/alltypes/[allTypes1.id].put({ + booleanType: allTypes3.booleanType, + intType: allTypes1Updated.intType, + floatType: allTypes1Updated.floatType, + decimalType: allTypes1Updated.decimalType, + stringType: allTypes1Updated.stringType, + byteArrayType: allTypes1Updated.byteArrayType, + dateType: allTypes1Updated.dateType, + timeOfDayType: allTypes1Updated.timeOfDayType, + civilType: allTypes1Updated.civilType, + booleanTypeOptional: allTypes1Updated.booleanTypeOptional, + intTypeOptional: allTypes1Updated.intTypeOptional, + floatTypeOptional: allTypes1Updated.floatTypeOptional, + decimalTypeOptional: allTypes1Updated.decimalTypeOptional, + stringTypeOptional: allTypes1Updated.stringTypeOptional, + dateTypeOptional: allTypes1Updated.dateTypeOptional, + timeOfDayTypeOptional: allTypes1Updated.timeOfDayTypeOptional, + civilTypeOptional: allTypes1Updated.civilTypeOptional, + enumType: allTypes1Updated.enumType, + enumTypeOptional: allTypes1Updated.enumTypeOptional + }); + test:assertEquals(allTypes, allTypes1UpdatedExpected); + + AllTypes allTypesRetrieved = check testEntitiesClient->/alltypes/[allTypes1.id].get(); + test:assertEquals(allTypesRetrieved, allTypes1UpdatedExpected); + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["all-types", "h2"], + dependsOn: [h2AllTypesUpdateTest] +} +function h2AllTypesDeleteTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + + AllTypes allTypes = check testEntitiesClient->/alltypes/[allTypes2.id].delete(); + test:assertEquals(allTypes, allTypes2Expected); + + stream allTypesStream = testEntitiesClient->/alltypes.get(); + AllTypes[] allTypesCollection = check from AllTypes allTypesRecord in allTypesStream + select allTypesRecord; + + test:assertEquals(allTypesCollection, [allTypes1UpdatedExpected, allTypes3Expected]); + check testEntitiesClient.close(); +} diff --git a/ballerina/tests/h2-associations-tests.bal b/ballerina/tests/h2-associations-tests.bal new file mode 100644 index 0000000..4336c4f --- /dev/null +++ b/ballerina/tests/h2-associations-tests.bal @@ -0,0 +1,288 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; +import ballerina/persist; + +@test:Config { + groups: ["associations", "h2"], + dependsOn: [h2EmployeeDeleteTestNegative] +} +function h2EmployeeRelationsTest() returns error? { + H2RainierClient rainierClient = check new (); + + Employee employee21 = { + empNo: "employee-21", + firstName: "Tom", + lastName: "Scott", + birthDate: {year: 1992, month: 11, day: 13}, + gender: MALE, + hireDate: {year: 2022, month: 8, day: 1}, + departmentDeptNo: "department-22", + workspaceWorkspaceId: "workspace-22" + }; + + Workspace workspace22 = { + workspaceId: "workspace-22", + workspaceType: "medium", + locationBuildingCode: "building-22" + }; + + BuildingInsert building22 = { + buildingCode: "building-22", + city: "Manhattan", + state: "New York", + country: "USA", + postalCode: "10570", + 'type: "owned" + }; + + Department department22 = { + deptNo: "department-22", + deptName: "Marketing" + }; + + _ = check rainierClient->/buildings.post([building22]); + _ = check rainierClient->/departments.post([department22]); + _ = check rainierClient->/workspaces.post([workspace22]); + _ = check rainierClient->/employees.post([employee21]); + + stream employeeStream = rainierClient->/employees.get(); + EmployeeInfo[] employees = check from EmployeeInfo employee in employeeStream + select employee; + + EmployeeInfo retrieved = check rainierClient->/employees/["employee-21"].get(); + + EmployeeInfo expected = { + firstName: "Tom", + lastName: "Scott", + department: { + deptName: "Marketing" + }, + workspace: { + workspaceId: "workspace-22", + workspaceType: "medium", + locationBuildingCode: "building-22" + } + }; + + test:assertTrue(employees.indexOf(expected) is int, "Expected EmployeeInfo not found."); + test:assertEquals(retrieved, expected); + check rainierClient.close(); +} + +@test:Config { + groups: ["associations", "h2"], + dependsOn: [h2EmployeeDeleteTestNegative] +} +function h2DepartmentRelationsTest() returns error? { + H2RainierClient rainierClient = check new (); + + Employee employee11 = { + empNo: "employee-11", + firstName: "Tom", + lastName: "Scott", + birthDate: {year: 1992, month: 11, day: 13}, + gender: MALE, + hireDate: {year: 2022, month: 8, day: 1}, + departmentDeptNo: "department-12", + workspaceWorkspaceId: "workspace-12" + }; + + Employee employee12 = { + empNo: "employee-12", + firstName: "Jane", + lastName: "Doe", + birthDate: {year: 1996, month: 9, day: 15}, + gender: FEMALE, + hireDate: {year: 2022, month: 6, day: 1}, + departmentDeptNo: "department-12", + workspaceWorkspaceId: "workspace-12" + }; + + Workspace workspace12 = { + workspaceId: "workspace-12", + workspaceType: "medium", + locationBuildingCode: "building-12" + }; + + BuildingInsert building12 = { + buildingCode: "building-12", + city: "Manhattan", + state: "New York", + country: "USA", + postalCode: "10570", + 'type: "owned" + }; + + Department department12 = { + deptNo: "department-12", + deptName: "Marketing" + }; + + _ = check rainierClient->/buildings.post([building12]); + _ = check rainierClient->/departments.post([department12]); + _ = check rainierClient->/workspaces.post([workspace12]); + _ = check rainierClient->/employees.post([employee11, employee12]); + + stream departmentStream = rainierClient->/departments.get(); + DepartmentInfo[] departments = check from DepartmentInfo department in departmentStream + select department; + + DepartmentInfo retrieved = check rainierClient->/departments/["department-12"].get(); + + DepartmentInfo expected = { + deptNo: "department-12", + deptName: "Marketing", + employees: [ + { + firstName: "Tom", + lastName: "Scott" + }, + { + firstName: "Jane", + lastName: "Doe" + } + ] + }; + + test:assertTrue(departments.indexOf(expected) is int, "Expected DepartmentInfo not found."); + test:assertEquals(retrieved, expected); + check rainierClient.close(); +} + +@test:Config { + groups: ["associations", "h2"], + dependsOn: [h2EmployeeRelationsTest] +} +function h2WorkspaceRelationsTest() returns error? { + H2RainierClient rainierClient = check new (); + + Employee employee22 = { + empNo: "employee-22", + firstName: "James", + lastName: "David", + birthDate: {year: 1996, month: 11, day: 13}, + gender: FEMALE, + hireDate: {year: 2021, month: 8, day: 1}, + departmentDeptNo: "department-22", + workspaceWorkspaceId: "workspace-22" + }; + _ = check rainierClient->/employees.post([employee22]); + + stream workspaceStream = rainierClient->/workspaces.get(); + WorkspaceInfo[] workspaces = check from WorkspaceInfo workspace in workspaceStream + select workspace; + + WorkspaceInfo retrieved = check rainierClient->/workspaces/["workspace-22"].get(); + + WorkspaceInfo expected = { + workspaceType: "medium", + location: { + buildingCode: "building-22", + city: "Manhattan", + state: "New York", + country: "USA", + postalCode: "10570", + 'type: "owned" + }, + employees: [ + { + empNo: "employee-21", + firstName: "Tom", + lastName: "Scott", + birthDate: {year: 1992, month: 11, day: 13}, + gender: MALE, + hireDate: {year: 2022, month: 8, day: 1}, + departmentDeptNo: "department-22", + workspaceWorkspaceId: "workspace-22" + }, + { + empNo: "employee-22", + firstName: "James", + lastName: "David", + birthDate: {year: 1996, month: 11, day: 13}, + gender: FEMALE, + hireDate: {year: 2021, month: 8, day: 1}, + departmentDeptNo: "department-22", + workspaceWorkspaceId: "workspace-22" + } + ] + }; + + boolean found = false; + _ = from WorkspaceInfo workspace in workspaces + do { + if workspace == expected { + found = true; + } + }; + + if !found { + test:assertFail("Expected WorkspaceInfo not found."); + } + + test:assertEquals(retrieved, expected); + + check rainierClient.close(); +} + +@test:Config { + groups: ["associations", "h2"], + dependsOn: [h2EmployeeRelationsTest] +} +function h2BuildingRelationsTest() returns error? { + H2RainierClient rainierClient = check new (); + + stream buildingStream = rainierClient->/buildings.get(); + BuildingInfo[] buildings = check from BuildingInfo building in buildingStream + select building; + + BuildingInfo retrieved = check rainierClient->/buildings/["building-22"].get(); + + BuildingInfo expected = { + buildingCode: "building-22", + city: "Manhattan", + state: "New York", + country: "USA", + postalCode: "10570", + 'type: "owned", + workspaces: [ + { + workspaceId: "workspace-22", + workspaceType: "medium", + locationBuildingCode: "building-22" + } + ] + }; + + boolean found = false; + _ = from BuildingInfo building in buildings + do { + if (building.buildingCode == "building-22") { + found = true; + test:assertEquals(building, expected); + } + }; + + if !found { + test:assertFail("Expected BuildingInfo not found."); + } + + test:assertEquals(retrieved, expected); + + check rainierClient.close(); +} diff --git a/ballerina/tests/h2-building-tests.bal b/ballerina/tests/h2-building-tests.bal new file mode 100644 index 0000000..1439697 --- /dev/null +++ b/ballerina/tests/h2-building-tests.bal @@ -0,0 +1,226 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; +import ballerina/persist; + +@test:Config { + groups: ["building", "h2"] +} +function h2BuildingCreateTest() returns error? { + H2RainierClient rainierClient = check new (); + + string[] buildingCodes = check rainierClient->/buildings.post([building1]); + test:assertEquals(buildingCodes, [building1.buildingCode]); + + Building buildingRetrieved = check rainierClient->/buildings/[building1.buildingCode].get(); + test:assertEquals(buildingRetrieved, building1); + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2"] +} +function h2BuildingCreateTest2() returns error? { + H2RainierClient rainierClient = check new (); + + string[] buildingCodes = check rainierClient->/buildings.post([building2, building3]); + + test:assertEquals(buildingCodes, [building2.buildingCode, building3.buildingCode]); + + Building buildingRetrieved = check rainierClient->/buildings/[building2.buildingCode].get(); + test:assertEquals(buildingRetrieved, building2); + + buildingRetrieved = check rainierClient->/buildings/[building3.buildingCode].get(); + test:assertEquals(buildingRetrieved, building3); + + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2"] +} +function h2BuildingCreateTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + string[]|error building = rainierClient->/buildings.post([invalidBuilding]); + if building is persist:Error { + test:assertTrue(building.message().includes("Value too long for column \"buildingCode CHARACTER VARYING(36)")); + } else { + test:assertFail("Error expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2"], + dependsOn: [h2BuildingCreateTest] +} +function h2BuildingReadOneTest() returns error? { + H2RainierClient rainierClient = check new (); + + Building buildingRetrieved = check rainierClient->/buildings/[building1.buildingCode].get(); + test:assertEquals(buildingRetrieved, building1); + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2"], + dependsOn: [h2BuildingCreateTest] +} +function h2BuildingReadOneTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + Building|error buildingRetrieved = rainierClient->/buildings/["invalid-building-code"].get(); + if buildingRetrieved is persist:NotFoundError { + test:assertEquals(buildingRetrieved.message(), "A record with the key 'invalid-building-code' does not exist for the entity 'Building'."); + } else { + test:assertFail("persist:NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2"], + dependsOn: [h2BuildingCreateTest, h2BuildingCreateTest2] +} +function h2BuildingReadManyTest() returns error? { + H2RainierClient rainierClient = check new (); + + stream buildingStream = rainierClient->/buildings.get(); + Building[] buildings = check from Building building in buildingStream + select building; + + test:assertEquals(buildings, [building1, building2, building3]); + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2", "dependent"], + dependsOn: [h2BuildingCreateTest, h2BuildingCreateTest2] +} +function h2BuildingReadManyDependentTest() returns error? { + H2RainierClient rainierClient = check new (); + + stream buildingStream = rainierClient->/buildings.get(); + BuildingInfo2[] buildings = check from BuildingInfo2 building in buildingStream + select building; + + test:assertEquals(buildings, [ + {city: building1.city, state: building1.state, country: building1.country, postalCode: building1.postalCode, 'type: building1.'type}, + {city: building2.city, state: building2.state, country: building2.country, postalCode: building2.postalCode, 'type: building2.'type}, + {city: building3.city, state: building3.state, country: building3.country, postalCode: building3.postalCode, 'type: building3.'type} + ]); + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2"], + dependsOn: [h2BuildingReadOneTest, h2BuildingReadManyTest, h2BuildingReadManyDependentTest] +} +function h2BuildingUpdateTest() returns error? { + H2RainierClient rainierClient = check new (); + + Building building = check rainierClient->/buildings/[building1.buildingCode].put({ + city: "Galle", + state: "Southern Province", + postalCode: "10890", + 'type: "owned" + }); + + test:assertEquals(building, updatedBuilding1); + + Building buildingRetrieved = check rainierClient->/buildings/[building1.buildingCode].get(); + test:assertEquals(buildingRetrieved, updatedBuilding1); + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2"], + dependsOn: [h2BuildingReadOneTest, h2BuildingReadManyTest, h2BuildingReadManyDependentTest] +} +function h2BuildingUpdateTestNegative1() returns error? { + H2RainierClient rainierClient = check new (); + + Building|error building = rainierClient->/buildings/["invalid-building-code"].put({ + city: "Galle", + state: "Southern Province", + postalCode: "10890" + }); + + if building is persist:NotFoundError { + test:assertEquals(building.message(), "A record with the key 'invalid-building-code' does not exist for the entity 'Building'."); + } else { + test:assertFail("persist:NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2"], + dependsOn: [h2BuildingReadOneTest, h2BuildingReadManyTest, h2BuildingReadManyDependentTest] +} +function h2BuildingUpdateTestNegative2() returns error? { + H2RainierClient rainierClient = check new (); + + Building|error building = rainierClient->/buildings/[building1.buildingCode].put({ + city: "unncessarily-long-city-name-to-force-error-on-update", + state: "Southern Province", + postalCode: "10890" + }); + + if building is persist:Error { + test:assertTrue(building.message().includes("unncessarily-long-city-name-to-force-error-on-update")); + } else { + test:assertFail("persist:NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2"], + dependsOn: [h2BuildingUpdateTest, h2BuildingUpdateTestNegative2] +} +function h2BuildingDeleteTest() returns error? { + H2RainierClient rainierClient = check new (); + + Building building = check rainierClient->/buildings/[building1.buildingCode].delete(); + test:assertEquals(building, updatedBuilding1); + + stream buildingStream = rainierClient->/buildings.get(); + Building[] buildings = check from Building building2 in buildingStream + select building2; + + test:assertEquals(buildings, [building2, building3]); + check rainierClient.close(); +} + +@test:Config { + groups: ["building", "h2"], + dependsOn: [h2BuildingDeleteTest] +} +function h2BuildingDeleteTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + Building|error building = rainierClient->/buildings/[building1.buildingCode].delete(); + + if building is error { + test:assertEquals(building.message(), string `A record with the key '${building1.buildingCode}' does not exist for the entity 'Building'.`); + } else { + test:assertFail("persist:NotFoundError expected."); + } + check rainierClient.close(); +} diff --git a/ballerina/tests/h2-composite-key-tests.bal b/ballerina/tests/h2-composite-key-tests.bal new file mode 100644 index 0000000..96f73de --- /dev/null +++ b/ballerina/tests/h2-composite-key-tests.bal @@ -0,0 +1,196 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; +import ballerina/persist; + +@test:Config { + groups: ["composite-key", "h2"] +} +function h2CompositeKeyCreateTest() returns error? { + H2RainierClient rainierClient = check new (); + + [string, string][] ids = check rainierClient->/orderitems.post([orderItem1, orderItem2]); + test:assertEquals(ids, [[orderItem1.orderId, orderItem1.itemId], [orderItem2.orderId, orderItem2.itemId]]); + + OrderItem orderItemRetrieved = check rainierClient->/orderitems/[orderItem1.orderId]/[orderItem1.itemId].get(); + test:assertEquals(orderItemRetrieved, orderItem1); + + orderItemRetrieved = check rainierClient->/orderitems/[orderItem2.orderId]/[orderItem2.itemId].get(); + test:assertEquals(orderItemRetrieved, orderItem2); + + check rainierClient.close(); +} + +@test:Config { + groups: ["composite-key", "h2"], + dependsOn: [h2CompositeKeyCreateTest] +} +function h2CompositeKeyCreateTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + [string, string][]|error ids = rainierClient->/orderitems.post([orderItem1]); + if ids is persist:AlreadyExistsError { + test:assertEquals(ids.message(), "A record with the key 'PUBLIC.PRIMARY_KEY_6' already exists for the entity 'OrderItem'."); + } else { + test:assertFail("persist:AlreadyExistsError expected"); + } + + check rainierClient.close(); +} + +@test:Config { + groups: ["composite-key", "h2"], + dependsOn: [h2CompositeKeyCreateTest] +} +function h2CompositeKeyReadManyTest() returns error? { + H2RainierClient rainierClient = check new (); + + stream orderItemStream = rainierClient->/orderitems.get(); + OrderItem[] orderitem = check from OrderItem orderItem in orderItemStream + select orderItem; + + test:assertEquals(orderitem, [orderItem1, orderItem2]); + check rainierClient.close(); +} + +@test:Config { + groups: ["composite-key", "h2"], + dependsOn: [h2CompositeKeyCreateTest] +} +function h2CompositeKeyReadOneTest() returns error? { + H2RainierClient rainierClient = check new (); + OrderItem orderItem = check rainierClient->/orderitems/[orderItem1.orderId]/[orderItem1.itemId].get(); + test:assertEquals(orderItem, orderItem1); + check rainierClient.close(); +} + +@test:Config { + groups: ["composite-key2"], + dependsOn: [h2CompositeKeyCreateTest] +} +function h2CompositeKeyReadOneTest2() returns error? { + H2RainierClient rainierClient = check new (); + OrderItem orderItem = check rainierClient->/orderitems/[orderItem1.orderId]/[orderItem1.itemId].get(); + test:assertEquals(orderItem, orderItem1); + check rainierClient.close(); +} + +@test:Config { + groups: ["composite-key", "h2"], + dependsOn: [h2CompositeKeyCreateTest] +} +function h2CompositeKeyReadOneTestNegative1() returns error? { + H2RainierClient rainierClient = check new (); + OrderItem|error orderItem = rainierClient->/orderitems/["invalid-order-id"]/[orderItem1.itemId].get(); + + if orderItem is persist:NotFoundError { + test:assertEquals(orderItem.message(), "A record with the key '{\"orderId\":\"invalid-order-id\",\"itemId\":\"item-1\"}' does not exist for the entity 'OrderItem'."); + } else { + test:assertFail("Error expected."); + } + + check rainierClient.close(); +} + +@test:Config { + groups: ["composite-key", "h2"], + dependsOn: [h2CompositeKeyCreateTest] +} +function h2CompositeKeyReadOneTestNegative2() returns error? { + H2RainierClient rainierClient = check new (); + OrderItem|error orderItem = rainierClient->/orderitems/[orderItem1.orderId]/["invalid-item-id"].get(); + + if orderItem is persist:NotFoundError { + test:assertEquals(orderItem.message(), "A record with the key '{\"orderId\":\"order-1\",\"itemId\":\"invalid-item-id\"}' does not exist for the entity 'OrderItem'."); + } else { + test:assertFail("Error expected."); + } + + check rainierClient.close(); +} + +@test:Config { + groups: ["composite-key", "h2"], + dependsOn: [h2CompositeKeyCreateTest, h2CompositeKeyReadOneTest, h2CompositeKeyReadManyTest, h2CompositeKeyReadOneTest2] +} +function h2CompositeKeyUpdateTest() returns error? { + H2RainierClient rainierClient = check new (); + + OrderItem orderItem = check rainierClient->/orderitems/[orderItem2.orderId]/[orderItem2.itemId].put({ + quantity: orderItem2Updated.quantity, + notes: orderItem2Updated.notes + }); + test:assertEquals(orderItem, orderItem2Updated); + + orderItem = check rainierClient->/orderitems/[orderItem2.orderId]/[orderItem2.itemId].get(); + test:assertEquals(orderItem, orderItem2Updated); + + check rainierClient.close(); +} + +@test:Config { + groups: ["composite-key", "h2"], + dependsOn: [h2CompositeKeyCreateTest, h2CompositeKeyReadOneTest, h2CompositeKeyReadManyTest, h2CompositeKeyReadOneTest2] +} +function h2CompositeKeyUpdateTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + OrderItem|error orderItem = rainierClient->/orderitems/[orderItem1.orderId]/[orderItem2.itemId].put({ + quantity: 239, + notes: "updated notes" + }); + if orderItem is persist:NotFoundError { + test:assertEquals(orderItem.message(), "A record with the key '{\"orderId\":\"order-1\",\"itemId\":\"item-2\"}' does not exist for the entity 'OrderItem'."); + } else { + test:assertFail("Error expected."); + } + + check rainierClient.close(); +} + +@test:Config { + groups: ["composite-key", "h2"], + dependsOn: [h2CompositeKeyUpdateTest] +} +function h2CompositeKeyDeleteTest() returns error? { + H2RainierClient rainierClient = check new (); + + OrderItem orderItem = check rainierClient->/orderitems/[orderItem2.orderId]/[orderItem2.itemId].delete(); + test:assertEquals(orderItem, orderItem2Updated); + + OrderItem|error orderItemRetrieved = rainierClient->/orderitems/[orderItem2.orderId]/[orderItem2.itemId].get(); + test:assertTrue(orderItemRetrieved is persist:NotFoundError); + + check rainierClient.close(); +} + +@test:Config { + groups: ["composite-key", "h2"], + dependsOn: [h2CompositeKeyUpdateTest] +} +function h2CompositeKeyDeleteTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + OrderItem|error orderItem = rainierClient->/orderitems/["invalid-order-id"]/[orderItem2.itemId].delete(); + if orderItem is persist:NotFoundError { + test:assertEquals(orderItem.message(), "A record with the key '{\"orderId\":\"invalid-order-id\",\"itemId\":\"item-2\"}' does not exist for the entity 'OrderItem'."); + } else { + test:assertFail("Error expected."); + } + + check rainierClient.close(); +} diff --git a/ballerina/tests/h2-department-tests.bal b/ballerina/tests/h2-department-tests.bal new file mode 100644 index 0000000..4d223c2 --- /dev/null +++ b/ballerina/tests/h2-department-tests.bal @@ -0,0 +1,217 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; +import ballerina/persist; + +@test:Config { + groups: ["department", "h2"] +} +function h2DepartmentCreateTest() returns error? { + H2RainierClient rainierClient = check new (); + + string[] deptNos = check rainierClient->/departments.post([department1]); + test:assertEquals(deptNos, [department1.deptNo]); + + Department departmentRetrieved = check rainierClient->/departments/[department1.deptNo].get(); + test:assertEquals(departmentRetrieved, department1); + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2"] +} +function h2DepartmentCreateTest2() returns error? { + H2RainierClient rainierClient = check new (); + + string[] deptNos = check rainierClient->/departments.post([department2, department3]); + + test:assertEquals(deptNos, [department2.deptNo, department3.deptNo]); + + Department departmentRetrieved = check rainierClient->/departments/[department2.deptNo].get(); + test:assertEquals(departmentRetrieved, department2); + + departmentRetrieved = check rainierClient->/departments/[department3.deptNo].get(); + test:assertEquals(departmentRetrieved, department3); + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2"] +} +function h2DepartmentCreateTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + string[]|error department = rainierClient->/departments.post([invalidDepartment]); + if department is persist:Error { + test:assertTrue(department.message().includes(".Value too long for column \"deptNo CHARACTER VARYING(36)")); + } else { + test:assertFail("Error expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2"], + dependsOn: [h2DepartmentCreateTest] +} +function h2DepartmentReadOneTest() returns error? { + H2RainierClient rainierClient = check new (); + + Department departmentRetrieved = check rainierClient->/departments/[department1.deptNo].get(); + test:assertEquals(departmentRetrieved, department1); + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2"], + dependsOn: [h2DepartmentCreateTest] +} +function h2DepartmentReadOneTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + Department|error departmentRetrieved = rainierClient->/departments/["invalid-department-id"].get(); + if departmentRetrieved is persist:NotFoundError { + test:assertEquals(departmentRetrieved.message(), "A record with the key 'invalid-department-id' does not exist for the entity 'Department'."); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2"], + dependsOn: [h2DepartmentCreateTest, h2DepartmentCreateTest2] +} +function h2DepartmentReadManyTest() returns error? { + H2RainierClient rainierClient = check new (); + stream departmentStream = rainierClient->/departments.get(); + Department[] departments = check from Department department in departmentStream + select department; + + test:assertEquals(departments, [department1, department2, department3]); + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2", "dependent"], + dependsOn: [h2DepartmentCreateTest, h2DepartmentCreateTest2] +} +function h2DepartmentReadManyTestDependent() returns error? { + H2RainierClient rainierClient = check new (); + + stream departmentStream = rainierClient->/departments.get(); + DepartmentInfo2[] departments = check from DepartmentInfo2 department in departmentStream + select department; + + test:assertEquals(departments, [ + {deptName: department1.deptName}, + {deptName: department2.deptName}, + {deptName: department3.deptName} + ]); + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2"], + dependsOn: [h2DepartmentReadOneTest, h2DepartmentReadManyTest, h2DepartmentReadManyTestDependent] +} +function h2DepartmentUpdateTest() returns error? { + H2RainierClient rainierClient = check new (); + + Department department = check rainierClient->/departments/[department1.deptNo].put({ + deptName: "Finance & Legalities" + }); + + test:assertEquals(department, updatedDepartment1); + + Department departmentRetrieved = check rainierClient->/departments/[department1.deptNo].get(); + test:assertEquals(departmentRetrieved, updatedDepartment1); + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2"], + dependsOn: [h2DepartmentReadOneTest, h2DepartmentReadManyTest, h2DepartmentReadManyTestDependent] +} +function h2DepartmentUpdateTestNegative1() returns error? { + H2RainierClient rainierClient = check new (); + + Department|error department = rainierClient->/departments/["invalid-department-id"].put({ + deptName: "Human Resources" + }); + + if department is persist:NotFoundError { + test:assertEquals(department.message(), "A record with the key 'invalid-department-id' does not exist for the entity 'Department'."); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2"], + dependsOn: [h2DepartmentReadOneTest, h2DepartmentReadManyTest, h2DepartmentReadManyTestDependent] +} +function h2DepartmentUpdateTestNegative2() returns error? { + H2RainierClient rainierClient = check new (); + + Department|error department = rainierClient->/departments/[department1.deptNo].put({ + deptName: "unncessarily-long-department-name-to-force-error-on-update" + }); + + if department is persist:Error { + test:assertTrue(department.message().includes("Value too long for column \"deptName CHARACTER VARYING(30)")); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2"], + dependsOn: [h2DepartmentUpdateTest, h2DepartmentUpdateTestNegative2] +} +function h2DepartmentDeleteTest() returns error? { + H2RainierClient rainierClient = check new (); + + Department department = check rainierClient->/departments/[department1.deptNo].delete(); + test:assertEquals(department, updatedDepartment1); + + stream departmentStream = rainierClient->/departments.get(); + Department[] departments = check from Department department2 in departmentStream + select department2; + + test:assertEquals(departments, [department2, department3]); + check rainierClient.close(); +} + +@test:Config { + groups: ["department", "h2"], + dependsOn: [h2DepartmentDeleteTest] +} +function h2DepartmentDeleteTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + Department|error department = rainierClient->/departments/[department1.deptNo].delete(); + + if department is persist:NotFoundError { + test:assertEquals(department.message(), string `A record with the key '${department1.deptNo}' does not exist for the entity 'Department'.`); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} diff --git a/ballerina/tests/h2-employee-tests.bal b/ballerina/tests/h2-employee-tests.bal new file mode 100644 index 0000000..7813ced --- /dev/null +++ b/ballerina/tests/h2-employee-tests.bal @@ -0,0 +1,260 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; +import ballerina/persist; + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2WorkspaceDeleteTestNegative, h2DepartmentDeleteTestNegative] +} +function h2EmployeeCreateTest() returns error? { + H2RainierClient rainierClient = check new (); + + string[] empNos = check rainierClient->/employees.post([employee1]); + test:assertEquals(empNos, [employee1.empNo]); + + Employee employeeRetrieved = check rainierClient->/employees/[employee1.empNo].get(); + test:assertEquals(employeeRetrieved, employee1); + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2WorkspaceDeleteTestNegative, h2DepartmentDeleteTestNegative] +} +function h2EmployeeCreateTest2() returns error? { + H2RainierClient rainierClient = check new (); + + string[] empNos = check rainierClient->/employees.post([employee2, employee3]); + + test:assertEquals(empNos, [employee2.empNo, employee3.empNo]); + + Employee employeeRetrieved = check rainierClient->/employees/[employee2.empNo].get(); + test:assertEquals(employeeRetrieved, employee2); + + employeeRetrieved = check rainierClient->/employees/[employee3.empNo].get(); + test:assertEquals(employeeRetrieved, employee3); + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"] +} +function h2EmployeeCreateTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + string[]|error employee = rainierClient->/employees.post([invalidEmployee]); + if employee is persist:Error { + test:assertTrue(employee.message().includes("Value too long for column \"empNo CHARACTER VARYING(36)")); + } else { + test:assertFail("Error expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2EmployeeCreateTest] +} +function h2EmployeeReadOneTest() returns error? { + H2RainierClient rainierClient = check new (); + + Employee employeeRetrieved = check rainierClient->/employees/[employee1.empNo].get(); + test:assertEquals(employeeRetrieved, employee1); + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2EmployeeCreateTest] +} +function h2EmployeeReadOneTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + Employee|error employeeRetrieved = rainierClient->/employees/["invalid-employee-id"].get(); + if employeeRetrieved is persist:NotFoundError { + test:assertEquals(employeeRetrieved.message(), "A record with the key 'invalid-employee-id' does not exist for the entity 'Employee'."); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2EmployeeCreateTest, h2EmployeeCreateTest2] +} +function h2EmployeeReadManyTest() returns error? { + H2RainierClient rainierClient = check new (); + + stream employeeStream = rainierClient->/employees.get(); + Employee[] employees = check from Employee employee in employeeStream + select employee; + + test:assertEquals(employees, [employee1, employee2, employee3]); + check rainierClient.close(); +} + +@test:Config { + groups: ["dependent", "employee"], + dependsOn: [h2EmployeeCreateTest, h2EmployeeCreateTest2] +} +function h2EmployeeReadManyDependentTest1() returns error? { + H2RainierClient rainierClient = check new (); + + stream employeeStream = rainierClient->/employees.get(); + EmployeeName[] employees = check from EmployeeName employee in employeeStream + select employee; + + test:assertEquals(employees, [ + {firstName: employee1.firstName, lastName: employee1.lastName}, + {firstName: employee2.firstName, lastName: employee2.lastName}, + {firstName: employee3.firstName, lastName: employee3.lastName} + ]); + check rainierClient.close(); +} + +@test:Config { + groups: ["dependent", "employee"], + dependsOn: [h2EmployeeCreateTest, h2EmployeeCreateTest2] +} +function h2EmployeeReadManyDependentTest2() returns error? { + H2RainierClient rainierClient = check new (); + + stream employeeStream = rainierClient->/employees.get(); + EmployeeInfo2[] employees = check from EmployeeInfo2 employee in employeeStream + select employee; + + test:assertEquals(employees, [ + {empNo: employee1.empNo, birthDate: employee1.birthDate, departmentDeptNo: employee1.departmentDeptNo, workspaceWorkspaceId: employee1.workspaceWorkspaceId}, + {empNo: employee2.empNo, birthDate: employee2.birthDate, departmentDeptNo: employee2.departmentDeptNo, workspaceWorkspaceId: employee2.workspaceWorkspaceId}, + {empNo: employee3.empNo, birthDate: employee3.birthDate, departmentDeptNo: employee3.departmentDeptNo, workspaceWorkspaceId: employee3.workspaceWorkspaceId} + ]); + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2EmployeeReadOneTest, h2EmployeeReadManyTest, h2EmployeeReadManyDependentTest1, h2EmployeeReadManyDependentTest2] +} +function h2EmployeeUpdateTest() returns error? { + H2RainierClient rainierClient = check new (); + + Employee employee = check rainierClient->/employees/[employee1.empNo].put({ + lastName: "Jones", + departmentDeptNo: "department-3", + birthDate: {year: 1994, month: 11, day: 13} + }); + + test:assertEquals(employee, updatedEmployee1); + + Employee employeeRetrieved = check rainierClient->/employees/[employee1.empNo].get(); + test:assertEquals(employeeRetrieved, updatedEmployee1); + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2EmployeeReadOneTest, h2EmployeeReadManyTest, h2EmployeeReadManyDependentTest1, h2EmployeeReadManyDependentTest2] +} +function h2EmployeeUpdateTestNegative1() returns error? { + H2RainierClient rainierClient = check new (); + + Employee|error employee = rainierClient->/employees/["invalid-employee-id"].put({ + lastName: "Jones" + }); + + if employee is persist:NotFoundError { + test:assertEquals(employee.message(), "A record with the key 'invalid-employee-id' does not exist for the entity 'Employee'."); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2EmployeeReadOneTest, h2EmployeeReadManyTest, h2EmployeeReadManyDependentTest1, h2EmployeeReadManyDependentTest2] +} +function h2EmployeeUpdateTestNegative2() returns error? { + H2RainierClient rainierClient = check new (); + + Employee|error employee = rainierClient->/employees/[employee1.empNo].put({ + firstName: "unncessarily-long-employee-name-to-force-error-on-update" + }); + + if employee is persist:Error { + test:assertTrue(employee.message().includes("Value too long for column \"firstName CHARACTER VARYING(30)")); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2EmployeeReadOneTest, h2EmployeeReadManyTest, h2EmployeeReadManyDependentTest1, h2EmployeeReadManyDependentTest2] +} +function h2EmployeeUpdateTestNegative3() returns error? { + H2RainierClient rainierClient = check new (); + + Employee|error employee = rainierClient->/employees/[employee1.empNo].put({ + workspaceWorkspaceId: "invalid-workspaceWorkspaceId" + }); + + if employee is persist:ConstraintViolationError { + test:assertTrue(employee.message().includes("Referential integrity constraint violation: \"CONSTRAINT_4AFD: PUBLIC.Employee FOREIGN KEY(workspaceWorkspaceId) REFERENCES PUBLIC.Workspace(workspaceId)")); + } else { + test:assertFail("persist:persist:ConstraintViolationError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2EmployeeUpdateTest, h2EmployeeUpdateTestNegative2, h2EmployeeUpdateTestNegative3] +} +function h2EmployeeDeleteTest() returns error? { + H2RainierClient rainierClient = check new (); + + Employee employee = check rainierClient->/employees/[employee1.empNo].delete(); + test:assertEquals(employee, updatedEmployee1); + + stream employeeStream = rainierClient->/employees.get(); + Employee[] employees = check from Employee employee2 in employeeStream + select employee2; + + test:assertEquals(employees, [employee2, employee3]); + check rainierClient.close(); +} + +@test:Config { + groups: ["employee", "h2"], + dependsOn: [h2EmployeeDeleteTest] +} +function h2EmployeeDeleteTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + Employee|error employee = rainierClient->/employees/[employee1.empNo].delete(); + + if employee is persist:NotFoundError { + test:assertEquals(employee.message(), string `A record with the key '${employee1.empNo}' does not exist for the entity 'Employee'.`); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} diff --git a/ballerina/tests/h2-id-fields-tests.bal b/ballerina/tests/h2-id-fields-tests.bal new file mode 100644 index 0000000..abc0b5f --- /dev/null +++ b/ballerina/tests/h2-id-fields-tests.bal @@ -0,0 +1,476 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; + +@test:Config { + groups: ["id-fields", "h2"] +} +function h2IntIdFieldTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + IntIdRecord intIdRecord1 = { + id: 1, + randomField: "test1" + }; + IntIdRecord intIdRecord2 = { + id: 2, + randomField: "test2" + }; + IntIdRecord intIdRecord3 = { + id: 3, + randomField: "test3" + }; + IntIdRecord intIdRecord1Updated = { + id: 1, + randomField: "test1Updated" + }; + + // create + int[] ids = check testEntitiesClient->/intidrecords.post([intIdRecord1, intIdRecord2, intIdRecord3]); + test:assertEquals(ids, [intIdRecord1.id, intIdRecord2.id, intIdRecord3.id]); + + // read one + IntIdRecord retrievedRecord1 = check testEntitiesClient->/intidrecords/[intIdRecord1.id].get(); + test:assertEquals(intIdRecord1, retrievedRecord1); + + // read one dependent + IntIdRecordDependent retrievedRecord1Dependent = check testEntitiesClient->/intidrecords/[intIdRecord1.id].get(); + test:assertEquals({randomField: intIdRecord1.randomField}, retrievedRecord1Dependent); + + // read + IntIdRecord[] intIdRecords = check from IntIdRecord intIdRecord in testEntitiesClient->/intidrecords.get(IntIdRecord) + select intIdRecord; + test:assertEquals(intIdRecords, [intIdRecord1, intIdRecord2, intIdRecord3]); + + // read dependent + IntIdRecordDependent[] intIdRecordsDependent = check from IntIdRecordDependent intIdRecord in testEntitiesClient->/intidrecords.get(IntIdRecordDependent) + select intIdRecord; + test:assertEquals(intIdRecordsDependent, [{randomField: intIdRecord1.randomField}, {randomField: intIdRecord2.randomField}, {randomField: intIdRecord3.randomField}]); + + // update + retrievedRecord1 = check testEntitiesClient->/intidrecords/[intIdRecord1.id].put({randomField: intIdRecord1Updated.randomField}); + test:assertEquals(intIdRecord1Updated, retrievedRecord1); + retrievedRecord1 = check testEntitiesClient->/intidrecords/[intIdRecord1.id].get(); + test:assertEquals(intIdRecord1Updated, retrievedRecord1); + + // delete + IntIdRecord retrievedRecord2 = check testEntitiesClient->/intidrecords/[intIdRecord2.id].delete(); + test:assertEquals(intIdRecord2, retrievedRecord2); + intIdRecords = check from IntIdRecord intIdRecord in testEntitiesClient->/intidrecords.get(IntIdRecord) + select intIdRecord; + test:assertEquals(intIdRecords, [intIdRecord1Updated, intIdRecord3]); + + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["id-fields", "h2"] +} +function h2StringIdFieldTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + StringIdRecord stringIdRecord1 = { + id: "id-1", + randomField: "test1" + }; + StringIdRecord stringIdRecord2 = { + id: "id-2", + randomField: "test2" + }; + StringIdRecord stringIdRecord3 = { + id: "id-3", + randomField: "test3" + }; + StringIdRecord stringIdRecord1Updated = { + id: "id-1", + randomField: "test1Updated" + }; + + // create + string[] ids = check testEntitiesClient->/stringidrecords.post([stringIdRecord1, stringIdRecord2, stringIdRecord3]); + test:assertEquals(ids, [stringIdRecord1.id, stringIdRecord2.id, stringIdRecord3.id]); + + // read one + StringIdRecord retrievedRecord1 = check testEntitiesClient->/stringidrecords/[stringIdRecord1.id].get(); + test:assertEquals(stringIdRecord1, retrievedRecord1); + + // read one dependent + StringIdRecordDependent retrievedRecord1Dependent = check testEntitiesClient->/stringidrecords/[stringIdRecord1.id].get(); + test:assertEquals({randomField: stringIdRecord1.randomField}, retrievedRecord1Dependent); + + // read + StringIdRecord[] stringIdRecords = check from StringIdRecord stringIdRecord in testEntitiesClient->/stringidrecords.get(StringIdRecord) + select stringIdRecord; + test:assertEquals(stringIdRecords, [stringIdRecord1, stringIdRecord2, stringIdRecord3]); + + // read dependent + StringIdRecordDependent[] stringIdRecordsDependent = check from StringIdRecordDependent stringIdRecord in testEntitiesClient->/stringidrecords.get(StringIdRecordDependent) + select stringIdRecord; + test:assertEquals(stringIdRecordsDependent, [{randomField: stringIdRecord1.randomField}, {randomField: stringIdRecord2.randomField}, {randomField: stringIdRecord3.randomField}]); + + // update + retrievedRecord1 = check testEntitiesClient->/stringidrecords/[stringIdRecord1.id].put({randomField: stringIdRecord1Updated.randomField}); + test:assertEquals(stringIdRecord1Updated, retrievedRecord1); + retrievedRecord1 = check testEntitiesClient->/stringidrecords/[stringIdRecord1.id].get(); + test:assertEquals(stringIdRecord1Updated, retrievedRecord1); + + // delete + StringIdRecord retrievedRecord2 = check testEntitiesClient->/stringidrecords/[stringIdRecord2.id].delete(); + test:assertEquals(stringIdRecord2, retrievedRecord2); + stringIdRecords = check from StringIdRecord stringIdRecord in testEntitiesClient->/stringidrecords.get(StringIdRecord) + select stringIdRecord; + test:assertEquals(stringIdRecords, [stringIdRecord1Updated, stringIdRecord3]); + + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["id-fields", "h2"] +} +function h2FloatIdFieldTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + FloatIdRecord floatIdRecord1 = { + id: 1.0, + randomField: "test1" + }; + FloatIdRecord floatIdRecord2 = { + id: 2.0, + randomField: "test2" + }; + FloatIdRecord floatIdRecord3 = { + id: 3.0, + randomField: "test3" + }; + FloatIdRecord floatIdRecord1Updated = { + id: 1.0, + randomField: "test1Updated" + }; + + // create + float[] ids = check testEntitiesClient->/floatidrecords.post([floatIdRecord1, floatIdRecord2, floatIdRecord3]); + test:assertEquals(ids, [floatIdRecord1.id, floatIdRecord2.id, floatIdRecord3.id]); + + // read one + FloatIdRecord retrievedRecord1 = check testEntitiesClient->/floatidrecords/[floatIdRecord1.id].get(); + test:assertEquals(floatIdRecord1, retrievedRecord1); + + // read one dependent + FloatIdRecordDependent retrievedRecord1Dependent = check testEntitiesClient->/floatidrecords/[floatIdRecord1.id].get(); + test:assertEquals({randomField: floatIdRecord1.randomField}, retrievedRecord1Dependent); + + // read + FloatIdRecord[] floatIdRecords = check from FloatIdRecord floatIdRecord in testEntitiesClient->/floatidrecords.get(FloatIdRecord) + select floatIdRecord; + test:assertEquals(floatIdRecords, [floatIdRecord1, floatIdRecord2, floatIdRecord3]); + + // read dependent + FloatIdRecordDependent[] floatIdRecordsDependent = check from FloatIdRecordDependent floatIdRecord in testEntitiesClient->/floatidrecords.get(FloatIdRecordDependent) + select floatIdRecord; + test:assertEquals(floatIdRecordsDependent, [{randomField: floatIdRecord1.randomField}, {randomField: floatIdRecord2.randomField}, {randomField: floatIdRecord3.randomField}]); + + // update + retrievedRecord1 = check testEntitiesClient->/floatidrecords/[floatIdRecord1.id].put({randomField: floatIdRecord1Updated.randomField}); + test:assertEquals(floatIdRecord1Updated, retrievedRecord1); + retrievedRecord1 = check testEntitiesClient->/floatidrecords/[floatIdRecord1.id].get(); + test:assertEquals(floatIdRecord1Updated, retrievedRecord1); + + // delete + FloatIdRecord retrievedRecord2 = check testEntitiesClient->/floatidrecords/[floatIdRecord2.id].delete(); + test:assertEquals(floatIdRecord2, retrievedRecord2); + floatIdRecords = check from FloatIdRecord floatIdRecord in testEntitiesClient->/floatidrecords.get(FloatIdRecord) + select floatIdRecord; + test:assertEquals(floatIdRecords, [floatIdRecord1Updated, floatIdRecord3]); +} + +@test:Config { + groups: ["id-fields", "h2"] +} +function h2DecimalIdFieldTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + DecimalIdRecord decimalIdRecord1 = { + id: 1.1d, + randomField: "test1" + }; + DecimalIdRecord decimalIdRecord2 = { + id: 2.2d, + randomField: "test2" + }; + DecimalIdRecord decimalIdRecord3 = { + id: 3.3d, + randomField: "test3" + }; + DecimalIdRecord decimalIdRecord1Updated = { + id: 1.1d, + randomField: "test1Updated" + }; + + // create + decimal[] ids = check testEntitiesClient->/decimalidrecords.post([decimalIdRecord1, decimalIdRecord2, decimalIdRecord3]); + test:assertEquals(ids, [decimalIdRecord1.id, decimalIdRecord2.id, decimalIdRecord3.id]); + + // read one + DecimalIdRecord retrievedRecord1 = check testEntitiesClient->/decimalidrecords/[decimalIdRecord1.id].get(); + test:assertEquals(decimalIdRecord1, retrievedRecord1); + + // read one dependent + DecimalIdRecordDependent retrievedRecord1Dependent = check testEntitiesClient->/decimalidrecords/[decimalIdRecord1.id].get(); + test:assertEquals({randomField: decimalIdRecord1.randomField}, retrievedRecord1Dependent); + + // read + DecimalIdRecord[] decimalIdRecords = check from DecimalIdRecord decimalIdRecord in testEntitiesClient->/decimalidrecords.get(DecimalIdRecord) + select decimalIdRecord; + test:assertEquals(decimalIdRecords, [decimalIdRecord1, decimalIdRecord2, decimalIdRecord3]); + + // read dependent + DecimalIdRecordDependent[] decimalIdRecordsDependent = check from DecimalIdRecordDependent decimalIdRecord in testEntitiesClient->/decimalidrecords.get(DecimalIdRecordDependent) + select decimalIdRecord; + test:assertEquals(decimalIdRecordsDependent, [{randomField: decimalIdRecord1.randomField}, {randomField: decimalIdRecord2.randomField}, {randomField: decimalIdRecord3.randomField}]); + + // update + retrievedRecord1 = check testEntitiesClient->/decimalidrecords/[decimalIdRecord1.id].put({randomField: decimalIdRecord1Updated.randomField}); + test:assertEquals(decimalIdRecord1Updated, retrievedRecord1); + retrievedRecord1 = check testEntitiesClient->/decimalidrecords/[decimalIdRecord1.id].get(); + test:assertEquals(decimalIdRecord1Updated, retrievedRecord1); + + // delete + DecimalIdRecord retrievedRecord2 = check testEntitiesClient->/decimalidrecords/[decimalIdRecord2.id].delete(); + test:assertEquals(decimalIdRecord2, retrievedRecord2); + decimalIdRecords = check from DecimalIdRecord decimalIdRecord in testEntitiesClient->/decimalidrecords.get(DecimalIdRecord) + select decimalIdRecord; + test:assertEquals(decimalIdRecords, [decimalIdRecord1Updated, decimalIdRecord3]); + + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["id-fields", "h2"] +} +function h2BooleanIdFieldTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + BooleanIdRecord booleanIdRecord1 = { + id: true, + randomField: "test1" + }; + BooleanIdRecord booleanIdRecord2 = { + id: false, + randomField: "test2" + }; + BooleanIdRecord booleanIdRecord1Updated = { + id: true, + randomField: "test1Updated" + }; + + // create + boolean[] ids = check testEntitiesClient->/booleanidrecords.post([booleanIdRecord1, booleanIdRecord2]); + test:assertEquals(ids, [booleanIdRecord1.id, booleanIdRecord2.id]); + + // read one + BooleanIdRecord retrievedRecord1 = check testEntitiesClient->/booleanidrecords/[booleanIdRecord1.id].get(); + test:assertEquals(booleanIdRecord1, retrievedRecord1); + + // read one dependent + BooleanIdRecordDependent retrievedRecord1Dependent = check testEntitiesClient->/booleanidrecords/[booleanIdRecord1.id].get(); + test:assertEquals({randomField: booleanIdRecord1.randomField}, retrievedRecord1Dependent); + + // read + BooleanIdRecord[] booleanIdRecords = check from BooleanIdRecord booleanIdRecord in testEntitiesClient->/booleanidrecords.get(BooleanIdRecord) + select booleanIdRecord; + test:assertEquals(booleanIdRecords, [booleanIdRecord1, booleanIdRecord2]); + + // read dependent + BooleanIdRecordDependent[] booleanIdRecordsDependent = check from BooleanIdRecordDependent booleanIdRecord in testEntitiesClient->/booleanidrecords.get(BooleanIdRecordDependent) + select booleanIdRecord; + test:assertEquals(booleanIdRecordsDependent, [{randomField: booleanIdRecord1.randomField}, {randomField: booleanIdRecord2.randomField}]); + + // update + retrievedRecord1 = check testEntitiesClient->/booleanidrecords/[booleanIdRecord1.id].put({randomField: booleanIdRecord1Updated.randomField}); + test:assertEquals(booleanIdRecord1Updated, retrievedRecord1); + retrievedRecord1 = check testEntitiesClient->/booleanidrecords/[booleanIdRecord1.id].get(); + test:assertEquals(booleanIdRecord1Updated, retrievedRecord1); + + // delete + BooleanIdRecord retrievedRecord2 = check testEntitiesClient->/booleanidrecords/[booleanIdRecord2.id].delete(); + test:assertEquals(booleanIdRecord2, retrievedRecord2); + booleanIdRecords = check from BooleanIdRecord booleanIdRecord in testEntitiesClient->/booleanidrecords.get(BooleanIdRecord) + select booleanIdRecord; + test:assertEquals(booleanIdRecords, [booleanIdRecord1Updated]); + + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["id-fields", "h2"] +} +function h2AllTypesIdFieldTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + AllTypesIdRecord allTypesIdRecord1 = { + intType: 1, + stringType: "id-1", + floatType: 1.0, + booleanType: true, + decimalType: 1.1d, + randomField: "test1" + }; + AllTypesIdRecord allTypesIdRecord2 = { + intType: 2, + stringType: "id-2", + floatType: 2.0, + booleanType: false, + decimalType: 2.2d, + randomField: "test2" + }; + AllTypesIdRecord allTypesIdRecord1Updated = { + intType: 1, + stringType: "id-1", + floatType: 1.0, + booleanType: true, + decimalType: 1.1d, + randomField: "test1Updated" + }; + + // create + [boolean, int, float, decimal, string][] ids = check testEntitiesClient->/alltypesidrecords.post([allTypesIdRecord1, allTypesIdRecord2]); + test:assertEquals(ids, [ + [allTypesIdRecord1.booleanType, allTypesIdRecord1.intType, allTypesIdRecord1.floatType, allTypesIdRecord1.decimalType, allTypesIdRecord1.stringType], + [allTypesIdRecord2.booleanType, allTypesIdRecord2.intType, allTypesIdRecord2.floatType, allTypesIdRecord2.decimalType, allTypesIdRecord2.stringType] + ]); + + // read one + AllTypesIdRecord retrievedRecord1 = check testEntitiesClient->/alltypesidrecords/[allTypesIdRecord1.booleanType]/[allTypesIdRecord1.intType]/[allTypesIdRecord1.floatType]/[allTypesIdRecord1.decimalType]/[allTypesIdRecord1.stringType].get(); + test:assertEquals(allTypesIdRecord1, retrievedRecord1); + + // read one dependent + AllTypesIdRecordDependent retrievedRecord1Dependent = check testEntitiesClient->/alltypesidrecords/[allTypesIdRecord1.booleanType]/[allTypesIdRecord1.intType]/[allTypesIdRecord1.floatType]/[allTypesIdRecord1.decimalType]/[allTypesIdRecord1.stringType].get(); + test:assertEquals({randomField: allTypesIdRecord1.randomField}, retrievedRecord1Dependent); + + // read + AllTypesIdRecord[] allTypesIdRecords = check from AllTypesIdRecord allTypesIdRecord in testEntitiesClient->/alltypesidrecords.get(AllTypesIdRecord) + order by allTypesIdRecord.intType + select allTypesIdRecord; + test:assertEquals(allTypesIdRecords, [allTypesIdRecord1, allTypesIdRecord2]); + + // read dependent + AllTypesIdRecordDependent[] allTypesIdRecordsDependent = check from AllTypesIdRecordDependent allTypesIdRecord in testEntitiesClient->/alltypesidrecords.get(AllTypesIdRecordDependent) + select allTypesIdRecord; + test:assertEquals(allTypesIdRecordsDependent, [{randomField: allTypesIdRecord1.randomField}, {randomField: allTypesIdRecord2.randomField}]); + + // update + retrievedRecord1 = check testEntitiesClient->/alltypesidrecords/[allTypesIdRecord1.booleanType]/[allTypesIdRecord1.intType]/[allTypesIdRecord1.floatType]/[allTypesIdRecord1.decimalType]/[allTypesIdRecord1.stringType].put({randomField: allTypesIdRecord1Updated.randomField}); + test:assertEquals(allTypesIdRecord1Updated, retrievedRecord1); + retrievedRecord1 = check testEntitiesClient->/alltypesidrecords/[allTypesIdRecord1.booleanType]/[allTypesIdRecord1.intType]/[allTypesIdRecord1.floatType]/[allTypesIdRecord1.decimalType]/[allTypesIdRecord1.stringType].get(); + test:assertEquals(allTypesIdRecord1Updated, retrievedRecord1); + + // delete + AllTypesIdRecord retrievedRecord2 = check testEntitiesClient->/alltypesidrecords/[allTypesIdRecord2.booleanType]/[allTypesIdRecord2.intType]/[allTypesIdRecord2.floatType]/[allTypesIdRecord2.decimalType]/[allTypesIdRecord2.stringType].delete(); + test:assertEquals(allTypesIdRecord2, retrievedRecord2); + allTypesIdRecords = check from AllTypesIdRecord allTypesIdRecord in testEntitiesClient->/alltypesidrecords.get(AllTypesIdRecord) + order by allTypesIdRecord.intType + select allTypesIdRecord; + test:assertEquals(allTypesIdRecords, [allTypesIdRecord1Updated]); + + check testEntitiesClient.close(); +} + +@test:Config { + groups: ["id-fields", "h2", "associations"], + dependsOn: [h2AllTypesIdFieldTest] +} +function h2CompositeAssociationsTest() returns error? { + H2TestEntitiesClient testEntitiesClient = check new (); + + CompositeAssociationRecord compositeAssociationRecord1 = { + id: "id-1", + randomField: "test1", + alltypesidrecordIntType: 1, + alltypesidrecordStringType: "id-1", + alltypesidrecordFloatType: 1.0, + alltypesidrecordBooleanType: true, + alltypesidrecordDecimalType: 1.10 + }; + + CompositeAssociationRecord compositeAssociationRecord2 = { + id: "id-2", + randomField: "test2", + alltypesidrecordIntType: 1, + alltypesidrecordStringType: "id-1", + alltypesidrecordFloatType: 1.0, + alltypesidrecordBooleanType: true, + alltypesidrecordDecimalType: 1.10 + }; + + CompositeAssociationRecord compositeAssociationRecordUpdated1 = { + id: "id-1", + randomField: "test1Updated", + alltypesidrecordIntType: 1, + alltypesidrecordStringType: "id-1", + alltypesidrecordFloatType: 1.0, + alltypesidrecordBooleanType: true, + alltypesidrecordDecimalType: 1.10 + }; + + AllTypesIdRecordOptionalized allTypesIdRecord1 = { + intType: 1, + stringType: "id-1", + floatType: 1.0, + booleanType: true, + decimalType: 1.10, + randomField: "test1Updated" + }; + + // create + string[] ids = check testEntitiesClient->/compositeassociationrecords.post([compositeAssociationRecord1, compositeAssociationRecord2]); + test:assertEquals(ids, [compositeAssociationRecord1.id, compositeAssociationRecord2.id]); + + // read one + CompositeAssociationRecord retrievedRecord1 = check testEntitiesClient->/compositeassociationrecords/[compositeAssociationRecord1.id].get(); + test:assertEquals(compositeAssociationRecord1, retrievedRecord1); + + // read one dependent + CompositeAssociationRecordDependent retrievedRecord1Dependent = check testEntitiesClient->/compositeassociationrecords/[compositeAssociationRecord1.id].get(); + test:assertEquals({ + randomField: compositeAssociationRecord1.randomField, + alltypesidrecordIntType: compositeAssociationRecord1.alltypesidrecordIntType, + alltypesidrecordDecimalType: compositeAssociationRecord1.alltypesidrecordDecimalType, + allTypesIdRecord: {intType: allTypesIdRecord1.intType, stringType: allTypesIdRecord1.stringType, booleanType: allTypesIdRecord1.booleanType, randomField: allTypesIdRecord1.randomField} + }, retrievedRecord1Dependent); + + // read + CompositeAssociationRecord[] compositeAssociationRecords = check from CompositeAssociationRecord compositeAssociationRecord in testEntitiesClient->/compositeassociationrecords.get(CompositeAssociationRecord) + select compositeAssociationRecord; + test:assertEquals(compositeAssociationRecords, [compositeAssociationRecord1, compositeAssociationRecord2]); + + // read dependent + CompositeAssociationRecordDependent[] compositeAssociationRecordsDependent = check from CompositeAssociationRecordDependent compositeAssociationRecord in testEntitiesClient->/compositeassociationrecords.get(CompositeAssociationRecordDependent) + select compositeAssociationRecord; + test:assertEquals(compositeAssociationRecordsDependent, [ + {randomField: compositeAssociationRecord1.randomField, alltypesidrecordIntType: compositeAssociationRecord1.alltypesidrecordIntType, alltypesidrecordDecimalType: compositeAssociationRecord1.alltypesidrecordDecimalType, allTypesIdRecord: {intType: allTypesIdRecord1.intType, stringType: allTypesIdRecord1.stringType, booleanType: allTypesIdRecord1.booleanType, randomField: allTypesIdRecord1.randomField}}, + {randomField: compositeAssociationRecord2.randomField, alltypesidrecordIntType: compositeAssociationRecord2.alltypesidrecordIntType, alltypesidrecordDecimalType: compositeAssociationRecord2.alltypesidrecordDecimalType, allTypesIdRecord: {intType: allTypesIdRecord1.intType, stringType: allTypesIdRecord1.stringType, booleanType: allTypesIdRecord1.booleanType, randomField: allTypesIdRecord1.randomField}} + ]); + + // update + retrievedRecord1 = check testEntitiesClient->/compositeassociationrecords/[compositeAssociationRecord1.id].put({randomField: "test1Updated"}); + test:assertEquals(compositeAssociationRecordUpdated1, retrievedRecord1); + retrievedRecord1 = check testEntitiesClient->/compositeassociationrecords/[compositeAssociationRecord1.id].get(); + test:assertEquals(compositeAssociationRecordUpdated1, retrievedRecord1); + + // delete + CompositeAssociationRecord retrievedRecord2 = check testEntitiesClient->/compositeassociationrecords/[compositeAssociationRecord2.id].delete(); + test:assertEquals(compositeAssociationRecord2, retrievedRecord2); + compositeAssociationRecords = check from CompositeAssociationRecord compositeAssociationRecord in testEntitiesClient->/compositeassociationrecords.get(CompositeAssociationRecord) + select compositeAssociationRecord; + test:assertEquals(compositeAssociationRecords, [compositeAssociationRecordUpdated1]); + + check testEntitiesClient.close(); +} diff --git a/ballerina/tests/h2-native-tests.bal b/ballerina/tests/h2-native-tests.bal new file mode 100644 index 0000000..8826a66 --- /dev/null +++ b/ballerina/tests/h2-native-tests.bal @@ -0,0 +1,303 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; +import ballerina/persist; + +@test:Config { + groups: ["native", "h2"], + dependsOn: [h2EmployeeRelationsTest, h2WorkspaceRelationsTest, h2BuildingRelationsTest, h2DepartmentRelationsTest] +} +function h2NativeExecuteTest() returns error? { + H2RainierClient rainierClient = check new (); + _ = check rainierClient->executeNativeSQL(`DELETE FROM "Employee"`); + _ = check rainierClient->executeNativeSQL(`DELETE FROM "Workspace"`); + _ = check rainierClient->executeNativeSQL(`DELETE FROM "Building"`); + _ = check rainierClient->executeNativeSQL(`DELETE FROM "Department"`); + + ExecutionResult executionResult = check rainierClient->executeNativeSQL(` + INSERT INTO "Department" ("deptNo", "deptName") + VALUES + (${departmentNative1.deptNo}, ${departmentNative1.deptName}), + (${departmentNative2.deptNo}, ${departmentNative2.deptName}), + (${departmentNative3.deptNo}, ${departmentNative3.deptName}) + `); + test:assertEquals(executionResult, {affectedRowCount: 3, lastInsertId: "department-native-1"}); + + executionResult = check rainierClient->executeNativeSQL(` + INSERT INTO "Building" ("buildingCode", "city", "state", "country", "postalCode", "type") + VALUES + (${buildingNative1.buildingCode}, ${buildingNative1.city}, ${buildingNative1.state}, ${buildingNative1.country}, ${buildingNative1.postalCode}, ${buildingNative1.'type}), + (${buildingNative2.buildingCode}, ${buildingNative2.city}, ${buildingNative2.state}, ${buildingNative2.country}, ${buildingNative2.postalCode}, ${buildingNative2.'type}), + (${buildingNative3.buildingCode}, ${buildingNative3.city}, ${buildingNative3.state}, ${buildingNative3.country}, ${buildingNative3.postalCode}, ${buildingNative3.'type}) + `); + test:assertEquals(executionResult, {affectedRowCount: 3, lastInsertId: "building-native-1"}); + + executionResult = check rainierClient->executeNativeSQL(` + INSERT INTO "Workspace" ("workspaceId", "workspaceType", "locationBuildingCode") + VALUES + (${workspaceNative1.workspaceId}, ${workspaceNative1.workspaceType}, ${workspaceNative1.locationBuildingCode}), + (${workspaceNative2.workspaceId}, ${workspaceNative2.workspaceType}, ${workspaceNative2.locationBuildingCode}), + (${workspaceNative3.workspaceId}, ${workspaceNative3.workspaceType}, ${workspaceNative3.locationBuildingCode}) + `); + test:assertEquals(executionResult, {affectedRowCount: 3, lastInsertId: "workspace-native-1"}); + + executionResult = check rainierClient->executeNativeSQL(` + INSERT INTO "Employee" ("empNo", "firstName", "lastName", "birthDate", "gender", "hireDate", "departmentDeptNo", "workspaceWorkspaceId") + VALUES + (${employeeNative1.empNo}, ${employeeNative1.firstName}, ${employeeNative1.lastName}, ${employeeNative1.birthDate}, ${employeeNative1.gender}, ${employeeNative1.hireDate}, ${employeeNative1.departmentDeptNo}, ${employeeNative1.workspaceWorkspaceId}), + (${employeeNative2.empNo}, ${employeeNative2.firstName}, ${employeeNative2.lastName}, ${employeeNative2.birthDate}, ${employeeNative2.gender}, ${employeeNative2.hireDate}, ${employeeNative2.departmentDeptNo}, ${employeeNative2.workspaceWorkspaceId}), + (${employeeNative3.empNo}, ${employeeNative3.firstName}, ${employeeNative3.lastName}, ${employeeNative3.birthDate}, ${employeeNative3.gender}, ${employeeNative3.hireDate}, ${employeeNative3.departmentDeptNo}, ${employeeNative3.workspaceWorkspaceId}) + `); + test:assertEquals(executionResult, {affectedRowCount: 3, lastInsertId: "employee-native-1"}); + + check rainierClient.close(); +} + +@test:Config { + groups: ["native", "h2"], + dependsOn: [h2NativeExecuteTest] +} +function h2NativeExecuteTestNegative1() returns error? { + H2RainierClient rainierClient = check new (); + ExecutionResult|persist:Error executionResult = rainierClient->executeNativeSQL(` + INSERT INTO "Department" ("deptNo", "deptName") + VALUES (${departmentNative1.deptNo}, ${departmentNative1.deptName}) + `); + + if executionResult is persist:Error { + test:assertTrue(executionResult.message().includes("Unique index or primary key violation: \"PUBLIC.PRIMARY_KEY_A9 ON PUBLIC.Department(deptNo) VALUES ( /* 6 */ 'department-native-1'")); + } else { + test:assertFail("persist:Error expected."); + } + + check rainierClient.close(); +} + +@test:Config { + groups: ["native", "h2"], + dependsOn: [h2NativeExecuteTest] +} +function h2NativeExecuteTestNegative2() returns error? { + H2RainierClient rainierClient = check new (); + ExecutionResult|persist:Error executionResult = rainierClient->executeNativeSQL(` + INSERT INTO "Departments" ("deptNo", "deptName") + VALUES (${departmentNative1.deptNo}, ${departmentNative1.deptName}) + `); + + if executionResult is persist:Error { + test:assertTrue(executionResult.message().includes("Table \"Departments\" not found;")); + } else { + test:assertFail("persist:Error expected."); + } + + check rainierClient.close(); +} + +@test:Config { + groups: ["native", "h2"], + dependsOn: [h2NativeExecuteTest] +} +function h2NativeQueryTest() returns error? { + H2RainierClient rainierClient = check new (); + stream departmentStream = rainierClient->queryNativeSQL(`SELECT * FROM "Department"`); + Department[] departments = check from Department department in departmentStream + select department; + check departmentStream.close(); + test:assertEquals(departments, [departmentNative1, departmentNative2, departmentNative3]); + + stream buildingStream = rainierClient->queryNativeSQL(`SELECT * FROM "Building"`); + Building[] buildings = check from Building building in buildingStream + select building; + check buildingStream.close(); + test:assertEquals(buildings, [buildingNative1, buildingNative2, buildingNative3]); + + stream workspaceStream = rainierClient->queryNativeSQL(`SELECT * FROM "Workspace"`); + Workspace[] workspaces = check from Workspace workspace in workspaceStream + select workspace; + check workspaceStream.close(); + test:assertEquals(workspaces, [workspaceNative1, workspaceNative2, workspaceNative3]); + + stream employeeStream = rainierClient->queryNativeSQL(`SELECT * FROM "Employee"`); + Employee[] employees = check from Employee employee in employeeStream + select employee; + check employeeStream.close(); + test:assertEquals(employees, [employeeNative1, employeeNative2, employeeNative3]); + + check rainierClient.close(); +} + +@test:Config { + groups: ["native", "h2"], + dependsOn: [h2NativeExecuteTest] +} +function h2NativeQueryTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + stream departmentStream = rainierClient->queryNativeSQL(`SELECT * FROM "Departments"`); + Department[]|persist:Error departments = from Department department in departmentStream + select department; + check departmentStream.close(); + + if departments is persist:Error { + test:assertTrue(departments.message().includes("Table \"Departments\" not found")); + } else { + test:assertFail("persist:Error expected."); + } + + check rainierClient.close(); +} + +@test:Config { + groups: ["native", "h2"], + dependsOn: [h2NativeExecuteTest] +} +function h2NativeQueryComplexTest() returns error? { + H2RainierClient rainierClient = check new (); + stream employeeInfoStream = rainierClient->queryNativeSQL(` + SELECT + "firstName", + "lastName", + department."deptName" AS "department.deptName", + workspace."workspaceId" AS "workspace.workspaceId", + workspace."workspaceType" AS "workspace.workspaceType", + workspace."locationBuildingCode" AS "workspace.locationBuildingCode" + FROM "Employee" + INNER JOIN + "Department" department ON "Employee"."departmentDeptNo" = department."deptNo" + INNER JOIN + "Workspace" workspace ON "Employee"."workspaceWorkspaceId" = workspace."workspaceId" + `); + EmployeeInfo[] employees = check from EmployeeInfo employee in employeeInfoStream + select employee; + check employeeInfoStream.close(); + test:assertEquals(employees, [employeeInfoNative1, employeeInfoNative2, employeeInfoNative3]); + + check rainierClient.close(); +} + +@test:Config { + groups: ["transactions", "h2", "native"], + dependsOn: [h2NativeExecuteTestNegative1, h2NativeQueryTest, h2NativeQueryTestNegative, h2NativeQueryComplexTest] +} +function h2NativeTransactionTest() returns error? { + H2RainierClient rainierClient = check new (); + _ = check rainierClient->executeNativeSQL(`DELETE FROM "Employee"`); + _ = check rainierClient->executeNativeSQL(`DELETE FROM "Workspace"`); + _ = check rainierClient->executeNativeSQL(`DELETE FROM "Building"`); + _ = check rainierClient->executeNativeSQL(`DELETE FROM "Department"`); + + transaction { + ExecutionResult executionResult = check rainierClient->executeNativeSQL(` + INSERT INTO "Building" ("buildingCode", "city", "state", "country", "postalCode", "type") + VALUES + (${building31.buildingCode}, ${building31.city}, ${building31.state}, ${building31.country}, ${building31.postalCode}, ${building31.'type}), + (${building32.buildingCode}, ${building32.city}, ${building32.state}, ${building32.country}, ${building32.postalCode}, ${building32.'type}) + `); + test:assertEquals(executionResult, {affectedRowCount: 2, lastInsertId: "building-31"}); + + stream buildingStream = rainierClient->queryNativeSQL(`SELECT * FROM "Building"`); + Building[] buildings = check from Building building in buildingStream + select building; + check buildingStream.close(); + test:assertEquals(buildings, [building31, building32]); + + executionResult = check rainierClient->executeNativeSQL(` + INSERT INTO "Building" ("buildingCode", "city", "state", "country", "postalCode", "type") + VALUES + (${building31.buildingCode}, ${building31.city}, ${building31.state}, ${building31.country}, ${building31.postalCode}, ${building31.'type}) + `); + check commit; + } on fail error e { + test:assertTrue(e is persist:Error, "persist:Error expected"); + } + + stream buildingStream = rainierClient->queryNativeSQL(`SELECT * FROM "Building"`); + Building[] buildings = check from Building building in buildingStream + select building; + check buildingStream.close(); + test:assertEquals(buildings, []); + + check rainierClient.close(); +} + +@test:Config { + groups: ["transactions", "h2", "native"], + dependsOn: [h2NativeExecuteTestNegative1, h2NativeQueryTest, h2NativeQueryTestNegative, h2NativeQueryComplexTest] +} +function h2NativeTransactionTest2() returns error? { + H2RainierClient rainierClient = check new (); + + ExecutionResult executionResult = check rainierClient->executeNativeSQL(` + INSERT INTO "Building" ("buildingCode", "city", "state", "country", "postalCode", "type") + VALUES + (${building33.buildingCode}, ${building33.city}, ${building33.state}, ${building33.country}, ${building33.postalCode}, ${building33.'type}) + `); + test:assertEquals(executionResult, {affectedRowCount: 1, lastInsertId: "building-33"}); + + stream buildingStream = rainierClient->queryNativeSQL(`SELECT * FROM "Building" WHERE "buildingCode" = ${building33.buildingCode}`); + Building[] buildings = check from Building building in buildingStream + select building; + check buildingStream.close(); + test:assertEquals(buildings, [building33]); + + transaction { + _ = check rainierClient->executeNativeSQL(` + UPDATE "Building" + SET + "city" = ${building33Updated.city}, + "state" = ${building33Updated.state}, + "country" = ${building33Updated.country} + WHERE "buildingCode" = ${building33.buildingCode} + `); + check commit; + } + + stream buildingStream3 = rainierClient->queryNativeSQL(`SELECT * FROM "Building" WHERE "buildingCode" = ${building33.buildingCode}`); + Building[] buildings3 = check from Building building in buildingStream3 + select building; + check buildingStream3.close(); + test:assertEquals(buildings3, [building33Updated]); + + check rainierClient.close(); +} + +@test:Config { + groups: ["h2", "native"], + dependsOn: [h2AllTypesDeleteTest] +} +function h2NativeAllTypesTest() returns error? { + H2RainierClient rainierClient = check new (); + _ = check rainierClient->executeNativeSQL(`DELETE FROM "AllTypes"`); + + ExecutionResult executionResult = check rainierClient->executeNativeSQL(` + INSERT INTO "AllTypes" ( + "id", "booleanType", "intType", "floatType", "decimalType", "stringType", "byteArrayType", "dateType", "timeOfDayType", "civilType", "booleanTypeOptional", "intTypeOptional", + "floatTypeOptional", "decimalTypeOptional", "stringTypeOptional", "dateTypeOptional", "timeOfDayTypeOptional", "civilTypeOptional", "enumType", "enumTypeOptional" + ) VALUES ( + ${allTypes1.id}, ${allTypes1.booleanType}, ${allTypes1.intType}, ${allTypes1.floatType}, ${allTypes1.decimalType}, ${allTypes1.stringType}, ${allTypes1.byteArrayType}, + ${allTypes1.dateType}, ${allTypes1.timeOfDayType}, ${allTypes1.civilType}, ${allTypes1.booleanTypeOptional}, ${allTypes1.intTypeOptional}, ${allTypes1.floatTypeOptional}, + ${allTypes1.decimalTypeOptional}, ${allTypes1.stringTypeOptional}, ${allTypes1.dateTypeOptional}, ${allTypes1.timeOfDayTypeOptional}, ${allTypes1.civilTypeOptional}, ${allTypes1.enumType}, ${allTypes1.enumTypeOptional} + ) + `); + test:assertEquals(executionResult, {affectedRowCount: 1, lastInsertId: 1}); + + stream allTypesStream = rainierClient->queryNativeSQL(`SELECT * FROM "AllTypes" WHERE "id" = ${allTypes1.id}`); + AllTypes[] allTypes = check from AllTypes allType in allTypesStream + select allType; + check allTypesStream.close(); + test:assertEquals(allTypes, [allTypes1]); + check rainierClient.close(); +} diff --git a/ballerina/tests/h2-transaction-tests.bal b/ballerina/tests/h2-transaction-tests.bal new file mode 100644 index 0000000..dc677d5 --- /dev/null +++ b/ballerina/tests/h2-transaction-tests.bal @@ -0,0 +1,75 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; +import ballerina/persist; + +@test:Config { + groups: ["transactions", "h2"] +} +function h2TransactionTest() returns error? { + H2RainierClient rainierClient = check new (); + + transaction { + string[] buildingCodes = check rainierClient->/buildings.post([building31, building32]); + test:assertEquals(buildingCodes, [building31.buildingCode, building32.buildingCode]); + + buildingCodes = check rainierClient->/buildings.post([building31]); + check commit; + } on fail error e { + test:assertTrue(e is persist:AlreadyExistsError, "AlreadyExistsError expected"); + } + + Building|persist:Error buildingRetrieved = rainierClient->/buildings/[building31.buildingCode].get(); + test:assertTrue(buildingRetrieved is persist:NotFoundError, "NotFoundError expected"); + + buildingRetrieved = rainierClient->/buildings/[building32.buildingCode].get(); + test:assertTrue(buildingRetrieved is persist:NotFoundError, "NotFoundError expected"); + + check rainierClient.close(); +} + +@test:Config { + groups: ["transactions", "h2"] +} +function h2TransactionTest2() returns error? { + H2RainierClient rainierClient = check new (); + + _ = check rainierClient->/buildings.post([building33]); + Building buildingRetrieved = check rainierClient->/buildings/[building33.buildingCode].get(); + test:assertEquals(buildingRetrieved, building33); + + transaction { + Building building = check rainierClient->/buildings/[building33.buildingCode].put({ + city: "ColomboUpdated", + state: "Western ProvinceUpdated", + country: "Sri LankaUpdated" + }); + + test:assertEquals(building, building33Updated); + + // below should retrieve the updated building record + buildingRetrieved = check rainierClient->/buildings/[building33.buildingCode].get(); + test:assertEquals(buildingRetrieved, building33Updated); + + check commit; + } + + buildingRetrieved = check rainierClient->/buildings/[building33.buildingCode].get(); + test:assertEquals(buildingRetrieved, building33Updated); + + check rainierClient.close(); +} diff --git a/ballerina/tests/h2-workspace-tests.bal b/ballerina/tests/h2-workspace-tests.bal new file mode 100644 index 0000000..cd8e1b4 --- /dev/null +++ b/ballerina/tests/h2-workspace-tests.bal @@ -0,0 +1,252 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; +import ballerina/persist; + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2BuildingDeleteTestNegative] +} +function h2WorkspaceCreateTest() returns error? { + H2RainierClient rainierClient = check new (); + + string[] workspaceIds = check rainierClient->/workspaces.post([workspace1]); + test:assertEquals(workspaceIds, [workspace1.workspaceId]); + + Workspace workspaceRetrieved = check rainierClient->/workspaces/[workspace1.workspaceId].get(); + test:assertEquals(workspaceRetrieved, workspace1); +} + +@test:Config { + groups: ["workspace", "h2"] +} +function h2WorkspaceCreateTest2() returns error? { + H2RainierClient rainierClient = check new (); + + string[] workspaceIds = check rainierClient->/workspaces.post([workspace2, workspace3]); + + test:assertEquals(workspaceIds, [workspace2.workspaceId, workspace3.workspaceId]); + + Workspace workspaceRetrieved = check rainierClient->/workspaces/[workspace2.workspaceId].get(); + test:assertEquals(workspaceRetrieved, workspace2); + + workspaceRetrieved = check rainierClient->/workspaces/[workspace3.workspaceId].get(); + test:assertEquals(workspaceRetrieved, workspace3); + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"] +} +function h2WorkspaceCreateTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + string[]|error workspace = rainierClient->/workspaces.post([invalidWorkspace]); + if workspace is persist:Error { + test:assertTrue(workspace.message().includes("Value too long for column \"workspaceId CHARACTER VARYING(36)")); + } else { + test:assertFail("Error expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2WorkspaceCreateTest] +} +function h2WorkspaceReadOneTest() returns error? { + H2RainierClient rainierClient = check new (); + + Workspace workspaceRetrieved = check rainierClient->/workspaces/[workspace1.workspaceId].get(); + test:assertEquals(workspaceRetrieved, workspace1); + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2WorkspaceCreateTest] +} +function h2WorkspaceReadOneDependentTest() returns error? { + H2RainierClient rainierClient = check new (); + + WorkspaceInfo2 workspaceRetrieved = check rainierClient->/workspaces/[workspace1.workspaceId].get(); + test:assertEquals(workspaceRetrieved, + { + workspaceType: workspace1.workspaceType, + locationBuildingCode: workspace1.locationBuildingCode + } + ); + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2WorkspaceCreateTest] +} +function h2WorkspaceReadOneTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + Workspace|error workspaceRetrieved = rainierClient->/workspaces/["invalid-workspace-id"].get(); + if workspaceRetrieved is persist:NotFoundError { + test:assertEquals(workspaceRetrieved.message(), "A record with the key 'invalid-workspace-id' does not exist for the entity 'Workspace'."); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2WorkspaceCreateTest, h2WorkspaceCreateTest2] +} +function h2WorkspaceReadManyTest() returns error? { + H2RainierClient rainierClient = check new (); + + stream workspaceStream = rainierClient->/workspaces.get(); + Workspace[] workspaces = check from Workspace workspace in workspaceStream + select workspace; + + test:assertEquals(workspaces, [workspace1, workspace2, workspace3]); + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2", "dependent"], + dependsOn: [h2WorkspaceCreateTest, h2WorkspaceCreateTest2] +} +function h2WorkspaceReadManyDependentTest() returns error? { + H2RainierClient rainierClient = check new (); + + stream workspaceStream = rainierClient->/workspaces.get(); + WorkspaceInfo2[] workspaces = check from WorkspaceInfo2 workspace in workspaceStream + select workspace; + + test:assertEquals(workspaces, [ + {workspaceType: workspace1.workspaceType, locationBuildingCode: workspace1.locationBuildingCode}, + {workspaceType: workspace2.workspaceType, locationBuildingCode: workspace2.locationBuildingCode}, + {workspaceType: workspace3.workspaceType, locationBuildingCode: workspace3.locationBuildingCode} + ]); + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2WorkspaceReadOneTest, h2WorkspaceReadManyTest, h2WorkspaceReadManyDependentTest] +} +function h2WorkspaceUpdateTest() returns error? { + H2RainierClient rainierClient = check new (); + + Workspace workspace = check rainierClient->/workspaces/[workspace1.workspaceId].put({ + workspaceType: "large" + }); + + test:assertEquals(workspace, updatedWorkspace1); + + Workspace workspaceRetrieved = check rainierClient->/workspaces/[workspace1.workspaceId].get(); + test:assertEquals(workspaceRetrieved, updatedWorkspace1); + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2WorkspaceCreateTest, h2WorkspaceCreateTest2] +} +function h2WorkspaceReadWithClauses() returns error? { + H2RainierClient rainierClient = check new (); + string value = "small"; + string value2 = "medium"; + string id = "\"Workspace\".\"workspaceId\""; + int count = 2; + stream workspaceStream = rainierClient->/workspaces.get(whereClause = `"Workspace"."workspaceType" = ${value} OR "Workspace"."workspaceType" = ${value2}`, orderByClause = `"Workspace"."workspaceId" DESC `, limitClause = ` ${count}`, groupByClause = `${id}`); + Workspace[] workspaces = check from Workspace workspace in workspaceStream + select workspace; + test:assertEquals(workspaces, [workspace3, workspace2]); + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2WorkspaceReadOneTest, h2WorkspaceReadManyTest, h2WorkspaceReadManyDependentTest, h2WorkspaceReadWithClauses] +} +function h2WorkspaceUpdateTestNegative1() returns error? { + H2RainierClient rainierClient = check new (); + + Workspace|error workspace = rainierClient->/workspaces/["invalid-workspace-id"].put({ + workspaceType: "large" + }); + + if workspace is persist:NotFoundError { + test:assertEquals(workspace.message(), "A record with the key 'invalid-workspace-id' does not exist for the entity 'Workspace'."); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2WorkspaceReadOneTest, h2WorkspaceReadManyTest, h2WorkspaceReadManyDependentTest, h2WorkspaceReadWithClauses] +} +function h2WorkspaceUpdateTestNegative2() returns error? { + H2RainierClient rainierClient = check new (); + + Workspace|error workspace = rainierClient->/workspaces/[workspace1.workspaceId].put({ + workspaceType: "unncessarily-long-workspace-type-to-force-error-on-update" + }); + + if workspace is persist:Error { + test:assertTrue(workspace.message().includes("Value too long for column \"workspaceType CHARACTER VARYING(10)")); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2WorkspaceUpdateTest, h2WorkspaceUpdateTestNegative2] +} +function h2WorkspaceDeleteTest() returns error? { + H2RainierClient rainierClient = check new (); + + Workspace workspace = check rainierClient->/workspaces/[workspace1.workspaceId].delete(); + test:assertEquals(workspace, updatedWorkspace1); + + stream workspaceStream = rainierClient->/workspaces.get(); + Workspace[] workspaces = check from Workspace workspace2 in workspaceStream + select workspace2; + + test:assertEquals(workspaces, [workspace2, workspace3]); + check rainierClient.close(); +} + +@test:Config { + groups: ["workspace", "h2"], + dependsOn: [h2WorkspaceDeleteTest] +} +function h2WorkspaceDeleteTestNegative() returns error? { + H2RainierClient rainierClient = check new (); + + Workspace|error workspace = rainierClient->/workspaces/[workspace1.workspaceId].delete(); + + if workspace is persist:NotFoundError { + test:assertEquals(workspace.message(), string `A record with the key '${workspace1.workspaceId}' does not exist for the entity 'Workspace'.`); + } else { + test:assertFail("NotFoundError expected."); + } + check rainierClient.close(); +} diff --git a/ballerina/tests/h2_rainier_generated_client.bal b/ballerina/tests/h2_rainier_generated_client.bal new file mode 100644 index 0000000..6d28e10 --- /dev/null +++ b/ballerina/tests/h2_rainier_generated_client.bal @@ -0,0 +1,363 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/jballerina.java; +import ballerinax/java.jdbc as jdbc; +import ballerinax/h2.driver as _; +import ballerina/sql; +import ballerina/persist; + +const EMPLOYEE = "employees"; +const WORKSPACE = "workspaces"; +const BUILDING = "buildings"; +const DEPARTMENT = "departments"; +const ORDER_ITEM = "orderitems"; + +public isolated client class H2RainierClient { + *persist:AbstractPersistClient; + + private final jdbc:Client dbClient; + + private final map persistClients; + + private final record {|SQLMetadata...;|} & readonly metadata = { + [EMPLOYEE] : { + entityName: "Employee", + tableName: "Employee", + fieldMetadata: { + empNo: {columnName: "empNo"}, + firstName: {columnName: "firstName"}, + lastName: {columnName: "lastName"}, + birthDate: {columnName: "birthDate"}, + gender: {columnName: "gender"}, + hireDate: {columnName: "hireDate"}, + departmentDeptNo: {columnName: "departmentDeptNo"}, + workspaceWorkspaceId: {columnName: "workspaceWorkspaceId"}, + "department.deptNo": {relation: {entityName: "department", refField: "deptNo"}}, + "department.deptName": {relation: {entityName: "department", refField: "deptName"}}, + "workspace.workspaceId": {relation: {entityName: "workspace", refField: "workspaceId"}}, + "workspace.workspaceType": {relation: {entityName: "workspace", refField: "workspaceType"}}, + "workspace.locationBuildingCode": {relation: {entityName: "workspace", refField: "locationBuildingCode"}} + }, + keyFields: ["empNo"], + joinMetadata: { + department: {entity: Department, fieldName: "department", refTable: "Department", refColumns: ["deptNo"], joinColumns: ["departmentDeptNo"], 'type: ONE_TO_MANY}, + workspace: {entity: Workspace, fieldName: "workspace", refTable: "Workspace", refColumns: ["workspaceId"], joinColumns: ["workspaceWorkspaceId"], 'type: ONE_TO_MANY} + } + }, + [WORKSPACE] : { + entityName: "Workspace", + tableName: "Workspace", + fieldMetadata: { + workspaceId: {columnName: "workspaceId"}, + workspaceType: {columnName: "workspaceType"}, + locationBuildingCode: {columnName: "locationBuildingCode"}, + "location.buildingCode": {relation: {entityName: "location", refField: "buildingCode"}}, + "location.city": {relation: {entityName: "location", refField: "city"}}, + "location.state": {relation: {entityName: "location", refField: "state"}}, + "location.country": {relation: {entityName: "location", refField: "country"}}, + "location.postalCode": {relation: {entityName: "location", refField: "postalCode"}}, + "location.type": {relation: {entityName: "location", refField: "type"}}, + "employees[].empNo": {relation: {entityName: "employees", refField: "empNo"}}, + "employees[].firstName": {relation: {entityName: "employees", refField: "firstName"}}, + "employees[].lastName": {relation: {entityName: "employees", refField: "lastName"}}, + "employees[].birthDate": {relation: {entityName: "employees", refField: "birthDate"}}, + "employees[].gender": {relation: {entityName: "employees", refField: "gender"}}, + "employees[].hireDate": {relation: {entityName: "employees", refField: "hireDate"}}, + "employees[].departmentDeptNo": {relation: {entityName: "employees", refField: "departmentDeptNo"}}, + "employees[].workspaceWorkspaceId": {relation: {entityName: "employees", refField: "workspaceWorkspaceId"}} + }, + keyFields: ["workspaceId"], + joinMetadata: { + location: {entity: Building, fieldName: "location", refTable: "Building", refColumns: ["buildingCode"], joinColumns: ["locationBuildingCode"], 'type: ONE_TO_MANY}, + employees: {entity: Employee, fieldName: "employees", refTable: "Employee", refColumns: ["workspaceWorkspaceId"], joinColumns: ["workspaceId"], 'type: MANY_TO_ONE} + } + }, + [BUILDING] : { + entityName: "Building", + tableName: "Building", + fieldMetadata: { + buildingCode: {columnName: "buildingCode"}, + city: {columnName: "city"}, + state: {columnName: "state"}, + country: {columnName: "country"}, + postalCode: {columnName: "postalCode"}, + 'type: {columnName: "type"}, + "workspaces[].workspaceId": {relation: {entityName: "workspaces", refField: "workspaceId"}}, + "workspaces[].workspaceType": {relation: {entityName: "workspaces", refField: "workspaceType"}}, + "workspaces[].locationBuildingCode": {relation: {entityName: "workspaces", refField: "locationBuildingCode"}} + }, + keyFields: ["buildingCode"], + joinMetadata: {workspaces: {entity: Workspace, fieldName: "workspaces", refTable: "Workspace", refColumns: ["locationBuildingCode"], joinColumns: ["buildingCode"], 'type: MANY_TO_ONE}} + }, + [DEPARTMENT] : { + entityName: "Department", + tableName: "Department", + fieldMetadata: { + deptNo: {columnName: "deptNo"}, + deptName: {columnName: "deptName"}, + "employees[].empNo": {relation: {entityName: "employees", refField: "empNo"}}, + "employees[].firstName": {relation: {entityName: "employees", refField: "firstName"}}, + "employees[].lastName": {relation: {entityName: "employees", refField: "lastName"}}, + "employees[].birthDate": {relation: {entityName: "employees", refField: "birthDate"}}, + "employees[].gender": {relation: {entityName: "employees", refField: "gender"}}, + "employees[].hireDate": {relation: {entityName: "employees", refField: "hireDate"}}, + "employees[].departmentDeptNo": {relation: {entityName: "employees", refField: "departmentDeptNo"}}, + "employees[].workspaceWorkspaceId": {relation: {entityName: "employees", refField: "workspaceWorkspaceId"}} + }, + keyFields: ["deptNo"], + joinMetadata: {employees: {entity: Employee, fieldName: "employees", refTable: "Employee", refColumns: ["departmentDeptNo"], joinColumns: ["deptNo"], 'type: MANY_TO_ONE}} + }, + [ORDER_ITEM] : { + entityName: "OrderItem", + tableName: "OrderItem", + fieldMetadata: { + orderId: {columnName: "orderId"}, + itemId: {columnName: "itemId"}, + quantity: {columnName: "quantity"}, + notes: {columnName: "notes"} + }, + keyFields: ["orderId", "itemId"] + } + }; + + public isolated function init() returns persist:Error? { + jdbc:Client|error dbClient = new (url = h2Url, user = h2User, password = h2Password); + if dbClient is error { + return error(dbClient.message()); + } + self.dbClient = dbClient; + self.persistClients = { + [EMPLOYEE] : check new (dbClient, self.metadata.get(EMPLOYEE), H2_SPECIFICS), + [WORKSPACE] : check new (dbClient, self.metadata.get(WORKSPACE), H2_SPECIFICS), + [BUILDING] : check new (dbClient, self.metadata.get(BUILDING), H2_SPECIFICS), + [DEPARTMENT] : check new (dbClient, self.metadata.get(DEPARTMENT), H2_SPECIFICS), + [ORDER_ITEM] : check new (dbClient, self.metadata.get(ORDER_ITEM), H2_SPECIFICS) + }; + } + + isolated resource function get employees(EmployeeTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get employees/[string empNo](EmployeeTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post employees(EmployeeInsert[] data) returns string[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(EMPLOYEE); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from EmployeeInsert inserted in data + select inserted.empNo; + } + + isolated resource function put employees/[string empNo](EmployeeUpdate value) returns Employee|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(EMPLOYEE); + } + _ = check sqlClient.runUpdateQuery(empNo, value); + return self->/employees/[empNo].get(); + } + + isolated resource function delete employees/[string empNo]() returns Employee|persist:Error { + Employee result = check self->/employees/[empNo].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(EMPLOYEE); + } + _ = check sqlClient.runDeleteQuery(empNo); + return result; + } + + isolated resource function get workspaces(WorkspaceTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get workspaces/[string workspaceId](WorkspaceTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post workspaces(WorkspaceInsert[] data) returns string[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(WORKSPACE); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from WorkspaceInsert inserted in data + select inserted.workspaceId; + } + + isolated resource function put workspaces/[string workspaceId](WorkspaceUpdate value) returns Workspace|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(WORKSPACE); + } + _ = check sqlClient.runUpdateQuery(workspaceId, value); + return self->/workspaces/[workspaceId].get(); + } + + isolated resource function delete workspaces/[string workspaceId]() returns Workspace|persist:Error { + Workspace result = check self->/workspaces/[workspaceId].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(WORKSPACE); + } + _ = check sqlClient.runDeleteQuery(workspaceId); + return result; + } + + isolated resource function get buildings(BuildingTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get buildings/[string buildingCode](BuildingTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post buildings(BuildingInsert[] data) returns string[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(BUILDING); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from BuildingInsert inserted in data + select inserted.buildingCode; + } + + isolated resource function put buildings/[string buildingCode](BuildingUpdate value) returns Building|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(BUILDING); + } + _ = check sqlClient.runUpdateQuery(buildingCode, value); + return self->/buildings/[buildingCode].get(); + } + + isolated resource function delete buildings/[string buildingCode]() returns Building|persist:Error { + Building result = check self->/buildings/[buildingCode].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(BUILDING); + } + _ = check sqlClient.runDeleteQuery(buildingCode); + return result; + } + + isolated resource function get departments(DepartmentTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get departments/[string deptNo](DepartmentTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post departments(DepartmentInsert[] data) returns string[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(DEPARTMENT); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from DepartmentInsert inserted in data + select inserted.deptNo; + } + + isolated resource function put departments/[string deptNo](DepartmentUpdate value) returns Department|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(DEPARTMENT); + } + _ = check sqlClient.runUpdateQuery(deptNo, value); + return self->/departments/[deptNo].get(); + } + + isolated resource function delete departments/[string deptNo]() returns Department|persist:Error { + Department result = check self->/departments/[deptNo].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(DEPARTMENT); + } + _ = check sqlClient.runDeleteQuery(deptNo); + return result; + } + + isolated resource function get orderitems(OrderItemTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get orderitems/[string orderId]/[string itemId](OrderItemTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post orderitems(OrderItemInsert[] data) returns [string, string][]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(ORDER_ITEM); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from OrderItemInsert inserted in data + select [inserted.orderId, inserted.itemId]; + } + + isolated resource function put orderitems/[string orderId]/[string itemId](OrderItemUpdate value) returns OrderItem|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(ORDER_ITEM); + } + _ = check sqlClient.runUpdateQuery({"orderId": orderId, "itemId": itemId}, value); + return self->/orderitems/[orderId]/[itemId].get(); + } + + isolated resource function delete orderitems/[string orderId]/[string itemId]() returns OrderItem|persist:Error { + OrderItem result = check self->/orderitems/[orderId]/[itemId].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(ORDER_ITEM); + } + _ = check sqlClient.runDeleteQuery({"orderId": orderId, "itemId": itemId}); + return result; + } + + remote isolated function queryNativeSQL(sql:ParameterizedQuery sqlQuery, typedesc rowType = <>) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor" + } external; + + remote isolated function executeNativeSQL(sql:ParameterizedQuery sqlQuery) returns ExecutionResult|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor" + } external; + + public isolated function close() returns persist:Error? { + error? result = self.dbClient.close(); + if result is error { + return error(result.message()); + } + return result; + } +} + diff --git a/ballerina/tests/h2_test_entities_generated_client.bal b/ballerina/tests/h2_test_entities_generated_client.bal new file mode 100644 index 0000000..570634c --- /dev/null +++ b/ballerina/tests/h2_test_entities_generated_client.bal @@ -0,0 +1,502 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/persist; +import ballerina/jballerina.java; +import ballerinax/java.jdbc as jdbc; +import ballerinax/h2.driver as _; +import ballerina/sql; + +const ALL_TYPES = "alltypes"; +const STRING_ID_RECORD = "stringidrecords"; +const INT_ID_RECORD = "intidrecords"; +const FLOAT_ID_RECORD = "floatidrecords"; +const DECIMAL_ID_RECORD = "decimalidrecords"; +const BOOLEAN_ID_RECORD = "booleanidrecords"; +const COMPOSITE_ASSOCIATION_RECORD = "compositeassociationrecords"; +const ALL_TYPES_ID_RECORD = "alltypesidrecords"; + +public isolated client class H2TestEntitiesClient { + *persist:AbstractPersistClient; + + private final jdbc:Client dbClient; + + private final map persistClients; + + private final record {|SQLMetadata...;|} & readonly metadata = { + [ALL_TYPES] : { + entityName: "AllTypes", + tableName: "AllTypes", + fieldMetadata: { + id: {columnName: "id"}, + booleanType: {columnName: "booleanType"}, + intType: {columnName: "intType"}, + floatType: {columnName: "floatType"}, + decimalType: {columnName: "decimalType"}, + stringType: {columnName: "stringType"}, + byteArrayType: {columnName: "byteArrayType"}, + dateType: {columnName: "dateType"}, + timeOfDayType: {columnName: "timeOfDayType"}, + civilType: {columnName: "civilType"}, + booleanTypeOptional: {columnName: "booleanTypeOptional"}, + intTypeOptional: {columnName: "intTypeOptional"}, + floatTypeOptional: {columnName: "floatTypeOptional"}, + decimalTypeOptional: {columnName: "decimalTypeOptional"}, + stringTypeOptional: {columnName: "stringTypeOptional"}, + dateTypeOptional: {columnName: "dateTypeOptional"}, + timeOfDayTypeOptional: {columnName: "timeOfDayTypeOptional"}, + civilTypeOptional: {columnName: "civilTypeOptional"}, + enumType: {columnName: "enumType"}, + enumTypeOptional: {columnName: "enumTypeOptional"} + }, + keyFields: ["id"] + }, + [STRING_ID_RECORD] : { + entityName: "StringIdRecord", + tableName: "StringIdRecord", + fieldMetadata: { + id: {columnName: "id"}, + randomField: {columnName: "randomField"} + }, + keyFields: ["id"] + }, + [INT_ID_RECORD] : { + entityName: "IntIdRecord", + tableName: "IntIdRecord", + fieldMetadata: { + id: {columnName: "id"}, + randomField: {columnName: "randomField"} + }, + keyFields: ["id"] + }, + [FLOAT_ID_RECORD] : { + entityName: "FloatIdRecord", + tableName: "FloatIdRecord", + fieldMetadata: { + id: {columnName: "id"}, + randomField: {columnName: "randomField"} + }, + keyFields: ["id"] + }, + [DECIMAL_ID_RECORD] : { + entityName: "DecimalIdRecord", + tableName: "DecimalIdRecord", + fieldMetadata: { + id: {columnName: "id"}, + randomField: {columnName: "randomField"} + }, + keyFields: ["id"] + }, + [BOOLEAN_ID_RECORD] : { + entityName: "BooleanIdRecord", + tableName: "BooleanIdRecord", + fieldMetadata: { + id: {columnName: "id"}, + randomField: {columnName: "randomField"} + }, + keyFields: ["id"] + }, + [COMPOSITE_ASSOCIATION_RECORD] : { + entityName: "CompositeAssociationRecord", + tableName: "CompositeAssociationRecord", + fieldMetadata: { + id: {columnName: "id"}, + randomField: {columnName: "randomField"}, + alltypesidrecordBooleanType: {columnName: "alltypesidrecordBooleanType"}, + alltypesidrecordIntType: {columnName: "alltypesidrecordIntType"}, + alltypesidrecordFloatType: {columnName: "alltypesidrecordFloatType"}, + alltypesidrecordDecimalType: {columnName: "alltypesidrecordDecimalType"}, + alltypesidrecordStringType: {columnName: "alltypesidrecordStringType"}, + "allTypesIdRecord.booleanType": {relation: {entityName: "allTypesIdRecord", refField: "booleanType"}}, + "allTypesIdRecord.intType": {relation: {entityName: "allTypesIdRecord", refField: "intType"}}, + "allTypesIdRecord.floatType": {relation: {entityName: "allTypesIdRecord", refField: "floatType"}}, + "allTypesIdRecord.decimalType": {relation: {entityName: "allTypesIdRecord", refField: "decimalType"}}, + "allTypesIdRecord.stringType": {relation: {entityName: "allTypesIdRecord", refField: "stringType"}}, + "allTypesIdRecord.randomField": {relation: {entityName: "allTypesIdRecord", refField: "randomField"}} + }, + keyFields: ["id"], + joinMetadata: {allTypesIdRecord: {entity: AllTypesIdRecord, fieldName: "allTypesIdRecord", refTable: "AllTypesIdRecord", refColumns: ["booleanType", "intType", "floatType", "decimalType", "stringType"], joinColumns: ["alltypesidrecordBooleanType", "alltypesidrecordIntType", "alltypesidrecordFloatType", "alltypesidrecordDecimalType", "alltypesidrecordStringType"], 'type: ONE_TO_ONE}} + }, + [ALL_TYPES_ID_RECORD] : { + entityName: "AllTypesIdRecord", + tableName: "AllTypesIdRecord", + fieldMetadata: { + booleanType: {columnName: "booleanType"}, + intType: {columnName: "intType"}, + floatType: {columnName: "floatType"}, + decimalType: {columnName: "decimalType"}, + stringType: {columnName: "stringType"}, + randomField: {columnName: "randomField"}, + "compositeAssociationRecord.id": {relation: {entityName: "compositeAssociationRecord", refField: "id"}}, + "compositeAssociationRecord.randomField": {relation: {entityName: "compositeAssociationRecord", refField: "randomField"}}, + "compositeAssociationRecord.alltypesidrecordBooleanType": {relation: {entityName: "compositeAssociationRecord", refField: "alltypesidrecordBooleanType"}}, + "compositeAssociationRecord.alltypesidrecordIntType": {relation: {entityName: "compositeAssociationRecord", refField: "alltypesidrecordIntType"}}, + "compositeAssociationRecord.alltypesidrecordFloatType": {relation: {entityName: "compositeAssociationRecord", refField: "alltypesidrecordFloatType"}}, + "compositeAssociationRecord.alltypesidrecordDecimalType": {relation: {entityName: "compositeAssociationRecord", refField: "alltypesidrecordDecimalType"}}, + "compositeAssociationRecord.alltypesidrecordStringType": {relation: {entityName: "compositeAssociationRecord", refField: "alltypesidrecordStringType"}} + }, + keyFields: ["booleanType", "intType", "floatType", "decimalType", "stringType"], + joinMetadata: {compositeAssociationRecord: {entity: CompositeAssociationRecord, fieldName: "compositeAssociationRecord", refTable: "CompositeAssociationRecord", refColumns: ["alltypesidrecordBooleanType", "alltypesidrecordIntType", "alltypesidrecordFloatType", "alltypesidrecordDecimalType", "alltypesidrecordStringType"], joinColumns: ["booleanType", "intType", "floatType", "decimalType", "stringType"], 'type: ONE_TO_ONE}} + } + }; + + public isolated function init() returns persist:Error? { + jdbc:Client|error dbClient = new (url = h2Url, user = h2User, password = h2Password); + if dbClient is error { + return error(dbClient.message()); + } + self.dbClient = dbClient; + self.persistClients = { + [ALL_TYPES] : check new (dbClient, self.metadata.get(ALL_TYPES), H2_SPECIFICS), + [STRING_ID_RECORD] : check new (dbClient, self.metadata.get(STRING_ID_RECORD), H2_SPECIFICS), + [INT_ID_RECORD] : check new (dbClient, self.metadata.get(INT_ID_RECORD), H2_SPECIFICS), + [FLOAT_ID_RECORD] : check new (dbClient, self.metadata.get(FLOAT_ID_RECORD), H2_SPECIFICS), + [DECIMAL_ID_RECORD] : check new (dbClient, self.metadata.get(DECIMAL_ID_RECORD), H2_SPECIFICS), + [BOOLEAN_ID_RECORD] : check new (dbClient, self.metadata.get(BOOLEAN_ID_RECORD), H2_SPECIFICS), + [COMPOSITE_ASSOCIATION_RECORD] : check new (dbClient, self.metadata.get(COMPOSITE_ASSOCIATION_RECORD), H2_SPECIFICS), + [ALL_TYPES_ID_RECORD] : check new (dbClient, self.metadata.get(ALL_TYPES_ID_RECORD), H2_SPECIFICS) + }; + } + + isolated resource function get alltypes(AllTypesTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get alltypes/[int id](AllTypesTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post alltypes(AllTypesInsert[] data) returns int[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(ALL_TYPES); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from AllTypesInsert inserted in data + select inserted.id; + } + + isolated resource function put alltypes/[int id](AllTypesUpdate value) returns AllTypes|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(ALL_TYPES); + } + _ = check sqlClient.runUpdateQuery(id, value); + return self->/alltypes/[id].get(); + } + + isolated resource function delete alltypes/[int id]() returns AllTypes|persist:Error { + AllTypes result = check self->/alltypes/[id].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(ALL_TYPES); + } + _ = check sqlClient.runDeleteQuery(id); + return result; + } + + isolated resource function get stringidrecords(StringIdRecordTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get stringidrecords/[string id](StringIdRecordTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post stringidrecords(StringIdRecordInsert[] data) returns string[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(STRING_ID_RECORD); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from StringIdRecordInsert inserted in data + select inserted.id; + } + + isolated resource function put stringidrecords/[string id](StringIdRecordUpdate value) returns StringIdRecord|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(STRING_ID_RECORD); + } + _ = check sqlClient.runUpdateQuery(id, value); + return self->/stringidrecords/[id].get(); + } + + isolated resource function delete stringidrecords/[string id]() returns StringIdRecord|persist:Error { + StringIdRecord result = check self->/stringidrecords/[id].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(STRING_ID_RECORD); + } + _ = check sqlClient.runDeleteQuery(id); + return result; + } + + isolated resource function get intidrecords(IntIdRecordTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get intidrecords/[int id](IntIdRecordTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post intidrecords(IntIdRecordInsert[] data) returns int[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(INT_ID_RECORD); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from IntIdRecordInsert inserted in data + select inserted.id; + } + + isolated resource function put intidrecords/[int id](IntIdRecordUpdate value) returns IntIdRecord|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(INT_ID_RECORD); + } + _ = check sqlClient.runUpdateQuery(id, value); + return self->/intidrecords/[id].get(); + } + + isolated resource function delete intidrecords/[int id]() returns IntIdRecord|persist:Error { + IntIdRecord result = check self->/intidrecords/[id].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(INT_ID_RECORD); + } + _ = check sqlClient.runDeleteQuery(id); + return result; + } + + isolated resource function get floatidrecords(FloatIdRecordTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get floatidrecords/[float id](FloatIdRecordTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post floatidrecords(FloatIdRecordInsert[] data) returns float[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(FLOAT_ID_RECORD); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from FloatIdRecordInsert inserted in data + select inserted.id; + } + + isolated resource function put floatidrecords/[float id](FloatIdRecordUpdate value) returns FloatIdRecord|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(FLOAT_ID_RECORD); + } + _ = check sqlClient.runUpdateQuery(id, value); + return self->/floatidrecords/[id].get(); + } + + isolated resource function delete floatidrecords/[float id]() returns FloatIdRecord|persist:Error { + FloatIdRecord result = check self->/floatidrecords/[id].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(FLOAT_ID_RECORD); + } + _ = check sqlClient.runDeleteQuery(id); + return result; + } + + isolated resource function get decimalidrecords(DecimalIdRecordTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get decimalidrecords/[decimal id](DecimalIdRecordTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post decimalidrecords(DecimalIdRecordInsert[] data) returns decimal[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(DECIMAL_ID_RECORD); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from DecimalIdRecordInsert inserted in data + select inserted.id; + } + + isolated resource function put decimalidrecords/[decimal id](DecimalIdRecordUpdate value) returns DecimalIdRecord|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(DECIMAL_ID_RECORD); + } + _ = check sqlClient.runUpdateQuery(id, value); + return self->/decimalidrecords/[id].get(); + } + + isolated resource function delete decimalidrecords/[decimal id]() returns DecimalIdRecord|persist:Error { + DecimalIdRecord result = check self->/decimalidrecords/[id].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(DECIMAL_ID_RECORD); + } + _ = check sqlClient.runDeleteQuery(id); + return result; + } + + isolated resource function get booleanidrecords(BooleanIdRecordTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get booleanidrecords/[boolean id](BooleanIdRecordTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post booleanidrecords(BooleanIdRecordInsert[] data) returns boolean[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(BOOLEAN_ID_RECORD); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from BooleanIdRecordInsert inserted in data + select inserted.id; + } + + isolated resource function put booleanidrecords/[boolean id](BooleanIdRecordUpdate value) returns BooleanIdRecord|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(BOOLEAN_ID_RECORD); + } + _ = check sqlClient.runUpdateQuery(id, value); + return self->/booleanidrecords/[id].get(); + } + + isolated resource function delete booleanidrecords/[boolean id]() returns BooleanIdRecord|persist:Error { + BooleanIdRecord result = check self->/booleanidrecords/[id].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(BOOLEAN_ID_RECORD); + } + _ = check sqlClient.runDeleteQuery(id); + return result; + } + + isolated resource function get compositeassociationrecords(CompositeAssociationRecordTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get compositeassociationrecords/[string id](CompositeAssociationRecordTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post compositeassociationrecords(CompositeAssociationRecordInsert[] data) returns string[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(COMPOSITE_ASSOCIATION_RECORD); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from CompositeAssociationRecordInsert inserted in data + select inserted.id; + } + + isolated resource function put compositeassociationrecords/[string id](CompositeAssociationRecordUpdate value) returns CompositeAssociationRecord|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(COMPOSITE_ASSOCIATION_RECORD); + } + _ = check sqlClient.runUpdateQuery(id, value); + return self->/compositeassociationrecords/[id].get(); + } + + isolated resource function delete compositeassociationrecords/[string id]() returns CompositeAssociationRecord|persist:Error { + CompositeAssociationRecord result = check self->/compositeassociationrecords/[id].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(COMPOSITE_ASSOCIATION_RECORD); + } + _ = check sqlClient.runDeleteQuery(id); + return result; + } + + isolated resource function get alltypesidrecords(AllTypesIdRecordTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get alltypesidrecords/[boolean booleanType]/[int intType]/[float floatType]/[decimal decimalType]/[string stringType](AllTypesIdRecordTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post alltypesidrecords(AllTypesIdRecordInsert[] data) returns [boolean, int, float, decimal, string][]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(ALL_TYPES_ID_RECORD); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from AllTypesIdRecordInsert inserted in data + select [inserted.booleanType, inserted.intType, inserted.floatType, inserted.decimalType, inserted.stringType]; + } + + isolated resource function put alltypesidrecords/[boolean booleanType]/[int intType]/[float floatType]/[decimal decimalType]/[string stringType](AllTypesIdRecordUpdate value) returns AllTypesIdRecord|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(ALL_TYPES_ID_RECORD); + } + _ = check sqlClient.runUpdateQuery({"booleanType": booleanType, "intType": intType, "floatType": floatType, "decimalType": decimalType, "stringType": stringType}, value); + return self->/alltypesidrecords/[booleanType]/[intType]/[floatType]/[decimalType]/[stringType].get(); + } + + isolated resource function delete alltypesidrecords/[boolean booleanType]/[int intType]/[float floatType]/[decimal decimalType]/[string stringType]() returns AllTypesIdRecord|persist:Error { + AllTypesIdRecord result = check self->/alltypesidrecords/[booleanType]/[intType]/[floatType]/[decimalType]/[stringType].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(ALL_TYPES_ID_RECORD); + } + _ = check sqlClient.runDeleteQuery({"booleanType": booleanType, "intType": intType, "floatType": floatType, "decimalType": decimalType, "stringType": stringType}); + return result; + } + + remote isolated function queryNativeSQL(sql:ParameterizedQuery sqlQuery, typedesc rowType = <>) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor" + } external; + + remote isolated function executeNativeSQL(sql:ParameterizedQuery sqlQuery) returns ExecutionResult|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor" + } external; + + public isolated function close() returns persist:Error? { + error? result = self.dbClient.close(); + if result is error { + return error(result.message()); + } + return result; + } +} + diff --git a/ballerina/tests/init-tests.bal b/ballerina/tests/init-tests.bal index 0f61446..3b72d32 100644 --- a/ballerina/tests/init-tests.bal +++ b/ballerina/tests/init-tests.bal @@ -13,15 +13,26 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. - import ballerina/test; -import ballerinax/mysql; -import ballerinax/mysql.driver as _; +import ballerina/time; +import ballerinax/h2.driver as _; +import ballerinax/java.jdbc; import ballerinax/mssql; import ballerinax/mssql.driver as _; +import ballerinax/mysql; +import ballerinax/mysql.driver as _; import ballerinax/postgresql; import ballerinax/postgresql.driver as _; -import ballerina/time; + +configurable string h2Url = ?; +configurable string h2User = ?; +configurable string h2Password = ?; + +configurable record {| + string url; + string user; + string password; +|} h2 = ?; configurable record {| int port; @@ -51,7 +62,14 @@ configurable record {| |} postgresql = ?; @test:BeforeSuite -function initTests() returns error? { +function initSuite() returns error? { + check initMySQLTest(); + //check initMSSQLTest(); + check initPostgreSQLTest(); + check initH2Test(); +} + +function initMySQLTest() returns error? { // MySQL mysql:Client mysqlDbClient = check new (host = mysql.host, user = mysql.user, password = mysql.password, database = mysql.database, port = mysql.port); _ = check mysqlDbClient->execute(`SET FOREIGN_KEY_CHECKS = 0`); @@ -70,7 +88,9 @@ function initTests() returns error? { _ = check mysqlDbClient->execute(`TRUNCATE CompositeAssociationRecord`); _ = check mysqlDbClient->execute(`SET FOREIGN_KEY_CHECKS = 1`); check mysqlDbClient.close(); +} +function initMSSQLTest() returns error? { //MSSQL mssql:Client mssqlDbClient = check new (host = mssql.host, user = mssql.user, password = mssql.password, port = mssql.port); _ = check mssqlDbClient->execute(`DROP DATABASE IF EXISTS test;`); @@ -221,7 +241,9 @@ function initTests() returns error? { PRIMARY KEY(id) ); `); +} +function initPostgreSQLTest() returns error? { // PostgreSQL postgresql:Client postgresqlDbClient = check new (host = postgresql.host, username = postgresql.user, password = postgresql.password, database = postgresql.database, port = postgresql.port); _ = check postgresqlDbClient->execute(`TRUNCATE "Employee" CASCADE`); @@ -240,6 +262,167 @@ function initTests() returns error? { check postgresqlDbClient.close(); } +function initH2Test() returns error? { + jdbc:Client h2DbClient = check new (url = h2.url, user = h2.user, password = h2.password); + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "Building"`); + _ = check h2DbClient->execute(` + CREATE TABLE "Building" ( + "buildingCode" VARCHAR(36) PRIMARY KEY, + "city" VARCHAR(50), + "state" VARCHAR(50), + "country" VARCHAR(50), + "postalCode" VARCHAR(50), + "type" VARCHAR(50) + ) + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "Workspace"`); + _ = check h2DbClient->execute(` + CREATE TABLE "Workspace" ( + "workspaceId" VARCHAR(36) PRIMARY KEY, + "workspaceType" VARCHAR(10), + "locationBuildingCode" VARCHAR(36), + FOREIGN KEY ("locationBuildingCode") REFERENCES "Building"("buildingCode") + ) + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "Department"`); + _ = check h2DbClient->execute(` + CREATE TABLE "Department" ( + "deptNo" VARCHAR(36) PRIMARY KEY, + "deptName" VARCHAR(30) + ) + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "Employee"`); + _ = check h2DbClient->execute(` + CREATE TABLE "Employee" ( + "empNo" VARCHAR(36) PRIMARY KEY, + "firstName" VARCHAR(30), + "lastName" VARCHAR(30), + "birthDate" DATE, + "gender" VARCHAR(6) CHECK ("gender" IN ('MALE', 'FEMALE')) NOT NULL, + "hireDate" DATE, + "departmentDeptNo" VARCHAR(36), + "workspaceWorkspaceId" VARCHAR(36), + FOREIGN KEY ("departmentDeptNo") REFERENCES "Department"("deptNo"), + FOREIGN KEY ("workspaceWorkspaceId") REFERENCES "Workspace"("workspaceId") + ) + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "OrderItem"`); + _ = check h2DbClient->execute(` + CREATE TABLE "OrderItem" ( + "orderId" VARCHAR(36), + "itemId" VARCHAR(30), + "quantity" INTEGER, + "notes" VARCHAR(255), + PRIMARY KEY("orderId", "itemId") + ) + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "AllTypes"`); + _ = check h2DbClient->execute(` + CREATE TABLE "AllTypes" ( + "id" INT NOT NULL, + "booleanType" BOOLEAN NOT NULL, + "intType" INT NOT NULL, + "floatType" FLOAT NOT NULL, + "decimalType" DECIMAL(10, 2) NOT NULL, + "stringType" VARCHAR(191) NOT NULL, + "byteArrayType" VARBINARY NOT NULL, + "dateType" DATE NOT NULL, + "timeOfDayType" TIME NOT NULL, + "civilType" TIMESTAMP NOT NULL, + "booleanTypeOptional" BOOLEAN, + "intTypeOptional" INT, + "floatTypeOptional" FLOAT, + "decimalTypeOptional" DECIMAL(10, 2), + "stringTypeOptional" VARCHAR(191), + "dateTypeOptional" DATE, + "timeOfDayTypeOptional" TIME, + "civilTypeOptional" TIMESTAMP, + "enumType" VARCHAR(6) CHECK ("enumType" IN ('TYPE_1', 'TYPE_2', 'TYPE_3', 'TYPE_4')) NOT NULL, + "enumTypeOptional" VARCHAR(6) CHECK ("enumTypeOptional" IN ('TYPE_1', 'TYPE_2', 'TYPE_3', 'TYPE_4')), + PRIMARY KEY("id") + ); + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "FloatIdRecord"`); + _ = check h2DbClient->execute(` + CREATE TABLE "FloatIdRecord" ( + "id" FLOAT NOT NULL, + "randomField" VARCHAR(191) NOT NULL, + PRIMARY KEY("id") + ); + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "StringIdRecord"`); + _ = check h2DbClient->execute(` + CREATE TABLE "StringIdRecord" ( + "id" VARCHAR(191) NOT NULL, + "randomField" VARCHAR(191) NOT NULL, + PRIMARY KEY("id") + ); + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "DecimalIdRecord"`); + _ = check h2DbClient->execute(` + CREATE TABLE "DecimalIdRecord" ( + "id" DECIMAL(10, 2) NOT NULL, + "randomField" VARCHAR(191) NOT NULL, + PRIMARY KEY("id") + ); + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "BooleanIdRecord"`); + _ = check h2DbClient->execute(` + CREATE TABLE "BooleanIdRecord" ( + "id" BOOLEAN NOT NULL, + "randomField" VARCHAR(191) NOT NULL, + PRIMARY KEY("id") + ); + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "IntIdRecord"`); + _ = check h2DbClient->execute(` + CREATE TABLE "IntIdRecord" ( + "id" INT NOT NULL, + "randomField" VARCHAR(191) NOT NULL, + PRIMARY KEY("id") + ); + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "AllTypesIdRecord"`); + _ = check h2DbClient->execute(` + CREATE TABLE "AllTypesIdRecord" ( + "booleanType" BOOLEAN NOT NULL, + "intType" INT NOT NULL, + "floatType" FLOAT NOT NULL, + "decimalType" DECIMAL(10, 2) NOT NULL, + "stringType" VARCHAR(191) NOT NULL, + "randomField" VARCHAR(191) NOT NULL, + PRIMARY KEY("booleanType","intType","floatType","decimalType","stringType") + ); + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "CompositeAssociationRecord"`); + _ = check h2DbClient->execute(` + CREATE TABLE "CompositeAssociationRecord" ( + "id" VARCHAR(191) NOT NULL, + "randomField" VARCHAR(191) NOT NULL, + "alltypesidrecordBooleanType" BOOLEAN NOT NULL, + "alltypesidrecordIntType" INT NOT NULL, + "alltypesidrecordFloatType" FLOAT NOT NULL, + "alltypesidrecordDecimalType" DECIMAL(10, 2) NOT NULL, + "alltypesidrecordStringType" VARCHAR(191) NOT NULL, + CONSTRAINT FK_COMPOSITEASSOCIATIONRECORD_ALLTYPESIDRECORD FOREIGN KEY("alltypesidrecordBooleanType", "alltypesidrecordIntType", "alltypesidrecordFloatType", "alltypesidrecordDecimalType", "alltypesidrecordStringType") REFERENCES "AllTypesIdRecord"("booleanType", "intType", "floatType", "decimalType", "stringType"), + PRIMARY KEY("id") + ); + `); + check h2DbClient.close(); +} + AllTypes allTypes1 = { id: 1, booleanType: false, @@ -302,7 +485,8 @@ AllTypes allTypes2 = { floatTypeOptional: 66.0, decimalTypeOptional: 233.44, stringTypeOptional: "test2", - dateTypeOptional: {year: 1293, month: 11, day: 3}, + // H2 database does not support very old dates(before 1582-10-15) + dateTypeOptional: {year: 1923, month: 11, day: 3}, timeOfDayTypeOptional: {hour: 19, minute: 32, second: 34}, civilTypeOptional: {year: 1989, month: 11, day: 3, hour: 12, minute: 32, second: 34}, enumType: "TYPE_1", diff --git a/build.gradle b/build.gradle index 91aadff..2d62704 100644 --- a/build.gradle +++ b/build.gradle @@ -93,9 +93,11 @@ subprojects { ballerinaStdLibs "io.ballerina.stdlib:mysql-ballerina:${stdlibMysqlVersion}" ballerinaStdLibs "io.ballerina.stdlib:mssql-ballerina:${stdlibMssqlVersion}" ballerinaStdLibs "io.ballerina.stdlib:postgresql-ballerina:${stdlibPostgresqlVersion}" + ballerinaStdLibs "io.ballerina.stdlib:java.jdbc-ballerina:${stdlibJdbcVersion}" ballerinaStdLibs "io.ballerina.stdlib:mysql.driver-ballerina:${stdlibMysqlDriverVersion}" ballerinaStdLibs "io.ballerina.stdlib:mssql.driver-ballerina:${stdlibMssqlDriverVersion}" ballerinaStdLibs "io.ballerina.stdlib:postgresql.driver-ballerina:${stdlibPostgresqlDriverVersion}" + ballerinaStdLibs "io.ballerina.stdlib:h2.driver-ballerina:${stdlibH2DriverVersion}" ballerinaStdLibs "io.ballerina.stdlib:observe-ballerina:${observeVersion}" ballerinaStdLibs "io.ballerina:observe-ballerina:${observeInternalVersion}" } diff --git a/changelog.md b/changelog.md index 5e7ec6a..7111586 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - [Added support for PostgreSQL as a datasource](https://github.com/ballerina-platform/ballerina-library/issues/5829) +- [Added support for H2 DB as a datasource](https://github.com/ballerina-platform/ballerina-library/issues/5715) ### Changed - [Fix class cast exception when executing query with non-global variable](https://github.com/ballerina-platform/persist-tools/issues/311) diff --git a/gradle.properties b/gradle.properties index f1d0e6b..a9c91aa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -40,6 +40,7 @@ stdlibPersistVersion=1.2.1-20231130-100000-cca5690 stdlibMysqlDriverVersion=1.5.0 stdlibMssqlDriverVersion=1.5.0 stdlibPostgresqlDriverVersion=1.5.0 +stdlibH2DriverVersion=1.1.0 # Ballerinax Observer observeVersion=1.2.0 @@ -70,7 +71,7 @@ stdlibTransactionVersion=1.8.0 stdlibMysqlVersion=1.11.0 stdlibMssqlVersion=1.11.0 stdlibPostgresqlVersion=1.11.0 - +stdlibJdbcVersion=1.11.0 # Enabled publishing insecure checksums, due to fail to publish to maven central # Refer https://github.com/gradle/gradle/issues/11308 diff --git a/native/src/main/java/io/ballerina/stdlib/persist/sql/datastore/H2Processor.java b/native/src/main/java/io/ballerina/stdlib/persist/sql/datastore/H2Processor.java new file mode 100644 index 0000000..9ed2e23 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/persist/sql/datastore/H2Processor.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.persist.sql.datastore; + +import io.ballerina.runtime.api.Environment; +import io.ballerina.runtime.api.values.BArray; +import io.ballerina.runtime.api.values.BObject; +import io.ballerina.runtime.api.values.BStream; +import io.ballerina.runtime.api.values.BTypedesc; + +public class H2Processor { + + private H2Processor() { + } + + public static BStream query(Environment env, BObject client, BTypedesc targetType, BObject whereClause, + BObject orderClause, BObject limitClause, BObject groupByClause) { + return SQLProcessor.query(env, client, targetType, whereClause, orderClause, limitClause, groupByClause); + } + + public static Object queryOne(Environment env, BObject client, BArray path, BTypedesc targetType) { + return SQLProcessor.queryOne(env, client, path, targetType); + } + + public static Object executeNativeSQL(Environment env, BObject client, BObject paramSQLString) { + return SQLProcessor.executeNativeSQL(env, client, paramSQLString); + } + + public static BStream queryNativeSQL(Environment env, BObject client, BObject paramSQLString, + BTypedesc targetType) { + return SQLProcessor.queryNativeSQL(env, client, paramSQLString, targetType); + } +} From f94d96d2fa94f9bf5aee6519ccb92a9fe31c2d1c Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 8 Feb 2024 14:14:32 +0530 Subject: [PATCH 06/23] enable mssql database tests --- ballerina/build.gradle | 116 ++++++++++++++++----------------- ballerina/tests/init-tests.bal | 2 +- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 2838bf4..7c47eaf 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -200,67 +200,67 @@ task stopMySQLTestDockerContainer() { } } -//task createMSSQLTestDockerImage(type: Exec) { -// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { -// def standardOutput = new ByteArrayOutputStream() -// commandLine 'sh', '-c', "docker build -f $project.projectDir/tests/resources/mssql/Dockerfile -t ballerina-persist-mssql" + -// " -q $project.projectDir/tests/resources/mssql/" -// doLast { -// checkExecResult(executionResult, 'Error', standardOutput) -// sleep(10 * 1000) -// } -// } -//} +task createMSSQLTestDockerImage(type: Exec) { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + def standardOutput = new ByteArrayOutputStream() + commandLine 'sh', '-c', "docker build -f $project.projectDir/tests/resources/mssql/Dockerfile -t ballerina-persist-mssql" + + " -q $project.projectDir/tests/resources/mssql/" + doLast { + checkExecResult(executionResult, 'Error', standardOutput) + sleep(10 * 1000) + } + } +} -//def checkMSSQLTestDockerContainerStatus(containerName) { -// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { -// try { -// return exec { -// commandLine 'sh', '-c', -// "docker exec ${containerName} /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Test123#" -// }.exitValue -// } catch (all) { -// return 1; -// } -// } -//} +def checkMSSQLTestDockerContainerStatus(containerName) { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + try { + return exec { + commandLine 'sh', '-c', + "docker exec ${containerName} /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Test123#" + }.exitValue + } catch (all) { + return 1; + } + } +} -//task startMSSQLTestDockerContainer(type: Exec) { -// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { -// def standardOutput = new ByteArrayOutputStream() -// commandLine 'sh', '-c', -// "docker run --rm -d --name ballerina-persist-mssql -e ACCEPT_EULA=1 -e SA_PASSWORD=Test123# -p 1433:1433 -d ballerina-persist-mssql" -// def healthCheck = 1; -// def counter = 0; -// doLast { -// checkExecResult(executionResult, 'Error', standardOutput) -// while (healthCheck != 0 && counter < 12) { -// sleep(5 * 1000) -// healthCheck = checkMSSQLTestDockerContainerStatus("ballerina-persist-mssql") -// counter = counter + 1; -// } -// if (healthCheck != 0) { -// throw new GradleException("Docker container 'ballerina-persist-mssql' health test exceeded timeout!") -// } -// } -// } -//} +task startMSSQLTestDockerContainer(type: Exec) { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + def standardOutput = new ByteArrayOutputStream() + commandLine 'sh', '-c', + "docker run --rm -d --name ballerina-persist-mssql -e ACCEPT_EULA=1 -e SA_PASSWORD=Test123# -p 1433:1433 -d ballerina-persist-mssql" + def healthCheck = 1; + def counter = 0; + doLast { + checkExecResult(executionResult, 'Error', standardOutput) + while (healthCheck != 0 && counter < 12) { + sleep(5 * 1000) + healthCheck = checkMSSQLTestDockerContainerStatus("ballerina-persist-mssql") + counter = counter + 1; + } + if (healthCheck != 0) { + throw new GradleException("Docker container 'ballerina-persist-mssql' health test exceeded timeout!") + } + } + } +} -//task stopMSSQLTestDockerContainer() { -// doLast { -// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { -// try { -// def stdOut = new ByteArrayOutputStream() -// exec { -// commandLine 'sh', '-c', "docker stop ballerina-persist-mssql" -// standardOutput = stdOut -// } -// } catch (all) { -// println("Process can safely ignore stopTestDockerContainer task") -// } -// } -// } -//} +task stopMSSQLTestDockerContainer() { + doLast { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + try { + def stdOut = new ByteArrayOutputStream() + exec { + commandLine 'sh', '-c', "docker stop ballerina-persist-mssql" + standardOutput = stdOut + } + } catch (all) { + println("Process can safely ignore stopTestDockerContainer task") + } + } + } +} task createPostgreSQLTestDockerImage(type: Exec) { if (!Os.isFamily(Os.FAMILY_WINDOWS)) { diff --git a/ballerina/tests/init-tests.bal b/ballerina/tests/init-tests.bal index 3b72d32..7ca47f0 100644 --- a/ballerina/tests/init-tests.bal +++ b/ballerina/tests/init-tests.bal @@ -64,7 +64,7 @@ configurable record {| @test:BeforeSuite function initSuite() returns error? { check initMySQLTest(); - //check initMSSQLTest(); + check initMSSQLTest(); check initPostgreSQLTest(); check initH2Test(); } From f8f8ed29ca401541f95fff2b0d0ea4206843b666 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 8 Feb 2024 14:16:22 +0530 Subject: [PATCH 07/23] change the docker platform --- ballerina/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 7c47eaf..478f73a 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -142,7 +142,7 @@ static def checkExecResult(executionResult, failText, standardOutput) { task createMySQLTestDockerImage(type: Exec) { if (!Os.isFamily(Os.FAMILY_WINDOWS)) { def standardOutput = new ByteArrayOutputStream() - commandLine 'sh', '-c', "docker build --platform linux/x86_64/v8 -f $project.projectDir/tests/resources/mysql/Dockerfile -t ballerina-persist-mysql" + + commandLine 'sh', '-c', "docker build --platform linux/amd64 -f $project.projectDir/tests/resources/mysql/Dockerfile -t ballerina-persist-mysql" + " -q $project.projectDir/tests/resources/mysql/" doLast { checkExecResult(executionResult, 'Error', standardOutput) From 1127aed8d4a4534aed60b239565c1eaded9524a3 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 8 Feb 2024 14:17:17 +0530 Subject: [PATCH 08/23] enable starting mssql db docker image --- ballerina/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 478f73a..e5bf9e0 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -325,18 +325,18 @@ task stopPostgreSQLTestDockerContainer() { updateTomlFiles.dependsOn copyStdlibs startMySQLTestDockerContainer.dependsOn createMySQLTestDockerImage -//startMSSQLTestDockerContainer.dependsOn createMSSQLTestDockerImage +startMSSQLTestDockerContainer.dependsOn createMSSQLTestDockerImage startPostgreSQLTestDockerContainer.dependsOn createPostgreSQLTestDockerImage build.dependsOn "generatePomFileForMavenPublication" build.dependsOn ":${packageName}-compiler-plugin:build" build.dependsOn ":${packageName}-native:build" build.finalizedBy stopMySQLTestDockerContainer -//build.finalizedBy stopMSSQLTestDockerContainer +build.finalizedBy stopMSSQLTestDockerContainer build.finalizedBy stopPostgreSQLTestDockerContainer test.dependsOn ":${packageName}-compiler-plugin:build" test.dependsOn ":${packageName}-native:build" test.dependsOn startMySQLTestDockerContainer -//test.dependsOn startMSSQLTestDockerContainer +test.dependsOn startMSSQLTestDockerContainer test.dependsOn startPostgreSQLTestDockerContainer From 246ae4ecacd98ab32dd6ff8c8d147442a16ec10d Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 8 Feb 2024 21:59:22 +0530 Subject: [PATCH 09/23] change the license year --- ballerina/tests/Config.toml | 4 ---- ballerina/tests/h2-all-types-tests.bal | 2 +- ballerina/tests/h2-associations-tests.bal | 2 +- ballerina/tests/h2-building-tests.bal | 2 +- ballerina/tests/h2-composite-key-tests.bal | 2 +- ballerina/tests/h2-department-tests.bal | 2 +- ballerina/tests/h2-employee-tests.bal | 2 +- ballerina/tests/h2-id-fields-tests.bal | 2 +- ballerina/tests/h2-native-tests.bal | 2 +- ballerina/tests/h2-transaction-tests.bal | 2 +- ballerina/tests/h2-workspace-tests.bal | 2 +- ballerina/tests/h2_rainier_generated_client.bal | 4 ++-- ballerina/tests/h2_test_entities_generated_client.bal | 4 ++-- ballerina/tests/init-tests.bal | 6 +----- 14 files changed, 15 insertions(+), 23 deletions(-) diff --git a/ballerina/tests/Config.toml b/ballerina/tests/Config.toml index b3130f8..62d9c85 100644 --- a/ballerina/tests/Config.toml +++ b/ballerina/tests/Config.toml @@ -1,7 +1,3 @@ -h2Url="jdbc:h2:./build/test" -h2User="sa" -h2Password="" - [mysql] user="root" password="Test123#" diff --git a/ballerina/tests/h2-all-types-tests.bal b/ballerina/tests/h2-all-types-tests.bal index 7a3fc04..56d62dc 100644 --- a/ballerina/tests/h2-all-types-tests.bal +++ b/ballerina/tests/h2-all-types-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-associations-tests.bal b/ballerina/tests/h2-associations-tests.bal index 4336c4f..58ecdad 100644 --- a/ballerina/tests/h2-associations-tests.bal +++ b/ballerina/tests/h2-associations-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-building-tests.bal b/ballerina/tests/h2-building-tests.bal index 1439697..08413b8 100644 --- a/ballerina/tests/h2-building-tests.bal +++ b/ballerina/tests/h2-building-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-composite-key-tests.bal b/ballerina/tests/h2-composite-key-tests.bal index 96f73de..0129dfa 100644 --- a/ballerina/tests/h2-composite-key-tests.bal +++ b/ballerina/tests/h2-composite-key-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-department-tests.bal b/ballerina/tests/h2-department-tests.bal index 4d223c2..3313ba7 100644 --- a/ballerina/tests/h2-department-tests.bal +++ b/ballerina/tests/h2-department-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-employee-tests.bal b/ballerina/tests/h2-employee-tests.bal index 7813ced..ac70dd5 100644 --- a/ballerina/tests/h2-employee-tests.bal +++ b/ballerina/tests/h2-employee-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-id-fields-tests.bal b/ballerina/tests/h2-id-fields-tests.bal index abc0b5f..bb7ab64 100644 --- a/ballerina/tests/h2-id-fields-tests.bal +++ b/ballerina/tests/h2-id-fields-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-native-tests.bal b/ballerina/tests/h2-native-tests.bal index 8826a66..f89f251 100644 --- a/ballerina/tests/h2-native-tests.bal +++ b/ballerina/tests/h2-native-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-transaction-tests.bal b/ballerina/tests/h2-transaction-tests.bal index dc677d5..2e92120 100644 --- a/ballerina/tests/h2-transaction-tests.bal +++ b/ballerina/tests/h2-transaction-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-workspace-tests.bal b/ballerina/tests/h2-workspace-tests.bal index cd8e1b4..50ab569 100644 --- a/ballerina/tests/h2-workspace-tests.bal +++ b/ballerina/tests/h2-workspace-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2_rainier_generated_client.bal b/ballerina/tests/h2_rainier_generated_client.bal index 6d28e10..ab16096 100644 --- a/ballerina/tests/h2_rainier_generated_client.bal +++ b/ballerina/tests/h2_rainier_generated_client.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except @@ -135,7 +135,7 @@ public isolated client class H2RainierClient { }; public isolated function init() returns persist:Error? { - jdbc:Client|error dbClient = new (url = h2Url, user = h2User, password = h2Password); + jdbc:Client|error dbClient = new (url = h2.url, user = h2.user, password = h2.password); if dbClient is error { return error(dbClient.message()); } diff --git a/ballerina/tests/h2_test_entities_generated_client.bal b/ballerina/tests/h2_test_entities_generated_client.bal index 570634c..c606708 100644 --- a/ballerina/tests/h2_test_entities_generated_client.bal +++ b/ballerina/tests/h2_test_entities_generated_client.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except @@ -154,7 +154,7 @@ public isolated client class H2TestEntitiesClient { }; public isolated function init() returns persist:Error? { - jdbc:Client|error dbClient = new (url = h2Url, user = h2User, password = h2Password); + jdbc:Client|error dbClient = new (url = h2.url, user = h2.user, password = h2.password); if dbClient is error { return error(dbClient.message()); } diff --git a/ballerina/tests/init-tests.bal b/ballerina/tests/init-tests.bal index 7ca47f0..523238a 100644 --- a/ballerina/tests/init-tests.bal +++ b/ballerina/tests/init-tests.bal @@ -24,15 +24,11 @@ import ballerinax/mysql.driver as _; import ballerinax/postgresql; import ballerinax/postgresql.driver as _; -configurable string h2Url = ?; -configurable string h2User = ?; -configurable string h2Password = ?; - configurable record {| string url; string user; string password; -|} h2 = ?; +|} & readonly h2 = ?; configurable record {| int port; From 01ff6f7d2ab617c54c5b829cd03147b3b925a74b Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Fri, 9 Feb 2024 06:07:14 +0530 Subject: [PATCH 10/23] Define jdbc advanced configurations --- ballerina/tests/h2_rainier_generated_client.bal | 9 ++++----- .../tests/h2_test_entities_generated_client.bal | 9 ++++----- ballerina/tests/init-tests.bal | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ballerina/tests/h2_rainier_generated_client.bal b/ballerina/tests/h2_rainier_generated_client.bal index ab16096..c61ffed 100644 --- a/ballerina/tests/h2_rainier_generated_client.bal +++ b/ballerina/tests/h2_rainier_generated_client.bal @@ -13,12 +13,11 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. - import ballerina/jballerina.java; -import ballerinax/java.jdbc as jdbc; -import ballerinax/h2.driver as _; -import ballerina/sql; import ballerina/persist; +import ballerina/sql; +import ballerinax/h2.driver as _; +import ballerinax/java.jdbc as jdbc; const EMPLOYEE = "employees"; const WORKSPACE = "workspaces"; @@ -135,7 +134,7 @@ public isolated client class H2RainierClient { }; public isolated function init() returns persist:Error? { - jdbc:Client|error dbClient = new (url = h2.url, user = h2.user, password = h2.password); + jdbc:Client|error dbClient = new (url = h2.url, user = h2.user, password = h2.password, options = {...h2.connectionOptions}); if dbClient is error { return error(dbClient.message()); } diff --git a/ballerina/tests/h2_test_entities_generated_client.bal b/ballerina/tests/h2_test_entities_generated_client.bal index c606708..0a331a0 100644 --- a/ballerina/tests/h2_test_entities_generated_client.bal +++ b/ballerina/tests/h2_test_entities_generated_client.bal @@ -1,3 +1,4 @@ +import ballerina/jballerina.java; // Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, @@ -13,12 +14,10 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. - import ballerina/persist; -import ballerina/jballerina.java; -import ballerinax/java.jdbc as jdbc; -import ballerinax/h2.driver as _; import ballerina/sql; +import ballerinax/h2.driver as _; +import ballerinax/java.jdbc as jdbc; const ALL_TYPES = "alltypes"; const STRING_ID_RECORD = "stringidrecords"; @@ -154,7 +153,7 @@ public isolated client class H2TestEntitiesClient { }; public isolated function init() returns persist:Error? { - jdbc:Client|error dbClient = new (url = h2.url, user = h2.user, password = h2.password); + jdbc:Client|error dbClient = new (url = h2.url, user = h2.user, password = h2.password, options = {...h2.connectionOptions}); if dbClient is error { return error(dbClient.message()); } diff --git a/ballerina/tests/init-tests.bal b/ballerina/tests/init-tests.bal index 523238a..507021d 100644 --- a/ballerina/tests/init-tests.bal +++ b/ballerina/tests/init-tests.bal @@ -28,8 +28,23 @@ configurable record {| string url; string user; string password; + Options connectionOptions = {}; |} & readonly h2 = ?; + +public type Options record {| + string datasourceName?; + map properties?; + Operations requestGeneratedKeys = ALL; +|}; + +public enum Operations { + NONE, + EXECUTE, + BATCH_EXECUTE, + ALL +} + configurable record {| int port; string host; From dcdec5937394e4458dc0cb058da6cc897c1827ea Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Mon, 15 Apr 2024 09:43:41 +0530 Subject: [PATCH 11/23] [Automated] Update native jar versions in toml files --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 3f8b346..ab44774 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -22,10 +22,10 @@ path = "../native/build/libs/persist.sql-native-1.3.0-SNAPSHOT.jar" groupId = "io.ballerina.stdlib" artifactId = "persist-native" version = "1.3.0" -path = "./lib/persist-native-1.3.0-20240409-100100-594c874.jar" +path = "./lib/persist-native-1.3.0-20240410-140300-bb3a202.jar" [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "sql-native" -version = "1.13.0-20240410-111000-2cc6b6c" -path = "./lib/sql-native-1.13.0-20240410-111000-2cc6b6c.jar" +version = "1.13.0-20240410-205900-22f19c6" +path = "./lib/sql-native-1.13.0-20240410-205900-22f19c6.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 824bd06..30cfbcc 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -6,7 +6,7 @@ class = "io.ballerina.stdlib.persist.sql.compiler.PersistSqlCompilerPlugin" path = "../compiler-plugin/build/libs/persist.sql-compiler-plugin-1.3.0-SNAPSHOT.jar" [[dependency]] -path = "./lib/persist-native-1.3.0-20240409-100100-594c874.jar" +path = "./lib/persist-native-1.3.0-20240410-140300-bb3a202.jar" [[dependency]] -path = "./lib/persist-compiler-plugin-1.3.0-20240409-100100-594c874.jar" +path = "./lib/persist-compiler-plugin-1.3.0-20240410-140300-bb3a202.jar" From 2b61c0d394a9fa4ee3a7417bf9730f63ca6fdae1 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Fri, 5 Jul 2024 15:56:22 +0530 Subject: [PATCH 12/23] [Automated] Update native jar versions in toml files --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index b60a683..6368def 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerinax" name = "persist.sql" -version = "1.3.0" +version = "1.3.1" authors = ["Ballerina"] keywords = ["persist", "sql", "mysql", "mssql", "sql-server"] repository = "https://github.com/ballerina-platform/module-ballerinax-persist.sql" @@ -15,8 +15,8 @@ graalvmCompatible = true [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "persist.sql-native" -version = "1.3.0" -path = "../native/build/libs/persist.sql-native-1.3.0.jar" +version = "1.3.1" +path = "../native/build/libs/persist.sql-native-1.3.1-SNAPSHOT.jar" [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 157fac9..38a6557 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,7 +3,7 @@ id = "persist.sql-compiler-plugin" class = "io.ballerina.stdlib.persist.sql.compiler.PersistSqlCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/persist.sql-compiler-plugin-1.3.0.jar" +path = "../compiler-plugin/build/libs/persist.sql-compiler-plugin-1.3.1-SNAPSHOT.jar" [[dependency]] path = "./lib/persist-native-1.3.0.jar" From 37d5c5f860ba0776d69e7a98bffb8ea30348e764 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Fri, 5 Jul 2024 15:59:30 +0530 Subject: [PATCH 13/23] [Automated] Update native jar versions in toml files --- ballerina/Dependencies.toml | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 2f17694..132ad07 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -44,7 +44,7 @@ dependencies = [ [[package]] org = "ballerina" name = "crypto" -version = "2.7.0" +version = "2.7.2" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, @@ -66,7 +66,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.11.0" +version = "2.11.2" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -294,7 +294,7 @@ modules = [ [[package]] org = "ballerina" name = "sql" -version = "1.13.0" +version = "1.13.2" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -383,6 +383,31 @@ modules = [ {org = "ballerinai", packageName = "transaction", moduleName = "transaction"} ] +[[package]] +org = "ballerinax" +name = "h2.driver" +version = "1.1.0" +scope = "testOnly" +modules = [ + {org = "ballerinax", packageName = "h2.driver", moduleName = "h2.driver"} +] + +[[package]] +org = "ballerinax" +name = "java.jdbc" +version = "1.11.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "sql"}, + {org = "ballerina", name = "time"} +] +modules = [ + {org = "ballerinax", packageName = "java.jdbc", moduleName = "java.jdbc"} +] + [[package]] org = "ballerinax" name = "mssql" @@ -435,7 +460,7 @@ modules = [ [[package]] org = "ballerinax" name = "persist.sql" -version = "1.3.0" +version = "1.3.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"}, @@ -444,6 +469,8 @@ dependencies = [ {org = "ballerina", name = "test"}, {org = "ballerina", name = "time"}, {org = "ballerinai", name = "transaction"}, + {org = "ballerinax", name = "h2.driver"}, + {org = "ballerinax", name = "java.jdbc"}, {org = "ballerinax", name = "mssql"}, {org = "ballerinax", name = "mssql.driver"}, {org = "ballerinax", name = "mysql"}, From ed05ddc254322ba6a3cd1d9cd9ec4fc8355795f9 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sat, 6 Jul 2024 22:47:47 +0530 Subject: [PATCH 14/23] add enable flag to mssql testcase --- ballerina/tests/mssql-all-types-tests.bal | 24 +++++++---- ballerina/tests/mssql-associations-tests.bal | 12 ++++-- ballerina/tests/mssql-building-tests.bal | 36 ++++++++++------ ballerina/tests/mssql-composite-key-tests.bal | 33 ++++++++++----- ballerina/tests/mssql-department-tests.bal | 36 ++++++++++------ ballerina/tests/mssql-employee-tests.bal | 42 ++++++++++++------- ballerina/tests/mssql-id-fields-tests.bal | 21 ++++++---- ballerina/tests/mssql-native-tests.bal | 27 ++++++++---- ballerina/tests/mssql-transaction-tests.bal | 6 ++- ballerina/tests/mssql-workspace-tests.bal | 39 +++++++++++------ ballerina/tests/mssql_hospital_tests.bal | 39 ++++++++++------- 11 files changed, 209 insertions(+), 106 deletions(-) diff --git a/ballerina/tests/mssql-all-types-tests.bal b/ballerina/tests/mssql-all-types-tests.bal index e52499d..e123c03 100644 --- a/ballerina/tests/mssql-all-types-tests.bal +++ b/ballerina/tests/mssql-all-types-tests.bal @@ -18,7 +18,8 @@ import ballerina/test; import ballerina/persist; @test:Config { - groups: ["all-types", "mssql"] + groups: ["all-types", "mssql"], + enable: true } function mssqlAllTypesCreateTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -36,7 +37,8 @@ function mssqlAllTypesCreateTest() returns error? { } @test:Config { - groups: ["all-types", "mssql"] + groups: ["all-types", "mssql"], + enable: true } function mssqlAllTypesCreateMixedTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -55,7 +57,8 @@ function mssqlAllTypesCreateMixedTest() returns error? { @test:Config { groups: ["all-types", "mssql"], - dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest] + dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest], + enable: true } function mssqlAllTypesReadTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -70,7 +73,8 @@ function mssqlAllTypesReadTest() returns error? { @test:Config { groups: ["all-types", "mssql", "dependent"], - dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest] + dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest], + enable: true } function mssqlAllTypesReadDependentTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -162,7 +166,8 @@ function mssqlAllTypesReadDependentTest() returns error? { @test:Config { groups: ["all-types", "mssql"], - dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest] + dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest], + enable: true } function mssqlAllTypesReadOneTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -183,7 +188,8 @@ function mssqlAllTypesReadOneTest() returns error? { } @test:Config { - groups: ["all-types", "mssql"] + groups: ["all-types", "mssql"], + enable: true } function mssqlAllTypesReadOneTestNegative() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -201,7 +207,8 @@ function mssqlAllTypesReadOneTestNegative() returns error? { @test:Config { groups: ["all-types", "mssql"], - dependsOn: [mssqlAllTypesReadOneTest, mssqlAllTypesReadTest, mssqlAllTypesReadDependentTest] + dependsOn: [mssqlAllTypesReadOneTest, mssqlAllTypesReadTest, mssqlAllTypesReadDependentTest], + enable: true } function mssqlAllTypesUpdateTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -236,7 +243,8 @@ function mssqlAllTypesUpdateTest() returns error? { @test:Config { groups: ["all-types", "mssql"], - dependsOn: [mssqlAllTypesUpdateTest] + dependsOn: [mssqlAllTypesUpdateTest], + enable: true } function mssqlAllTypesDeleteTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); diff --git a/ballerina/tests/mssql-associations-tests.bal b/ballerina/tests/mssql-associations-tests.bal index dfdcee3..5b7cce1 100644 --- a/ballerina/tests/mssql-associations-tests.bal +++ b/ballerina/tests/mssql-associations-tests.bal @@ -19,7 +19,8 @@ import ballerina/persist; @test:Config { groups: ["associations", "mssql"], - dependsOn: [mssqlEmployeeDeleteTestNegative] + dependsOn: [mssqlEmployeeDeleteTestNegative], + enable: true } function mssqlEmployeeRelationsTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -86,7 +87,8 @@ function mssqlEmployeeRelationsTest() returns error? { @test:Config { groups: ["associations", "mssql"], - dependsOn: [mssqlEmployeeDeleteTestNegative] + dependsOn: [mssqlEmployeeDeleteTestNegative], + enable: true } function mssqlDepartmentRelationsTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -166,7 +168,8 @@ function mssqlDepartmentRelationsTest() returns error? { @test:Config { groups: ["associations", "mssql"], - dependsOn: [mssqlEmployeeRelationsTest] + dependsOn: [mssqlEmployeeRelationsTest], + enable: true } function mssqlWorkspaceRelationsTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -242,7 +245,8 @@ function mssqlWorkspaceRelationsTest() returns error? { @test:Config { groups: ["associations", "mssql"], - dependsOn: [mssqlEmployeeRelationsTest] + dependsOn: [mssqlEmployeeRelationsTest], + enable: true } function mssqlBuildingRelationsTest() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-building-tests.bal b/ballerina/tests/mssql-building-tests.bal index b2efa41..2de0a22 100644 --- a/ballerina/tests/mssql-building-tests.bal +++ b/ballerina/tests/mssql-building-tests.bal @@ -18,7 +18,8 @@ import ballerina/test; import ballerina/persist; @test:Config { - groups: ["building", "mssql"] + groups: ["building", "mssql"], + enable: true } function mssqlBuildingCreateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -32,7 +33,8 @@ function mssqlBuildingCreateTest() returns error? { } @test:Config { - groups: ["building", "mssql"] + groups: ["building", "mssql"], + enable: true } function mssqlBuildingCreateTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -51,7 +53,8 @@ function mssqlBuildingCreateTest2() returns error? { } @test:Config { - groups: ["building", "mssql"] + groups: ["building", "mssql"], + enable: true } function mssqlBuildingCreateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -67,7 +70,8 @@ function mssqlBuildingCreateTestNegative() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingCreateTest] + dependsOn: [mssqlBuildingCreateTest], + enable: true } function mssqlBuildingReadOneTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -79,7 +83,8 @@ function mssqlBuildingReadOneTest() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingCreateTest] + dependsOn: [mssqlBuildingCreateTest], + enable: true } function mssqlBuildingReadOneTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -95,7 +100,8 @@ function mssqlBuildingReadOneTestNegative() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingCreateTest, mssqlBuildingCreateTest2] + dependsOn: [mssqlBuildingCreateTest, mssqlBuildingCreateTest2], + enable: true } function mssqlBuildingReadManyTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -110,7 +116,8 @@ function mssqlBuildingReadManyTest() returns error? { @test:Config { groups: ["building", "mssql", "dependent"], - dependsOn: [mssqlBuildingCreateTest, mssqlBuildingCreateTest2] + dependsOn: [mssqlBuildingCreateTest, mssqlBuildingCreateTest2], + enable: true } function mssqlBuildingReadManyDependentTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -129,7 +136,8 @@ function mssqlBuildingReadManyDependentTest() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest] + dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest], + enable: true } function mssqlBuildingUpdateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -150,7 +158,8 @@ function mssqlBuildingUpdateTest() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest] + dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest], + enable: true } function mssqlBuildingUpdateTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -171,7 +180,8 @@ function mssqlBuildingUpdateTestNegative1() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest] + dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest], + enable: true } function mssqlBuildingUpdateTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -192,7 +202,8 @@ function mssqlBuildingUpdateTestNegative2() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingUpdateTest, mssqlBuildingUpdateTestNegative2] + dependsOn: [mssqlBuildingUpdateTest, mssqlBuildingUpdateTestNegative2], + enable: true } function mssqlBuildingDeleteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -210,7 +221,8 @@ function mssqlBuildingDeleteTest() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingDeleteTest] + dependsOn: [mssqlBuildingDeleteTest], + enable: true } function mssqlBuildingDeleteTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-composite-key-tests.bal b/ballerina/tests/mssql-composite-key-tests.bal index 6aaf8cc..21c4fe8 100644 --- a/ballerina/tests/mssql-composite-key-tests.bal +++ b/ballerina/tests/mssql-composite-key-tests.bal @@ -18,7 +18,8 @@ import ballerina/test; import ballerina/persist; @test:Config { - groups: ["composite-key", "mssql"] + groups: ["composite-key", "mssql"], + enable: true } function mssqlCompositeKeyCreateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -37,7 +38,8 @@ function mssqlCompositeKeyCreateTest() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest] + dependsOn: [mssqlCompositeKeyCreateTest], + enable: true } function mssqlCompositeKeyCreateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -54,7 +56,8 @@ function mssqlCompositeKeyCreateTestNegative() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest] + dependsOn: [mssqlCompositeKeyCreateTest], + enable: true } function mssqlCompositeKeyReadManyTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -69,7 +72,8 @@ function mssqlCompositeKeyReadManyTest() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest] + dependsOn: [mssqlCompositeKeyCreateTest], + enable: true } function mssqlCompositeKeyReadOneTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -80,7 +84,8 @@ function mssqlCompositeKeyReadOneTest() returns error? { @test:Config { groups: ["composite-key2"], - dependsOn: [mssqlCompositeKeyCreateTest] + dependsOn: [mssqlCompositeKeyCreateTest], + enable: true } function mssqlCompositeKeyReadOneTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -91,7 +96,8 @@ function mssqlCompositeKeyReadOneTest2() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest] + dependsOn: [mssqlCompositeKeyCreateTest], + enable: true } function mssqlCompositeKeyReadOneTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -108,7 +114,8 @@ function mssqlCompositeKeyReadOneTestNegative1() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest] + dependsOn: [mssqlCompositeKeyCreateTest], + enable: true } function mssqlCompositeKeyReadOneTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -125,7 +132,8 @@ function mssqlCompositeKeyReadOneTestNegative2() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest, mssqlCompositeKeyReadOneTest, mssqlCompositeKeyReadManyTest, mssqlCompositeKeyReadOneTest2] + dependsOn: [mssqlCompositeKeyCreateTest, mssqlCompositeKeyReadOneTest, mssqlCompositeKeyReadManyTest, mssqlCompositeKeyReadOneTest2], + enable: true } function mssqlCompositeKeyUpdateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -144,7 +152,8 @@ function mssqlCompositeKeyUpdateTest() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest, mssqlCompositeKeyReadOneTest, mssqlCompositeKeyReadManyTest, mssqlCompositeKeyReadOneTest2] + dependsOn: [mssqlCompositeKeyCreateTest, mssqlCompositeKeyReadOneTest, mssqlCompositeKeyReadManyTest, mssqlCompositeKeyReadOneTest2], + enable: true } function mssqlCompositeKeyUpdateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -164,7 +173,8 @@ function mssqlCompositeKeyUpdateTestNegative() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyUpdateTest] + dependsOn: [mssqlCompositeKeyUpdateTest], + enable: true } function mssqlCompositeKeyDeleteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -180,7 +190,8 @@ function mssqlCompositeKeyDeleteTest() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyUpdateTest] + dependsOn: [mssqlCompositeKeyUpdateTest], + enable: true } function mssqlCompositeKeyDeleteTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-department-tests.bal b/ballerina/tests/mssql-department-tests.bal index 55ab8ae..73180fe 100644 --- a/ballerina/tests/mssql-department-tests.bal +++ b/ballerina/tests/mssql-department-tests.bal @@ -18,7 +18,8 @@ import ballerina/test; import ballerina/persist; @test:Config { - groups: ["department", "mssql"] + groups: ["department", "mssql"], + enable: true } function mssqlDepartmentCreateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -32,7 +33,8 @@ function mssqlDepartmentCreateTest() returns error? { } @test:Config { - groups: ["department", "mssql"] + groups: ["department", "mssql"], + enable: true } function mssqlDepartmentCreateTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -50,7 +52,8 @@ function mssqlDepartmentCreateTest2() returns error? { } @test:Config { - groups: ["department", "mssql"] + groups: ["department", "mssql"], + enable: true } function mssqlDepartmentCreateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -66,7 +69,8 @@ function mssqlDepartmentCreateTestNegative() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentCreateTest] + dependsOn: [mssqlDepartmentCreateTest], + enable: true } function mssqlDepartmentReadOneTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -78,7 +82,8 @@ function mssqlDepartmentReadOneTest() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentCreateTest] + dependsOn: [mssqlDepartmentCreateTest], + enable: true } function mssqlDepartmentReadOneTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -94,7 +99,8 @@ function mssqlDepartmentReadOneTestNegative() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentCreateTest, mssqlDepartmentCreateTest2] + dependsOn: [mssqlDepartmentCreateTest, mssqlDepartmentCreateTest2], + enable: true } function mssqlDepartmentReadManyTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -108,7 +114,8 @@ function mssqlDepartmentReadManyTest() returns error? { @test:Config { groups: ["department", "mssql", "dependent"], - dependsOn: [mssqlDepartmentCreateTest, mssqlDepartmentCreateTest2] + dependsOn: [mssqlDepartmentCreateTest, mssqlDepartmentCreateTest2], + enable: true } function mssqlDepartmentReadManyTestDependent() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -127,7 +134,8 @@ function mssqlDepartmentReadManyTestDependent() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent] + dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent], + enable: true } function mssqlDepartmentUpdateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -145,7 +153,8 @@ function mssqlDepartmentUpdateTest() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent] + dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent], + enable: true } function mssqlDepartmentUpdateTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -164,7 +173,8 @@ function mssqlDepartmentUpdateTestNegative1() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent] + dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent], + enable: true } function mssqlDepartmentUpdateTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -183,7 +193,8 @@ function mssqlDepartmentUpdateTestNegative2() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentUpdateTest, mssqlDepartmentUpdateTestNegative2] + dependsOn: [mssqlDepartmentUpdateTest, mssqlDepartmentUpdateTestNegative2], + enable: true } function mssqlDepartmentDeleteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -201,7 +212,8 @@ function mssqlDepartmentDeleteTest() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentDeleteTest] + dependsOn: [mssqlDepartmentDeleteTest], + enable: true } function mssqlDepartmentDeleteTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-employee-tests.bal b/ballerina/tests/mssql-employee-tests.bal index 20d401f..dec9b19 100644 --- a/ballerina/tests/mssql-employee-tests.bal +++ b/ballerina/tests/mssql-employee-tests.bal @@ -19,7 +19,8 @@ import ballerina/persist; @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlWorkspaceDeleteTestNegative, mssqlDepartmentDeleteTestNegative] + dependsOn: [mssqlWorkspaceDeleteTestNegative, mssqlDepartmentDeleteTestNegative], + enable: true } function mssqlEmployeeCreateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -34,7 +35,8 @@ function mssqlEmployeeCreateTest() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlWorkspaceDeleteTestNegative, mssqlDepartmentDeleteTestNegative] + dependsOn: [mssqlWorkspaceDeleteTestNegative, mssqlDepartmentDeleteTestNegative], + enable: true } function mssqlEmployeeCreateTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -52,7 +54,8 @@ function mssqlEmployeeCreateTest2() returns error? { } @test:Config { - groups: ["employee", "mssql"] + groups: ["employee", "mssql"], + enable: true } function mssqlEmployeeCreateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -68,7 +71,8 @@ function mssqlEmployeeCreateTestNegative() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeCreateTest] + dependsOn: [mssqlEmployeeCreateTest], + enable: true } function mssqlEmployeeReadOneTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -80,7 +84,8 @@ function mssqlEmployeeReadOneTest() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeCreateTest] + dependsOn: [mssqlEmployeeCreateTest], + enable: true } function mssqlEmployeeReadOneTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -96,7 +101,8 @@ function mssqlEmployeeReadOneTestNegative() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2] + dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2], + enable: true } function mssqlEmployeeReadManyTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -111,7 +117,8 @@ function mssqlEmployeeReadManyTest() returns error? { @test:Config { groups: ["dependent", "employee"], - dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2] + dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2], + enable: true } function mssqlEmployeeReadManyDependentTest1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -130,7 +137,8 @@ function mssqlEmployeeReadManyDependentTest1() returns error? { @test:Config { groups: ["dependent", "employee"], - dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2] + dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2], + enable: true } function mssqlEmployeeReadManyDependentTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -149,7 +157,8 @@ function mssqlEmployeeReadManyDependentTest2() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2] + dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2], + enable: true } function mssqlEmployeeUpdateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -169,7 +178,8 @@ function mssqlEmployeeUpdateTest() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2] + dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2], + enable: true } function mssqlEmployeeUpdateTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -188,7 +198,8 @@ function mssqlEmployeeUpdateTestNegative1() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2] + dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2], + enable: true } function mssqlEmployeeUpdateTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -207,7 +218,8 @@ function mssqlEmployeeUpdateTestNegative2() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2] + dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2], + enable: true } function mssqlEmployeeUpdateTestNegative3() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -222,7 +234,8 @@ function mssqlEmployeeUpdateTestNegative3() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeUpdateTest, mssqlEmployeeUpdateTestNegative2, mssqlEmployeeUpdateTestNegative3] + dependsOn: [mssqlEmployeeUpdateTest, mssqlEmployeeUpdateTestNegative2, mssqlEmployeeUpdateTestNegative3], + enable: true } function mssqlEmployeeDeleteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -240,7 +253,8 @@ function mssqlEmployeeDeleteTest() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeDeleteTest] + dependsOn: [mssqlEmployeeDeleteTest], + enable: true } function mssqlEmployeeDeleteTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-id-fields-tests.bal b/ballerina/tests/mssql-id-fields-tests.bal index ad74afa..2521fae 100644 --- a/ballerina/tests/mssql-id-fields-tests.bal +++ b/ballerina/tests/mssql-id-fields-tests.bal @@ -17,7 +17,8 @@ import ballerina/test; @test:Config { - groups: ["id-fields", "mssql"] + groups: ["id-fields", "mssql"], + enable: true } function mssqlIntIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -77,7 +78,8 @@ function mssqlIntIdFieldTest() returns error? { } @test:Config { - groups: ["id-fields", "mssql"] + groups: ["id-fields", "mssql"], + enable: true } function mssqlStringIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -137,7 +139,8 @@ function mssqlStringIdFieldTest() returns error? { } @test:Config { - groups: ["id-fields", "mssql"] + groups: ["id-fields", "mssql"], + enable: true } function mssqlFloatIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -195,7 +198,8 @@ function mssqlFloatIdFieldTest() returns error? { } @test:Config { - groups: ["id-fields", "mssql"] + groups: ["id-fields", "mssql"], + enable: true } function mssqlDecimalIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -255,7 +259,8 @@ function mssqlDecimalIdFieldTest() returns error? { } @test:Config { - groups: ["id-fields", "mssql"] + groups: ["id-fields", "mssql"], + enable: true } function mssqlBooleanIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -311,7 +316,8 @@ function mssqlBooleanIdFieldTest() returns error? { } @test:Config { - groups: ["id-fields", "mssql"] + groups: ["id-fields", "mssql"], + enable: true } function mssqlAllTypesIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -383,7 +389,8 @@ function mssqlAllTypesIdFieldTest() returns error? { @test:Config { groups: ["id-fields", "mssql", "associations"], - dependsOn: [mssqlAllTypesIdFieldTest] + dependsOn: [mssqlAllTypesIdFieldTest], + enable: true } function mssqlCompositeAssociationsTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); diff --git a/ballerina/tests/mssql-native-tests.bal b/ballerina/tests/mssql-native-tests.bal index fd6205d..89f4d27 100644 --- a/ballerina/tests/mssql-native-tests.bal +++ b/ballerina/tests/mssql-native-tests.bal @@ -19,7 +19,8 @@ import ballerina/persist; @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlEmployeeRelationsTest, mssqlWorkspaceRelationsTest, mssqlBuildingRelationsTest, mssqlDepartmentRelationsTest] + dependsOn: [mssqlEmployeeRelationsTest, mssqlWorkspaceRelationsTest, mssqlBuildingRelationsTest, mssqlDepartmentRelationsTest], + enable: true } function mssqlNativeExecuteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -69,7 +70,8 @@ function mssqlNativeExecuteTest() returns error? { @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlNativeExecuteTest] + dependsOn: [mssqlNativeExecuteTest], + enable: true } function mssqlNativeExecuteTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -89,7 +91,8 @@ function mssqlNativeExecuteTestNegative1() returns error? { @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlNativeExecuteTest] + dependsOn: [mssqlNativeExecuteTest], + enable: true } function mssqlNativeExecuteTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -109,7 +112,8 @@ function mssqlNativeExecuteTestNegative2() returns error? { @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlNativeExecuteTest] + dependsOn: [mssqlNativeExecuteTest], + enable: true } function mssqlNativeQueryTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -142,7 +146,8 @@ function mssqlNativeQueryTest() returns error? { @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlNativeExecuteTest] + dependsOn: [mssqlNativeExecuteTest], + enable: true } function mssqlNativeQueryTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -162,7 +167,8 @@ function mssqlNativeQueryTestNegative() returns error? { @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlNativeExecuteTest] + dependsOn: [mssqlNativeExecuteTest], + enable: true } function mssqlNativeQueryComplexTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -190,7 +196,8 @@ function mssqlNativeQueryComplexTest() returns error? { @test:Config { groups: ["transactions", "mssql", "native"], - dependsOn: [mssqlNativeExecuteTestNegative1, mssqlNativeQueryTest, mssqlNativeQueryTestNegative, mssqlNativeQueryComplexTest] + dependsOn: [mssqlNativeExecuteTestNegative1, mssqlNativeQueryTest, mssqlNativeQueryTestNegative, mssqlNativeQueryComplexTest], + enable: true } function mssqlNativeTransactionTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -235,7 +242,8 @@ function mssqlNativeTransactionTest() returns error? { @test:Config { groups: ["transactions", "mssql", "native"], - dependsOn: [mssqlNativeExecuteTestNegative1, mssqlNativeQueryTest, mssqlNativeQueryTestNegative, mssqlNativeQueryComplexTest] + dependsOn: [mssqlNativeExecuteTestNegative1, mssqlNativeQueryTest, mssqlNativeQueryTestNegative, mssqlNativeQueryComplexTest], + enable: true } function mssqlNativeTransactionTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -276,7 +284,8 @@ function mssqlNativeTransactionTest2() returns error? { @test:Config { groups: ["mssql", "native"], - dependsOn: [mssqlAllTypesDeleteTest] + dependsOn: [mssqlAllTypesDeleteTest], + enable: true } function mssqlNativeAllTypesTest() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-transaction-tests.bal b/ballerina/tests/mssql-transaction-tests.bal index 22ea5fd..5737b5d 100644 --- a/ballerina/tests/mssql-transaction-tests.bal +++ b/ballerina/tests/mssql-transaction-tests.bal @@ -18,7 +18,8 @@ import ballerina/test; import ballerina/persist; @test:Config { - groups: ["transactions", "mssql"] + groups: ["transactions", "mssql"], + enable: true } function mssqlTransactionTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -43,7 +44,8 @@ function mssqlTransactionTest() returns error? { } @test:Config { - groups: ["transactions", "mssql"] + groups: ["transactions", "mssql"], + enable: true } function mssqlTransactionTest2() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-workspace-tests.bal b/ballerina/tests/mssql-workspace-tests.bal index 7b4cc31..248aa38 100644 --- a/ballerina/tests/mssql-workspace-tests.bal +++ b/ballerina/tests/mssql-workspace-tests.bal @@ -19,7 +19,8 @@ import ballerina/persist; @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlBuildingDeleteTestNegative] + dependsOn: [mssqlBuildingDeleteTestNegative], + enable: true } function mssqlWorkspaceCreateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -32,7 +33,8 @@ function mssqlWorkspaceCreateTest() returns error? { } @test:Config { - groups: ["workspace", "mssql"] + groups: ["workspace", "mssql"], + enable: true } function mssqlWorkspaceCreateTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -50,7 +52,8 @@ function mssqlWorkspaceCreateTest2() returns error? { } @test:Config { - groups: ["workspace", "mssql"] + groups: ["workspace", "mssql"], + enable: true } function mssqlWorkspaceCreateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -66,7 +69,8 @@ function mssqlWorkspaceCreateTestNegative() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceCreateTest] + dependsOn: [mssqlWorkspaceCreateTest], + enable: true } function mssqlWorkspaceReadOneTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -78,7 +82,8 @@ function mssqlWorkspaceReadOneTest() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceCreateTest] + dependsOn: [mssqlWorkspaceCreateTest], + enable: true } function mssqlWorkspaceReadOneDependentTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -95,7 +100,8 @@ function mssqlWorkspaceReadOneDependentTest() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceCreateTest] + dependsOn: [mssqlWorkspaceCreateTest], + enable: true } function mssqlWorkspaceReadOneTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -111,7 +117,8 @@ function mssqlWorkspaceReadOneTestNegative() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceCreateTest, mssqlWorkspaceCreateTest2] + dependsOn: [mssqlWorkspaceCreateTest, mssqlWorkspaceCreateTest2], + enable: true } function mssqlWorkspaceReadManyTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -126,7 +133,8 @@ function mssqlWorkspaceReadManyTest() returns error? { @test:Config { groups: ["workspace", "mssql", "dependent"], - dependsOn: [mssqlWorkspaceCreateTest, mssqlWorkspaceCreateTest2] + dependsOn: [mssqlWorkspaceCreateTest, mssqlWorkspaceCreateTest2], + enable: true } function mssqlWorkspaceReadManyDependentTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -145,7 +153,8 @@ function mssqlWorkspaceReadManyDependentTest() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest] + dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest], + enable: true } function mssqlWorkspaceUpdateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -163,7 +172,8 @@ function mssqlWorkspaceUpdateTest() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest] + dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest], + enable: true } function mssqlWorkspaceUpdateTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -182,7 +192,8 @@ function mssqlWorkspaceUpdateTestNegative1() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest] + dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest], + enable: true } function mssqlWorkspaceUpdateTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -201,7 +212,8 @@ function mssqlWorkspaceUpdateTestNegative2() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceUpdateTest, mssqlWorkspaceUpdateTestNegative2] + dependsOn: [mssqlWorkspaceUpdateTest, mssqlWorkspaceUpdateTestNegative2], + enable: true } function mssqlWorkspaceDeleteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -219,7 +231,8 @@ function mssqlWorkspaceDeleteTest() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceDeleteTest] + dependsOn: [mssqlWorkspaceDeleteTest], + enable: true } function mssqlWorkspaceDeleteTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql_hospital_tests.bal b/ballerina/tests/mssql_hospital_tests.bal index a00208f..2698bfc 100644 --- a/ballerina/tests/mssql_hospital_tests.bal +++ b/ballerina/tests/mssql_hospital_tests.bal @@ -18,7 +18,7 @@ import ballerina/persist; import ballerina/test; -@test:Config{} +@test:Config{enable: true} function testCreatePatientMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); PatientInsert patient = { @@ -31,7 +31,7 @@ function testCreatePatientMsSql() returns error? { _ = check mssqlDbHospital->/patients.post([patient]); } -@test:Config{} +@test:Config{enable: true} function testCreateDoctorMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); DoctorInsert doctor = { @@ -45,7 +45,8 @@ function testCreateDoctorMsSql() returns error? { } @test:Config{ - dependsOn: [testCreateDoctorMsSql] + dependsOn: [testCreateDoctorMsSql], + enable: true } function testCreateDoctorAlreadyExistsMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -63,7 +64,8 @@ function testCreateDoctorAlreadyExistsMsSql() returns error? { } @test:Config{ - dependsOn: [testCreatePatientMsSql, testCreateDoctorMsSql] + dependsOn: [testCreatePatientMsSql, testCreateDoctorMsSql], + enable: true } function testCreateAppointmentMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -79,7 +81,8 @@ function testCreateAppointmentMsSql() returns error? { } @test:Config{ - dependsOn: [testCreatePatientMsSql, testCreateDoctorMsSql, testCreateAppointmentMsSql] + dependsOn: [testCreatePatientMsSql, testCreateDoctorMsSql, testCreateAppointmentMsSql], + enable: true } function testCreateAppointmentAlreadyExistsMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -98,7 +101,8 @@ function testCreateAppointmentAlreadyExistsMsSql() returns error? { } @test:Config{ - dependsOn: [testCreateDoctorMsSql] + dependsOn: [testCreateDoctorMsSql], + enable: true } function testGetDoctorsMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -111,7 +115,8 @@ function testGetDoctorsMsSql() returns error? { } @test:Config{ - dependsOn: [testCreatePatientMsSql] + dependsOn: [testCreatePatientMsSql], + enable: true } function testGetPatientByIdMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -120,7 +125,7 @@ function testGetPatientByIdMsSql() returns error? { test:assertEquals(patient, expected, "Patient details should be returned"); } -@test:Config{} +@test:Config{enable: true} function testGetPatientNotFoundMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); Patient|persist:Error patient = mssqlDbHospital->/patients/[10].get(); @@ -130,7 +135,8 @@ function testGetPatientNotFoundMsSql() returns error? { } @test:Config{ - dependsOn: [testCreateAppointmentMsSql] + dependsOn: [testCreateAppointmentMsSql], + enable: true } function testGetAppointmentByDoctorMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -186,7 +192,8 @@ function testGetAppointmentByDoctorMsSql() returns error? { } @test:Config{ - dependsOn: [testCreateAppointmentMsSql] + dependsOn: [testCreateAppointmentMsSql], + enable: true } function testGetAppointmentByPatientMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -235,7 +242,8 @@ function testGetAppointmentByPatientMsSql() returns error? { } @test:Config{ - dependsOn: [testCreateAppointmentMsSql, testGetAppointmentByDoctorMsSql, testGetAppointmentByPatientMsSql] + dependsOn: [testCreateAppointmentMsSql, testGetAppointmentByDoctorMsSql, testGetAppointmentByPatientMsSql], + enable: true } function testPatchAppointmentMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -287,7 +295,8 @@ function testPatchAppointmentMsSql() returns error? { } @test:Config{ - dependsOn: [testCreateAppointmentMsSql, testGetAppointmentByDoctorMsSql, testGetAppointmentByPatientMsSql, testPatchAppointmentMsSql] + dependsOn: [testCreateAppointmentMsSql, testGetAppointmentByDoctorMsSql, testGetAppointmentByPatientMsSql, testPatchAppointmentMsSql], + enable: true } function testDeleteAppointmentByPatientIdMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -318,7 +327,8 @@ function testDeleteAppointmentByPatientIdMsSql() returns error? { } @test:Config{ - dependsOn: [testGetPatientByIdMsSql, testDeleteAppointmentByPatientIdMsSql] + dependsOn: [testGetPatientByIdMsSql, testDeleteAppointmentByPatientIdMsSql], + enable: true } function testDeletePatientMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -329,7 +339,8 @@ function testDeletePatientMsSql() returns error? { } @test:Config{ - dependsOn: [testGetDoctorsMsSql, testDeleteAppointmentByPatientIdMsSql] + dependsOn: [testGetDoctorsMsSql, testDeleteAppointmentByPatientIdMsSql], + enable: true } function testDeleteDoctorMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); From ae4ba0d6399b510abcb98b4145049e4dc0656bbe Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sat, 6 Jul 2024 22:54:44 +0530 Subject: [PATCH 15/23] rename init functions --- ballerina/tests/init-tests.bal | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ballerina/tests/init-tests.bal b/ballerina/tests/init-tests.bal index 50f7bb4..a2d8d8d 100644 --- a/ballerina/tests/init-tests.bal +++ b/ballerina/tests/init-tests.bal @@ -75,10 +75,10 @@ configurable record {| @test:BeforeSuite function initSuite() returns error? { - check initMySQLTest(); - check initMSSQLTest(); - check initPostgreSQLTest(); - check initH2Test(); + check initMySqlTests(); + check initMsSqlTests(); + check initPostgreSqlTests(); + check initH2Tests(); } function initMySqlTests() returns error? { @@ -309,7 +309,7 @@ function initPostgreSqlTests() returns error? { check postgresqlDbClient.close(); } -function initH2Test() returns error? { +function initH2Tests() returns error? { jdbc:Client h2DbClient = check new (url = h2.url, user = h2.user, password = h2.password); _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "Building"`); _ = check h2DbClient->execute(` @@ -532,7 +532,7 @@ AllTypes allTypes2 = { floatTypeOptional: 66.0, decimalTypeOptional: 233.44, stringTypeOptional: "test2", - dateTypeOptional: {year: 1293, month: 11, day: 3}, + dateTypeOptional: {year: 1993, month: 11, day: 3}, timeOfDayTypeOptional: {hour: 19, minute: 32, second: 34}, civilTypeOptional: {year: 1989, month: 11, day: 3, hour: 12, minute: 32, second: 34}, enumType: "TYPE_1", @@ -580,7 +580,7 @@ AllTypes allTypes3 = { floatTypeOptional: 66.0, decimalTypeOptional: (), stringTypeOptional: (), - dateTypeOptional: {year: 1293, month: 11, day: 3}, + dateTypeOptional: {year: 1993, month: 11, day: 3}, timeOfDayTypeOptional: {hour: 19, minute: 32, second: 34}, civilTypeOptional: {year: 1989, month: 11, day: 3, hour: 12, minute: 32, second: 34}, enumType: "TYPE_1", From d85f2c0ffede15d6bbc7e4f4dff5d98759ba487b Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sun, 7 Jul 2024 01:01:19 +0530 Subject: [PATCH 16/23] Add h2 testcases for the recent annotation support --- .../tests/h2_hospital_persist_client.bal | 254 +++++++++++++ ballerina/tests/h2_hospital_tests.bal | 343 ++++++++++++++++++ ballerina/tests/init-tests.bal | 40 +- ballerina/tests/persist/hospital.bal | 76 ++++ 4 files changed, 712 insertions(+), 1 deletion(-) create mode 100644 ballerina/tests/h2_hospital_persist_client.bal create mode 100644 ballerina/tests/h2_hospital_tests.bal create mode 100644 ballerina/tests/persist/hospital.bal diff --git a/ballerina/tests/h2_hospital_persist_client.bal b/ballerina/tests/h2_hospital_persist_client.bal new file mode 100644 index 0000000..9785982 --- /dev/null +++ b/ballerina/tests/h2_hospital_persist_client.bal @@ -0,0 +1,254 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// AUTO-GENERATED FILE. DO NOT MODIFY. +// This file is an auto-generated file by Ballerina persistence layer for model. +// It should not be modified by hand. +import ballerina/jballerina.java; +import ballerina/persist; +import ballerina/sql; +import ballerinax/h2.driver as _; +import ballerinax/java.jdbc as jdbc; + +const APPOINTMENT = "appointments"; +const PATIENT = "patients"; +const DOCTOR = "doctors"; + +public isolated client class H2HospitalClient { + *persist:AbstractPersistClient; + + private final jdbc:Client dbClient; + + private final map persistClients; + + private final record {|SQLMetadata...;|} & readonly metadata = { + [APPOINTMENT]: { + entityName: "Appointment", + tableName: "appointment", + fieldMetadata: { + id: {columnName: "id"}, + reason: {columnName: "reason"}, + appointmentTime: {columnName: "appointmentTime"}, + status: {columnName: "status"}, + patientId: {columnName: "patient_id"}, + doctorId: {columnName: "doctorId"}, + "patient.id": {relation: {entityName: "patient", refField: "id", refColumn: "IDP"}}, + "patient.name": {relation: {entityName: "patient", refField: "name"}}, + "patient.age": {relation: {entityName: "patient", refField: "age"}}, + "patient.address": {relation: {entityName: "patient", refField: "address", refColumn: "ADD_RESS"}}, + "patient.phoneNumber": {relation: {entityName: "patient", refField: "phoneNumber"}}, + "patient.gender": {relation: {entityName: "patient", refField: "gender"}}, + "doctor.id": {relation: {entityName: "doctor", refField: "id"}}, + "doctor.name": {relation: {entityName: "doctor", refField: "name"}}, + "doctor.specialty": {relation: {entityName: "doctor", refField: "specialty"}}, + "doctor.phoneNumber": {relation: {entityName: "doctor", refField: "phoneNumber", refColumn: "phone_number"}}, + "doctor.salary": {relation: {entityName: "doctor", refField: "salary"}} + }, + keyFields: ["id"], + joinMetadata: { + patient: {entity: Patient, fieldName: "patient", refTable: "patients", refColumns: ["IDP"], joinColumns: ["patient_id"], 'type: ONE_TO_MANY}, + doctor: {entity: Doctor, fieldName: "doctor", refTable: "Doctor", refColumns: ["id"], joinColumns: ["doctorId"], 'type: ONE_TO_MANY} + } + }, + [PATIENT]: { + entityName: "Patient", + tableName: "patients", + fieldMetadata: { + id: {columnName: "IDP", dbGenerated: true}, + name: {columnName: "name"}, + age: {columnName: "age"}, + address: {columnName: "ADD_RESS"}, + phoneNumber: {columnName: "phoneNumber"}, + gender: {columnName: "gender"}, + "appointments[].id": {relation: {entityName: "appointments", refField: "id"}}, + "appointments[].reason": {relation: {entityName: "appointments", refField: "reason"}}, + "appointments[].appointmentTime": {relation: {entityName: "appointments", refField: "appointmentTime"}}, + "appointments[].status": {relation: {entityName: "appointments", refField: "status"}}, + "appointments[].patientId": {relation: {entityName: "appointments", refField: "patientId", refColumn: "patient_id"}}, + "appointments[].doctorId": {relation: {entityName: "appointments", refField: "doctorId"}} + }, + keyFields: ["id"], + joinMetadata: {appointments: {entity: Appointment, fieldName: "appointments", refTable: "appointment", refColumns: ["patient_id"], joinColumns: ["IDP"], 'type: MANY_TO_ONE}} + }, + [DOCTOR]: { + entityName: "Doctor", + tableName: "Doctor", + fieldMetadata: { + id: {columnName: "id"}, + name: {columnName: "name"}, + specialty: {columnName: "specialty"}, + phoneNumber: {columnName: "phone_number"}, + salary: {columnName: "salary"}, + "appointments[].id": {relation: {entityName: "appointments", refField: "id"}}, + "appointments[].reason": {relation: {entityName: "appointments", refField: "reason"}}, + "appointments[].appointmentTime": {relation: {entityName: "appointments", refField: "appointmentTime"}}, + "appointments[].status": {relation: {entityName: "appointments", refField: "status"}}, + "appointments[].patientId": {relation: {entityName: "appointments", refField: "patientId", refColumn: "patient_id"}}, + "appointments[].doctorId": {relation: {entityName: "appointments", refField: "doctorId"}} + }, + keyFields: ["id"], + joinMetadata: {appointments: {entity: Appointment, fieldName: "appointments", refTable: "appointment", refColumns: ["doctorId"], joinColumns: ["id"], 'type: MANY_TO_ONE}} + } + }; + + public isolated function init() returns persist:Error? { + jdbc:Client|error dbClient = new (url = h2.url, user = h2.user, password = h2.password, options = {...h2.connectionOptions}); + if dbClient is error { + return error(dbClient.message()); + } + self.dbClient = dbClient; + self.persistClients = { + [APPOINTMENT]: check new (dbClient, self.metadata.get(APPOINTMENT), H2_SPECIFICS), + [PATIENT]: check new (dbClient, self.metadata.get(PATIENT), H2_SPECIFICS), + [DOCTOR]: check new (dbClient, self.metadata.get(DOCTOR), H2_SPECIFICS) + }; + } + + isolated resource function get appointments(AppointmentTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get appointments/[int id](AppointmentTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post appointments(AppointmentInsert[] data) returns int[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(APPOINTMENT); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from AppointmentInsert inserted in data + select inserted.id; + } + + isolated resource function put appointments/[int id](AppointmentUpdate value) returns Appointment|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(APPOINTMENT); + } + _ = check sqlClient.runUpdateQuery(id, value); + return self->/appointments/[id].get(); + } + + isolated resource function delete appointments/[int id]() returns Appointment|persist:Error { + Appointment result = check self->/appointments/[id].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(APPOINTMENT); + } + _ = check sqlClient.runDeleteQuery(id); + return result; + } + + isolated resource function get patients(PatientTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get patients/[int id](PatientTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post patients(PatientInsert[] data) returns int[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(PATIENT); + } + sql:ExecutionResult[] result = check sqlClient.runBatchInsertQuery(data); + return from sql:ExecutionResult inserted in result + where inserted.lastInsertId != () + select inserted.lastInsertId; + } + + isolated resource function put patients/[int id](PatientUpdate value) returns Patient|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(PATIENT); + } + _ = check sqlClient.runUpdateQuery(id, value); + return self->/patients/[id].get(); + } + + isolated resource function delete patients/[int id]() returns Patient|persist:Error { + Patient result = check self->/patients/[id].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(PATIENT); + } + _ = check sqlClient.runDeleteQuery(id); + return result; + } + + isolated resource function get doctors(DoctorTargetType targetType = <>, sql:ParameterizedQuery whereClause = ``, sql:ParameterizedQuery orderByClause = ``, sql:ParameterizedQuery limitClause = ``, sql:ParameterizedQuery groupByClause = ``) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "query" + } external; + + isolated resource function get doctors/[int id](DoctorTargetType targetType = <>) returns targetType|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor", + name: "queryOne" + } external; + + isolated resource function post doctors(DoctorInsert[] data) returns int[]|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(DOCTOR); + } + _ = check sqlClient.runBatchInsertQuery(data); + return from DoctorInsert inserted in data + select inserted.id; + } + + isolated resource function put doctors/[int id](DoctorUpdate value) returns Doctor|persist:Error { + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(DOCTOR); + } + _ = check sqlClient.runUpdateQuery(id, value); + return self->/doctors/[id].get(); + } + + isolated resource function delete doctors/[int id]() returns Doctor|persist:Error { + Doctor result = check self->/doctors/[id].get(); + SQLClient sqlClient; + lock { + sqlClient = self.persistClients.get(DOCTOR); + } + _ = check sqlClient.runDeleteQuery(id); + return result; + } + + remote isolated function queryNativeSQL(sql:ParameterizedQuery sqlQuery, typedesc rowType = <>) returns stream = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor" + } external; + + remote isolated function executeNativeSQL(sql:ParameterizedQuery sqlQuery) returns ExecutionResult|persist:Error = @java:Method { + 'class: "io.ballerina.stdlib.persist.sql.datastore.H2Processor" + } external; + + public isolated function close() returns persist:Error? { + error? result = self.dbClient.close(); + if result is error { + return error(result.message()); + } + return result; + } +} + diff --git a/ballerina/tests/h2_hospital_tests.bal b/ballerina/tests/h2_hospital_tests.bal new file mode 100644 index 0000000..7f100ed --- /dev/null +++ b/ballerina/tests/h2_hospital_tests.bal @@ -0,0 +1,343 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/persist; +import ballerina/test; + + +@test:Config{} +function testCreatePatientH2() returns error? { + H2HospitalClient H2DbHospital = check new(); + PatientInsert patient = { + name: "John Doe", + age: 30, + phoneNumber: "0771690000", + gender: "MALE", + address: "123, Main Street, Colombo 05" + }; + int[] unionResult = check h2DbHospital->/patients.post([patient]); + test:assertEquals(unionResult[0], 1, "Patient should be created"); +} + +@test:Config{} +function testCreateDoctorH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + DoctorInsert doctor = { + id: 1, + name: "Doctor Mouse", + specialty: "Physician", + phoneNumber: "077100100", + salary: 20000 + }; + int[] res = check h2DbHospital->/doctors.post([doctor]); + test:assertEquals(res[0], 1, "Doctor should be created"); +} + +@test:Config{ + dependsOn: [testCreateDoctorH2] +} +function testCreateDoctorAlreadyExistsH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + DoctorInsert doctor = { + id: 1, + name: "Doctor Mouse", + specialty: "Physician", + phoneNumber: "077100100", + salary: 20000.00 + }; + int[]|persist:Error res = h2DbHospital->/doctors.post([doctor]); + if !(res is persist:AlreadyExistsError) { + test:assertFail("Doctor should not be created"); + } +} + +@test:Config{ + dependsOn: [testCreatePatientH2, testCreateDoctorH2] +} +function testCreateAppointmentH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + AppointmentInsert appointment = { + id: 1, + patientId: 1, + doctorId: 1, + appointmentTime: {year: 2023, month: 7, day: 1, hour: 10, minute: 30}, + status: "SCHEDULED", + reason: "Headache" + }; + int[] res = check h2DbHospital->/appointments.post([appointment]); + test:assertEquals(res[0], 1, "Appointment should be created"); +} + +@test:Config{ + dependsOn: [testCreatePatientH2, testCreateDoctorH2, testCreateAppointmentH2] +} +function testCreateAppointmentAlreadyExistsH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + AppointmentInsert appointment = { + id: 1, + patientId: 1, + doctorId: 1, + appointmentTime: {year: 2023, month: 7, day: 1, hour: 10, minute: 30}, + status: "SCHEDULED", + reason: "Headache" + }; + int[]|persist:Error res = h2DbHospital->/appointments.post([appointment]); + if !(res is persist:AlreadyExistsError) { + test:assertFail("Appointment should not be created"); + } +} + +@test:Config{ + dependsOn: [testCreateDoctorH2] +} +function testGetDoctorsH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + stream doctors = h2DbHospital->/doctors.get(); + Doctor[]|persist:Error doctorsArr = from Doctor doctor in doctors select doctor; + Doctor[] expected = [ + {id: 1, name: "Doctor Mouse", specialty: "Physician", phoneNumber: "077100100", salary: 20000} + ]; + test:assertEquals(doctorsArr, expected, "Doctor details should be returned"); +} + +@test:Config{ + dependsOn: [testCreatePatientH2] +} +function testGetPatientByIdH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + Patient|persist:Error patient = h2DbHospital->/patients/[1].get(); + Patient expected = {"id":1, "name": "John Doe", "age": 30, "address": "123, Main Street, Colombo 05", "phoneNumber":"0771690000", "gender":"MALE"}; + test:assertEquals(patient, expected, "Patient details should be returned"); +} + +@test:Config{} +function testGetPatientNotFoundH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + Patient|persist:Error patient = h2DbHospital->/patients/[10].get(); + if !(patient is persist:NotFoundError) { + test:assertFail("Patient should be not found"); + } +} + +@test:Config{ + dependsOn: [testCreateAppointmentH2] +} +function testGetAppointmentByDoctorH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + stream appointments = h2DbHospital->/appointments(); + AppointmentWithRelations[]|persist:Error? filteredAppointments = from AppointmentWithRelations appointment in appointments + where appointment.doctorId == 1 && + appointment.appointmentTime?.year == 2023 && + appointment.appointmentTime?.month == 7 && + appointment.appointmentTime?.day == 1 + select appointment; + AppointmentWithRelations[] expected = [ + { + "id": 1, + "doctorId": 1, + "patientId": 1, + "reason": "Headache", + "appointmentTime": { + "year": 2023, + "month": 7, + "day": 1, + "hour": 10, + "minute": 30, + "second": 0 + }, + "status": "SCHEDULED", + "patient": { + "id": 1, + "name": "John Doe", + "age": 30, + "address": "123, Main Street, Colombo 05", + "phoneNumber": "0771690000", + "gender": "MALE" + }, + "doctor": { + "id": 1, + "name": "Doctor Mouse", + "specialty": "Physician", + "phoneNumber": "077100100", + "salary": 20000 + } + } + ]; + test:assertEquals(filteredAppointments, expected, "Appointment details should be returned"); + + stream appointments2 = h2DbHospital->/appointments(); + Appointment[]|persist:Error? filteredAppointments2 = from Appointment appointment in appointments2 + where appointment.doctorId == 5 && + appointment.appointmentTime.year == 2023 && + appointment.appointmentTime.month == 7 && + appointment.appointmentTime.day == 1 + select appointment; + test:assertEquals(filteredAppointments2, [], "Appointment details should be empty"); +} + +@test:Config{ + dependsOn: [testCreateAppointmentH2] +} +function testGetAppointmentByPatientH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + stream appointments = h2DbHospital->/appointments(); + AppointmentWithRelations[]|persist:Error? filteredAppointments = from AppointmentWithRelations appointment in appointments + where appointment.patientId == 1 + select appointment; + AppointmentWithRelations[] expected = [ + { + "id": 1, + "doctorId": 1, + "patientId": 1, + "reason": "Headache", + "appointmentTime": { + "year": 2023, + "month": 7, + "day": 1, + "hour": 10, + "minute": 30, + "second": 0 + }, + "status": "SCHEDULED", + "patient": { + "id": 1, + "name": "John Doe", + "age": 30, + "address": "123, Main Street, Colombo 05", + "phoneNumber": "0771690000", + "gender": "MALE" + }, + "doctor": { + "id": 1, + "name": "Doctor Mouse", + "specialty": "Physician", + "phoneNumber": "077100100", + "salary": 20000 + } + } + ]; + test:assertEquals(filteredAppointments, expected, "Appointment details should be returned"); + stream appointments2 = h2DbHospital->/appointments(); + AppointmentWithRelations[]|persist:Error? filteredAppointments2 = from AppointmentWithRelations appointment in appointments2 + where appointment.patientId == 5 + select appointment; + test:assertEquals(filteredAppointments2, [], "Appointment details should be empty"); +} + +@test:Config{ + dependsOn: [testCreateAppointmentH2, testGetAppointmentByDoctorH2, testGetAppointmentByPatientH2] +} +function testPatchAppointmentH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + Appointment|persist:Error result = h2DbHospital->/appointments/[1].put({status: "STARTED"}); + if result is persist:Error { + test:assertFail("Appointment should be updated"); + } + stream appointments = h2DbHospital->/appointments(); + AppointmentWithRelations[]|persist:Error? filteredAppointments = from AppointmentWithRelations appointment in appointments + where appointment.patientId == 1 + select appointment; + AppointmentWithRelations[] expected = [ + { + "id": 1, + "doctorId": 1, + "patientId": 1, + "reason": "Headache", + "appointmentTime": { + "year": 2023, + "month": 7, + "day": 1, + "hour": 10, + "minute": 30, + "second": 0 + }, + "status": "STARTED", + "patient": { + "id": 1, + "name": "John Doe", + "age": 30, + "address": "123, Main Street, Colombo 05", + "phoneNumber": "0771690000", + "gender": "MALE" + }, + "doctor": { + "id": 1, + "name": "Doctor Mouse", + "specialty": "Physician", + "phoneNumber": "077100100", + "salary": 20000 + } + } + ]; + test:assertEquals(filteredAppointments, expected, "Appointment details should be updated"); + Appointment|persist:Error result2 = h2DbHospital->/appointments/[0].put({status: "STARTED"}); + if !(result2 is persist:NotFoundError) { + test:assertFail("Appointment should not be found"); + } +} + +@test:Config{ + dependsOn: [testCreateAppointmentH2, testGetAppointmentByDoctorH2, testGetAppointmentByPatientH2, testPatchAppointmentH2] +} +function testDeleteAppointmentByPatientIdH2() returns error? { + H2HospitalClient h2DbHospital = check new(); + stream appointments = h2DbHospital->/appointments; + Appointment[]|persist:Error result = from Appointment appointment in appointments + where appointment.patientId == 1 + && appointment.appointmentTime.year == 2023 + && appointment.appointmentTime.month == 7 + && appointment.appointmentTime.day == 1 + select appointment; + if (result is persist:Error) { + test:assertFail("Appointment should be found"); + } + foreach Appointment appointment in result { + Appointment|persist:Error result2 = h2DbHospital->/appointments/[appointment.id].delete(); + if result2 is persist:Error { + test:assertFail("Appointment should be deleted"); + } + } + stream appointments2 = h2DbHospital->/appointments; + Appointment[]|persist:Error result3 = from Appointment appointment in appointments2 + where appointment.patientId == 1 + && appointment.appointmentTime.year == 2023 + && appointment.appointmentTime.month == 7 + && appointment.appointmentTime.day == 1 + select appointment; + test:assertEquals(result3, [], "Appointment details should be empty"); +} + +@test:Config{ + dependsOn: [testGetPatientByIdH2, testDeleteAppointmentByPatientIdH2] +} +function testDeletePatientH2() returns error? { + MySqlHospitalClient h2DbHospital = check new(); + Patient|persist:Error result = h2DbHospital->/patients/[1].delete(); + if result is persist:Error { + test:assertFail("Patient should be deleted"); + } +} + +@test:Config{ + dependsOn: [testGetDoctorsH2, testDeleteAppointmentByPatientIdH2] +} +function testDeleteDoctorH2() returns error? { + MySqlHospitalClient h2DbHospital = check new(); + Doctor|persist:Error result = h2DbHospital->/doctors/[1].delete(); + if result is persist:Error { + test:assertFail("Patient should be deleted"); + } +} diff --git a/ballerina/tests/init-tests.bal b/ballerina/tests/init-tests.bal index a2d8d8d..138048a 100644 --- a/ballerina/tests/init-tests.bal +++ b/ballerina/tests/init-tests.bal @@ -32,7 +32,6 @@ configurable record {| Options connectionOptions = {}; |} & readonly h2 = ?; - public type Options record {| string datasourceName?; map properties?; @@ -467,6 +466,45 @@ function initH2Tests() returns error? { PRIMARY KEY("id") ); `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "Doctor"`); + _ = check h2DbClient->execute(` + CREATE TABLE "Doctor" ( + "id" INT NOT NULL, + "name" VARCHAR(191) NOT NULL, + "specialty" VARCHAR(191) NOT NULL, + "phone_number" VARCHAR(191) NOT NULL, + "salary" DECIMAL(10,2), + PRIMARY KEY("id") + ); + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "patients"`); + _ = check h2DbClient->execute(` + CREATE TABLE "patients" ( + "IDP" INT AUTO_INCREMENT, + "name" VARCHAR(191) NOT NULL, + "age" INT NOT NULL, + "ADD_RESS" VARCHAR(191) NOT NULL, + "phoneNumber" CHAR(10) NOT NULL, + "gender" ENUM('MALE', 'FEMALE') NOT NULL, + PRIMARY KEY("IDP") + ); + `); + + _ = check h2DbClient->execute(`DROP TABLE IF EXISTS "appointment"`); + _ = check h2DbClient->execute(`CREATE TABLE "appointment" ( + "id" INT NOT NULL, + "reason" VARCHAR(191) NOT NULL, + "appointmentTime" DATETIME NOT NULL, + "status" ENUM('SCHEDULED', 'STARTED', 'ENDED') NOT NULL, + "patient_id" INT NOT NULL, + FOREIGN KEY("patient_id") REFERENCES "patients"("IDP"), + "doctorId" INT NOT NULL, + FOREIGN KEY("doctorId") REFERENCES "Doctor"("id"), + PRIMARY KEY("id") + )`); + check h2DbClient.close(); } diff --git a/ballerina/tests/persist/hospital.bal b/ballerina/tests/persist/hospital.bal new file mode 100644 index 0000000..5ef61c9 --- /dev/null +++ b/ballerina/tests/persist/hospital.bal @@ -0,0 +1,76 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/persist as _; +import ballerina/time; +import ballerinax/persist.sql; + +public enum AppointmentStatus { + SCHEDULED = "SCHEDULED", + STARTED = "STARTED", + ENDED = "ENDED" +} + +public enum PatientGender { + MALE = "MALE", + FEMALE = "FEMALE" +} + +@sql:Name {value: "appointment"} +public type Appointment record {| + readonly int id; + @sql:UniqueIndex {name: "reason_index"} + string reason; + time:Civil appointmentTime; + AppointmentStatus status; + @sql:Name {value: "patient_id"} + @sql:Index {name: "patient_id"} + int patientId; + @sql:Index {name: "doctorId"} + int doctorId; + @sql:Relation {keys: ["patientId"]} + Patient patient; + @sql:Relation {keys: ["doctorId"]} + Doctor doctor; +|}; + +@sql:Name {value: "patients"} +public type Patient record {| + @sql:Name {value: "ID_P"} + @sql:Generated + readonly int idP; + string name; + int age; + @sql:Name {value: "ADDRESS"} + string address; + @sql:Char {length: 10} + string phoneNumber; + PatientGender gender; + Appointment[] appointments; +|}; + +public type Doctor record {| + readonly int id; + string name; + @sql:Varchar {length: 20} + @sql:Index {name: "specialty_index"} + string specialty; + @sql:Name {value: "phone_number"} + string phoneNumber; + @sql:Decimal {precision: [10, 2]} + decimal? salary; + Appointment[] appointments; +|}; \ No newline at end of file From 736f6e299341e72ec14fedd8732a8637cdd2e43b Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sun, 7 Jul 2024 01:29:12 +0530 Subject: [PATCH 17/23] fix failling testcases --- ballerina/tests/h2_hospital_tests.bal | 2 +- ballerina/tests/init-tests.bal | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/tests/h2_hospital_tests.bal b/ballerina/tests/h2_hospital_tests.bal index 7f100ed..619f923 100644 --- a/ballerina/tests/h2_hospital_tests.bal +++ b/ballerina/tests/h2_hospital_tests.bal @@ -20,7 +20,7 @@ import ballerina/test; @test:Config{} function testCreatePatientH2() returns error? { - H2HospitalClient H2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new(); PatientInsert patient = { name: "John Doe", age: 30, diff --git a/ballerina/tests/init-tests.bal b/ballerina/tests/init-tests.bal index 138048a..1ac9e74 100644 --- a/ballerina/tests/init-tests.bal +++ b/ballerina/tests/init-tests.bal @@ -487,7 +487,7 @@ function initH2Tests() returns error? { "age" INT NOT NULL, "ADD_RESS" VARCHAR(191) NOT NULL, "phoneNumber" CHAR(10) NOT NULL, - "gender" ENUM('MALE', 'FEMALE') NOT NULL, + "gender" VARCHAR(6) CHECK ("gender" IN ('MALE', 'FEMALE')) NOT NULL, PRIMARY KEY("IDP") ); `); @@ -497,7 +497,7 @@ function initH2Tests() returns error? { "id" INT NOT NULL, "reason" VARCHAR(191) NOT NULL, "appointmentTime" DATETIME NOT NULL, - "status" ENUM('SCHEDULED', 'STARTED', 'ENDED') NOT NULL, + "status" VARCHAR(9) CHECK ("status" IN ('SCHEDULED', 'STARTED', 'ENDED')) NOT NULL, "patient_id" INT NOT NULL, FOREIGN KEY("patient_id") REFERENCES "patients"("IDP"), "doctorId" INT NOT NULL, From 8fcb5edeb8e8fd5dab5cbe9a93c1e2222aae7298 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sun, 7 Jul 2024 14:14:29 +0530 Subject: [PATCH 18/23] add error logs --- ballerina/tests/h2_hospital_tests.bal | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ballerina/tests/h2_hospital_tests.bal b/ballerina/tests/h2_hospital_tests.bal index 619f923..7978f8b 100644 --- a/ballerina/tests/h2_hospital_tests.bal +++ b/ballerina/tests/h2_hospital_tests.bal @@ -14,6 +14,7 @@ // specific language governing permissions and limitations // under the License. +import ballerina/log; import ballerina/persist; import ballerina/test; @@ -327,7 +328,8 @@ function testDeletePatientH2() returns error? { MySqlHospitalClient h2DbHospital = check new(); Patient|persist:Error result = h2DbHospital->/patients/[1].delete(); if result is persist:Error { - test:assertFail("Patient should be deleted"); + log:printError("Error: ", result); + test:assertFail("Patient should be deleted"); } } @@ -338,6 +340,6 @@ function testDeleteDoctorH2() returns error? { MySqlHospitalClient h2DbHospital = check new(); Doctor|persist:Error result = h2DbHospital->/doctors/[1].delete(); if result is persist:Error { - test:assertFail("Patient should be deleted"); + test:assertFail("Patient should be deleted"); } } From eb0a76a527ff5075b85ace41455a4d3debb06879 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sun, 7 Jul 2024 18:29:57 +0530 Subject: [PATCH 19/23] Fix the issue failure and add grouping --- ballerina/tests/h2_hospital_tests.bal | 374 +++++++++--------- ballerina/tests/mssql_hospital_tests.bal | 26 +- ballerina/tests/mysql_hospital_tests.bal | 45 ++- ballerina/tests/postgresql_hospital_tests.bal | 67 ++-- 4 files changed, 292 insertions(+), 220 deletions(-) diff --git a/ballerina/tests/h2_hospital_tests.bal b/ballerina/tests/h2_hospital_tests.bal index 7978f8b..7e6a942 100644 --- a/ballerina/tests/h2_hospital_tests.bal +++ b/ballerina/tests/h2_hospital_tests.bal @@ -18,46 +18,50 @@ import ballerina/log; import ballerina/persist; import ballerina/test; - -@test:Config{} +@test:Config { + groups: ["annotation", "h2"] +} function testCreatePatientH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); PatientInsert patient = { - name: "John Doe", - age: 30, - phoneNumber: "0771690000", - gender: "MALE", - address: "123, Main Street, Colombo 05" + name: "John Doe", + age: 30, + phoneNumber: "0771690000", + gender: "MALE", + address: "123, Main Street, Colombo 05" }; int[] unionResult = check h2DbHospital->/patients.post([patient]); test:assertEquals(unionResult[0], 1, "Patient should be created"); } -@test:Config{} +@test:Config { + groups: ["annotation", "h2"] +} function testCreateDoctorH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); DoctorInsert doctor = { - id: 1, - name: "Doctor Mouse", - specialty: "Physician", - phoneNumber: "077100100", - salary: 20000 + id: 1, + name: "Doctor Mouse", + specialty: "Physician", + phoneNumber: "077100100", + salary: 20000 }; int[] res = check h2DbHospital->/doctors.post([doctor]); test:assertEquals(res[0], 1, "Doctor should be created"); } -@test:Config{ - dependsOn: [testCreateDoctorH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testCreateDoctorH2] } function testCreateDoctorAlreadyExistsH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); DoctorInsert doctor = { - id: 1, - name: "Doctor Mouse", - specialty: "Physician", - phoneNumber: "077100100", - salary: 20000.00 + id: 1, + name: "Doctor Mouse", + specialty: "Physician", + phoneNumber: "077100100", + salary: 20000.00 }; int[]|persist:Error res = h2DbHospital->/doctors.post([doctor]); if !(res is persist:AlreadyExistsError) { @@ -65,35 +69,37 @@ function testCreateDoctorAlreadyExistsH2() returns error? { } } -@test:Config{ - dependsOn: [testCreatePatientH2, testCreateDoctorH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testCreatePatientH2, testCreateDoctorH2] } function testCreateAppointmentH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); AppointmentInsert appointment = { - id: 1, - patientId: 1, - doctorId: 1, - appointmentTime: {year: 2023, month: 7, day: 1, hour: 10, minute: 30}, - status: "SCHEDULED", - reason: "Headache" + id: 1, + patientId: 1, + doctorId: 1, + appointmentTime: {year: 2023, month: 7, day: 1, hour: 10, minute: 30}, + status: "SCHEDULED", + reason: "Headache" }; int[] res = check h2DbHospital->/appointments.post([appointment]); test:assertEquals(res[0], 1, "Appointment should be created"); } -@test:Config{ - dependsOn: [testCreatePatientH2, testCreateDoctorH2, testCreateAppointmentH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testCreatePatientH2, testCreateDoctorH2, testCreateAppointmentH2] } function testCreateAppointmentAlreadyExistsH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); AppointmentInsert appointment = { - id: 1, - patientId: 1, - doctorId: 1, - appointmentTime: {year: 2023, month: 7, day: 1, hour: 10, minute: 30}, - status: "SCHEDULED", - reason: "Headache" + id: 1, + patientId: 1, + doctorId: 1, + appointmentTime: {year: 2023, month: 7, day: 1, hour: 10, minute: 30}, + status: "SCHEDULED", + reason: "Headache" }; int[]|persist:Error res = h2DbHospital->/appointments.post([appointment]); if !(res is persist:AlreadyExistsError) { @@ -101,188 +107,196 @@ function testCreateAppointmentAlreadyExistsH2() returns error? { } } -@test:Config{ - dependsOn: [testCreateDoctorH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testCreateDoctorH2] } function testGetDoctorsH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); stream doctors = h2DbHospital->/doctors.get(); - Doctor[]|persist:Error doctorsArr = from Doctor doctor in doctors select doctor; + Doctor[]|persist:Error doctorsArr = from Doctor doctor in doctors + select doctor; Doctor[] expected = [ - {id: 1, name: "Doctor Mouse", specialty: "Physician", phoneNumber: "077100100", salary: 20000} + {id: 1, name: "Doctor Mouse", specialty: "Physician", phoneNumber: "077100100", salary: 20000} ]; test:assertEquals(doctorsArr, expected, "Doctor details should be returned"); } -@test:Config{ - dependsOn: [testCreatePatientH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testCreatePatientH2] } function testGetPatientByIdH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); Patient|persist:Error patient = h2DbHospital->/patients/[1].get(); - Patient expected = {"id":1, "name": "John Doe", "age": 30, "address": "123, Main Street, Colombo 05", "phoneNumber":"0771690000", "gender":"MALE"}; + Patient expected = {"id": 1, "name": "John Doe", "age": 30, "address": "123, Main Street, Colombo 05", "phoneNumber": "0771690000", "gender": "MALE"}; test:assertEquals(patient, expected, "Patient details should be returned"); } -@test:Config{} +@test:Config { + groups: ["annotation", "h2"] +} function testGetPatientNotFoundH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); Patient|persist:Error patient = h2DbHospital->/patients/[10].get(); if !(patient is persist:NotFoundError) { test:assertFail("Patient should be not found"); } } -@test:Config{ - dependsOn: [testCreateAppointmentH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testCreateAppointmentH2] } function testGetAppointmentByDoctorH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); stream appointments = h2DbHospital->/appointments(); - AppointmentWithRelations[]|persist:Error? filteredAppointments = from AppointmentWithRelations appointment in appointments - where appointment.doctorId == 1 && + AppointmentWithRelations[]|persist:Error? filteredAppointments = from AppointmentWithRelations appointment in appointments + where appointment.doctorId == 1 && appointment.appointmentTime?.year == 2023 && appointment.appointmentTime?.month == 7 && appointment.appointmentTime?.day == 1 - select appointment; + select appointment; AppointmentWithRelations[] expected = [ - { - "id": 1, - "doctorId": 1, - "patientId": 1, - "reason": "Headache", - "appointmentTime": { - "year": 2023, - "month": 7, - "day": 1, - "hour": 10, - "minute": 30, - "second": 0 - }, - "status": "SCHEDULED", - "patient": { - "id": 1, - "name": "John Doe", - "age": 30, - "address": "123, Main Street, Colombo 05", - "phoneNumber": "0771690000", - "gender": "MALE" - }, - "doctor": { - "id": 1, - "name": "Doctor Mouse", - "specialty": "Physician", - "phoneNumber": "077100100", - "salary": 20000 + { + "id": 1, + "doctorId": 1, + "patientId": 1, + "reason": "Headache", + "appointmentTime": { + "year": 2023, + "month": 7, + "day": 1, + "hour": 10, + "minute": 30, + "second": 0 + }, + "status": "SCHEDULED", + "patient": { + "id": 1, + "name": "John Doe", + "age": 30, + "address": "123, Main Street, Colombo 05", + "phoneNumber": "0771690000", + "gender": "MALE" + }, + "doctor": { + "id": 1, + "name": "Doctor Mouse", + "specialty": "Physician", + "phoneNumber": "077100100", + "salary": 20000 + } } - } ]; test:assertEquals(filteredAppointments, expected, "Appointment details should be returned"); stream appointments2 = h2DbHospital->/appointments(); - Appointment[]|persist:Error? filteredAppointments2 = from Appointment appointment in appointments2 - where appointment.doctorId == 5 && + Appointment[]|persist:Error? filteredAppointments2 = from Appointment appointment in appointments2 + where appointment.doctorId == 5 && appointment.appointmentTime.year == 2023 && appointment.appointmentTime.month == 7 && appointment.appointmentTime.day == 1 - select appointment; + select appointment; test:assertEquals(filteredAppointments2, [], "Appointment details should be empty"); } -@test:Config{ - dependsOn: [testCreateAppointmentH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testCreateAppointmentH2] } function testGetAppointmentByPatientH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); stream appointments = h2DbHospital->/appointments(); - AppointmentWithRelations[]|persist:Error? filteredAppointments = from AppointmentWithRelations appointment in appointments - where appointment.patientId == 1 - select appointment; + AppointmentWithRelations[]|persist:Error? filteredAppointments = from AppointmentWithRelations appointment in appointments + where appointment.patientId == 1 + select appointment; AppointmentWithRelations[] expected = [ - { - "id": 1, - "doctorId": 1, - "patientId": 1, - "reason": "Headache", - "appointmentTime": { - "year": 2023, - "month": 7, - "day": 1, - "hour": 10, - "minute": 30, - "second": 0 - }, - "status": "SCHEDULED", - "patient": { - "id": 1, - "name": "John Doe", - "age": 30, - "address": "123, Main Street, Colombo 05", - "phoneNumber": "0771690000", - "gender": "MALE" - }, - "doctor": { - "id": 1, - "name": "Doctor Mouse", - "specialty": "Physician", - "phoneNumber": "077100100", - "salary": 20000 + { + "id": 1, + "doctorId": 1, + "patientId": 1, + "reason": "Headache", + "appointmentTime": { + "year": 2023, + "month": 7, + "day": 1, + "hour": 10, + "minute": 30, + "second": 0 + }, + "status": "SCHEDULED", + "patient": { + "id": 1, + "name": "John Doe", + "age": 30, + "address": "123, Main Street, Colombo 05", + "phoneNumber": "0771690000", + "gender": "MALE" + }, + "doctor": { + "id": 1, + "name": "Doctor Mouse", + "specialty": "Physician", + "phoneNumber": "077100100", + "salary": 20000 + } } - } - ]; + ]; test:assertEquals(filteredAppointments, expected, "Appointment details should be returned"); stream appointments2 = h2DbHospital->/appointments(); - AppointmentWithRelations[]|persist:Error? filteredAppointments2 = from AppointmentWithRelations appointment in appointments2 - where appointment.patientId == 5 - select appointment; + AppointmentWithRelations[]|persist:Error? filteredAppointments2 = from AppointmentWithRelations appointment in appointments2 + where appointment.patientId == 5 + select appointment; test:assertEquals(filteredAppointments2, [], "Appointment details should be empty"); } -@test:Config{ - dependsOn: [testCreateAppointmentH2, testGetAppointmentByDoctorH2, testGetAppointmentByPatientH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testCreateAppointmentH2, testGetAppointmentByDoctorH2, testGetAppointmentByPatientH2] } function testPatchAppointmentH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); Appointment|persist:Error result = h2DbHospital->/appointments/[1].put({status: "STARTED"}); if result is persist:Error { test:assertFail("Appointment should be updated"); } stream appointments = h2DbHospital->/appointments(); - AppointmentWithRelations[]|persist:Error? filteredAppointments = from AppointmentWithRelations appointment in appointments - where appointment.patientId == 1 - select appointment; + AppointmentWithRelations[]|persist:Error? filteredAppointments = from AppointmentWithRelations appointment in appointments + where appointment.patientId == 1 + select appointment; AppointmentWithRelations[] expected = [ - { - "id": 1, - "doctorId": 1, - "patientId": 1, - "reason": "Headache", - "appointmentTime": { - "year": 2023, - "month": 7, - "day": 1, - "hour": 10, - "minute": 30, - "second": 0 - }, - "status": "STARTED", - "patient": { - "id": 1, - "name": "John Doe", - "age": 30, - "address": "123, Main Street, Colombo 05", - "phoneNumber": "0771690000", - "gender": "MALE" - }, - "doctor": { - "id": 1, - "name": "Doctor Mouse", - "specialty": "Physician", - "phoneNumber": "077100100", - "salary": 20000 + { + "id": 1, + "doctorId": 1, + "patientId": 1, + "reason": "Headache", + "appointmentTime": { + "year": 2023, + "month": 7, + "day": 1, + "hour": 10, + "minute": 30, + "second": 0 + }, + "status": "STARTED", + "patient": { + "id": 1, + "name": "John Doe", + "age": 30, + "address": "123, Main Street, Colombo 05", + "phoneNumber": "0771690000", + "gender": "MALE" + }, + "doctor": { + "id": 1, + "name": "Doctor Mouse", + "specialty": "Physician", + "phoneNumber": "077100100", + "salary": 20000 + } } - } - ]; + ]; test:assertEquals(filteredAppointments, expected, "Appointment details should be updated"); Appointment|persist:Error result2 = h2DbHospital->/appointments/[0].put({status: "STARTED"}); if !(result2 is persist:NotFoundError) { @@ -290,18 +304,19 @@ function testPatchAppointmentH2() returns error? { } } -@test:Config{ - dependsOn: [testCreateAppointmentH2, testGetAppointmentByDoctorH2, testGetAppointmentByPatientH2, testPatchAppointmentH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testCreateAppointmentH2, testGetAppointmentByDoctorH2, testGetAppointmentByPatientH2, testPatchAppointmentH2] } function testDeleteAppointmentByPatientIdH2() returns error? { - H2HospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); stream appointments = h2DbHospital->/appointments; Appointment[]|persist:Error result = from Appointment appointment in appointments - where appointment.patientId == 1 + where appointment.patientId == 1 && appointment.appointmentTime.year == 2023 && appointment.appointmentTime.month == 7 && appointment.appointmentTime.day == 1 - select appointment; + select appointment; if (result is persist:Error) { test:assertFail("Appointment should be found"); } @@ -313,19 +328,20 @@ function testDeleteAppointmentByPatientIdH2() returns error? { } stream appointments2 = h2DbHospital->/appointments; Appointment[]|persist:Error result3 = from Appointment appointment in appointments2 - where appointment.patientId == 1 + where appointment.patientId == 1 && appointment.appointmentTime.year == 2023 && appointment.appointmentTime.month == 7 && appointment.appointmentTime.day == 1 - select appointment; + select appointment; test:assertEquals(result3, [], "Appointment details should be empty"); } -@test:Config{ - dependsOn: [testGetPatientByIdH2, testDeleteAppointmentByPatientIdH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testGetPatientByIdH2, testDeleteAppointmentByPatientIdH2] } function testDeletePatientH2() returns error? { - MySqlHospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); Patient|persist:Error result = h2DbHospital->/patients/[1].delete(); if result is persist:Error { log:printError("Error: ", result); @@ -333,13 +349,15 @@ function testDeletePatientH2() returns error? { } } -@test:Config{ - dependsOn: [testGetDoctorsH2, testDeleteAppointmentByPatientIdH2] +@test:Config { + groups: ["annotation", "h2"], + dependsOn: [testGetDoctorsH2, testDeleteAppointmentByPatientIdH2] } function testDeleteDoctorH2() returns error? { - MySqlHospitalClient h2DbHospital = check new(); + H2HospitalClient h2DbHospital = check new (); Doctor|persist:Error result = h2DbHospital->/doctors/[1].delete(); if result is persist:Error { + log:printError("Error: ", result); test:assertFail("Patient should be deleted"); } } diff --git a/ballerina/tests/mssql_hospital_tests.bal b/ballerina/tests/mssql_hospital_tests.bal index 2698bfc..0dd6ddc 100644 --- a/ballerina/tests/mssql_hospital_tests.bal +++ b/ballerina/tests/mssql_hospital_tests.bal @@ -18,7 +18,10 @@ import ballerina/persist; import ballerina/test; -@test:Config{enable: true} +@test:Config{ + groups: ["annotation", "mssql"], + enable: true +} function testCreatePatientMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); PatientInsert patient = { @@ -31,7 +34,10 @@ function testCreatePatientMsSql() returns error? { _ = check mssqlDbHospital->/patients.post([patient]); } -@test:Config{enable: true} +@test:Config{ + groups: ["annotation", "mssql"], + enable: true +} function testCreateDoctorMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); DoctorInsert doctor = { @@ -45,6 +51,7 @@ function testCreateDoctorMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testCreateDoctorMsSql], enable: true } @@ -64,6 +71,7 @@ function testCreateDoctorAlreadyExistsMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testCreatePatientMsSql, testCreateDoctorMsSql], enable: true } @@ -81,6 +89,7 @@ function testCreateAppointmentMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testCreatePatientMsSql, testCreateDoctorMsSql, testCreateAppointmentMsSql], enable: true } @@ -101,6 +110,7 @@ function testCreateAppointmentAlreadyExistsMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testCreateDoctorMsSql], enable: true } @@ -115,6 +125,7 @@ function testGetDoctorsMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testCreatePatientMsSql], enable: true } @@ -125,7 +136,10 @@ function testGetPatientByIdMsSql() returns error? { test:assertEquals(patient, expected, "Patient details should be returned"); } -@test:Config{enable: true} +@test:Config{ + groups: ["annotation", "mssql"], + enable: true +} function testGetPatientNotFoundMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); Patient|persist:Error patient = mssqlDbHospital->/patients/[10].get(); @@ -135,6 +149,7 @@ function testGetPatientNotFoundMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testCreateAppointmentMsSql], enable: true } @@ -192,6 +207,7 @@ function testGetAppointmentByDoctorMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testCreateAppointmentMsSql], enable: true } @@ -242,6 +258,7 @@ function testGetAppointmentByPatientMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testCreateAppointmentMsSql, testGetAppointmentByDoctorMsSql, testGetAppointmentByPatientMsSql], enable: true } @@ -295,6 +312,7 @@ function testPatchAppointmentMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testCreateAppointmentMsSql, testGetAppointmentByDoctorMsSql, testGetAppointmentByPatientMsSql, testPatchAppointmentMsSql], enable: true } @@ -327,6 +345,7 @@ function testDeleteAppointmentByPatientIdMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testGetPatientByIdMsSql, testDeleteAppointmentByPatientIdMsSql], enable: true } @@ -339,6 +358,7 @@ function testDeletePatientMsSql() returns error? { } @test:Config{ + groups: ["annotation", "mssql"], dependsOn: [testGetDoctorsMsSql, testDeleteAppointmentByPatientIdMsSql], enable: true } diff --git a/ballerina/tests/mysql_hospital_tests.bal b/ballerina/tests/mysql_hospital_tests.bal index 97f116f..39583ac 100644 --- a/ballerina/tests/mysql_hospital_tests.bal +++ b/ballerina/tests/mysql_hospital_tests.bal @@ -18,7 +18,9 @@ import ballerina/persist; import ballerina/test; -@test:Config{} +@test:Config{ + groups: ["annotation", "mysql"] +} function testCreatePatientMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); PatientInsert patient = { @@ -32,7 +34,9 @@ function testCreatePatientMySql() returns error? { test:assertEquals(unionResult[0], 1, "Patient should be created"); } -@test:Config{} +@test:Config{ + groups: ["annotation", "mysql"] +} function testCreateDoctorMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); DoctorInsert doctor = { @@ -47,7 +51,8 @@ function testCreateDoctorMySql() returns error? { } @test:Config{ - dependsOn: [testCreateDoctorMySql] + groups: ["annotation", "mysql"], + dependsOn: [testCreateDoctorMySql] } function testCreateDoctorAlreadyExistsMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); @@ -65,7 +70,8 @@ function testCreateDoctorAlreadyExistsMySql() returns error? { } @test:Config{ - dependsOn: [testCreatePatientMySql, testCreateDoctorMySql] + groups: ["annotation", "mysql"], + dependsOn: [testCreatePatientMySql, testCreateDoctorMySql] } function testCreateAppointmentMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); @@ -82,7 +88,8 @@ function testCreateAppointmentMySql() returns error? { } @test:Config{ - dependsOn: [testCreatePatientMySql, testCreateDoctorMySql, testCreateAppointmentMySql] + groups: ["annotation", "mysql"], + dependsOn: [testCreatePatientMySql, testCreateDoctorMySql, testCreateAppointmentMySql] } function testCreateAppointmentAlreadyExistsMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); @@ -101,7 +108,8 @@ function testCreateAppointmentAlreadyExistsMySql() returns error? { } @test:Config{ - dependsOn: [testCreateDoctorMySql] + groups: ["annotation", "mysql"], + dependsOn: [testCreateDoctorMySql] } function testGetDoctorsMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); @@ -114,7 +122,8 @@ function testGetDoctorsMySql() returns error? { } @test:Config{ - dependsOn: [testCreatePatientMySql] + groups: ["annotation", "mysql"], + dependsOn: [testCreatePatientMySql] } function testGetPatientByIdMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); @@ -123,7 +132,9 @@ function testGetPatientByIdMySql() returns error? { test:assertEquals(patient, expected, "Patient details should be returned"); } -@test:Config{} +@test:Config{ + groups: ["annotation", "mysql"] +} function testGetPatientNotFoundMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); Patient|persist:Error patient = mysqlDbHospital->/patients/[10].get(); @@ -133,7 +144,8 @@ function testGetPatientNotFoundMySql() returns error? { } @test:Config{ - dependsOn: [testCreateAppointmentMySql] + groups: ["annotation", "mysql"], + dependsOn: [testCreateAppointmentMySql] } function testGetAppointmentByDoctorMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); @@ -189,7 +201,8 @@ function testGetAppointmentByDoctorMySql() returns error? { } @test:Config{ - dependsOn: [testCreateAppointmentMySql] + groups: ["annotation", "mysql"], + dependsOn: [testCreateAppointmentMySql] } function testGetAppointmentByPatientMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); @@ -238,7 +251,8 @@ function testGetAppointmentByPatientMySql() returns error? { } @test:Config{ - dependsOn: [testCreateAppointmentMySql, testGetAppointmentByDoctorMySql, testGetAppointmentByPatientMySql] + groups: ["annotation", "mysql"], + dependsOn: [testCreateAppointmentMySql, testGetAppointmentByDoctorMySql, testGetAppointmentByPatientMySql] } function testPatchAppointmentMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); @@ -290,7 +304,8 @@ function testPatchAppointmentMySql() returns error? { } @test:Config{ - dependsOn: [testCreateAppointmentMySql, testGetAppointmentByDoctorMySql, testGetAppointmentByPatientMySql, testPatchAppointmentMySql] + groups: ["annotation", "mysql"], + dependsOn: [testCreateAppointmentMySql, testGetAppointmentByDoctorMySql, testGetAppointmentByPatientMySql, testPatchAppointmentMySql] } function testDeleteAppointmentByPatientIdMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); @@ -321,7 +336,8 @@ function testDeleteAppointmentByPatientIdMySql() returns error? { } @test:Config{ - dependsOn: [testGetPatientByIdMySql, testDeleteAppointmentByPatientIdMySql] + groups: ["annotation", "mysql"], + dependsOn: [testGetPatientByIdMySql, testDeleteAppointmentByPatientIdMySql] } function testDeletePatientMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); @@ -332,7 +348,8 @@ function testDeletePatientMySql() returns error? { } @test:Config{ - dependsOn: [testGetDoctorsMySql, testDeleteAppointmentByPatientIdMySql] + groups: ["annotation", "mysql"], + dependsOn: [testGetDoctorsMySql, testDeleteAppointmentByPatientIdMySql] } function testDeleteDoctorMySql() returns error? { MySqlHospitalClient mysqlDbHospital = check new(); diff --git a/ballerina/tests/postgresql_hospital_tests.bal b/ballerina/tests/postgresql_hospital_tests.bal index a7cc584..25a4bd5 100644 --- a/ballerina/tests/postgresql_hospital_tests.bal +++ b/ballerina/tests/postgresql_hospital_tests.bal @@ -18,7 +18,9 @@ import ballerina/persist; import ballerina/test; -@test:Config{} +@test:Config { + groups: ["annotation", "postgresql"] +} function testCreatePatientPostgreSql() returns error? { PostgreSqlHospitalClient postgreSqlDbHospital = check new(); PatientInsert patient = { @@ -31,7 +33,9 @@ function testCreatePatientPostgreSql() returns error? { _ = check postgreSqlDbHospital->/patients.post([patient]); } -@test:Config{} +@test:Config { + groups: ["annotation", "postgresql"] +} function testCreateDoctorPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); DoctorInsert doctor = { @@ -44,8 +48,9 @@ function testCreateDoctorPostgreSql() returns error? { _ = check postgresSqlDbHospital->/doctors.post([doctor]); } -@test:Config{ - dependsOn: [testCreateDoctorPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testCreateDoctorPostgreSql] } function testCreateDoctorAlreadyExistsPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); @@ -62,8 +67,9 @@ function testCreateDoctorAlreadyExistsPostgreSql() returns error? { } } -@test:Config{ - dependsOn: [testCreatePatientPostgreSql, testCreateDoctorPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testCreatePatientPostgreSql, testCreateDoctorPostgreSql] } function testCreateAppointmentPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); @@ -78,8 +84,9 @@ function testCreateAppointmentPostgreSql() returns error? { _ = check postgresSqlDbHospital->/appointments.post([appointment]); } -@test:Config{ - dependsOn: [testCreatePatientPostgreSql, testCreateDoctorPostgreSql, testCreateAppointmentPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testCreatePatientPostgreSql, testCreateDoctorPostgreSql, testCreateAppointmentPostgreSql] } function testCreateAppointmentAlreadyExistsPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); @@ -97,8 +104,9 @@ function testCreateAppointmentAlreadyExistsPostgreSql() returns error? { } } -@test:Config{ - dependsOn: [testCreateDoctorPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testCreateDoctorPostgreSql] } function testGetDoctorsPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); @@ -110,8 +118,9 @@ function testGetDoctorsPostgreSql() returns error? { test:assertEquals(doctorsArr, expected, "Doctor details should be returned"); } -@test:Config{ - dependsOn: [testCreatePatientPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testCreatePatientPostgreSql] } function testGetPatientByIdPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); @@ -120,7 +129,9 @@ function testGetPatientByIdPostgreSql() returns error? { test:assertEquals(patient, expected, "Patient details should be returned"); } -@test:Config{} +@test:Config { + groups: ["annotation", "postgresql"] +} function testGetPatientNotFoundPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); Patient|persist:Error patient = postgresSqlDbHospital->/patients/[10].get(); @@ -129,8 +140,9 @@ function testGetPatientNotFoundPostgreSql() returns error? { } } -@test:Config{ - dependsOn: [testCreateAppointmentPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testCreateAppointmentPostgreSql] } function testGetAppointmentByDoctorPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); @@ -185,8 +197,9 @@ function testGetAppointmentByDoctorPostgreSql() returns error? { test:assertEquals(filteredAppointments2, [], "Appointment details should be empty"); } -@test:Config{ - dependsOn: [testCreateAppointmentPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testCreateAppointmentPostgreSql] } function testGetAppointmentByPatientPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); @@ -234,8 +247,9 @@ function testGetAppointmentByPatientPostgreSql() returns error? { test:assertEquals(filteredAppointments2, [], "Appointment details should be empty"); } -@test:Config{ - dependsOn: [testCreateAppointmentPostgreSql, testGetAppointmentByDoctorPostgreSql, testGetAppointmentByPatientPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testCreateAppointmentPostgreSql, testGetAppointmentByDoctorPostgreSql, testGetAppointmentByPatientPostgreSql] } function testPatchAppointmentPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); @@ -286,8 +300,9 @@ function testPatchAppointmentPostgreSql() returns error? { } } -@test:Config{ - dependsOn: [testCreateAppointmentPostgreSql, testGetAppointmentByDoctorPostgreSql, testGetAppointmentByPatientPostgreSql, testPatchAppointmentPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testCreateAppointmentPostgreSql, testGetAppointmentByDoctorPostgreSql, testGetAppointmentByPatientPostgreSql, testPatchAppointmentPostgreSql] } function testDeleteAppointmentByPatientIdPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); @@ -317,8 +332,9 @@ function testDeleteAppointmentByPatientIdPostgreSql() returns error? { test:assertEquals(result3, [], "Appointment details should be empty"); } -@test:Config{ - dependsOn: [testGetPatientByIdPostgreSql, testDeleteAppointmentByPatientIdPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testGetPatientByIdPostgreSql, testDeleteAppointmentByPatientIdPostgreSql] } function testDeletePatientPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); @@ -328,8 +344,9 @@ function testDeletePatientPostgreSql() returns error? { } } -@test:Config{ - dependsOn: [testGetDoctorsPostgreSql, testDeleteAppointmentByPatientIdPostgreSql] +@test:Config { + groups: ["annotation", "postgresql"], + dependsOn: [testGetDoctorsPostgreSql, testDeleteAppointmentByPatientIdPostgreSql] } function testDeleteDoctorPostgreSql() returns error? { PostgreSqlHospitalClient postgresSqlDbHospital = check new(); From 6f9f8b93bc3acd22cd5704aa247f9c9ca5ecdbb5 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sun, 7 Jul 2024 21:44:16 +0530 Subject: [PATCH 20/23] [Automated] Update native jar versions in toml files --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 6368def..7338544 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerinax" name = "persist.sql" -version = "1.3.1" +version = "1.4.0" authors = ["Ballerina"] keywords = ["persist", "sql", "mysql", "mssql", "sql-server"] repository = "https://github.com/ballerina-platform/module-ballerinax-persist.sql" @@ -15,8 +15,8 @@ graalvmCompatible = true [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "persist.sql-native" -version = "1.3.1" -path = "../native/build/libs/persist.sql-native-1.3.1-SNAPSHOT.jar" +version = "1.4.0" +path = "../native/build/libs/persist.sql-native-1.4.0-SNAPSHOT.jar" [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 38a6557..0ed7b40 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,7 +3,7 @@ id = "persist.sql-compiler-plugin" class = "io.ballerina.stdlib.persist.sql.compiler.PersistSqlCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/persist.sql-compiler-plugin-1.3.1-SNAPSHOT.jar" +path = "../compiler-plugin/build/libs/persist.sql-compiler-plugin-1.4.0-SNAPSHOT.jar" [[dependency]] path = "./lib/persist-native-1.3.0.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 132ad07..2ba9bb0 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -460,7 +460,7 @@ modules = [ [[package]] org = "ballerinax" name = "persist.sql" -version = "1.3.1" +version = "1.4.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"}, From f7155b31484ac933bbf33a37a725b9e156fbb1a0 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sun, 7 Jul 2024 21:46:37 +0530 Subject: [PATCH 21/23] bump a minor version --- ballerina/tests/h2_test_entities_generated_client.bal | 2 +- ballerina/tests/persist/hospital.bal | 2 +- gradle.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/tests/h2_test_entities_generated_client.bal b/ballerina/tests/h2_test_entities_generated_client.bal index 0a331a0..eed662f 100644 --- a/ballerina/tests/h2_test_entities_generated_client.bal +++ b/ballerina/tests/h2_test_entities_generated_client.bal @@ -1,4 +1,3 @@ -import ballerina/jballerina.java; // Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. // // WSO2 LLC. licenses this file to you under the Apache License, @@ -14,6 +13,7 @@ import ballerina/jballerina.java; // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. +import ballerina/jballerina.java; import ballerina/persist; import ballerina/sql; import ballerinax/h2.driver as _; diff --git a/ballerina/tests/persist/hospital.bal b/ballerina/tests/persist/hospital.bal index 5ef61c9..985aa3c 100644 --- a/ballerina/tests/persist/hospital.bal +++ b/ballerina/tests/persist/hospital.bal @@ -73,4 +73,4 @@ public type Doctor record {| @sql:Decimal {precision: [10, 2]} decimal? salary; Appointment[] appointments; -|}; \ No newline at end of file +|}; diff --git a/gradle.properties b/gradle.properties index c7cdf5c..e8a518f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=io.ballerina.stdlib -version=1.3.1-SNAPSHOT +version=1.4.0-SNAPSHOT puppycrawlCheckstyleVersion=10.12.1 checkstyleToolVersion=10.12.1 From a3ccc93fa486d64421d74d3bfebeb8ec535cca9d Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sun, 7 Jul 2024 21:56:58 +0530 Subject: [PATCH 22/23] Remove enable flag from mssql testcases --- ballerina/tests/mssql-all-types-tests.bal | 24 ++++------- ballerina/tests/mssql-associations-tests.bal | 12 ++---- ballerina/tests/mssql-building-tests.bal | 36 ++++++---------- ballerina/tests/mssql-composite-key-tests.bal | 33 +++++---------- ballerina/tests/mssql-department-tests.bal | 36 ++++++---------- ballerina/tests/mssql-employee-tests.bal | 42 +++++++------------ ballerina/tests/mssql-id-fields-tests.bal | 21 ++++------ ballerina/tests/mssql-native-tests.bal | 27 ++++-------- ballerina/tests/mssql-transaction-tests.bal | 6 +-- ballerina/tests/mssql-workspace-tests.bal | 39 ++++++----------- ballerina/tests/mssql_hospital_tests.bal | 39 ++++++----------- 11 files changed, 105 insertions(+), 210 deletions(-) diff --git a/ballerina/tests/mssql-all-types-tests.bal b/ballerina/tests/mssql-all-types-tests.bal index e123c03..e52499d 100644 --- a/ballerina/tests/mssql-all-types-tests.bal +++ b/ballerina/tests/mssql-all-types-tests.bal @@ -18,8 +18,7 @@ import ballerina/test; import ballerina/persist; @test:Config { - groups: ["all-types", "mssql"], - enable: true + groups: ["all-types", "mssql"] } function mssqlAllTypesCreateTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -37,8 +36,7 @@ function mssqlAllTypesCreateTest() returns error? { } @test:Config { - groups: ["all-types", "mssql"], - enable: true + groups: ["all-types", "mssql"] } function mssqlAllTypesCreateMixedTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -57,8 +55,7 @@ function mssqlAllTypesCreateMixedTest() returns error? { @test:Config { groups: ["all-types", "mssql"], - dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest], - enable: true + dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest] } function mssqlAllTypesReadTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -73,8 +70,7 @@ function mssqlAllTypesReadTest() returns error? { @test:Config { groups: ["all-types", "mssql", "dependent"], - dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest], - enable: true + dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest] } function mssqlAllTypesReadDependentTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -166,8 +162,7 @@ function mssqlAllTypesReadDependentTest() returns error? { @test:Config { groups: ["all-types", "mssql"], - dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest], - enable: true + dependsOn: [mssqlAllTypesCreateTest, mssqlAllTypesCreateMixedTest] } function mssqlAllTypesReadOneTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -188,8 +183,7 @@ function mssqlAllTypesReadOneTest() returns error? { } @test:Config { - groups: ["all-types", "mssql"], - enable: true + groups: ["all-types", "mssql"] } function mssqlAllTypesReadOneTestNegative() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -207,8 +201,7 @@ function mssqlAllTypesReadOneTestNegative() returns error? { @test:Config { groups: ["all-types", "mssql"], - dependsOn: [mssqlAllTypesReadOneTest, mssqlAllTypesReadTest, mssqlAllTypesReadDependentTest], - enable: true + dependsOn: [mssqlAllTypesReadOneTest, mssqlAllTypesReadTest, mssqlAllTypesReadDependentTest] } function mssqlAllTypesUpdateTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -243,8 +236,7 @@ function mssqlAllTypesUpdateTest() returns error? { @test:Config { groups: ["all-types", "mssql"], - dependsOn: [mssqlAllTypesUpdateTest], - enable: true + dependsOn: [mssqlAllTypesUpdateTest] } function mssqlAllTypesDeleteTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); diff --git a/ballerina/tests/mssql-associations-tests.bal b/ballerina/tests/mssql-associations-tests.bal index 5b7cce1..dfdcee3 100644 --- a/ballerina/tests/mssql-associations-tests.bal +++ b/ballerina/tests/mssql-associations-tests.bal @@ -19,8 +19,7 @@ import ballerina/persist; @test:Config { groups: ["associations", "mssql"], - dependsOn: [mssqlEmployeeDeleteTestNegative], - enable: true + dependsOn: [mssqlEmployeeDeleteTestNegative] } function mssqlEmployeeRelationsTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -87,8 +86,7 @@ function mssqlEmployeeRelationsTest() returns error? { @test:Config { groups: ["associations", "mssql"], - dependsOn: [mssqlEmployeeDeleteTestNegative], - enable: true + dependsOn: [mssqlEmployeeDeleteTestNegative] } function mssqlDepartmentRelationsTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -168,8 +166,7 @@ function mssqlDepartmentRelationsTest() returns error? { @test:Config { groups: ["associations", "mssql"], - dependsOn: [mssqlEmployeeRelationsTest], - enable: true + dependsOn: [mssqlEmployeeRelationsTest] } function mssqlWorkspaceRelationsTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -245,8 +242,7 @@ function mssqlWorkspaceRelationsTest() returns error? { @test:Config { groups: ["associations", "mssql"], - dependsOn: [mssqlEmployeeRelationsTest], - enable: true + dependsOn: [mssqlEmployeeRelationsTest] } function mssqlBuildingRelationsTest() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-building-tests.bal b/ballerina/tests/mssql-building-tests.bal index 2de0a22..b2efa41 100644 --- a/ballerina/tests/mssql-building-tests.bal +++ b/ballerina/tests/mssql-building-tests.bal @@ -18,8 +18,7 @@ import ballerina/test; import ballerina/persist; @test:Config { - groups: ["building", "mssql"], - enable: true + groups: ["building", "mssql"] } function mssqlBuildingCreateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -33,8 +32,7 @@ function mssqlBuildingCreateTest() returns error? { } @test:Config { - groups: ["building", "mssql"], - enable: true + groups: ["building", "mssql"] } function mssqlBuildingCreateTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -53,8 +51,7 @@ function mssqlBuildingCreateTest2() returns error? { } @test:Config { - groups: ["building", "mssql"], - enable: true + groups: ["building", "mssql"] } function mssqlBuildingCreateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -70,8 +67,7 @@ function mssqlBuildingCreateTestNegative() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingCreateTest], - enable: true + dependsOn: [mssqlBuildingCreateTest] } function mssqlBuildingReadOneTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -83,8 +79,7 @@ function mssqlBuildingReadOneTest() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingCreateTest], - enable: true + dependsOn: [mssqlBuildingCreateTest] } function mssqlBuildingReadOneTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -100,8 +95,7 @@ function mssqlBuildingReadOneTestNegative() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingCreateTest, mssqlBuildingCreateTest2], - enable: true + dependsOn: [mssqlBuildingCreateTest, mssqlBuildingCreateTest2] } function mssqlBuildingReadManyTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -116,8 +110,7 @@ function mssqlBuildingReadManyTest() returns error? { @test:Config { groups: ["building", "mssql", "dependent"], - dependsOn: [mssqlBuildingCreateTest, mssqlBuildingCreateTest2], - enable: true + dependsOn: [mssqlBuildingCreateTest, mssqlBuildingCreateTest2] } function mssqlBuildingReadManyDependentTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -136,8 +129,7 @@ function mssqlBuildingReadManyDependentTest() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest], - enable: true + dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest] } function mssqlBuildingUpdateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -158,8 +150,7 @@ function mssqlBuildingUpdateTest() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest], - enable: true + dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest] } function mssqlBuildingUpdateTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -180,8 +171,7 @@ function mssqlBuildingUpdateTestNegative1() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest], - enable: true + dependsOn: [mssqlBuildingReadOneTest, mssqlBuildingReadManyTest, mssqlBuildingReadManyDependentTest] } function mssqlBuildingUpdateTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -202,8 +192,7 @@ function mssqlBuildingUpdateTestNegative2() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingUpdateTest, mssqlBuildingUpdateTestNegative2], - enable: true + dependsOn: [mssqlBuildingUpdateTest, mssqlBuildingUpdateTestNegative2] } function mssqlBuildingDeleteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -221,8 +210,7 @@ function mssqlBuildingDeleteTest() returns error? { @test:Config { groups: ["building", "mssql"], - dependsOn: [mssqlBuildingDeleteTest], - enable: true + dependsOn: [mssqlBuildingDeleteTest] } function mssqlBuildingDeleteTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-composite-key-tests.bal b/ballerina/tests/mssql-composite-key-tests.bal index 21c4fe8..6aaf8cc 100644 --- a/ballerina/tests/mssql-composite-key-tests.bal +++ b/ballerina/tests/mssql-composite-key-tests.bal @@ -18,8 +18,7 @@ import ballerina/test; import ballerina/persist; @test:Config { - groups: ["composite-key", "mssql"], - enable: true + groups: ["composite-key", "mssql"] } function mssqlCompositeKeyCreateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -38,8 +37,7 @@ function mssqlCompositeKeyCreateTest() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest], - enable: true + dependsOn: [mssqlCompositeKeyCreateTest] } function mssqlCompositeKeyCreateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -56,8 +54,7 @@ function mssqlCompositeKeyCreateTestNegative() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest], - enable: true + dependsOn: [mssqlCompositeKeyCreateTest] } function mssqlCompositeKeyReadManyTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -72,8 +69,7 @@ function mssqlCompositeKeyReadManyTest() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest], - enable: true + dependsOn: [mssqlCompositeKeyCreateTest] } function mssqlCompositeKeyReadOneTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -84,8 +80,7 @@ function mssqlCompositeKeyReadOneTest() returns error? { @test:Config { groups: ["composite-key2"], - dependsOn: [mssqlCompositeKeyCreateTest], - enable: true + dependsOn: [mssqlCompositeKeyCreateTest] } function mssqlCompositeKeyReadOneTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -96,8 +91,7 @@ function mssqlCompositeKeyReadOneTest2() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest], - enable: true + dependsOn: [mssqlCompositeKeyCreateTest] } function mssqlCompositeKeyReadOneTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -114,8 +108,7 @@ function mssqlCompositeKeyReadOneTestNegative1() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest], - enable: true + dependsOn: [mssqlCompositeKeyCreateTest] } function mssqlCompositeKeyReadOneTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -132,8 +125,7 @@ function mssqlCompositeKeyReadOneTestNegative2() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest, mssqlCompositeKeyReadOneTest, mssqlCompositeKeyReadManyTest, mssqlCompositeKeyReadOneTest2], - enable: true + dependsOn: [mssqlCompositeKeyCreateTest, mssqlCompositeKeyReadOneTest, mssqlCompositeKeyReadManyTest, mssqlCompositeKeyReadOneTest2] } function mssqlCompositeKeyUpdateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -152,8 +144,7 @@ function mssqlCompositeKeyUpdateTest() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyCreateTest, mssqlCompositeKeyReadOneTest, mssqlCompositeKeyReadManyTest, mssqlCompositeKeyReadOneTest2], - enable: true + dependsOn: [mssqlCompositeKeyCreateTest, mssqlCompositeKeyReadOneTest, mssqlCompositeKeyReadManyTest, mssqlCompositeKeyReadOneTest2] } function mssqlCompositeKeyUpdateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -173,8 +164,7 @@ function mssqlCompositeKeyUpdateTestNegative() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyUpdateTest], - enable: true + dependsOn: [mssqlCompositeKeyUpdateTest] } function mssqlCompositeKeyDeleteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -190,8 +180,7 @@ function mssqlCompositeKeyDeleteTest() returns error? { @test:Config { groups: ["composite-key", "mssql"], - dependsOn: [mssqlCompositeKeyUpdateTest], - enable: true + dependsOn: [mssqlCompositeKeyUpdateTest] } function mssqlCompositeKeyDeleteTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-department-tests.bal b/ballerina/tests/mssql-department-tests.bal index 73180fe..55ab8ae 100644 --- a/ballerina/tests/mssql-department-tests.bal +++ b/ballerina/tests/mssql-department-tests.bal @@ -18,8 +18,7 @@ import ballerina/test; import ballerina/persist; @test:Config { - groups: ["department", "mssql"], - enable: true + groups: ["department", "mssql"] } function mssqlDepartmentCreateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -33,8 +32,7 @@ function mssqlDepartmentCreateTest() returns error? { } @test:Config { - groups: ["department", "mssql"], - enable: true + groups: ["department", "mssql"] } function mssqlDepartmentCreateTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -52,8 +50,7 @@ function mssqlDepartmentCreateTest2() returns error? { } @test:Config { - groups: ["department", "mssql"], - enable: true + groups: ["department", "mssql"] } function mssqlDepartmentCreateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -69,8 +66,7 @@ function mssqlDepartmentCreateTestNegative() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentCreateTest], - enable: true + dependsOn: [mssqlDepartmentCreateTest] } function mssqlDepartmentReadOneTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -82,8 +78,7 @@ function mssqlDepartmentReadOneTest() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentCreateTest], - enable: true + dependsOn: [mssqlDepartmentCreateTest] } function mssqlDepartmentReadOneTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -99,8 +94,7 @@ function mssqlDepartmentReadOneTestNegative() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentCreateTest, mssqlDepartmentCreateTest2], - enable: true + dependsOn: [mssqlDepartmentCreateTest, mssqlDepartmentCreateTest2] } function mssqlDepartmentReadManyTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -114,8 +108,7 @@ function mssqlDepartmentReadManyTest() returns error? { @test:Config { groups: ["department", "mssql", "dependent"], - dependsOn: [mssqlDepartmentCreateTest, mssqlDepartmentCreateTest2], - enable: true + dependsOn: [mssqlDepartmentCreateTest, mssqlDepartmentCreateTest2] } function mssqlDepartmentReadManyTestDependent() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -134,8 +127,7 @@ function mssqlDepartmentReadManyTestDependent() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent], - enable: true + dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent] } function mssqlDepartmentUpdateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -153,8 +145,7 @@ function mssqlDepartmentUpdateTest() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent], - enable: true + dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent] } function mssqlDepartmentUpdateTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -173,8 +164,7 @@ function mssqlDepartmentUpdateTestNegative1() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent], - enable: true + dependsOn: [mssqlDepartmentReadOneTest, mssqlDepartmentReadManyTest, mssqlDepartmentReadManyTestDependent] } function mssqlDepartmentUpdateTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -193,8 +183,7 @@ function mssqlDepartmentUpdateTestNegative2() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentUpdateTest, mssqlDepartmentUpdateTestNegative2], - enable: true + dependsOn: [mssqlDepartmentUpdateTest, mssqlDepartmentUpdateTestNegative2] } function mssqlDepartmentDeleteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -212,8 +201,7 @@ function mssqlDepartmentDeleteTest() returns error? { @test:Config { groups: ["department", "mssql"], - dependsOn: [mssqlDepartmentDeleteTest], - enable: true + dependsOn: [mssqlDepartmentDeleteTest] } function mssqlDepartmentDeleteTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-employee-tests.bal b/ballerina/tests/mssql-employee-tests.bal index dec9b19..20d401f 100644 --- a/ballerina/tests/mssql-employee-tests.bal +++ b/ballerina/tests/mssql-employee-tests.bal @@ -19,8 +19,7 @@ import ballerina/persist; @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlWorkspaceDeleteTestNegative, mssqlDepartmentDeleteTestNegative], - enable: true + dependsOn: [mssqlWorkspaceDeleteTestNegative, mssqlDepartmentDeleteTestNegative] } function mssqlEmployeeCreateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -35,8 +34,7 @@ function mssqlEmployeeCreateTest() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlWorkspaceDeleteTestNegative, mssqlDepartmentDeleteTestNegative], - enable: true + dependsOn: [mssqlWorkspaceDeleteTestNegative, mssqlDepartmentDeleteTestNegative] } function mssqlEmployeeCreateTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -54,8 +52,7 @@ function mssqlEmployeeCreateTest2() returns error? { } @test:Config { - groups: ["employee", "mssql"], - enable: true + groups: ["employee", "mssql"] } function mssqlEmployeeCreateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -71,8 +68,7 @@ function mssqlEmployeeCreateTestNegative() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeCreateTest], - enable: true + dependsOn: [mssqlEmployeeCreateTest] } function mssqlEmployeeReadOneTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -84,8 +80,7 @@ function mssqlEmployeeReadOneTest() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeCreateTest], - enable: true + dependsOn: [mssqlEmployeeCreateTest] } function mssqlEmployeeReadOneTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -101,8 +96,7 @@ function mssqlEmployeeReadOneTestNegative() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2], - enable: true + dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2] } function mssqlEmployeeReadManyTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -117,8 +111,7 @@ function mssqlEmployeeReadManyTest() returns error? { @test:Config { groups: ["dependent", "employee"], - dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2], - enable: true + dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2] } function mssqlEmployeeReadManyDependentTest1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -137,8 +130,7 @@ function mssqlEmployeeReadManyDependentTest1() returns error? { @test:Config { groups: ["dependent", "employee"], - dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2], - enable: true + dependsOn: [mssqlEmployeeCreateTest, mssqlEmployeeCreateTest2] } function mssqlEmployeeReadManyDependentTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -157,8 +149,7 @@ function mssqlEmployeeReadManyDependentTest2() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2], - enable: true + dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2] } function mssqlEmployeeUpdateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -178,8 +169,7 @@ function mssqlEmployeeUpdateTest() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2], - enable: true + dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2] } function mssqlEmployeeUpdateTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -198,8 +188,7 @@ function mssqlEmployeeUpdateTestNegative1() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2], - enable: true + dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2] } function mssqlEmployeeUpdateTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -218,8 +207,7 @@ function mssqlEmployeeUpdateTestNegative2() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2], - enable: true + dependsOn: [mssqlEmployeeReadOneTest, mssqlEmployeeReadManyTest, mssqlEmployeeReadManyDependentTest1, mssqlEmployeeReadManyDependentTest2] } function mssqlEmployeeUpdateTestNegative3() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -234,8 +222,7 @@ function mssqlEmployeeUpdateTestNegative3() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeUpdateTest, mssqlEmployeeUpdateTestNegative2, mssqlEmployeeUpdateTestNegative3], - enable: true + dependsOn: [mssqlEmployeeUpdateTest, mssqlEmployeeUpdateTestNegative2, mssqlEmployeeUpdateTestNegative3] } function mssqlEmployeeDeleteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -253,8 +240,7 @@ function mssqlEmployeeDeleteTest() returns error? { @test:Config { groups: ["employee", "mssql"], - dependsOn: [mssqlEmployeeDeleteTest], - enable: true + dependsOn: [mssqlEmployeeDeleteTest] } function mssqlEmployeeDeleteTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-id-fields-tests.bal b/ballerina/tests/mssql-id-fields-tests.bal index 2521fae..ad74afa 100644 --- a/ballerina/tests/mssql-id-fields-tests.bal +++ b/ballerina/tests/mssql-id-fields-tests.bal @@ -17,8 +17,7 @@ import ballerina/test; @test:Config { - groups: ["id-fields", "mssql"], - enable: true + groups: ["id-fields", "mssql"] } function mssqlIntIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -78,8 +77,7 @@ function mssqlIntIdFieldTest() returns error? { } @test:Config { - groups: ["id-fields", "mssql"], - enable: true + groups: ["id-fields", "mssql"] } function mssqlStringIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -139,8 +137,7 @@ function mssqlStringIdFieldTest() returns error? { } @test:Config { - groups: ["id-fields", "mssql"], - enable: true + groups: ["id-fields", "mssql"] } function mssqlFloatIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -198,8 +195,7 @@ function mssqlFloatIdFieldTest() returns error? { } @test:Config { - groups: ["id-fields", "mssql"], - enable: true + groups: ["id-fields", "mssql"] } function mssqlDecimalIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -259,8 +255,7 @@ function mssqlDecimalIdFieldTest() returns error? { } @test:Config { - groups: ["id-fields", "mssql"], - enable: true + groups: ["id-fields", "mssql"] } function mssqlBooleanIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -316,8 +311,7 @@ function mssqlBooleanIdFieldTest() returns error? { } @test:Config { - groups: ["id-fields", "mssql"], - enable: true + groups: ["id-fields", "mssql"] } function mssqlAllTypesIdFieldTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); @@ -389,8 +383,7 @@ function mssqlAllTypesIdFieldTest() returns error? { @test:Config { groups: ["id-fields", "mssql", "associations"], - dependsOn: [mssqlAllTypesIdFieldTest], - enable: true + dependsOn: [mssqlAllTypesIdFieldTest] } function mssqlCompositeAssociationsTest() returns error? { MSSQLTestEntitiesClient testEntitiesClient = check new (); diff --git a/ballerina/tests/mssql-native-tests.bal b/ballerina/tests/mssql-native-tests.bal index 89f4d27..fd6205d 100644 --- a/ballerina/tests/mssql-native-tests.bal +++ b/ballerina/tests/mssql-native-tests.bal @@ -19,8 +19,7 @@ import ballerina/persist; @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlEmployeeRelationsTest, mssqlWorkspaceRelationsTest, mssqlBuildingRelationsTest, mssqlDepartmentRelationsTest], - enable: true + dependsOn: [mssqlEmployeeRelationsTest, mssqlWorkspaceRelationsTest, mssqlBuildingRelationsTest, mssqlDepartmentRelationsTest] } function mssqlNativeExecuteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -70,8 +69,7 @@ function mssqlNativeExecuteTest() returns error? { @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlNativeExecuteTest], - enable: true + dependsOn: [mssqlNativeExecuteTest] } function mssqlNativeExecuteTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -91,8 +89,7 @@ function mssqlNativeExecuteTestNegative1() returns error? { @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlNativeExecuteTest], - enable: true + dependsOn: [mssqlNativeExecuteTest] } function mssqlNativeExecuteTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -112,8 +109,7 @@ function mssqlNativeExecuteTestNegative2() returns error? { @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlNativeExecuteTest], - enable: true + dependsOn: [mssqlNativeExecuteTest] } function mssqlNativeQueryTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -146,8 +142,7 @@ function mssqlNativeQueryTest() returns error? { @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlNativeExecuteTest], - enable: true + dependsOn: [mssqlNativeExecuteTest] } function mssqlNativeQueryTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -167,8 +162,7 @@ function mssqlNativeQueryTestNegative() returns error? { @test:Config { groups: ["native", "mssql"], - dependsOn: [mssqlNativeExecuteTest], - enable: true + dependsOn: [mssqlNativeExecuteTest] } function mssqlNativeQueryComplexTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -196,8 +190,7 @@ function mssqlNativeQueryComplexTest() returns error? { @test:Config { groups: ["transactions", "mssql", "native"], - dependsOn: [mssqlNativeExecuteTestNegative1, mssqlNativeQueryTest, mssqlNativeQueryTestNegative, mssqlNativeQueryComplexTest], - enable: true + dependsOn: [mssqlNativeExecuteTestNegative1, mssqlNativeQueryTest, mssqlNativeQueryTestNegative, mssqlNativeQueryComplexTest] } function mssqlNativeTransactionTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -242,8 +235,7 @@ function mssqlNativeTransactionTest() returns error? { @test:Config { groups: ["transactions", "mssql", "native"], - dependsOn: [mssqlNativeExecuteTestNegative1, mssqlNativeQueryTest, mssqlNativeQueryTestNegative, mssqlNativeQueryComplexTest], - enable: true + dependsOn: [mssqlNativeExecuteTestNegative1, mssqlNativeQueryTest, mssqlNativeQueryTestNegative, mssqlNativeQueryComplexTest] } function mssqlNativeTransactionTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -284,8 +276,7 @@ function mssqlNativeTransactionTest2() returns error? { @test:Config { groups: ["mssql", "native"], - dependsOn: [mssqlAllTypesDeleteTest], - enable: true + dependsOn: [mssqlAllTypesDeleteTest] } function mssqlNativeAllTypesTest() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-transaction-tests.bal b/ballerina/tests/mssql-transaction-tests.bal index 5737b5d..22ea5fd 100644 --- a/ballerina/tests/mssql-transaction-tests.bal +++ b/ballerina/tests/mssql-transaction-tests.bal @@ -18,8 +18,7 @@ import ballerina/test; import ballerina/persist; @test:Config { - groups: ["transactions", "mssql"], - enable: true + groups: ["transactions", "mssql"] } function mssqlTransactionTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -44,8 +43,7 @@ function mssqlTransactionTest() returns error? { } @test:Config { - groups: ["transactions", "mssql"], - enable: true + groups: ["transactions", "mssql"] } function mssqlTransactionTest2() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql-workspace-tests.bal b/ballerina/tests/mssql-workspace-tests.bal index 248aa38..7b4cc31 100644 --- a/ballerina/tests/mssql-workspace-tests.bal +++ b/ballerina/tests/mssql-workspace-tests.bal @@ -19,8 +19,7 @@ import ballerina/persist; @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlBuildingDeleteTestNegative], - enable: true + dependsOn: [mssqlBuildingDeleteTestNegative] } function mssqlWorkspaceCreateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -33,8 +32,7 @@ function mssqlWorkspaceCreateTest() returns error? { } @test:Config { - groups: ["workspace", "mssql"], - enable: true + groups: ["workspace", "mssql"] } function mssqlWorkspaceCreateTest2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -52,8 +50,7 @@ function mssqlWorkspaceCreateTest2() returns error? { } @test:Config { - groups: ["workspace", "mssql"], - enable: true + groups: ["workspace", "mssql"] } function mssqlWorkspaceCreateTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -69,8 +66,7 @@ function mssqlWorkspaceCreateTestNegative() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceCreateTest], - enable: true + dependsOn: [mssqlWorkspaceCreateTest] } function mssqlWorkspaceReadOneTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -82,8 +78,7 @@ function mssqlWorkspaceReadOneTest() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceCreateTest], - enable: true + dependsOn: [mssqlWorkspaceCreateTest] } function mssqlWorkspaceReadOneDependentTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -100,8 +95,7 @@ function mssqlWorkspaceReadOneDependentTest() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceCreateTest], - enable: true + dependsOn: [mssqlWorkspaceCreateTest] } function mssqlWorkspaceReadOneTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -117,8 +111,7 @@ function mssqlWorkspaceReadOneTestNegative() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceCreateTest, mssqlWorkspaceCreateTest2], - enable: true + dependsOn: [mssqlWorkspaceCreateTest, mssqlWorkspaceCreateTest2] } function mssqlWorkspaceReadManyTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -133,8 +126,7 @@ function mssqlWorkspaceReadManyTest() returns error? { @test:Config { groups: ["workspace", "mssql", "dependent"], - dependsOn: [mssqlWorkspaceCreateTest, mssqlWorkspaceCreateTest2], - enable: true + dependsOn: [mssqlWorkspaceCreateTest, mssqlWorkspaceCreateTest2] } function mssqlWorkspaceReadManyDependentTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -153,8 +145,7 @@ function mssqlWorkspaceReadManyDependentTest() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest], - enable: true + dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest] } function mssqlWorkspaceUpdateTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -172,8 +163,7 @@ function mssqlWorkspaceUpdateTest() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest], - enable: true + dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest] } function mssqlWorkspaceUpdateTestNegative1() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -192,8 +182,7 @@ function mssqlWorkspaceUpdateTestNegative1() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest], - enable: true + dependsOn: [mssqlWorkspaceReadOneTest, mssqlWorkspaceReadManyTest, mssqlWorkspaceReadManyDependentTest] } function mssqlWorkspaceUpdateTestNegative2() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -212,8 +201,7 @@ function mssqlWorkspaceUpdateTestNegative2() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceUpdateTest, mssqlWorkspaceUpdateTestNegative2], - enable: true + dependsOn: [mssqlWorkspaceUpdateTest, mssqlWorkspaceUpdateTestNegative2] } function mssqlWorkspaceDeleteTest() returns error? { MSSQLRainierClient rainierClient = check new (); @@ -231,8 +219,7 @@ function mssqlWorkspaceDeleteTest() returns error? { @test:Config { groups: ["workspace", "mssql"], - dependsOn: [mssqlWorkspaceDeleteTest], - enable: true + dependsOn: [mssqlWorkspaceDeleteTest] } function mssqlWorkspaceDeleteTestNegative() returns error? { MSSQLRainierClient rainierClient = check new (); diff --git a/ballerina/tests/mssql_hospital_tests.bal b/ballerina/tests/mssql_hospital_tests.bal index 0dd6ddc..9281d91 100644 --- a/ballerina/tests/mssql_hospital_tests.bal +++ b/ballerina/tests/mssql_hospital_tests.bal @@ -19,8 +19,7 @@ import ballerina/test; @test:Config{ - groups: ["annotation", "mssql"], - enable: true + groups: ["annotation", "mssql"] } function testCreatePatientMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -35,8 +34,7 @@ function testCreatePatientMsSql() returns error? { } @test:Config{ - groups: ["annotation", "mssql"], - enable: true + groups: ["annotation", "mssql"] } function testCreateDoctorMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -52,8 +50,7 @@ function testCreateDoctorMsSql() returns error? { @test:Config{ groups: ["annotation", "mssql"], - dependsOn: [testCreateDoctorMsSql], - enable: true + dependsOn: [testCreateDoctorMsSql] } function testCreateDoctorAlreadyExistsMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -72,8 +69,7 @@ function testCreateDoctorAlreadyExistsMsSql() returns error? { @test:Config{ groups: ["annotation", "mssql"], - dependsOn: [testCreatePatientMsSql, testCreateDoctorMsSql], - enable: true + dependsOn: [testCreatePatientMsSql, testCreateDoctorMsSql] } function testCreateAppointmentMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -90,8 +86,7 @@ function testCreateAppointmentMsSql() returns error? { @test:Config{ groups: ["annotation", "mssql"], - dependsOn: [testCreatePatientMsSql, testCreateDoctorMsSql, testCreateAppointmentMsSql], - enable: true + dependsOn: [testCreatePatientMsSql, testCreateDoctorMsSql, testCreateAppointmentMsSql] } function testCreateAppointmentAlreadyExistsMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -111,8 +106,7 @@ function testCreateAppointmentAlreadyExistsMsSql() returns error? { @test:Config{ groups: ["annotation", "mssql"], - dependsOn: [testCreateDoctorMsSql], - enable: true + dependsOn: [testCreateDoctorMsSql] } function testGetDoctorsMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -126,8 +120,7 @@ function testGetDoctorsMsSql() returns error? { @test:Config{ groups: ["annotation", "mssql"], - dependsOn: [testCreatePatientMsSql], - enable: true + dependsOn: [testCreatePatientMsSql] } function testGetPatientByIdMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -137,8 +130,7 @@ function testGetPatientByIdMsSql() returns error? { } @test:Config{ - groups: ["annotation", "mssql"], - enable: true + groups: ["annotation", "mssql"] } function testGetPatientNotFoundMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -150,8 +142,7 @@ function testGetPatientNotFoundMsSql() returns error? { @test:Config{ groups: ["annotation", "mssql"], - dependsOn: [testCreateAppointmentMsSql], - enable: true + dependsOn: [testCreateAppointmentMsSql] } function testGetAppointmentByDoctorMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -208,8 +199,7 @@ function testGetAppointmentByDoctorMsSql() returns error? { @test:Config{ groups: ["annotation", "mssql"], - dependsOn: [testCreateAppointmentMsSql], - enable: true + dependsOn: [testCreateAppointmentMsSql] } function testGetAppointmentByPatientMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -259,8 +249,7 @@ function testGetAppointmentByPatientMsSql() returns error? { @test:Config{ groups: ["annotation", "mssql"], - dependsOn: [testCreateAppointmentMsSql, testGetAppointmentByDoctorMsSql, testGetAppointmentByPatientMsSql], - enable: true + dependsOn: [testCreateAppointmentMsSql, testGetAppointmentByDoctorMsSql, testGetAppointmentByPatientMsSql] } function testPatchAppointmentMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -313,8 +302,7 @@ function testPatchAppointmentMsSql() returns error? { @test:Config{ groups: ["annotation", "mssql"], - dependsOn: [testCreateAppointmentMsSql, testGetAppointmentByDoctorMsSql, testGetAppointmentByPatientMsSql, testPatchAppointmentMsSql], - enable: true + dependsOn: [testCreateAppointmentMsSql, testGetAppointmentByDoctorMsSql, testGetAppointmentByPatientMsSql, testPatchAppointmentMsSql] } function testDeleteAppointmentByPatientIdMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); @@ -346,8 +334,7 @@ function testDeleteAppointmentByPatientIdMsSql() returns error? { @test:Config{ groups: ["annotation", "mssql"], - dependsOn: [testGetPatientByIdMsSql, testDeleteAppointmentByPatientIdMsSql], - enable: true + dependsOn: [testGetPatientByIdMsSql, testDeleteAppointmentByPatientIdMsSql] } function testDeletePatientMsSql() returns error? { MsSqlHospitalClient mssqlDbHospital = check new(); From ff1938fbdffe07650cd3b3613cce018ad4c4aba1 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Mon, 8 Jul 2024 15:16:01 +0530 Subject: [PATCH 23/23] Update license headers --- ballerina/tests/h2-all-types-tests.bal | 2 +- ballerina/tests/h2-associations-tests.bal | 2 +- ballerina/tests/h2-building-tests.bal | 2 +- ballerina/tests/h2-composite-key-tests.bal | 2 +- ballerina/tests/h2-department-tests.bal | 2 +- ballerina/tests/h2-employee-tests.bal | 2 +- ballerina/tests/h2-id-fields-tests.bal | 2 +- ballerina/tests/h2-native-tests.bal | 2 +- ballerina/tests/h2-transaction-tests.bal | 2 +- ballerina/tests/h2-workspace-tests.bal | 2 +- ballerina/tests/h2_rainier_generated_client.bal | 2 +- ballerina/tests/h2_test_entities_generated_client.bal | 2 +- ballerina/tests/persist/hospital.bal | 2 +- .../io/ballerina/stdlib/persist/sql/datastore/H2Processor.java | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ballerina/tests/h2-all-types-tests.bal b/ballerina/tests/h2-all-types-tests.bal index 56d62dc..78228a3 100644 --- a/ballerina/tests/h2-all-types-tests.bal +++ b/ballerina/tests/h2-all-types-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-associations-tests.bal b/ballerina/tests/h2-associations-tests.bal index 58ecdad..aeff6af 100644 --- a/ballerina/tests/h2-associations-tests.bal +++ b/ballerina/tests/h2-associations-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-building-tests.bal b/ballerina/tests/h2-building-tests.bal index 08413b8..e4360f6 100644 --- a/ballerina/tests/h2-building-tests.bal +++ b/ballerina/tests/h2-building-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-composite-key-tests.bal b/ballerina/tests/h2-composite-key-tests.bal index 0129dfa..d7d316e 100644 --- a/ballerina/tests/h2-composite-key-tests.bal +++ b/ballerina/tests/h2-composite-key-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-department-tests.bal b/ballerina/tests/h2-department-tests.bal index 3313ba7..7903f4a 100644 --- a/ballerina/tests/h2-department-tests.bal +++ b/ballerina/tests/h2-department-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-employee-tests.bal b/ballerina/tests/h2-employee-tests.bal index ac70dd5..3e7de65 100644 --- a/ballerina/tests/h2-employee-tests.bal +++ b/ballerina/tests/h2-employee-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-id-fields-tests.bal b/ballerina/tests/h2-id-fields-tests.bal index bb7ab64..6f4c5ea 100644 --- a/ballerina/tests/h2-id-fields-tests.bal +++ b/ballerina/tests/h2-id-fields-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-native-tests.bal b/ballerina/tests/h2-native-tests.bal index f89f251..b1391e3 100644 --- a/ballerina/tests/h2-native-tests.bal +++ b/ballerina/tests/h2-native-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-transaction-tests.bal b/ballerina/tests/h2-transaction-tests.bal index 2e92120..03a246e 100644 --- a/ballerina/tests/h2-transaction-tests.bal +++ b/ballerina/tests/h2-transaction-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2-workspace-tests.bal b/ballerina/tests/h2-workspace-tests.bal index 50ab569..70b8cc2 100644 --- a/ballerina/tests/h2-workspace-tests.bal +++ b/ballerina/tests/h2-workspace-tests.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2_rainier_generated_client.bal b/ballerina/tests/h2_rainier_generated_client.bal index c61ffed..d3203f5 100644 --- a/ballerina/tests/h2_rainier_generated_client.bal +++ b/ballerina/tests/h2_rainier_generated_client.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/h2_test_entities_generated_client.bal b/ballerina/tests/h2_test_entities_generated_client.bal index eed662f..d530b39 100644 --- a/ballerina/tests/h2_test_entities_generated_client.bal +++ b/ballerina/tests/h2_test_entities_generated_client.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/ballerina/tests/persist/hospital.bal b/ballerina/tests/persist/hospital.bal index 985aa3c..9d3ed0c 100644 --- a/ballerina/tests/persist/hospital.bal +++ b/ballerina/tests/persist/hospital.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/native/src/main/java/io/ballerina/stdlib/persist/sql/datastore/H2Processor.java b/native/src/main/java/io/ballerina/stdlib/persist/sql/datastore/H2Processor.java index 9ed2e23..1c65cfe 100644 --- a/native/src/main/java/io/ballerina/stdlib/persist/sql/datastore/H2Processor.java +++ b/native/src/main/java/io/ballerina/stdlib/persist/sql/datastore/H2Processor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except