Skip to content
Merged
Show file tree
Hide file tree
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 @@ -15,9 +15,7 @@
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.*;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
Expand All @@ -29,7 +27,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import org.junit.jupiter.api.Test;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

Expand Down Expand Up @@ -58,6 +56,28 @@ static void create() throws Exception {
random.nextBytes(LARGE_BYTES);
}

@AfterEach
void tearDown() throws Exception {
TestAccounts.KeyUser user = TestAccounts.KeyUser.SPK_NORMAL;
given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV2)
.header("Authorization", user.toHeaderValue())
.queryParam(Controllers.OFFICE, OFFICE)
.when()
.redirects().follow(true)
.redirects().max(3)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(Controllers.BEGIN, BEGIN_STR)
.queryParam(Controllers.END, END_STR)
.queryParam(Controllers.OFFICE, OFFICE)
.delete("/timeseries/binary/" + tsId)
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_NO_CONTENT));
}

@BeforeEach
void setup() throws Exception {
tsId = locationId + ".Flow.Inst.1Hour.0." + Instant.now().getEpochSecond() + (int)(Math.random() * 100);
Expand Down Expand Up @@ -138,6 +158,24 @@ void test_get_create_get(String format) throws IOException {
.body("binary-values.size()", equalTo(3))
;

// Delete the binary time series
given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(format)
.header("Authorization", user.toHeaderValue())
.queryParam(Controllers.OFFICE, OFFICE)
.when()
.redirects().follow(true)
.redirects().max(3)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(Controllers.BEGIN, BEGIN_STR)
.queryParam(Controllers.END, END_STR)
.queryParam(Controllers.OFFICE, OFFICE)
.delete("/timeseries/binary/" + tsId)
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_NO_CONTENT));

}

Expand Down Expand Up @@ -545,7 +583,7 @@ void test_create_get_update_get(String format) throws IOException {
// 2)Create the binary time series
// 3)Retrieve the binary time series and assert that it exists
// 4)Update the binary time series
// 5)Retrieve the binary time series and assert that it does not exist
// 5)Retrieve the binary time series and assert that value has updated


// Step 1)
Expand Down Expand Up @@ -637,7 +675,7 @@ void test_create_get_update_get(String format) throws IOException {

String newValue = "bmV3VmFsdWU=";
// Step 5)
// Retrieve the binary time series and assert that it does not exist
// Retrieve the binary time series and assert that it has new value
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(format)
Expand All @@ -656,6 +694,7 @@ void test_create_get_update_get(String format) throws IOException {
.body("binary-values.size()", equalTo(3))
.body("binary-values[1].binary-value", equalTo(newValue))
;

}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.flogger.FluentLogger;
import cwms.cda.formatters.Formats;
import fixtures.TestAccounts;
import io.restassured.RestAssured;
Expand All @@ -28,14 +29,15 @@

@Tag("integration")
class TimeSeriesFilteredControllerTestIT extends DataApiTestIT {
static FluentLogger logger = FluentLogger.forEnclosingClass();
public static final String JSON_FILE = "/cwms/cda/api/lrl/1hour.json";

@ParameterizedTest
@ValueSource(strings = {Formats.JSONV2, Formats.DEFAULT})
void test_filter_nulls(String format) throws Exception {
ObjectMapper mapper = new ObjectMapper();

InputStream resource = this.getClass().getResourceAsStream(
"/cwms/cda/api/lrl/pseudo_reg_1hour.json");
InputStream resource = this.getClass().getResourceAsStream(JSON_FILE);
assertNotNull(resource);
String tsData = IOUtils.toString(resource, StandardCharsets.UTF_8);

Expand Down Expand Up @@ -74,7 +76,7 @@ void test_filter_nulls(String format) throws Exception {
.queryParam(Controllers.UNIT,"cfs")
.queryParam(Controllers.NAME, ts.get(Controllers.NAME).asText())
.queryParam(Controllers.BEGIN,"2023-01-11T12:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T13:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T15:00:00-00:00")
.when()
.redirects().follow(true)
.redirects().max(3)
Expand All @@ -98,7 +100,7 @@ void test_filter_nulls(String format) throws Exception {
.queryParam(Controllers.UNIT,"cfs")
.queryParam(Controllers.NAME, ts.get(Controllers.NAME).asText())
.queryParam(Controllers.BEGIN,"2023-01-11T12:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T13:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T15:00:00-00:00")
.queryParam(Controllers.QUERY,"value!=null")
.when()
.redirects().follow(true)
Expand All @@ -110,7 +112,7 @@ void test_filter_nulls(String format) throws Exception {
.statusCode(is(HttpServletResponse.SC_OK))
.body("time-series.values[0][0]", equalTo(1673438400000L))
.body("time-series.values[0][1]", closeTo(500.0,0.0001))
.body("time-series.values[1][0]", equalTo(1673442000000L))
.body("time-series.values[1][0]", equalTo(1673449200000L))
.body("time-series.values[1][1]", closeTo(600.0,0.0001))
.body("time-series.values.size()", equalTo(2))
;
Expand All @@ -124,8 +126,7 @@ void test_filter_nulls(String format) throws Exception {
void test_min_value(String format) throws Exception {
ObjectMapper mapper = new ObjectMapper();

InputStream resource = this.getClass().getResourceAsStream(
"/cwms/cda/api/lrl/pseudo_reg_1hour.json");
InputStream resource = this.getClass().getResourceAsStream(JSON_FILE);
assertNotNull(resource);
String tsData = IOUtils.toString(resource, StandardCharsets.UTF_8);

Expand Down Expand Up @@ -164,7 +165,7 @@ void test_min_value(String format) throws Exception {
.queryParam(Controllers.UNIT,"cfs")
.queryParam(Controllers.NAME, ts.get(Controllers.NAME).asText())
.queryParam(Controllers.BEGIN,"2023-01-11T12:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T13:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T15:00:00-00:00")
.queryParam(Controllers.QUERY, "value>550.0")
.when()
.redirects().follow(true)
Expand All @@ -174,7 +175,7 @@ void test_min_value(String format) throws Exception {
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK))
.body("time-series.values[0][0]", equalTo(1673442000000L))
.body("time-series.values[0][0]", equalTo(1673449200000L))
.body("time-series.values[0][1]", closeTo(600.0,0.0001))
.body("time-series.values.size()", equalTo(1))
;
Expand All @@ -188,8 +189,7 @@ void test_min_value(String format) throws Exception {
void test_max_value(String format) throws Exception {
ObjectMapper mapper = new ObjectMapper();

InputStream resource = this.getClass().getResourceAsStream(
"/cwms/cda/api/lrl/pseudo_reg_1hour.json");
InputStream resource = this.getClass().getResourceAsStream(JSON_FILE);
assertNotNull(resource);
String tsData = IOUtils.toString(resource, StandardCharsets.UTF_8);

Expand Down Expand Up @@ -228,7 +228,7 @@ void test_max_value(String format) throws Exception {
.queryParam(Controllers.UNIT,"cfs")
.queryParam(Controllers.NAME, ts.get(Controllers.NAME).asText())
.queryParam(Controllers.BEGIN,"2023-01-11T12:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T13:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T15:00:00-00:00")
.queryParam(Controllers.QUERY, "value<=550.0")
.when()
.redirects().follow(true)
Expand All @@ -252,8 +252,7 @@ void test_max_value(String format) throws Exception {
void test_min_max_value_combined(String format) throws Exception {
ObjectMapper mapper = new ObjectMapper();

InputStream resource = this.getClass().getResourceAsStream(
"/cwms/cda/api/lrl/pseudo_reg_1hour.json");
InputStream resource = this.getClass().getResourceAsStream(JSON_FILE);
assertNotNull(resource);
String tsData = IOUtils.toString(resource, StandardCharsets.UTF_8);

Expand Down Expand Up @@ -292,7 +291,7 @@ void test_min_max_value_combined(String format) throws Exception {
.queryParam(Controllers.UNIT,"cfs")
.queryParam(Controllers.NAME, ts.get(Controllers.NAME).asText())
.queryParam(Controllers.BEGIN,"2023-01-11T12:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T13:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T15:00:00-00:00")
.queryParam(Controllers.QUERY, "value>450.0 and value <=550.0")
.when()
.redirects().follow(true)
Expand All @@ -316,8 +315,7 @@ void test_min_max_value_combined(String format) throws Exception {
void test_all_filters_combined(String format) throws Exception {
ObjectMapper mapper = new ObjectMapper();

InputStream resource = this.getClass().getResourceAsStream(
"/cwms/cda/api/lrl/pseudo_reg_1hour.json");
InputStream resource = this.getClass().getResourceAsStream(JSON_FILE);
assertNotNull(resource);
String tsData = IOUtils.toString(resource, StandardCharsets.UTF_8);

Expand Down Expand Up @@ -356,7 +354,7 @@ void test_all_filters_combined(String format) throws Exception {
.queryParam(Controllers.UNIT,"cfs")
.queryParam(Controllers.NAME, ts.get(Controllers.NAME).asText())
.queryParam(Controllers.BEGIN,"2023-01-11T12:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T13:00:00-00:00")
.queryParam(Controllers.END,"2023-01-11T15:00:00-00:00")
.queryParam(Controllers.QUERY, "value!=null and value>450.0 and value <=550.0")
.when()
.redirects().follow(true)
Expand Down
27 changes: 27 additions & 0 deletions cwms-data-api/src/test/resources/cwms/cda/api/lrl/1hour.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Calhoun.Flow.Inst.1Hour.0.cda-test",
"office-id": "SPK",
"units": "cfs",
"values": [
[
1673438400000,
500,
0
],
[
1673442000000,
null,
5
],
[
1673445600000,
-340282346638528859811704183484516925440,
5
],
[
1673449200000,
600,
0
]
]
}
Loading