Skip to content

Commit

Permalink
ODE-1158 Added more unit tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hmusavi committed Mar 12, 2019
1 parent c12ce6f commit c8b38d6
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ public OdeLogMetadata(String payloadType, SerialId serialId, String receivedAt)
super(payloadType, serialId, receivedAt);
}

public void calculateGeneratedBy() {
ReceivedMessageDetails receivedMessageDetails = getReceivedMessageDetails();
if (receivedMessageDetails != null) {
if (receivedMessageDetails.getRxSource() != null) {
switch (receivedMessageDetails.getRxSource()) {
case RSU:
setRecordGeneratedBy(GeneratedBy.RSU);
break;
case RV:
case NA:
setRecordGeneratedBy(GeneratedBy.OBU);
break;
case SAT:
setRecordGeneratedBy(GeneratedBy.TMC_VIA_SAT);
break;
case SNMP:
setRecordGeneratedBy(GeneratedBy.TMC_VIA_SNMP);
break;
default:
setRecordGeneratedBy(GeneratedBy.UNKNOWN);
break;
}
}
} else {
setRecordGeneratedBy(GeneratedBy.OBU);
}
}

public String getLogFileName() {
return logFileName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public enum RxSource {
SAT, // XM satelite
RV, // for BSM rx
SNMP,// for SRM payload from backend/ODE
NA, UNKNOWN
NA, // Not applicable (for example, Distress Notification or Driver Allert
UNKNOWN
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static BigDecimal genericHeading(JsonNode heading) {
}

public static BigDecimal genericHeading(long heading) {
return AngleBuilder.longToDecimal(heading).setScale(4, RoundingMode.HALF_DOWN);
BigDecimal angle = AngleBuilder.longToDecimal(heading);
return (angle == null ? null : angle.setScale(4, RoundingMode.HALF_DOWN));
}

public static BigDecimal genericCoarseHeading(JsonNode coarseHeading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import us.dot.its.jpo.ode.model.OdeLogMetadata;
import us.dot.its.jpo.ode.model.OdeLogMetadata.RecordType;
import us.dot.its.jpo.ode.model.OdeLogMsgMetadataLocation;
import us.dot.its.jpo.ode.model.OdeMsgMetadata.GeneratedBy;
import us.dot.its.jpo.ode.model.ReceivedMessageDetails;
import us.dot.its.jpo.ode.model.RxSource;
import us.dot.its.jpo.ode.plugin.j2735.builders.ElevationBuilder;
Expand Down Expand Up @@ -227,35 +226,9 @@ public void updateMetadata(OdeLogMetadata metadata) {
odeBsmMetadata.setBsmSource(bsmSource);
}

ReceivedMessageDetails receivedMessageDetails = metadata.getReceivedMessageDetails();
if (receivedMessageDetails != null) {
if (receivedMessageDetails.getRxSource() != null) {
switch (receivedMessageDetails.getRxSource()) {
case RSU:
metadata.setRecordGeneratedBy(GeneratedBy.RSU);
break;
case RV:
case NA:
metadata.setRecordGeneratedBy(GeneratedBy.OBU);
break;
case SAT:
metadata.setRecordGeneratedBy(GeneratedBy.TMC_VIA_SAT);
break;
case SNMP:
metadata.setRecordGeneratedBy(GeneratedBy.TMC_VIA_SNMP);
break;
default:
metadata.setRecordGeneratedBy(GeneratedBy.UNKNOWN);
break;
}
} else {
receivedMessageDetails.setRxSource(RxSource.UNKNOWN);
}
} else {
metadata.setRecordGeneratedBy(GeneratedBy.OBU);
}
metadata.calculateGeneratedBy();
}

private static ReceivedMessageDetails buildReceivedMessageDetails(LogFileParser parser) {
LocationParser locationParser = parser.getLocationParser();
ReceivedMessageDetails rxMsgDetails = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws F
status = parseStep(bis, RX_SOURCE_LENGTH);
if (status != ParserStatus.COMPLETE)
return status;
setRxSource(RxSource.values()[readBuffer[0]]);
try {
setRxSource(RxSource.values()[readBuffer[0]]);
} catch (Exception e) {
setRxSource(RxSource.UNKNOWN);
}
}

if (getStep() == 2) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package us.dot.its.jpo.ode.importer.parser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand Down Expand Up @@ -236,6 +237,38 @@ public void testUpdateMetadata_rxMsgBsm() throws FileParserException {
assertEquals(BsmSource.RV, metadata.getBsmSource());
}

@Test
public void testUpdateMetadata_rxMsgTimRSU() throws FileParserException {
byte[] buf = new byte[] {
(byte)0x00, //1. RxSource = RSU
(byte)0x6f, (byte)0x75, (byte)0x4d, (byte)0x19, //2.0 latitude
(byte)0xa4, (byte)0xa1, (byte)0x5c, (byte)0xce, //2.1 longitude
(byte)0x67, (byte)0x06, (byte)0x00, (byte)0x00, //2.3 elevation
(byte)0x04, (byte)0x00, //2.3 speed
(byte)0x09, (byte)0x27, //2.4 heading
(byte)0xa9, (byte)0x2c, (byte)0xe2, (byte)0x5a, //3. utcTimeInSec
(byte)0x8f, (byte)0x01, //4. mSec
(byte)0x00, //5. securityResultCode
(byte)0x06, (byte)0x00, //6.0 payloadLength
//6.1 payload
(byte)0x03, (byte)0x81, (byte)0x00, (byte)0x40, (byte)0x03, (byte)0x80
};

BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf));

RecordType recordType = RecordType.rxMsg;
String filename = recordType.name() + GZ;
RxMsgFileParser parser = (RxMsgFileParser) LogFileParser.factory(filename);
ParserStatus status = parser.parseFile(bis, filename);

OdeLogMetadata metadata = new OdeLogMetadata();
parser.updateMetadata(metadata);

assertEquals(ParserStatus.COMPLETE, status);
assertEquals(GeneratedBy.RSU, metadata.getRecordGeneratedBy());
assertEquals(RxSource.RSU, metadata.getReceivedMessageDetails().getRxSource());
}

@Test
public void testUpdateMetadata_rxMsgTimSAT() throws FileParserException {
byte[] buf = new byte[] {
Expand Down Expand Up @@ -303,7 +336,7 @@ public void testUpdateMetadata_rxMsgTimSNMP() throws FileParserException {
@Test
public void testUpdateMetadata_rxMsgTimUnknownRxSource() throws FileParserException {
byte[] buf = new byte[] {
(byte)0x04, //1. RxSource = unknown value
(byte)0x09, //1. RxSource = unknown value
(byte)0x6f, (byte)0x75, (byte)0x4d, (byte)0x19, //2.0 latitude
(byte)0xa4, (byte)0xa1, (byte)0x5c, (byte)0xce, //2.1 longitude
(byte)0x67, (byte)0x06, (byte)0x00, (byte)0x00, //2.3 elevation
Expand All @@ -328,8 +361,77 @@ public void testUpdateMetadata_rxMsgTimUnknownRxSource() throws FileParserExcept
parser.updateMetadata(metadata);

assertEquals(ParserStatus.COMPLETE, status);
assertEquals(GeneratedBy.OBU, metadata.getRecordGeneratedBy());
assertEquals(RxSource.NA, metadata.getReceivedMessageDetails().getRxSource());
assertEquals(GeneratedBy.UNKNOWN, metadata.getRecordGeneratedBy());
assertEquals(RxSource.UNKNOWN, metadata.getReceivedMessageDetails().getRxSource());
}

@Test
public void testUpdateMetadata_rxMsgTimNullLocations() throws FileParserException {
byte[] buf = new byte[] {
(byte)0x09, //1. RxSource = unknown value
(byte)0x01, (byte)0xE9, (byte)0xA4, (byte)0x35, //2.0 latitude unavailable
(byte)0x01, (byte)0xD2, (byte)0x49, (byte)0x6B, //2.1 longitude unavailable
(byte)0x00, (byte)0xF0, (byte)0xFF, (byte)0xFF, //2.3 elevation unavailable
(byte)0xFF, (byte)0x1F, //2.3 speed unavailable
(byte)0x80, (byte)0x70, //2.4 heading unavailable
(byte)0xa9, (byte)0x2c, (byte)0xe2, (byte)0x5a, //3. utcTimeInSec
(byte)0x8f, (byte)0x01, //4. mSec
(byte)0x00, //5. securityResultCode
(byte)0x06, (byte)0x00, //6.0 payloadLength
//6.1 payload
(byte)0x03, (byte)0x81, (byte)0x00, (byte)0x40, (byte)0x03, (byte)0x80
};

BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf));

RecordType recordType = RecordType.rxMsg;
String filename = recordType.name() + GZ;
RxMsgFileParser parser = (RxMsgFileParser) LogFileParser.factory(filename);
ParserStatus status = parser.parseFile(bis, filename);

OdeLogMetadata metadata = new OdeLogMetadata();
parser.updateMetadata(metadata);

assertEquals(ParserStatus.COMPLETE, status);
assertEquals(GeneratedBy.UNKNOWN, metadata.getRecordGeneratedBy());
assertEquals(RxSource.UNKNOWN, metadata.getReceivedMessageDetails().getRxSource());
assertNull(metadata.getReceivedMessageDetails().getLocationData().getElevation());
assertNull(metadata.getReceivedMessageDetails().getLocationData().getHeading());
assertNull(metadata.getReceivedMessageDetails().getLocationData().getLatitude());
assertNull(metadata.getReceivedMessageDetails().getLocationData().getLongitude());
assertNull(metadata.getReceivedMessageDetails().getLocationData().getSpeed());
}

@Test
public void testUpdateMetadata_rxMsgNullReceivedMessageDetails() throws FileParserException {
byte[] buf = new byte[] {
(byte)0x09, //1. RxSource = unknown value
(byte)0x01, (byte)0xE9, (byte)0xA4, (byte)0x35, //2.0 latitude unavailable
(byte)0x01, (byte)0xD2, (byte)0x49, (byte)0x6B, //2.1 longitude unavailable
(byte)0x00, (byte)0xF0, (byte)0xFF, (byte)0xFF, //2.3 elevation unavailable
(byte)0xFF, (byte)0x1F, //2.3 speed unavailable
(byte)0x80, (byte)0x70, //2.4 heading unavailable
(byte)0xa9, (byte)0x2c, (byte)0xe2, (byte)0x5a, //3. utcTimeInSec
(byte)0x8f, (byte)0x01, //4. mSec
(byte)0x00, //5. securityResultCode
(byte)0x06, (byte)0x00, //6.0 payloadLength
//6.1 payload
(byte)0x03, (byte)0x81, (byte)0x00, (byte)0x40, (byte)0x03, (byte)0x80
};

BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf));

RecordType recordType = RecordType.rxMsg;
String filename = recordType.name() + GZ;
RxMsgFileParser parser = (RxMsgFileParser) LogFileParser.factory(filename);
ParserStatus status = parser.parseFile(bis, filename);
parser.setLocationParser(null);

OdeLogMetadata metadata = new OdeLogMetadata();
parser.updateMetadata(metadata);

assertEquals(ParserStatus.COMPLETE, status);
assertEquals(GeneratedBy.OBU, metadata.getRecordGeneratedBy());
assertNull(metadata.getReceivedMessageDetails());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,23 @@ public void testStep0() {
}
}

@Test
public void testSetRxSource() {
RxMsgFileParser parser = new RxMsgFileParser();

parser.setRxSource(0);
assertEquals(RxSource.RSU, parser.getRxSource());
parser.setRxSource(1);
assertEquals(RxSource.SAT, parser.getRxSource());
parser.setRxSource(2);
assertEquals(RxSource.RV, parser.getRxSource());
parser.setRxSource(3);
assertEquals(RxSource.SNMP, parser.getRxSource());
parser.setRxSource(4);
assertEquals(RxSource.NA, parser.getRxSource());
parser.setRxSource(5);
assertEquals(RxSource.UNKNOWN, parser.getRxSource());
parser.setRxSource(6);
assertEquals(RxSource.UNKNOWN, parser.getRxSource());
}
}

0 comments on commit c8b38d6

Please sign in to comment.