Skip to content

Commit

Permalink
add schema version to JUnit5 test names (#899)
Browse files Browse the repository at this point in the history
this will help distinguish which schema version is being run given
TeamCity is running against a specific version as well as the latest.
  • Loading branch information
adamkorynta authored Oct 4, 2024
1 parent 43f07af commit 2ca9755
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cwms-data-api/src/test/java/cwms/cda/api/DataApiTestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import cwms.cda.data.dto.LocationCategory;
import cwms.cda.data.dto.LocationGroup;
import fixtures.CwmsDataApiSetupCallback;
import fixtures.IntegrationTestNameGenerator;
import fixtures.TestAccounts;
import fixtures.users.MockCwmsUserPrincipalImpl;
import java.io.File;
Expand Down Expand Up @@ -64,13 +65,15 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ExtendWith;
import usace.cwms.db.jooq.codegen.packages.CWMS_ENV_PACKAGE;
/**
* Helper class to manage cycling tests multiple times against a database.
* NOTE: Not thread safe, do not run parallel tests. That may be future work though.
*/
@DisplayNameGeneration(IntegrationTestNameGenerator.class)
@Tag("integration")
@ExtendWith(CwmsDataApiSetupCallback.class)
public class DataApiTestIT {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void testRename() throws Exception {
Turbine retrievedTurbine = turbineDao.retrieveTurbine(newId, office);
assertEquals(newId, retrievedTurbine.getLocation().getName());
turbineDao.deleteTurbine(newId, office, DeleteRule.DELETE_ALL);
});
}, CwmsDataApiSetupCallback.getWebUser());
}

@Test
Expand Down Expand Up @@ -241,8 +241,7 @@ void testTurbineChangesRoundTrip() throws Exception {
turbineDao.deleteTurbine(TURBINE_LOC1.getName(), TURBINE_LOC1.getOfficeId(), DeleteRule.DELETE_ALL);
turbineDao.deleteTurbine(TURBINE_LOC2.getName(), TURBINE_LOC2.getOfficeId(), DeleteRule.DELETE_ALL);
turbineDao.deleteTurbine(TURBINE_LOC3.getName(), TURBINE_LOC3.getOfficeId(), DeleteRule.DELETE_ALL);
});

}, CwmsDataApiSetupCallback.getWebUser());
}

private static Location buildProjectLocation(String projectId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CwmsDataApiSetupCallback implements BeforeAllCallback,AfterAllCallb

private static final String ORACLE_IMAGE = System.getProperty("CDA.oracle.database.image",System.getProperty("RADAR.oracle.database.image", CwmsDatabaseContainer.ORACLE_19C));
private static final String ORACLE_VOLUME = System.getProperty("CDA.oracle.database.volume",System.getProperty("RADAR.oracle.database.volume", "cwmsdb_data_api_volume"));
private static final String CWMS_DB_IMAGE = System.getProperty("CDA.cwms.database.image",System.getProperty("RADAR.cwms.database.image", "registry.hecdev.net/cwms/schema_installer:99.99.99.2-CDA_STAGING"));
static final String CWMS_DB_IMAGE = System.getProperty("CDA.cwms.database.image",System.getProperty("RADAR.cwms.database.image", "registry.hecdev.net/cwms/schema_installer:99.99.99.2-CDA_STAGING"));


private static String webUser = null;
Expand Down Expand Up @@ -91,7 +91,7 @@ public void beforeAll(ExtensionContext context) throws Exception {
logger.atInfo().log("Tomcat Listing on " + cdaInstance.getPort());
RestAssured.baseURI=CwmsDataApiSetupCallback.httpUrl();
RestAssured.port = CwmsDataApiSetupCallback.httpPort();
RestAssured.basePath = "/cwms-data";
RestAssured.basePath = System.getProperty("warContext");
// we only use doubles
RestAssured.config()
.jsonConfig(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* MIT License
*
* Copyright (c) 2024 Hydrologic Engineering Center
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package fixtures;

import java.lang.reflect.Method;
import org.junit.jupiter.api.DisplayNameGenerator;

public final class IntegrationTestNameGenerator implements DisplayNameGenerator {
private static String schemaVersion;

static {
// Fetch the schema version from a system property
String[] split = CwmsDataApiSetupCallback.CWMS_DB_IMAGE.split(":");
schemaVersion = split[split.length - 1];
}

@Override
public String generateDisplayNameForClass(Class<?> testClass) {
return testClass.getSimpleName() + " (schema: " + schemaVersion + ")";
}

@Override
public String generateDisplayNameForNestedClass(Class<?> nestedClass) {
return nestedClass.getSimpleName() + " (schema: " + schemaVersion + ")";
}

@Override
public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) {
return testClass.getSimpleName() + "." + testMethod.getName() + " (schema: " + schemaVersion + ")";
}
}

0 comments on commit 2ca9755

Please sign in to comment.