From 031d16cb1fcd9596059ca75fdafc6595e5e9ec7a Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Tue, 5 Nov 2024 11:09:50 -0700 Subject: [PATCH] Cleaned up new tim transmogrifier unit test --- .../ode/traveler/TimTransmogrifierTest.java | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimTransmogrifierTest.java b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimTransmogrifierTest.java index c9acdc0b4..4deaa6f02 100644 --- a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimTransmogrifierTest.java +++ b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimTransmogrifierTest.java @@ -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); @@ -326,10 +316,9 @@ public void testConvertToXML_VerifyPositionElementNotInCircleElementAfterConvers // execute String actualXML = TimTransmogrifier.convertToXml(null, encodableTid, timMetadata, serialId); - // replace with a fixed value for comparison - actualXML = actualXML.replaceFirst(".*", "2024-11-05T16:51:14.473Z"); // verify + actualXML = actualXML.replaceFirst(".*", "2024-11-05T16:51:14.473Z"); // replace 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); }