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 @@ -113,17 +113,7 @@ public ResponseEntity<List<TimUpdateModel>> GetExpiringActiveTims() {
activeTim.setFrameType(TravelerInfoType.advisory);
}

// set dataFrame content. it's required for the ODE, so if we didn't record it,
// assume Advisory
String serializedContent = rs.getString("DF_CONTENT");
ContentEnum contentType;
if (serializedContent == null || serializedContent.isEmpty()) {
contentType = ContentEnum.advisory;
} else {
contentType = ContentEnum.fromString(serializedContent);
}
activeTim.setDfContent(contentType);

activeTim.setDfContent(ContentEnum.advisory);
activeTims.add(activeTim);
}
} catch (Exception e) {
Expand Down Expand Up @@ -169,16 +159,7 @@ public ResponseEntity<TimUpdateModel> GetUpdateModelFromActiveTimId(@PathVariabl
activeTim.setFrameType(TravelerInfoType.advisory);
}

// set dataFrame content. it's required for the ODE, so if we didn't record it,
// assume Advisory
String serializedContent = rs.getString("DF_CONTENT");
ContentEnum contentType;
if (serializedContent == null || serializedContent.isEmpty()) {
contentType = ContentEnum.advisory;
} else {
contentType = ContentEnum.fromString(serializedContent);
}
activeTim.setDfContent(contentType);
activeTim.setDfContent(ContentEnum.advisory);
}
} catch (Exception e) {
log.error("Error getting active tim", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void setupPreparedStatement() {
public void GetExpiringActiveTims_SUCCESS() throws SQLException {
// Arrange
// we only set one property to verify its returned
when(mockRs.getLong("ACTIVE_TIM_ID")).thenReturn(999l);
when(mockRs.getLong("ACTIVE_TIM_ID")).thenReturn(999L);
when(mockRs.getInt(any())).thenReturn(0);
when(mockRs.getInt("FRAME_TYPE")).thenReturn(FrameType.TravelerInfoType.advisory.ordinal());
String selectStatement = "SELECT atim.*, tt.type as tim_type_name, tt.description as tim_type_description";
Expand Down Expand Up @@ -108,23 +108,22 @@ public void GetExpiringActiveTims_FAIL() throws SQLException {
public void GetExpiringActiveTims_CorrectContentType() throws SQLException {
// Arrange
when(mockRs.getString(any())).thenReturn("");
when(mockRs.getString("DF_CONTENT")).thenReturn("workZone");
when(mockRs.getLong("ACTIVE_TIM_ID")).thenReturn(999l);
when(mockRs.getLong("ACTIVE_TIM_ID")).thenReturn(999L);

// Act
ResponseEntity<List<TimUpdateModel>> tums = uut.GetExpiringActiveTims();

// Assert
Assertions.assertEquals(HttpStatus.OK, tums.getStatusCode());
Assertions.assertEquals(1, tums.getBody().size());
Assertions.assertEquals(ContentEnum.workZone, tums.getBody().get(0).getDfContent());
Assertions.assertEquals(ContentEnum.advisory, tums.getBody().get(0).getDfContent());
}

@Test
public void GetUpdateModelFromActiveTimId_SUCCESS() throws SQLException {
// Arrange
// we only set one property to verify its returned
when(mockRs.getLong("ACTIVE_TIM_ID")).thenReturn(999l);
when(mockRs.getLong("ACTIVE_TIM_ID")).thenReturn(999L);
when(mockRs.getInt(any())).thenReturn(0);
when(mockRs.getInt("FRAME_TYPE")).thenReturn(FrameType.TravelerInfoType.advisory.ordinal());

Expand All @@ -140,10 +139,10 @@ public void GetUpdateModelFromActiveTimId_SUCCESS() throws SQLException {
selectStatement += " LEFT JOIN data_frame df on atim.tim_id = df.tim_id";
selectStatement += " LEFT JOIN region r on df.data_frame_id = r.data_frame_id";
selectStatement += " LEFT JOIN tim_type tt ON atim.tim_type_id = tt.tim_type_id";
selectStatement += " WHERE atim.active_tim_id = " + 999l;
selectStatement += " WHERE atim.active_tim_id = " + 999L;

// Act
ResponseEntity<TimUpdateModel> tum = uut.GetUpdateModelFromActiveTimId(999l);
ResponseEntity<TimUpdateModel> tum = uut.GetUpdateModelFromActiveTimId(999L);

// Assert
Assertions.assertEquals(HttpStatus.OK, tum.getStatusCode());
Expand All @@ -159,7 +158,7 @@ public void GetUpdateModelFromActiveTimId_FAIL() throws SQLException {
when(mockRs.getLong("ACTIVE_TIM_ID")).thenThrow(new SQLException());

// Act
ResponseEntity<TimUpdateModel> tum = uut.GetUpdateModelFromActiveTimId(999l);
ResponseEntity<TimUpdateModel> tum = uut.GetUpdateModelFromActiveTimId(999L);

// Assert
Assertions.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, tum.getStatusCode());
Expand All @@ -172,16 +171,15 @@ public void GetUpdateModelFromActiveTimId_FAIL() throws SQLException {
public void GetUpdateModelFromActiveTimId_CorrectContentType() throws SQLException {
// Arrange
when(mockRs.getString(any())).thenReturn("");
when(mockRs.getString("DF_CONTENT")).thenReturn("workZone");
when(mockRs.getLong("ACTIVE_TIM_ID")).thenReturn(999l);
when(mockRs.getLong("ACTIVE_TIM_ID")).thenReturn(999L);

// Act
ResponseEntity<TimUpdateModel> tum = uut.GetUpdateModelFromActiveTimId(999l);
ResponseEntity<TimUpdateModel> tum = uut.GetUpdateModelFromActiveTimId(999L);

// Assert
Assertions.assertEquals(HttpStatus.OK, tum.getStatusCode());
Assertions.assertNotNull(tum.getBody());
Assertions.assertEquals(ContentEnum.workZone, tum.getBody().getDfContent());
Assertions.assertEquals(ContentEnum.advisory, tum.getBody().getDfContent());
}

@Test
Expand All @@ -191,7 +189,7 @@ public void UpdateActiveTim_SatRecordId_FAIL() {
doReturn(false).when(mockDbInteractions).updateOrDelete(mockPreparedStatement);

// Act
ResponseEntity<Boolean> success = uut.updateActiveTim_SatRecordId(-1l, "asdf");
ResponseEntity<Boolean> success = uut.updateActiveTim_SatRecordId(-1L, "asdf");

// Assert
Assertions.assertFalse(success.getBody(), "UpdateActiveTim_SatRecordId succeeded when it should have failed");
Expand All @@ -204,7 +202,7 @@ public void UpdateActiveTim_SatRecordId_SUCCESS() {
doReturn(true).when(mockDbInteractions).updateOrDelete(mockPreparedStatement);

// Act
ResponseEntity<Boolean> success = uut.updateActiveTim_SatRecordId(-1l, "asdf");
ResponseEntity<Boolean> success = uut.updateActiveTim_SatRecordId(-1L, "asdf");

// Assert
Assertions.assertTrue(success.getBody(), "UpdateActiveTim_SatRecordId failed when it should have succeeded");
Expand All @@ -216,7 +214,7 @@ public void UpdateActiveTim_SatRecordId_EXCEPTION() throws SQLException {
doThrow(new SQLException()).when(mockDbInteractions).getConnectionPool();

// Act
ResponseEntity<Boolean> success = uut.updateActiveTim_SatRecordId(-1l, "asdf");
ResponseEntity<Boolean> success = uut.updateActiveTim_SatRecordId(-1L, "asdf");

// Assert
Assertions.assertFalse(success.getBody(), "UpdateActiveTim_SatRecordId was successful during an error");
Expand Down Expand Up @@ -431,7 +429,7 @@ public void GetActiveTimIndicesByRsu_FAIL() throws SQLException {
public void GetActiveTimsByClientIdDirection_SUCCESS() throws SQLException {
// Arrange
String clientId = "clientId";
Long timTypeId = -1l;
Long timTypeId = -1L;
String direction = "eastward";
String selectStatement = "select * from active_tim where CLIENT_ID like '" + clientId + "' and TIM_TYPE_ID = " + timTypeId;
selectStatement += " and DIRECTION = '" + direction + "'";
Expand Down Expand Up @@ -465,7 +463,7 @@ public void GetActiveTimsByClientIdDirection_SUCCESS() throws SQLException {
public void GetActiveTimsByClientIdDirection_FAIL() throws SQLException {
// Arrange
String clientId = "clientId";
Long timTypeId = -1l;
Long timTypeId = -1L;
String direction = "eastward";
String selectStatement = "select * from active_tim where CLIENT_ID like '" + clientId + "' and TIM_TYPE_ID = " + timTypeId;
selectStatement += " and DIRECTION = '" + direction + "'";
Expand Down Expand Up @@ -536,7 +534,7 @@ public void GetBufferTimsByClientId_FAIL() throws SQLException {
@Test
public void GetItisCodesForActiveTim_SUCCESS() throws SQLException {
// Arrange
Long activeTimId = -1l;
Long activeTimId = -1L;
String selectStatement = "select itis_code from active_tim ";
selectStatement += "inner join tim on tim.tim_id = active_tim.tim_id ";
selectStatement += "inner join data_frame on tim.tim_id = data_frame.tim_id ";
Expand All @@ -560,7 +558,7 @@ public void GetItisCodesForActiveTim_SUCCESS() throws SQLException {
@Test
public void GetItisCodesForActiveTim_FAIL() throws SQLException {
// Arrange
Long activeTimId = -1l;
Long activeTimId = -1L;
String selectStatement =
"select itis_code from active_tim inner join tim on tim.tim_id = active_tim.tim_id inner join data_frame on tim.tim_id = data_frame.tim_id inner join data_frame_itis_code on data_frame_itis_code.data_frame_id = data_frame.data_frame_id inner join itis_code on data_frame_itis_code.itis_code_id = itis_code.itis_code_id where active_tim_id = " +
activeTimId + " order by data_frame_itis_code.position asc";
Expand All @@ -580,7 +578,7 @@ public void GetItisCodesForActiveTim_FAIL() throws SQLException {
@Test
public void DeleteActiveTim_SUCCESS() throws SQLException {
// Arrange
Long activeTimId = -1l;
Long activeTimId = -1L;
// Act
ResponseEntity<Boolean> data = uut.DeleteActiveTim(activeTimId);

Expand All @@ -596,7 +594,7 @@ public void DeleteActiveTim_SUCCESS() throws SQLException {
@Test
public void DeleteActiveTim_FAIL() throws SQLException {
// Arrange
Long activeTimId = -1l;
Long activeTimId = -1L;
doThrow(new SQLException()).when(mockPreparedStatement).setLong(1, activeTimId);

// Act
Expand Down Expand Up @@ -624,7 +622,7 @@ public void DeleteActiveTimsById_SUCCESS() throws SQLException {
Assertions.assertEquals(HttpStatus.OK, data.getStatusCode());
Assertions.assertTrue(data.getBody(), "Fail return on success");
verify(mockConnection).prepareStatement("DELETE FROM ACTIVE_TIM WHERE ACTIVE_TIM_ID in (?)");
verify(mockPreparedStatement).setLong(1, -1l);
verify(mockPreparedStatement).setLong(1, -1L);
verify(mockPreparedStatement).close();
verify(mockConnection).close();
}
Expand All @@ -634,7 +632,7 @@ public void DeleteActiveTimsById_FAIL() throws SQLException {
// Arrange
List<Long> activeTimIds = new ArrayList<>();
activeTimIds.add(Long.valueOf(-1));
doThrow(new SQLException()).when(mockPreparedStatement).setLong(1, -1l);
doThrow(new SQLException()).when(mockPreparedStatement).setLong(1, -1L);

// Act
ResponseEntity<Boolean> data = uut.DeleteActiveTimsById(activeTimIds);
Expand All @@ -653,7 +651,7 @@ public void GetActiveTimsByIds_SUCCESS() throws SQLException {
String query = "select * from active_tim where active_tim_id in (?, ?)";

// Act
var response = uut.GetActiveTimsByIds(Arrays.asList(-1l, -2l));
var response = uut.GetActiveTimsByIds(Arrays.asList(-1L, -2L));

// Assert
Assertions.assertEquals(HttpStatus.OK, response.getStatusCode());
Expand All @@ -666,10 +664,10 @@ public void GetActiveTimsByIds_SUCCESS() throws SQLException {
public void GetActiveTimsByIds_FAIL() throws SQLException {
// Arrange
String query = "select * from active_tim where active_tim_id in (?, ?)";
doThrow(new SQLException()).when(mockPreparedStatement).setLong(1, -1l);
doThrow(new SQLException()).when(mockPreparedStatement).setLong(1, -1L);

// Act
var response = uut.GetActiveTimsByIds(Arrays.asList(-1l, -2l));
var response = uut.GetActiveTimsByIds(Arrays.asList(-1L, -2L));

// Assert
Assertions.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
Expand Down Expand Up @@ -697,7 +695,7 @@ public void GetActiveTimsByWydotTim_SUCCESS() throws SQLException {
wydotTim.setClientId("clientId");
wydotTim.setDirection("westward");
wydotTims.add(wydotTim);
Long timTypeId = -1l;
Long timTypeId = -1L;
String query = "select * from active_tim where TIM_TYPE_ID = ? and ((CLIENT_ID like ? and DIRECTION = ?))";

// Act
Expand Down Expand Up @@ -735,7 +733,7 @@ public void GetActiveTimsByWydotTim_BothDirections() throws SQLException {
wydotTim.setClientId("clientId");
wydotTim.setDirection("B");
wydotTims.add(wydotTim);
Long timTypeId = -1l;
Long timTypeId = -1L;
String query = "select * from active_tim where TIM_TYPE_ID = ? and ((CLIENT_ID like ?))";

// Act
Expand Down Expand Up @@ -772,7 +770,7 @@ public void GetActiveTimsByWydotTim_FAIL() throws SQLException {
wydotTim.setClientId("clientId");
wydotTim.setDirection("westward");
wydotTims.add(wydotTim);
Long timTypeId = -1l;
Long timTypeId = -1L;
String query = "select * from active_tim where TIM_TYPE_ID = ? and ((CLIENT_ID like ? and DIRECTION = ?))";
doThrow(new SQLException()).when(mockPreparedStatement).setLong(1, timTypeId);

Expand All @@ -790,7 +788,7 @@ public void GetActiveTimsByWydotTim_FAIL() throws SQLException {
@Test
public void GetActivesTimByType_SUCCESS() throws SQLException {
// Arrange
Long timTypeId = -1l;
Long timTypeId = -1L;
String query = "select * from active_tim where TIM_TYPE_ID = " + timTypeId;

// Act
Expand Down Expand Up @@ -822,7 +820,7 @@ public void GetActivesTimByType_SUCCESS() throws SQLException {
@Test
public void GetActivesTimByType_FAIL() throws SQLException {
// Arrange
Long timTypeId = -1l;
Long timTypeId = -1L;
String query = "select * from active_tim where TIM_TYPE_ID = " + timTypeId;
doThrow(new SQLException()).when(mockRs).getLong("ACTIVE_TIM_ID");

Expand Down Expand Up @@ -1189,7 +1187,7 @@ public void ResetExpirationDate_SUCCESS() throws SQLException {
Assertions.assertEquals(HttpStatus.OK, data.getStatusCode());
Assertions.assertTrue(data.getBody(), "Fail return on success");
verify(mockConnection).prepareStatement("UPDATE ACTIVE_TIM SET EXPIRATION_DATE = NULL WHERE ACTIVE_TIM_ID IN (?)");
verify(mockPreparedStatement).setLong(1, -1l);
verify(mockPreparedStatement).setLong(1, -1L);
verify(mockPreparedStatement).close();
verify(mockConnection).close();
}
Expand Down Expand Up @@ -1239,7 +1237,7 @@ public void ResetExpirationDate_FAIL() throws SQLException {
// Arrange
List<Long> activeTimIds = new ArrayList<>();
activeTimIds.add(Long.valueOf(-1));
doThrow(new SQLException()).when(mockPreparedStatement).setLong(1, -1l);
doThrow(new SQLException()).when(mockPreparedStatement).setLong(1, -1L);

// Act
ResponseEntity<Boolean> data = uut.ResetExpirationDate(activeTimIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ public void InjectDependencies(Utility _utility) {
*
* @param wydotTim The WydotTim object containing the data for the TIM.
* @param genProps The TimGenerationProps object containing the generation properties.
* @param content The ContentEnum object representing the content of the TIM.
* @param frameType The TravelerInfoType object representing the frame type of the TIM.
* @param allMileposts The list of Milepost objects representing all mileposts.
* @param reducedMileposts The list of Milepost objects representing reduced mileposts.
* @param anchor The Milepost object representing the anchor milepost.
* @return The WydotTravelerInputData object containing the built TIM.
*/
public WydotTravelerInputData buildTim(WydotTim wydotTim, TimGenerationProps genProps, ContentEnum content,
public WydotTravelerInputData buildTim(WydotTim wydotTim, TimGenerationProps genProps,
TravelerInfoType frameType, List<Milepost> allMileposts, List<Milepost> reducedMileposts, Milepost anchor) {

ContentEnum content = ContentEnum.advisory;

// build TIM object with data
WydotTravelerInputData timToSend = new WydotTravelerInputData();
OdeTravelerInformationMessage tim = new OdeTravelerInformationMessage();
Expand Down Expand Up @@ -195,7 +196,7 @@ protected OdeTravelerInformationMessage.DataFrame.Region buildSingleRegion(BigDe
region.setDirection(directionString); // heading slice

// set path nodes
if (reducedMileposts != null && reducedMileposts.size() > 0) {
if (reducedMileposts != null && !reducedMileposts.isEmpty()) {
OdeTravelerInformationMessage.NodeXY[] nodes = buildNodePathFromMileposts(reducedMileposts, anchor);
OdeTravelerInformationMessage.DataFrame.Region.Path path = new OdeTravelerInformationMessage.DataFrame.Region.Path();
path.setScale(0);
Expand Down Expand Up @@ -243,7 +244,7 @@ public String buildHeadingSliceFromMileposts(List<Milepost> allMileposts, OdePos
int timDirection = 0;
// this is a regular tim, so we need to set the direction normally
// path list - change later
if (allMileposts != null && allMileposts.size() > 0) {
if (allMileposts != null && !allMileposts.isEmpty()) {
double startLat = anchorPosition.getLatitude().doubleValue();
double startLon = anchorPosition.getLongitude().doubleValue();
for (int j = 0; j < allMileposts.size(); j++) {
Expand Down
Loading
Loading