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
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024 Hydrologic Engineering Center
* Copyright (c) 2025 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
Expand All @@ -24,12 +24,11 @@

package mil.army.usace.hec.cwms.data.api.client.controllers;

import mil.army.usace.hec.cwms.data.api.client.model.LocationLevel;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevels;
import mil.army.usace.hec.cwms.data.api.client.model.RadarObjectMapper;
import mil.army.usace.hec.cwms.data.api.client.model.SpecifiedLevel;
import mil.army.usace.hec.cwms.data.api.client.model.TimeSeries;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.time.Instant;
Expand All @@ -38,8 +37,17 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.*;
import mil.army.usace.hec.cwms.data.api.client.model.ConstantLocationLevel;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevel;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevelConstituent;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevels;
import mil.army.usace.hec.cwms.data.api.client.model.RadarObjectMapper;
import mil.army.usace.hec.cwms.data.api.client.model.SeasonalLocationLevel;
import mil.army.usace.hec.cwms.data.api.client.model.SpecifiedLevel;
import mil.army.usace.hec.cwms.data.api.client.model.TimeSeries;
import mil.army.usace.hec.cwms.data.api.client.model.TimeSeriesLocationLevel;
import mil.army.usace.hec.cwms.data.api.client.model.VirtualLocationLevel;
import org.junit.jupiter.api.Test;

class TestLevelController extends TestController {

Expand Down Expand Up @@ -114,13 +122,51 @@ void testRetrieveLocationLevels() throws IOException {
assertEquals("Top of Flood", level.get().getSpecifiedLevelId());
assertEquals(LocationLevel.ParameterTypeIdEnum.INST, level.get().getParameterTypeId());
assertEquals("Elev", level.get().getParameterId());
assertEquals(321.564, level.get().getConstantValue());
assertEquals(321.564, ((ConstantLocationLevel) level.get()).getConstantValue());
assertEquals("m", level.get().getLevelUnitsId());
ZonedDateTime effectiveDate = ZonedDateTime.of(1900, 1, 1, 5, 0, 0, 0, ZoneId.of("UTC"));
assertEquals(effectiveDate.toInstant(), level.get().getLevelDate().toInstant());
assertEquals("0", level.get().getDurationId());
}

@Test
void testRetrieveLocationLevelSubtypes() throws IOException {
String resource = "radar/v2/json/location_levels.json";
String collect = readJsonFile(resource);
mockHttpServer.enqueue(collect);
mockHttpServer.start();
LocationLevelEndpointInput.GetAll input = LocationLevelEndpointInput.getAll()
.officeId("LRL");
LocationLevels locationLevels = new LevelController().retrieveLocationLevels(buildConnectionInfo(), input);
assertTrue(locationLevels.getLevels().stream()
.anyMatch(l -> l instanceof VirtualLocationLevel));
assertTrue(locationLevels.getLevels().stream()
.anyMatch(l -> l instanceof ConstantLocationLevel));
assertTrue(locationLevels.getLevels().stream()
.anyMatch(l -> l instanceof TimeSeriesLocationLevel));
assertTrue(locationLevels.getLevels().stream()
.anyMatch(l -> l instanceof SeasonalLocationLevel));
}

@Test
void testRetrieveVirtualLevel() throws IOException {
String resource = "radar/v2/json/location_levels.json";
String collect = readJsonFile(resource);
mockHttpServer.enqueue(collect);
mockHttpServer.start();
LocationLevelEndpointInput.GetAll input = LocationLevelEndpointInput.getAll()
.officeId("LRL");
LocationLevels locationLevels = new LevelController().retrieveLocationLevels(buildConnectionInfo(), input);
VirtualLocationLevel virtualLevel = (VirtualLocationLevel) locationLevels.getLevels().stream()
.filter(l -> l instanceof VirtualLocationLevel)
.findAny()
.get();
assertTrue(virtualLevel.getConstituents().stream()
.anyMatch(l -> !(l instanceof LocationLevelConstituent)));
assertTrue(virtualLevel.getConstituents().stream()
.anyMatch(l -> l instanceof LocationLevelConstituent));
}

@Test
void testRetrieveLocationLevel() throws IOException {
String resource = "radar/v2/json/location_level.json";
Expand All @@ -135,10 +181,12 @@ void testRetrieveLocationLevel() throws IOException {
assertEquals("Bottom of Inlet", level.getSpecifiedLevelId());
assertEquals(LocationLevel.ParameterTypeIdEnum.INST, level.getParameterTypeId());
assertEquals("Elev", level.getParameterId());
assertEquals(145.6944, level.getConstantValue());
assertEquals(145.6944, ((ConstantLocationLevel) level).getConstantValue());
assertEquals("m", level.getLevelUnitsId());
assertEquals(instant, level.getLevelDate().toInstant());
assertEquals("0", level.getDurationId());
Instant expiration = Instant.parse("2900-01-01T06:00:00Z");
assertEquals(expiration, level.getExpirationDate().toInstant());
}

@Test
Expand Down Expand Up @@ -175,7 +223,7 @@ void testLevelAsTimeSeries() throws IOException {
String collect = readJsonFile(resource);
mockHttpServer.enqueue(collect);
mockHttpServer.start();
LocationLevel locationLevel = RadarObjectMapper.mapJsonToObject(collect, LocationLevel.class);
LocationLevel locationLevel = RadarObjectMapper.mapJsonToObject(collect, TimeSeriesLocationLevel.class);
Instant begin = Instant.parse("2023-06-01T07:00:00Z");
Instant end = Instant.parse("2023-06-11T07:00:00Z");
String unit = locationLevel.getLevelUnitsId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"constant-value": 145.6944,
"level-units-id": "m",
"level-date": "1900-01-01T06:00:00Z",
"duration-id": "0"
"duration-id": "0",
"expiration-date": "2900-01-01T06:00:00Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,54 @@
"level-units-id": "m3",
"level-date": "1900-01-01T05:00:00Z",
"duration-id": "0"
},
{
"office-id": "SPK",
"location-level-id": "virtual_level_value_2.Stor.Ave.1Day.Regulating",
"level-units-id": "ac-ft",
"level-date": "2023-06-01T00:00:00-07:00",
"expiration-date": 1685689200000,
"constituents": [
{
"type": "LOCATION_LEVEL",
"abbr": "L1",
"name": "level_get_all_loc3.Stage.Ave.1Day.Regulating",
"attribute-id": "Stage",
"attribute-value": 8.99
},
{
"type": "RATING",
"abbr": "R1",
"name": "LevelsControllerTestIT.Stage;Flow.COE.Production"
}
],
"constituent-connections": "L1=R1I1"
},
{
"seasonal-values": [
{
"value": 10,
"offset-minutes": 0,
"offset-months": 0
}
],
"level-units-id": "ft",
"level-date": "2008-12-03T10:15:30+01:00[UTC]",
"level-comment": "for testing purposes",
"interval-origin": "2008-12-03T10:15:30+01:00[UTC]",
"interval-months": 1,
"interpolate-string": "false",
"location-level-id": "LOC_TEST.Elev.Inst.0.Bottom of Inlet",
"office-id": "LRL"
},
{
"seasonal-time-series-id": "RYAN3.Stage.Inst.5Minutes.0.ZSTORE_TS_TEST630",
"level-units-id": "ft",
"level-date": "2008-12-03T10:15:30+01:00[UTC]",
"level-comment": "for testing purposes",
"interpolate-string": "false",
"location-level-id": "LOC_TEST.Elev.Inst.0.Bottom of Inlet",
"office-id": "LRL"
}
]
}
Loading
Loading