Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import static cwms.cda.security.ApiKeyIdentityProvider.AUTH_HEADER;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@Tag("integration")
Expand Down Expand Up @@ -116,6 +117,9 @@
buildTestGateSetting(CONDUIT_GATE_2_ID, 3, 4));
private static final GateChange CHANGE_3 = buildTestGateChange(PROJECT_1_ID, JAN_THIRD);

private static final GateChange UNPROTECTED_CHANGE_1 = buildUnprotectedTestGateChange(PROJECT_1_ID, JAN_FIRST,
buildTestGateSetting(CONDUIT_GATE_1_ID, 12, 20));

@BeforeAll
static void setup() throws Exception {
setupProject();
Expand Down Expand Up @@ -348,6 +352,72 @@
.statusCode(is(HttpServletResponse.SC_NO_CONTENT));
}

@Test
void test_override_protection()
{
String json = Formats.format(Formats.parseHeader(Formats.JSONV1, GateChange.class), List.of(CHANGE_1), GateChange.class);

//Create the gate changes
given()
.log().ifValidationFails(LogDetail.ALL, true)
.contentType(Formats.JSONV1)
.body(json)
.header(AUTH_HEADER, USER.toHeaderValue())
.queryParam(OVERRIDE_PROTECTION, "true")
.when()
.redirects().follow(true)
.redirects().max(3)
.post("projects/gate-changes")
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED));

String unprotectedJson = Formats.format(Formats.parseHeader(Formats.JSONV1, GateChange.class), List.of(UNPROTECTED_CHANGE_1), GateChange.class);

//Try creating it again with OVERRIDE_PROTECTION=false, this should fail.
given()
.log().ifValidationFails(LogDetail.ALL, true)
.contentType(Formats.JSONV1)
.body(unprotectedJson)
.header(AUTH_HEADER, USER.toHeaderValue())
.queryParam(OVERRIDE_PROTECTION, "false")
.when()
.redirects().follow(true)
.redirects().max(3)
.post("projects/gate-changes")
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED));

String allJson = given().log()
.ifValidationFails(LogDetail.ALL, true)
.contentType(Formats.JSONV1)
.accept(Formats.DEFAULT)
.when()
.redirects()
.follow(true)
.redirects()
.max(3)
.queryParam(BEGIN, JAN_FIRST.toString())
.queryParam(END, JAN_SECOND.toString())
.queryParam(START_TIME_INCLUSIVE, true)
.queryParam(END_TIME_INCLUSIVE, true)
.get("projects/" + OFFICE_ID + "/" + PROJECT_1_ID.getName() + "/gate-changes")
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK))
.extract()
.body()
.asString();
List<GateChange> changes = Formats.parseContentList(Formats.parseHeader(Formats.JSONV1, GateChange.class),
allJson, GateChange.class);

DTOMatch.assertContainsDto(changes, CHANGE_1, this::isSimilar, DTOMatch::assertMatch, "Does not contain change for " + CHANGE_1.getChangeDate());

Check failure on line 418 in cwms-data-api/src/test/java/cwms/cda/api/location/kind/GateChangeControllerTestIT.java

View workflow job for this annotation

GitHub Actions / build and test (jdk 17, schema latest)

GateChangeControllerTestIT.GateChangeControllerTestIT.test_override_protection (schema: latest-dev)

org.gradle.internal.exceptions.DefaultMultiCauseException: Multiple Failures (2 failures) org.opentest4j.MultipleFailuresError: Multiple Failures (1 failure) org.opentest4j.MultipleFailuresError: Multiple Failures (1 failure) org.opentest4j.AssertionFailedError: Opening ==> expected: <10.0> but was: <12.0> org.opentest4j.AssertionFailedError: Protected status does not match ==> expected: <true> but was: <false>

Check failure on line 418 in cwms-data-api/src/test/java/cwms/cda/api/location/kind/GateChangeControllerTestIT.java

View workflow job for this annotation

GitHub Actions / build and test (jdk 17, schema release)

GateChangeControllerTestIT.GateChangeControllerTestIT.test_override_protection (schema: 26.07.16)

org.gradle.internal.exceptions.DefaultMultiCauseException: Multiple Failures (2 failures) org.opentest4j.MultipleFailuresError: Multiple Failures (1 failure) org.opentest4j.MultipleFailuresError: Multiple Failures (1 failure) org.opentest4j.AssertionFailedError: Opening ==> expected: <10.0> but was: <12.0> org.opentest4j.AssertionFailedError: Protected status does not match ==> expected: <true> but was: <false>

Check failure on line 418 in cwms-data-api/src/test/java/cwms/cda/api/location/kind/GateChangeControllerTestIT.java

View workflow job for this annotation

GitHub Actions / build and test (jdk 17, schema next-release)

GateChangeControllerTestIT.GateChangeControllerTestIT.test_override_protection (schema: 26.07.16)

org.gradle.internal.exceptions.DefaultMultiCauseException: Multiple Failures (2 failures) org.opentest4j.MultipleFailuresError: Multiple Failures (1 failure) org.opentest4j.MultipleFailuresError: Multiple Failures (1 failure) org.opentest4j.AssertionFailedError: Opening ==> expected: <10.0> but was: <12.0> org.opentest4j.AssertionFailedError: Protected status does not match ==> expected: <true> but was: <false>

Check failure on line 418 in cwms-data-api/src/test/java/cwms/cda/api/location/kind/GateChangeControllerTestIT.java

View workflow job for this annotation

GitHub Actions / build and test (jdk 17, schema previous)

GateChangeControllerTestIT.GateChangeControllerTestIT.test_override_protection (schema: 26.02.17)

org.gradle.internal.exceptions.DefaultMultiCauseException: Multiple Failures (2 failures) org.opentest4j.MultipleFailuresError: Multiple Failures (1 failure) org.opentest4j.MultipleFailuresError: Multiple Failures (1 failure) org.opentest4j.AssertionFailedError: Opening ==> expected: <10.0> but was: <12.0> org.opentest4j.AssertionFailedError: Protected status does not match ==> expected: <true> but was: <false>
}

private boolean isSimilar(GateChange left, GateChange right) {
boolean output = false;

Expand Down Expand Up @@ -409,6 +479,43 @@
.build();
}

static GateChange buildUnprotectedTestGateChange(CwmsId projectId, Instant changeDate, GateSetting... settingVargs) {
LookupType dischargeComputationType = new LookupType.Builder().withActive(true)
.withDisplayValue("A")
.withTooltip("Adjusted by an automated method")
.withOfficeId(OFFICE_ID)
.build();
LookupType reasonType = new LookupType.Builder().withActive(true)
.withDisplayValue("O")
.withTooltip("Other release")
.withOfficeId(OFFICE_ID)
.build();
boolean isProtected = false;
Double newTotalDischargeOverride = 1.0;
Double oldTotalDischargeOverride = 2.0;
String dischargeUnits = "cfs";
Double poolElevation = 3.0;
Double tailwaterElevation = 4.0;
String elevationUnits = "ft";
String notes = "Test notes";
List<GateSetting> settings = Arrays.asList(settingVargs);

return new GateChange.Builder().withProjectId(projectId)
.withDischargeComputationType(dischargeComputationType)
.withReasonType(reasonType)
.withProtected(isProtected)
.withNewTotalDischargeOverride(newTotalDischargeOverride)
.withOldTotalDischargeOverride(oldTotalDischargeOverride)
.withDischargeUnits(dischargeUnits)
.withPoolElevation(poolElevation)
.withTailwaterElevation(tailwaterElevation)
.withElevationUnits(elevationUnits)
.withNotes(notes)
.withChangeDate(changeDate)
.withSettings(settings)
.build();
}

static GateSetting buildTestGateSetting(CwmsId locationId, double opening, double invertElev) {
return new GateSetting.Builder().withLocationId(locationId)
.withOpening(opening)
Expand Down
Loading