Skip to content

Commit

Permalink
Add check to skip project-api tests if Asgadeo dev is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
Dilhasha committed Jun 27, 2023
1 parent 7be6b18 commit 742f353
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencyJREVersion=jdk-11.0.18+10-jre
specVersion=2022R4
slf4jVersion=1.7.30
balstdlibBranch=master
devIdpUrl=https://dev.api.asgardeo.io/oauth2/token/.well-known/openid-configuration

# Stdlib Level 01
stdlibConstraintVersion=1.2.0
Expand Down
44 changes: 40 additions & 4 deletions project-api-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
~ */

apply from: "$rootDir/gradle/javaProject.gradle"

description = 'Ballerina - Central Tests'
description = 'Ballerina - Central Tests'

configurations {
jBallerinaDistribution
Expand Down Expand Up @@ -48,7 +48,6 @@ task centralTests {
dependsOn configurations.jBallerinaDistribution
dependsOn configurations.ballerinaDistribution
dependsOn configurations.ballerinaLinuxDistribution
dependsOn configurations.ballerinaLinuxDistribution
dependsOn configurations.ballerinaWindowsDistribution
test {
systemProperty "distributions.dir", "$buildDir/../../ballerina/build/distributions"
Expand All @@ -69,4 +68,41 @@ task centralTests {
}
}

test.dependsOn centralTests

task checkURL {
doLast {
try {
URL url = new URL("${devIdpUrl}")
HttpURLConnection connection = (HttpURLConnection) url.openConnection()
connection.setRequestMethod("GET")
connection.connect()

int code = connection.getResponseCode()
if (code == 200) {
logger.lifecycle("Connection to ${devIdpUrl} is successful. Running tests...")
ext.isURLAvailable = true
} else {
logger.lifecycle("Connection to ${devIdpUrl} is not successful. Skipping tests...")
logger.lifecycle("-----------------------------------------")
logger.lifecycle(" WARNING: Skipping the project api tests")
logger.lifecycle("-----------------------------------------")
ext.isURLAvailable = false
}
} catch(Exception ex) {
logger.lifecycle("Connection to ${devIdpUrl} is not successful. Exception while connecting to " +
"${devIdpUrl}. Skipping tests...")
logger.lifecycle("-----------------------------------------")
logger.lifecycle(" WARNING: Skipping the project api tests")
logger.lifecycle("-----------------------------------------")
ext.isURLAvailable = false
}
}
}

test {
dependsOn checkURL
onlyIf {
checkURL.isURLAvailable
}
dependsOn centralTests
}

0 comments on commit 742f353

Please sign in to comment.