Skip to content

Commit

Permalink
Cleaned up new tim transmogrifier unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dmccoystephenson committed Nov 5, 2024
1 parent a62ac30 commit 031d16c
Showing 1 changed file with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,33 +288,23 @@ public void testConvertToXML_VerifyPositionElementNotInCircleElementAfterConvers
String timRequestContainingCircleGeometry = new String(Files.readAllBytes(Paths.get("src/test/resources/us/dot/its/jpo/ode/traveler/timRequestContainingCircleGeometry.json")));
OdeTravelerInputData odeTID = (OdeTravelerInputData) JsonUtils.jacksonFromJson(timRequestContainingCircleGeometry, OdeTravelerInputData.class, true);
ServiceRequest request = odeTID.getRequest();
if (request.getOde() == null) {
request.setOde(new ServiceRequest.OdeInternal());
}
request.setOde(new ServiceRequest.OdeInternal());
request.getOde().setVerb(ServiceRequest.OdeInternal.RequestVerb.PUT);
OdeTravelerInformationMessage tim = odeTID.getTim();
OdeMsgPayload timDataPayload = new OdeMsgPayload(tim);
OdeRequestMsgMetadata timMetadata = new OdeRequestMsgMetadata(timDataPayload, request);
timMetadata.setOdePacketID(tim.getPacketID());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
if (null != tim.getDataframes() && tim.getDataframes().length > 0) {
int maxDurationTime = 0;
Date latestStartDateTime = null;
for (OdeTravelerInformationMessage.DataFrame dataFrameItem : tim.getDataframes()) {
maxDurationTime = maxDurationTime > dataFrameItem.getDurationTime() ? maxDurationTime
: dataFrameItem.getDurationTime();
try {
latestStartDateTime = (latestStartDateTime == null || (latestStartDateTime != null
&& latestStartDateTime.before(dateFormat.parse(dataFrameItem.getStartDateTime())))
? dateFormat.parse(dataFrameItem.getStartDateTime())
: latestStartDateTime);
} catch (ParseException e) {
// logger.error("Invalid dateTime parse: " + e);
}
}
timMetadata.setMaxDurationTime(maxDurationTime);
timMetadata.setOdeTimStartDateTime(dateFormat.format(latestStartDateTime));
int maxDurationTime = 0;
Date latestStartDateTime = null;
for (OdeTravelerInformationMessage.DataFrame dataFrameItem : tim.getDataframes()) {
maxDurationTime = Math.max(maxDurationTime, dataFrameItem.getDurationTime());
latestStartDateTime = latestStartDateTime == null || latestStartDateTime.before(dateFormat.parse(dataFrameItem.getStartDateTime()))
? dateFormat.parse(dataFrameItem.getStartDateTime())
: latestStartDateTime;
}
timMetadata.setMaxDurationTime(maxDurationTime);
timMetadata.setOdeTimStartDateTime(dateFormat.format(latestStartDateTime));
SerialId serialId = new SerialId();
serialId.setStreamId("testStreamId");
timMetadata.setSerialId(serialId);
Expand All @@ -326,10 +316,9 @@ public void testConvertToXML_VerifyPositionElementNotInCircleElementAfterConvers

// execute
String actualXML = TimTransmogrifier.convertToXml(null, encodableTid, timMetadata, serialId);
// replace <odeReceivedAt> with a fixed value for comparison
actualXML = actualXML.replaceFirst("<odeReceivedAt>.*</odeReceivedAt>", "<odeReceivedAt>2024-11-05T16:51:14.473Z</odeReceivedAt>");

// verify
actualXML = actualXML.replaceFirst("<odeReceivedAt>.*</odeReceivedAt>", "<odeReceivedAt>2024-11-05T16:51:14.473Z</odeReceivedAt>"); // replace <odeReceivedAt> with a fixed value for comparison
String expectedXml = new String(Files.readAllBytes(Paths.get("src/test/resources/us/dot/its/jpo/ode/traveler/aemInputContainingCircleGeometry.xml")));
Assertions.assertEquals(expectedXml, actualXML);
}
Expand Down

0 comments on commit 031d16c

Please sign in to comment.