Skip to content

Commit

Permalink
bug fixes from integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkorynta committed Apr 18, 2024
1 parent 17706b3 commit 8c14034
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public void create(@NotNull Context ctx) {
+ "owning office of the forecast spec whose data is to be deleted."),
@OpenApiParam(name = DESIGNATOR, required = true, description = "Specifies the "
+ "designator of the forecast spec whose data is to be deleted."),
@OpenApiParam(name = METHOD, description = "Specifies the delete method used.",
@OpenApiParam(name = METHOD, description = "Specifies the delete method used. " +
"Defaults to \"DELETE_KEY\"",
type = JooqDao.DeleteMethod.class)
},
responses = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void create(ForecastInstance forecastInst) {
BLOB_FILE_T blob = new BLOB_FILE_T(forecastInst.getFilename(), null, OffsetDateTime.now(), 0L, fileData);
connection(dsl, conn -> {
setOffice(conn, officeId);
CWMS_FCST_PACKAGE.call_STORE_FCST(dsl.configuration(), forecastInst.getSpec().getSpecId(),
CWMS_FCST_PACKAGE.call_STORE_FCST(DSL.using(conn).configuration(), forecastInst.getSpec().getSpecId(),
forecastInst.getSpec().getDesignator(), forecastDate, issueDate,
"UTC", forecastInst.getMaxAge(), forecastInst.getNotes(), forecastInfo,
blob, "F", "T", officeId);
Expand All @@ -80,15 +80,11 @@ private static Map<String, String> mapFromJson(String forecastInfo) {
}

public List<ForecastInstance> getForecastInstances(String office, String name, String designator) {
return connectionResult(dsl, conn -> {
setOffice(conn, office);
AV_FCST_SPEC spec = AV_FCST_SPEC.AV_FCST_SPEC;

return instanceQuery().where(JooqDao.filterExact(spec.OFFICE_ID, office))
.and(JooqDao.filterExact(spec.FCST_SPEC_ID, name))
.and(JooqDao.filterExact(spec.FCST_DESIGNATOR, designator))
.fetch().map(ForecastInstanceDao::map);
});
AV_FCST_SPEC spec = AV_FCST_SPEC.AV_FCST_SPEC;
return instanceQuery().where(JooqDao.filterExact(spec.OFFICE_ID, office))
.and(JooqDao.filterExact(spec.FCST_SPEC_ID, name))
.and(JooqDao.filterExact(spec.FCST_DESIGNATOR, designator))
.fetch().map(ForecastInstanceDao::map);
}

private static ForecastInstance map(Record16<String, String, String, String, String, String, Timestamp, Timestamp,
Expand Down Expand Up @@ -194,27 +190,25 @@ String, Timestamp, Timestamp, JSON>> instanceQuery() {

public ForecastInstance getForecastInstance(String office, String name, String designator,
Instant forecastDate, Instant issueDate) {
return connectionResult(dsl, conn -> {
setOffice(conn, office);
AV_FCST_INST inst = AV_FCST_INST.AV_FCST_INST;
AV_FCST_SPEC spec = AV_FCST_SPEC.AV_FCST_SPEC;
Record16<String, String, String, String, String, String,
Timestamp, Timestamp, Integer, String, String, String, String,
Timestamp, Timestamp, JSON> fetch = instanceQuery()
.where(spec.OFFICE_ID.eq(office))
.and(spec.FCST_SPEC_ID.eq(name))
.and(spec.FCST_DESIGNATOR.eq(designator))
.and(inst.FCST_DATE_TIME_UTC.eq(Timestamp.from(forecastDate)))
.and(inst.ISSUE_DATE_TIME_UTC.eq(Timestamp.from(issueDate)))
.fetchOne();
if (fetch == null) {
String message = format("Could not find forecast instance for " +
"office id: %s, spec id: %s, designator: %s, forecast date: %s, issue date: %s",
office, name, designator, forecastDate, issueDate);
throw new NotFoundException(message);
}
return map(fetch);
});

AV_FCST_INST inst = AV_FCST_INST.AV_FCST_INST;
AV_FCST_SPEC spec = AV_FCST_SPEC.AV_FCST_SPEC;
Record16<String, String, String, String, String, String,
Timestamp, Timestamp, Integer, String, String, String, String,
Timestamp, Timestamp, JSON> fetch = instanceQuery()
.where(spec.OFFICE_ID.eq(office))
.and(spec.FCST_SPEC_ID.eq(name))
.and(spec.FCST_DESIGNATOR.eq(designator))
.and(inst.FCST_DATE_TIME_UTC.eq(Timestamp.from(forecastDate)))
.and(inst.ISSUE_DATE_TIME_UTC.eq(Timestamp.from(issueDate)))
.fetchOne();
if (fetch == null) {
String message = format("Could not find forecast instance for " +
"office id: %s, spec id: %s, designator: %s, forecast date: %s, issue date: %s",
office, name, designator, forecastDate, issueDate);
throw new NotFoundException(message);
}
return map(fetch);
}

public void update(ForecastInstance forecastInst) {
Expand All @@ -234,7 +228,7 @@ public void delete(String office, String name, String designator,
Instant forecastDate, Instant issueDate) {
connection(dsl, conn -> {
setOffice(conn, office);
CWMS_FCST_PACKAGE.call_DELETE_FCST(dsl.configuration(), name, designator, Timestamp.from(forecastDate),
CWMS_FCST_PACKAGE.call_DELETE_FCST(DSL.using(conn).configuration(), name, designator, Timestamp.from(forecastDate),
Timestamp.from(issueDate), "UTC", office);
});
}
Expand Down
51 changes: 23 additions & 28 deletions cwms-data-api/src/main/java/cwms/cda/data/dao/ForecastSpecDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
Expand All @@ -37,7 +35,7 @@ public void create(ForecastSpec forecastSpec) {
if (forecastSpec.getTimeSeriesIds() != null) {
timeSeriesIds = String.join("\n", forecastSpec.getTimeSeriesIds());
}
CWMS_FCST_PACKAGE.call_STORE_FCST_SPEC(dsl.configuration(), forecastSpec.getSpecId(),
CWMS_FCST_PACKAGE.call_STORE_FCST_SPEC(DSL.using(conn).configuration(), forecastSpec.getSpecId(),
forecastSpec.getDesignator(), forecastSpec.getSourceEntityId(),
forecastSpec.getDescription(), forecastSpec.getLocationId(),
timeSeriesIds, "F", "F", forecastSpec.getOfficeId());
Expand All @@ -47,26 +45,25 @@ public void create(ForecastSpec forecastSpec) {
public void delete(String office, String specId, String designator, DeleteRule deleteRule) {
connection(dsl, conn -> {
setOffice(conn, office);
CWMS_FCST_PACKAGE.call_DELETE_FCST_SPEC(dsl.configuration(), specId, designator,
CWMS_FCST_PACKAGE.call_DELETE_FCST_SPEC(DSL.using(conn).configuration(), specId, designator,
deleteRule.getRule(), office);
});
}

public List<ForecastSpec> getForecastSpecs(String office, String specIdRegex,
String designator, String sourceEntity) {
AV_FCST_SPEC spec = AV_FCST_SPEC.AV_FCST_SPEC;
return connectionResult(dsl, conn ->
forecastSpecQuery(dsl)
.where(JooqDao.caseInsensitiveLikeRegex(spec.OFFICE_ID, office))
.and(JooqDao.caseInsensitiveLikeRegex(spec.FCST_SPEC_ID, specIdRegex))
.and(JooqDao.caseInsensitiveLikeRegex(spec.FCST_DESIGNATOR, designator))
.and(JooqDao.caseInsensitiveLikeRegex(spec.ENTITY_ID, sourceEntity))
.fetch()
.map(ForecastSpecDao::map));
return forecastSpecQuery(dsl)
.where(JooqDao.caseInsensitiveLikeRegex(spec.OFFICE_ID, office))
.and(JooqDao.caseInsensitiveLikeRegex(spec.FCST_SPEC_ID, specIdRegex))
.and(JooqDao.caseInsensitiveLikeRegex(spec.FCST_DESIGNATOR, designator))
.and(JooqDao.caseInsensitiveLikeRegex(spec.ENTITY_ID, sourceEntity))
.fetch()
.map(ForecastSpecDao::map);
}

private static SelectOnConditionStep<Record7<String, String, String, String, String, String, String>> forecastSpecQuery(
DSLContext dsl) {
private static SelectOnConditionStep<Record7<String, String, String, String,
String, String, String>> forecastSpecQuery(DSLContext dsl) {
AV_FCST_SPEC spec = AV_FCST_SPEC.AV_FCST_SPEC;
AV_FCST_TIME_SERIES timeSeries = AV_FCST_TIME_SERIES.AV_FCST_TIME_SERIES;
AV_FCST_LOCATION loc = AV_FCST_LOCATION.AV_FCST_LOCATION;
Expand Down Expand Up @@ -105,20 +102,18 @@ private static ForecastSpec map(Record7<String, String, String, String, String,

public ForecastSpec getForecastSpec(String office, String name, String designator) {
AV_FCST_SPEC spec = AV_FCST_SPEC.AV_FCST_SPEC;
return connectionResult(dsl, conn -> {
setOffice(conn, office);
Record7<String, String, String, String, String, String, String> fetch = forecastSpecQuery(dsl)
.where(spec.OFFICE_ID.eq(office))
.and(spec.FCST_SPEC_ID.eq(name))
.and(spec.FCST_DESIGNATOR.eq(designator))
.fetchOne();
if (fetch == null) {
throw new NotFoundException(
format("Could not find forecast instance for office id: %s, spec id: %s, designator: %s",
office, name, designator));
}
return map(fetch);
});

Record7<String, String, String, String, String, String, String> fetch = forecastSpecQuery(dsl)
.where(spec.OFFICE_ID.eq(office))
.and(spec.FCST_SPEC_ID.eq(name))
.and(spec.FCST_DESIGNATOR.eq(designator))
.fetchOne();
if (fetch == null) {
throw new NotFoundException(
format("Could not find forecast instance for office id: %s, spec id: %s, designator: %s",
office, name, designator));
}
return map(fetch);
}

public void update(ForecastSpec forecastSpec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.google.common.flogger.FluentLogger;
import cwms.cda.data.dao.DeleteRule;
import cwms.cda.formatters.Formats;
import fixtures.CwmsDataApiSetupCallback;
import fixtures.TestAccounts;
import io.restassured.filter.log.LogDetail;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.jooq.exception.DataAccessException;
import org.jooq.util.oracle.OracleDSL;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import usace.cwms.db.jooq.codegen.packages.CWMS_FCST_PACKAGE;

@Tag("integration")
public class ForecastInstanceControllerTestIT extends DataApiTestIT {
private static final FluentLogger LOGGER = FluentLogger.forEnclosingClass();
private static final String OFFICE = "SPK";
private static final String SPEC_ID = "test-spec";
private static final String SPEC_ID = "TEST-SPEC";
private static final String designator = "designator";
private static final String locationId = "FcstInstTestLoc";
private static final String forecastDate = "2021-06-21T14:00:10+00:00";
private static final String issueDate = "2022-05-22T12:03:40+00:00";
Expand All @@ -30,6 +38,15 @@ public class ForecastInstanceControllerTestIT extends DataApiTestIT {
@BeforeAll
public static void create() throws Exception {
createLocation(locationId, true, OFFICE);
try {
CwmsDataApiSetupCallback.getDatabaseLink()
.connection(c -> {
CWMS_FCST_PACKAGE.call_DELETE_FCST_SPEC(OracleDSL.using(c).configuration(), SPEC_ID, designator,
DeleteRule.DELETE_ALL.getRule(), OFFICE);
});
} catch(DataAccessException e) {
LOGGER.atFine().withCause(e).log("Couldn't clean up forecast spec before executing tests. Probably didn't exist");
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,54 @@
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.google.common.flogger.FluentLogger;
import cwms.cda.data.dao.DeleteRule;
import cwms.cda.formatters.Formats;
import fixtures.CwmsDataApiSetupCallback;
import fixtures.TestAccounts;
import io.restassured.filter.log.LogDetail;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.jooq.exception.DataAccessException;
import org.jooq.util.oracle.OracleDSL;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import usace.cwms.db.jooq.codegen.packages.CWMS_FCST_PACKAGE;

@Tag("integration")
public class ForecastSpecControllerTestIT extends DataApiTestIT {
private static final FluentLogger LOGGER = FluentLogger.forEnclosingClass();
private static final String OFFICE = "SPK";
private static final String SPEC_ID = "test-spec";
private static final String SPEC_ID = "TEST-SPEC";
private static final String locationId = "TsBinTestLoc";
private static final String designator = "designator";

public static final String PATH = "/forecast/spec/";
public static final String PATH = "/forecast-spec/";

@BeforeAll
public static void create() throws Exception {
createLocation(locationId, true, OFFICE);
try {
CwmsDataApiSetupCallback.getDatabaseLink()
.connection(c -> {
CWMS_FCST_PACKAGE.call_DELETE_FCST_SPEC(OracleDSL.using(c).configuration(), SPEC_ID, designator,
DeleteRule.DELETE_ALL.getRule(), OFFICE);
});
} catch(DataAccessException e) {
LOGGER.atFine().withCause(e).log("Couldn't clean up forecast spec before executing tests. Probably didn't exist");
}
}


@Test
void test_get_create_get() throws IOException {


// Structure of test:
// 1)Retrieve a ForecastSpec and assert that it does not exist
// 2)Create the ForecastSpec
Expand All @@ -48,12 +66,11 @@ void test_get_create_get() throws IOException {
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSONV2)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(Controllers.NAME, SPEC_ID)
.queryParam(Controllers.DESIGNATOR, designator)
.when()
.redirects().follow(true)
.redirects().max(3)
.get(PATH)
.get(PATH + SPEC_ID)
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"spec": {
"spec-id": "TEST-SPEC",
"office-id": "SPK",
"spec-id": "test-spec",
"location-id": "FcstInstTestLoc",
"source-entity-id": "sourceEntity",
"designator": "designator",
"location-id": "FcstInstTestLoc"
"description": "description",
"time-series-ids": [
"TsBinTestLoc.Flow.Ave.1Day.1Day.tsid1",
"TsBinTestLoc.Flow.Ave.1Day.1Day.tsid2",
"TsBinTestLoc.Flow.Ave.1Day.1Day.tsid3"
]
},
"date-time": 1624284010000,
"issue-date-time": 1653221020000,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"spec": {
"spec-id": "TEST-SPEC",
"office-id": "SPK",
"spec-id": "test-spec",
"location-id": "FcstInstTestLoc",
"source-entity-id": "sourceEntity",
"designator": "designator",
"location-id": "FcstInstTestLoc"
"description": "description",
"time-series-ids": [
"TsBinTestLoc.Flow.Ave.1Day.1Day.tsid1",
"TsBinTestLoc.Flow.Ave.1Day.1Day.tsid2",
"TsBinTestLoc.Flow.Ave.1Day.1Day.tsid3"
]
},
"date-time": 1624284010000,
"issue-date-time": 1653221020000,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
{
"spec-id": "test-spec",
"spec-id": "TEST-SPEC",
"office-id": "SPK",
"location-id": "location",
"source-entity-id": "sourceEntity",
"location-id": "TsBinTestLoc",
"source-entity-id": "USACE",
"designator": "designator",
"description": "description",
"time-series-ids": [
{
"time-series-id": "tsid1",
"active": false
},
{
"time-series-id": "tsid2",
"active": false
},
{
"time-series-id": "tsid3",
"active": false
}
"TsBinTestLoc.Flow.Ave.1Day.1Day.tsid1",
"TsBinTestLoc.Flow.Ave.1Day.1Day.tsid2",
"TsBinTestLoc.Flow.Ave.1Day.1Day.tsid3"
]
}
Loading

0 comments on commit 8c14034

Please sign in to comment.