Skip to content

Commit

Permalink
Updated tests with parser existence verification, diagnosing TC build…
Browse files Browse the repository at this point in the history
… errors
  • Loading branch information
zack-rma committed Oct 28, 2024
1 parent 284a6b2 commit 47807ec
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public void tearDown() throws Exception {

@Test
void test_create_retrieve_TimeSeriesProfile() {

// Create a new TimeSeriesProfile
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -167,7 +166,6 @@ void test_store_retrieve_with_ref_TS() throws Exception {
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED))
;

// Retrieve the TimeSeriesProfile
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -212,7 +210,6 @@ void test_get_all_TimeSeriesProfilePaginated() {
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED))
;

// Create a new TimeSeriesProfile
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -349,7 +346,6 @@ void test_get_all_TimeSeriesProfilePaginated_minimum() {

@Test
void test_get_all_TimeSeriesProfile() {

// Create a new TimeSeriesProfile
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -496,5 +492,4 @@ private void cleanupTS(String locationId, String keyParameter) throws Exception
LOGGER.log(Level.CONFIG, "Unable to cleanup TS Profile - not found", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static cwms.cda.security.KeyAccessManager.AUTH_HEADER;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;

import cwms.cda.api.errors.NotFoundException;
import cwms.cda.data.dao.StoreRule;
Expand All @@ -40,12 +40,14 @@
import cwms.cda.data.dto.CwmsId;
import cwms.cda.data.dto.timeseriesprofile.TimeSeriesProfile;
import cwms.cda.data.dto.timeseriesprofile.TimeSeriesProfileInstance;
import cwms.cda.data.dto.timeseriesprofile.TimeSeriesProfileParser;
import cwms.cda.data.dto.timeseriesprofile.TimeSeriesProfileParserColumnar;
import cwms.cda.data.dto.timeseriesprofile.TimeSeriesProfileParserIndexed;
import cwms.cda.formatters.Formats;
import fixtures.CwmsDataApiSetupCallback;
import fixtures.TestAccounts;
import io.restassured.filter.log.LogDetail;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
Expand All @@ -60,6 +62,7 @@
import org.apache.commons.io.IOUtils;
import org.jooq.DSLContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -105,6 +108,14 @@ final class TimeSeriesProfileInstanceControllerIT extends DataApiTestIT {
private String tspData;
private String tspData2;
private final String units = "m,F";
private static final String LOCATION_1_NAME = "Beaverdam Ck Dam";
private static final String LOCATION_2_NAME = "Sacramento Dam";

@BeforeAll
public static void beforeAll() throws Exception {
createLocation(LOCATION_1_NAME, true, OFFICE_ID, "SITE");
createLocation(LOCATION_2_NAME, true, OFFICE_ID, "SITE");
}

@BeforeEach
public void setup() throws Exception {
Expand Down Expand Up @@ -146,8 +157,6 @@ public void setup() throws Exception {
.withFirstDate(tspInstance.getFirstDate())
.withLastDate(tspInstance.getLastDate())
.build();
createLocation(tsProfile.getLocationId().getName(), true, OFFICE_ID, "SITE");
createLocation(tsProfile2.getLocationId().getName(), true, OFFICE_ID, "SITE");
CwmsDatabaseContainer<?> db = CwmsDataApiSetupCallback.getDatabaseLink();
db.connection(c -> {
DSLContext dsl = dslContext(c, OFFICE_ID);
Expand Down Expand Up @@ -205,6 +214,8 @@ void test_create_retrieve_TimeSeriesProfileInstance_Columnar() throws Exception

storeParser(null, tspParserColumnar);

assertParserInDb(tspParserColumnar);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -265,6 +276,8 @@ void test_create_retrieve_TimeSeriesProfileInstance_Columnar() throws Exception
void store_retrieve_instance_with_ref_TS() throws Exception {
storeParser(tspParserIndexed2, null);

assertParserInDb(tspParserIndexed2);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -328,6 +341,8 @@ void test_create_retrieve_TimeSeriesProfileInstance_Indexed() throws Exception {

storeParser(tspParserIndexed, null);

assertParserInDb(tspParserIndexed);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -390,6 +405,8 @@ void test_create_retrieve_paged_TimeSeriesProfileInstance_Indexed() throws Excep

storeParser(tspParserIndexed, null);

assertParserInDb(tspParserIndexed);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -498,6 +515,8 @@ void test_create_retrieve_paged_TimeSeriesProfileInstance_Columnar() throws Exce

storeParser(null, tspParserColumnar);

assertParserInDb(tspParserColumnar);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -600,6 +619,8 @@ void test_create_retrieve_paged_TimeSeriesProfileInstance_Columnar() throws Exce
void test_retrieve_TimeSeriesProfileInstance_Columnar_maxVersion() throws Exception {
storeParser(null, tspParserColumnar);

assertParserInDb(tspParserColumnar);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -788,6 +809,8 @@ void test_retrieve_TimeSeriesProfileInstance_Columnar_maxVersion() throws Except
void test_previous_next_TimeSeriesProfileInstance_Indexed() throws Exception {
storeParser(tspParserIndexed, null);

assertParserInDb(tspParserIndexed);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -926,6 +949,9 @@ void test_previous_next_TimeSeriesProfileInstance_Indexed() throws Exception {
void test_delete_TimeSeriesProfileInstance_Columnar() throws Exception {

storeParser(null, tspParserColumnar);

assertParserInDb(tspParserColumnar);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -1003,6 +1029,8 @@ void test_delete_TimeSeriesProfileInstance_Indexed() throws Exception {

storeParser(tspParserIndexed, null);

assertParserInDb(tspParserIndexed);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -1103,6 +1131,8 @@ void test_delete_nonExistent_TimeSeriesProfileInstance() {
void test_retrieve_all_TimeSeriesProfileInstance_Columnar() throws Exception {
storeParser(null, tspParserColumnar);

assertParserInDb(tspParserColumnar);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -1176,6 +1206,8 @@ void test_retrieve_all_TimeSeriesProfileInstance_Columnar() throws Exception {
void test_retrieve_all_TimeSeriesProfileInstance_Indexed() throws Exception {
storeParser(tspParserIndexed, null);

assertParserInDb(tspParserIndexed);

// Create instance
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -1286,6 +1318,22 @@ private void storeParser(TimeSeriesProfileParserIndexed parserI, TimeSeriesProfi
} else {
dao.storeTimeSeriesProfileParser(parserC, false);
}
try {
c.commit();
} catch (SQLException e) {
LOGGER.log(Level.CONFIG, "Failed to commit transaction", e);
}
});
}

private void assertParserInDb(TimeSeriesProfileParser parser) throws Exception {
CwmsDatabaseContainer<?> db = CwmsDataApiSetupCallback.getDatabaseLink();
db.connection(c -> {
DSLContext dsl = dslContext(c, OFFICE_ID);
TimeSeriesProfileParserDao dao = new TimeSeriesProfileParserDao(dsl);
TimeSeriesProfileParser dbParser = dao.retrieveTimeSeriesProfileParser(parser.getLocationId().getName(),
parser.getKeyParameter(), OFFICE_ID);
assertNotNull(dbParser);
}, CwmsDataApiSetupCallback.getWebUser());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import cwms.cda.data.dao.timeseriesprofile.TimeSeriesProfileParserDao;
import cwms.cda.data.dto.CwmsId;
import cwms.cda.data.dto.timeseriesprofile.TimeSeriesProfile;
import cwms.cda.data.dto.timeseriesprofile.TimeSeriesProfileParser;
import cwms.cda.data.dto.timeseriesprofile.TimeSeriesProfileParserColumnar;
import cwms.cda.data.dto.timeseriesprofile.TimeSeriesProfileParserIndexed;
import cwms.cda.formatters.ContentType;
Expand Down Expand Up @@ -122,7 +123,7 @@ public void tearDown() throws Exception {
}

@Test
void test_create_retrieve_TimeSeriesProfileParser_Indexed() {
void test_create_retrieve_TimeSeriesProfileParser_Indexed() throws Exception {
// Create a Time Series Profile Parser
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand All @@ -141,6 +142,8 @@ void test_create_retrieve_TimeSeriesProfileParser_Indexed() {
.statusCode(is(HttpServletResponse.SC_CREATED))
;

assertParserInDb(tspParserIndexed);

// Retrieve the Time Series Profile Parser
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -168,7 +171,7 @@ void test_create_retrieve_TimeSeriesProfileParser_Indexed() {
}

@Test
void test_create_retrieve_TimeSeriesProfileParser_Columnar() {
void test_create_retrieve_TimeSeriesProfileParser_Columnar() throws Exception {
// Create a Time Series Profile Parser
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand All @@ -187,6 +190,8 @@ void test_create_retrieve_TimeSeriesProfileParser_Columnar() {
.statusCode(is(HttpServletResponse.SC_CREATED))
;

assertParserInDb(tspParserColumnar);

// Retrieve the Time Series Profile Parser
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand All @@ -212,7 +217,7 @@ void test_create_retrieve_TimeSeriesProfileParser_Columnar() {
}

@Test
void test_delete_TimeSeriesProfileParser() {
void test_delete_TimeSeriesProfileParser() throws Exception {
// Create a Time Series Profile Parser
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand All @@ -231,6 +236,8 @@ void test_delete_TimeSeriesProfileParser() {
.statusCode(is(HttpServletResponse.SC_CREATED))
;

assertParserInDb(tspParserIndexed);

// Delete the Time Series Profile Parser
given()
.log().ifValidationFails(LogDetail.ALL, true)
Expand Down Expand Up @@ -321,6 +328,8 @@ void test_get_all_TimeSeriesProfileParser() throws Exception {
.statusCode(is(HttpServletResponse.SC_CREATED))
;

assertParserInDb(tspIndex);

given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV1)
Expand Down Expand Up @@ -411,4 +420,15 @@ private void cleanupTS(String locationId, String keyParameter) throws Exception
LOGGER.log(Level.CONFIG, "TS Cleanup failed", e);
}
}

private void assertParserInDb(TimeSeriesProfileParser parser) throws Exception {
CwmsDatabaseContainer<?> db = CwmsDataApiSetupCallback.getDatabaseLink();
db.connection(c -> {
DSLContext dsl = dslContext(c, OFFICE_ID);
TimeSeriesProfileParserDao dao = new TimeSeriesProfileParserDao(dsl);
TimeSeriesProfileParser dbParser = dao.retrieveTimeSeriesProfileParser(parser.getLocationId().getName(),
parser.getKeyParameter(), OFFICE_ID);
assertNotNull(dbParser);
}, CwmsDataApiSetupCallback.getWebUser());
}
}

0 comments on commit 47807ec

Please sign in to comment.