Skip to content

Commit

Permalink
Feature/cwms db implementation tests (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkorynta authored Dec 20, 2024
1 parent f108fe7 commit 3b1da8a
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 98 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ jobs:
dependency-graph: generate-and-submit
- name: Build
run: ./gradlew build
- name: Integration Tests
run: ./gradlew integrationTest --stacktrace --info
# Disabled for now. Need test fixture updated to install the CCP schema
# - name: Integration Tests CWMS
# run: ./gradlew integrationTestCWMS --stacktrace --info
- name: Integration Tests OpenTSDB
run: ./gradlew integrationTestOpenTSDB --stacktrace --info
- name: Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rest-assured = "5.5.0"
hamcrest = "3.0"
tomcat = "9.0.91"
testcontainers = "1.18.1"
hec-testcontainers-cwms = "1.0.7"
hec-testcontainers-cwms = "2.0.0"
commons-io = "2.11.0"
derby = "10.14.2.0"
webcompere = "2.0.2"
Expand Down
56 changes: 49 additions & 7 deletions opendcs-rest-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
sonarqube {
properties {
property 'sonar.exclusions', 'src/main/resources/swaggerui/**'
property 'sonar.coverage.jacoco.xmlReportPaths', "${layout.buildDirectory.get().asFile.toString()}/reports/jacoco/test/jacocoTestReport.xml,${layout.buildDirectory.get().asFile.toString()}/reports/jacoco/integrationTestReport/integrationTestReport.xml"
property 'sonar.coverage.jacoco.xmlReportPaths', "${layout.buildDirectory.get().asFile.toString()}/reports/jacoco/test/jacocoTestReport.xml," +
"${layout.buildDirectory.get().asFile.toString()}/reports/jacoco/integrationTestReportCWMS/integrationTestReportCWMS.xml," +
"${layout.buildDirectory.get().asFile.toString()}/reports/jacoco/integrationTestReportOpenTSDB/integrationTestReportOpenTSDB.xml"
}
}
}
Expand All @@ -148,10 +150,11 @@ tasks.register('generateConfig', Copy) {
outputs.dir layout.buildDirectory.file("tomcat/conf")
}

tasks.register('integrationTest', Test) {
tasks.register('integrationTestOpenTSDB', Test) {
group "verification"
useJUnitPlatform {
includeTags "integration"
includeTags "integration-opentsdb-only"
}
doFirst {
classpath = classpath.filter {
Expand All @@ -166,10 +169,36 @@ tasks.register('integrationTest', Test) {
jvmArgs += "-Djava.util.logging.config.file=$projectDir/test/resources/logging.properties"
jvmArgs += "-Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource"
jvmArgs += "-Dcatalina.base=${layout.buildDirectory.file("tomcat")}"
jvmArgs += "-Dopendcs.test.integration.CWMS-Oracle.disabled=true"
jvmArgs += "-Dopendcs.test.integration.db=OpenDCS-Postgres"
def outputDir = downloadAndUnzipInstaller.outputs.files.singleFile
systemProperties.put("DCSTOOL_HOME", outputDir)
finalizedBy integrationTestReport
finalizedBy integrationTestReportOpenTSDB
}

tasks.register('integrationTestCWMS', Test) {
group "verification"
useJUnitPlatform {
includeTags "integration"
includeTags "integration-cwms-only"
}
doFirst {
classpath = classpath.filter {
!it.name.endsWith('opendcs-7.0.13.jar')
}
}
shouldRunAfter test
dependsOn war
dependsOn generateConfig
dependsOn downloadAndUnzipInstaller
jvmArgs += "-DwarContext=/opendcs-rest-api"
jvmArgs += "-Djava.util.logging.config.file=$projectDir/test/resources/logging.properties"
jvmArgs += "-Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource"
jvmArgs += "-Dcatalina.base=${layout.buildDirectory.file("tomcat")}"
jvmArgs += "-Dopendcs.test.integration.db=CWMS-Oracle"
jvmArgs += "-Dopendcs.cwms.oracle.image=registry-public.hecdev.net/cwms/database-ready-ora-23.5:24.12.04-RC3"
def outputDir = downloadAndUnzipInstaller.outputs.files.singleFile
systemProperties.put("DCSTOOL_HOME", outputDir)
finalizedBy integrationTestReportCWMS
}


Expand Down Expand Up @@ -200,13 +229,26 @@ task downloadAndUnzipInstaller {
test {
useJUnitPlatform {
excludeTags "integration"
excludeTags "integration-opentsdb-only"
excludeTags "integration-cwms-only"
}
}

tasks.register('integrationTestReportCWMS', JacocoReport) {
group = "verification"
dependsOn tasks.named('integrationTestCWMS')
executionData = files(layout.buildDirectory.dir("jacoco").get().file("integrationTestCWMS.exec"))
sourceDirectories.setFrom(files("src/main/java"))
classDirectories.setFrom(files(layout.buildDirectory.dir("classes/java/main").get().getAsFile()))
reports {
xml.required.set(true)
}
}

tasks.register('integrationTestReport', JacocoReport) {
tasks.register('integrationTestReportOpenTSDB', JacocoReport) {
group = "verification"
dependsOn tasks.named('integrationTest')
executionData = files(layout.buildDirectory.dir("jacoco").get().file("integrationTest.exec"))
dependsOn tasks.named('integrationTestOpenTSDB')
executionData = files(layout.buildDirectory.dir("jacoco").get().file("integrationTestOpenTSDB.exec"))
sourceDirectories.setFrom(files("src/main/java"))
classDirectories.setFrom(files(layout.buildDirectory.dir("classes/java/main").get().getAsFile()))
reports {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ final OpenDcsDatabase createDb()
{
throw new IllegalStateException("Error connecting to the database via JNDI", ex);
}
// throw new IllegalStateException("Error connecting to the database via JNDI", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean supportsTestTemplate(ExtensionContext context)
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context)
{
return Arrays.stream(DbType.values())
.filter(d -> !Boolean.getBoolean("opendcs.test.integration." + d + ".disabled"))
.filter(d -> System.getProperty("opendcs.test.integration.db").equals(d.toString()))
.map(DatabaseInvocationContext::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ private TomcatServer startTomcat(String warContext) throws Exception
SystemProperties properties = new SystemProperties();
config.start(exit, environment, properties);
environment.getVariables().forEach(System::setProperty);
if(dbType == DbType.CWMS)
{
System.setProperty("DB_DRIVER_CLASS", "oracle.jdbc.driver.OracleDriver");
}
else
{
System.setProperty("DB_DRIVER_CLASS", "org.postgresql.Driver");
}
TomcatServer tomcat = new TomcatServer("build/tomcat", 0, warContext);
tomcat.start();
RestAssured.baseURI = "http://localhost";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

@Tag("integration")
@Tag("integration-opentsdb-only")
@ExtendWith(DatabaseContextProvider.class)
final class BasicAuthIT
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
username="${DB_USERNAME}"
password="${DB_PASSWORD}"
driverClassName="org.postgresql.Driver"
driverClassName="${DB_DRIVER_CLASS}"
url="${DB_URL}"
validationQuery="select 1"
maxActive="10"
Expand Down

0 comments on commit 3b1da8a

Please sign in to comment.