Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mock client generation for persist clients #374

Merged
merged 19 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
259 changes: 125 additions & 134 deletions examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def ballerinaDist = "${project.buildDir}/ballerina-distribution"
def examples = ["medical-center", "rainier"]
def introspectionExamples = ["hospital", "hospital_unsupported"]
def redisDBExamples = ["social_media", "redis_cache"]
def mockExamples = ["hospital_mock"]

configurations {
balTools
Expand Down Expand Up @@ -142,6 +143,14 @@ task copyTestResources() {
}
}
}
copy {
mockExamples.each { example ->
into buildDir
into("generated-examples/${example}/") {
from "${example}"
}
}
}
}

}
Expand All @@ -157,9 +166,10 @@ task initDbExamples {
into("${project.projectDir}/build/generated-examples/${example}")
}
delete "${project.projectDir}/build/generated-examples/${example}/generated"
delete "${project.projectDir}/build/generated-examples/${example}/modules"
workingDir "${project.projectDir}/build/generated-examples/${example}"
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal persist generate --module=entities --datastore=mysql"
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal persist add --module=entities --datastore=mysql"
} else {
commandLine 'cmd', 'slmgr /dlv'
println('\n' + "Windows Instance detected")
Expand All @@ -174,71 +184,22 @@ task initDbExamples {
}
}

task initInMemoryExamples {
doLast {
examples.each { example ->
if (example != "gsheet_automation") {
try {
exec {
workingDir "${project.projectDir}/build/generated-examples/${example}"
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal persist generate --module=entities --datastore=inmemory"
} else {
commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat persist generate --module=entities --datastore=inmemory"
}
}
} catch (Exception e) {
println("Example '${example}' Generation failed: " + e.message)
throw e
}
}
}
}
}

// task initGSheetExamples {
// doLast {
// examples.each { example ->
// try {
// exec {
// copy {
// from(file("${project.projectDir}/build/generated-examples/${example}/resources/gsheet/files"))
// into("${project.projectDir}/build/generated-examples/${example}")
// }
// delete "${project.projectDir}/build/generated-examples/${example}/generated"
// workingDir "${project.projectDir}/build/generated-examples/${example}"
// if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
// commandLine 'sh', '-c', "${ballerinaDist}/bin/bal persist init --module=entities --datastore=googlesheets"
// } else {
// commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat persist init --module=entities --datastore=googlesheets"
// }
// }
// } catch (Exception e) {
// println("Example '${example}' Generation failed: " + e.message)
// throw e
// }
// }
// }
// }

task generateDbExamples {
doLast {
examples.each { example ->
if (example != "gsheet_automation") {
try {
exec {
workingDir "${project.projectDir}/build/generated-examples/${example}"
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal persist generate --module=entities --datastore=inmemory"
} else {
commandLine 'cmd', 'slmgr /dlv'
println('\n' + "Windows Instance detected")
}
try {
exec {
workingDir "${project.projectDir}/build/generated-examples/${example}"
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal build"
} else {
commandLine 'cmd', 'slmgr /dlv'
println('\n' + "Windows Instance detected")
}
} catch (Exception e) {
println("Example '${example}' Generation failed: " + e.message)
throw e
}
} catch (Exception e) {
println("Example '${example}' Generation failed: " + e.message)
throw e
}
}
}
Expand All @@ -247,20 +208,18 @@ task generateDbExamples {
task generateInMemoryExamples {
doLast {
examples.each { example ->
if (example != "gsheet_automation") {
try {
exec {
workingDir "${project.projectDir}/build/generated-examples/${example}"
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal persist generate --datastore=inmemory --module=entities"
} else {
commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat persist generate --datastore=inmemory --module=entities"
}
try {
exec {
workingDir "${project.projectDir}/build/generated-examples/${example}"
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal persist generate --datastore=inmemory --module=entities"
} else {
commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat persist generate --datastore=inmemory --module=entities"
}
} catch (Exception e) {
println("Example '${example}' Generation failed: " + e.message)
throw e
}
} catch (Exception e) {
println("Example '${example}' Generation failed: " + e.message)
throw e
}
}
}
Expand Down Expand Up @@ -306,29 +265,55 @@ task generateRedisDBExamples {
}
}

// task generateGSheetExamples {
// doLast {
// examples.each { example ->
// try {
// exec {
// workingDir "${project.projectDir}/build/generated-examples/${example}"
// if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
// commandLine 'sh', '-c', "${ballerinaDist}/bin/bal persist generate"
// } else {
// commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat persist generate"
// }
// copy {
// from(file("${project.projectDir}/build/generated-examples/${example}/resources/gsheet/persist_config"))
// into("${project.projectDir}/build/generated-examples/${example}/generated/entities")
// }
// }
// } catch (Exception e) {
// println("Example '${example}' Generation failed: " + e.message)
// throw e
// }
// }
// }
// }
task generateDBMockExamples {
doLast {
mockExamples.each { example ->
try {
exec {
copy {
from(file("${project.projectDir}/build/generated-examples/${example}/resources/mysql"))
into("${project.projectDir}/build/generated-examples/${example}/tests")
}
delete "${project.projectDir}/build/generated-examples/${example}/modules"
workingDir "${project.projectDir}/build/generated-examples/${example}"
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal persist generate --datastore=mysql --module=entities --test-datastore=h2"
} else {
commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat persist generate --datastore=mysql --module=entities --test-datastore=h2"
}
}
} catch (Exception e) {
println("Example '${example}' Generation failed: " + e.message)
throw e
}
}
}
}

task generateRedisMockExamples {
doLast {
mockExamples.each { example ->
try {
exec {
copy {
from(file("${project.projectDir}/build/generated-examples/${example}/resources/redis"))
into("${project.projectDir}/build/generated-examples/${example}/tests")
}
delete "${project.projectDir}/build/generated-examples/${example}/modules"
workingDir "${project.projectDir}/build/generated-examples/${example}"
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal persist generate --datastore=redis --module=entities --test-datastore=inmemory"
} else {
commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat persist generate --datastore=redis --module=entities --test-datastore=inmemory"
}
}
} catch (Exception e) {
println("Example '${example}' Generation failed: " + e.message)
throw e
}
}
}
}

def checkTestDockerContainerStatus(dockerName) {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
Expand Down Expand Up @@ -565,53 +550,60 @@ task testRedisDBExamples {
}
}

task automateGSheetTable {
doLast {
try {
exec {
workingDir "${project.projectDir}/gsheet_automation"
task testDBMockExamples {
doLast {
mockExamples.each { example ->
try {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal run --offline"
exec {
workingDir "${project.projectDir}/build/generated-examples/${example}"
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal test"
}
} else {
commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat run --offline"
exec {
workingDir "${project.projectDir}/build/generated-examples/${example}"
commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat test"
}
}
} catch (Exception e) {
println("Example '${example}' Tests failed: " + e.message)
throw e
}
} catch (Exception e) {
println("Example '${example}' test failed: " + e.message)
throw e
}
}
}

// task testGSheetExamples {
// doLast {
// examples.each { example ->
// try {
// exec {
// new File("${project.projectDir}/build/generated-examples/${example}/Config.toml").delete()
// workingDir "${project.projectDir}/build/generated-examples/${example}"
// if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
// commandLine 'sh', '-c', "${ballerinaDist}/bin/bal run --offline"
// } else {
// commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat run --offline"
// }
// }
// } catch (Exception e) {
// println("Example '${example}' test failed: " + e.message)
// throw e
// }
// }
// }
// }
task testRedisMockExamples {
doLast {
mockExamples.each { example ->
try {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
exec {
workingDir "${project.projectDir}/build/generated-examples/${example}"
commandLine 'sh', '-c', "${ballerinaDist}/bin/bal test"
}
} else {
exec {
workingDir "${project.projectDir}/build/generated-examples/${example}"
commandLine 'cmd', '/c', "${ballerinaDist}/bin/bal.bat test"
}
}
} catch (Exception e) {
println("Example '${example}' Tests failed: " + e.message)
throw e
}
}
}
}

copyPersistTool.dependsOn ":persist-cli-tests:build"
copyPersistTool.dependsOn ":persist-cli:build"
copyTestResources.dependsOn copyPersistTool

initInMemoryExamples.dependsOn copyTestResources
generateIntrospectionExamples.dependsOn copyTestResources
generateRedisDBExamples.dependsOn copyTestResources
generateInMemoryExamples.dependsOn initInMemoryExamples
generateInMemoryExamples.dependsOn copyTestResources
generateDBMockExamples.dependsOn copyTestResources
testInMemoryExamples.dependsOn generateInMemoryExamples

initDbExamples.dependsOn testInMemoryExamples
Expand All @@ -620,16 +612,15 @@ pushExamples.dependsOn generateDbExamples
testDbExamples.dependsOn pushExamples
testIntrospectionExamples.dependsOn generateIntrospectionExamples
testRedisDBExamples.dependsOn generateRedisDBExamples

// initGSheetExamples.dependsOn testDbExamples
// generateGSheetExamples.dependsOn initGSheetExamples
// automateGSheetTable.dependsOn generateGSheetExamples
// testGSheetExamples.dependsOn automateGSheetTable
testDBMockExamples.dependsOn generateDBMockExamples
generateRedisMockExamples.dependsOn testDBMockExamples
testRedisMockExamples.dependsOn generateRedisMockExamples

build.dependsOn testInMemoryExamples
build.dependsOn testDbExamples
build.dependsOn testIntrospectionExamples
build.dependsOn testRedisDBExamples
//build.dependsOn testGSheetExamples
build.dependsOn testDBMockExamples
build.dependsOn testRedisMockExamples
build.finalizedBy stopTestDockerContainer
build.finalizedBy stopTestRedisContainer
16 changes: 16 additions & 0 deletions examples/hospital_mock/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
org = "wso2"
name = "Demo"
version = "0.1.0"
distribution = "2201.8.4"

[build-options]
observabilityIncluded = true

[[platform.java17.repository]]
id="wso2-nexus"
url = "https://maven.wso2.org/nexus/content/groups/public/"

[[platform.java17.repository]]
id="wso2-nexus-snapshot"
url = "https://maven.wso2.org/nexus/content/repositories/snapshots/"
Loading
Loading