diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..9545c8368 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic", + "java.test.config": { + "name": "testConfig", + "vmArgs": ["-javaagent:/root/.m2/repository/org/jmockit/jmockit/1.49/jmockit-1.49.jar"] + }, + "java.test.defaultConfig": "testConfig" +} \ No newline at end of file diff --git a/jpo-ode-common/src/main/java/us/dot/its/jpo/ode/util/JsonUtils.java b/jpo-ode-common/src/main/java/us/dot/its/jpo/ode/util/JsonUtils.java index 1b77fa493..7979f7dc8 100644 --- a/jpo-ode-common/src/main/java/us/dot/its/jpo/ode/util/JsonUtils.java +++ b/jpo-ode-common/src/main/java/us/dot/its/jpo/ode/util/JsonUtils.java @@ -25,16 +25,20 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.cfg.CoercionAction; +import com.fasterxml.jackson.databind.cfg.CoercionInputShape; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import com.fasterxml.jackson.databind.type.LogicalType; public class JsonUtils { - + public static class JsonUtilsException extends Exception { private static final long serialVersionUID = 1L; @@ -45,9 +49,8 @@ public JsonUtilsException(String string, Exception e) { } - private static Gson gsonCompact; - private static Gson gsonVerbose; private static ObjectMapper mapper; + private static ObjectMapper mapper_noNulls; private static Logger logger; private JsonUtils() { @@ -55,22 +58,36 @@ private JsonUtils() { } static { - gsonCompact = new GsonBuilder().create(); - gsonVerbose = new GsonBuilder().serializeNulls().create(); mapper = new ObjectMapper(); + mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + mapper.coercionConfigFor(LogicalType.Enum) + .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull); + + mapper_noNulls = new ObjectMapper(); + mapper_noNulls.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + mapper_noNulls.setSerializationInclusion(Include.NON_NULL); } public static String toJson(Object o, boolean verbose) { - // convert java object to JSON format, // and returned as JSON formatted string - return verbose ? gsonVerbose.toJson(o) : gsonCompact.toJson(o); + try { + return verbose ? mapper.writeValueAsString(o) : mapper_noNulls.writeValueAsString(o); + } catch (JsonProcessingException e) { + e.printStackTrace(); + return ""; + } } public static Object fromJson(String s, Class clazz) { - return gsonCompact.fromJson(s, clazz); + try { + return jacksonFromJson(s, clazz); + } catch (JsonUtilsException e) { + e.printStackTrace(); + return null; + } } - + public static Object jacksonFromJson(String s, Class clazz) throws JsonUtilsException { try { return mapper.readValue(s, clazz); @@ -86,7 +103,7 @@ public static String newJson(String key, Object value) { public static ObjectNode cloneObjectNode(ObjectNode src) { return src.deepCopy(); } - + public static ObjectNode newObjectNode(String key, Object value) { ObjectNode json = mapper.createObjectNode(); json.putPOJO(key, value); @@ -155,7 +172,7 @@ public static HashMap jsonNodeToHashMap(JsonNode jsonNode) { } return nodeProps; } - + /** * Takes in a key, value pair and returns a valid JSON string such as * {"error":"message"} @@ -167,14 +184,14 @@ public static HashMap jsonNodeToHashMap(JsonNode jsonNode) { public static String jsonKeyValue(String key, String value) { return "{\"" + key + "\":\"" + value + "\"}"; } - + public static BigDecimal decimalValue(JsonNode v) { - BigDecimal result; - if (v.isTextual()) { - result = new BigDecimal(v.textValue()); - } else { - result = v.decimalValue(); - } - return result; + BigDecimal result; + if (v.isTextual()) { + result = new BigDecimal(v.textValue()); + } else { + result = v.decimalValue(); + } + return result; } } diff --git a/jpo-ode-common/src/test/java/us/dot/its/jpo/ode/inet/InetPacketTest.java b/jpo-ode-common/src/test/java/us/dot/its/jpo/ode/inet/InetPacketTest.java index e555d05ce..0ff31a480 100644 --- a/jpo-ode-common/src/test/java/us/dot/its/jpo/ode/inet/InetPacketTest.java +++ b/jpo-ode-common/src/test/java/us/dot/its/jpo/ode/inet/InetPacketTest.java @@ -16,18 +16,15 @@ package us.dot.its.jpo.ode.inet; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.net.DatagramPacket; -import java.net.DatagramSocket; import java.net.InetAddress; import java.net.UnknownHostException; import org.junit.Before; import org.junit.Test; -import mockit.Capturing; import mockit.Expectations; import mockit.Mock; import mockit.MockUp; @@ -41,14 +38,13 @@ public class InetPacketTest { DatagramPacket mockDatagramPacket; byte[] mockPayload; - @Mocked InetAddress address; + @Mocked InetAddress mockAddress; @Before public void setup() { new MockUp() { - @Mock - public InetAddress getByName(String host) { - return address; + @Mock InetAddress getByName(String host) { + return mockAddress; } }; } @@ -87,7 +83,7 @@ public void testByteConstructor() { */ @Test - public void parseBundleNulll() { + public void parseBundleNull() { InetPacket testPacket = new InetPacket(new byte[] { 1, 2, 3 }); byte[] bundle = null; diff --git a/jpo-ode-common/src/test/java/us/dot/its/jpo/ode/util/JsonUtilsTest.java b/jpo-ode-common/src/test/java/us/dot/its/jpo/ode/util/JsonUtilsTest.java index 28ad2c3db..5487aacb4 100644 --- a/jpo-ode-common/src/test/java/us/dot/its/jpo/ode/util/JsonUtilsTest.java +++ b/jpo-ode-common/src/test/java/us/dot/its/jpo/ode/util/JsonUtilsTest.java @@ -120,21 +120,21 @@ public void testToJson() { @Test public void testNewJson() { String j = JsonUtils.newJson("key", "value"); - assertEquals("{\"key\":value}", j); + assertEquals("{\"key\":\"value\"}", j); } @Test public void testNewObjectNode() { ObjectNode j = JsonUtils.newObjectNode("key", "value"); - assertEquals("{\"key\":value}", j.toString()); + assertEquals("{\"key\":\"value\"}", j.toString()); } @Test public void testAddNode() { ObjectNode j = JsonUtils.newObjectNode("key", "value"); ObjectNode j2 = JsonUtils.addNode(j, "key2", "value2"); - assertEquals("{\"key\":value,\"key2\":value2}", j.toString()); - assertEquals("{\"key\":value,\"key2\":value2}", j2.toString()); + assertEquals("{\"key\":\"value\",\"key2\":\"value2\"}", j.toString()); + assertEquals("{\"key\":\"value\",\"key2\":\"value2\"}", j2.toString()); } @Test @@ -157,7 +157,7 @@ public void testToObjectNode() throws JsonUtilsException { assertEquals(expectedOvdf, ovdf.toString()); JsonUtils.addNode(ovdf, "avgSpeed", "2.22"); assertEquals( - "{\"className\":\"com.bah.ode.model.OdeVehicleDataFlat\",\"serialId\":\"10817812-036b-4d7b-867b-ae0bc62a2b3e.0\",\"receivedAt\":\"2015-07-22T19:21:16.413+0000\",\"groupId\":\"4130008F\",\"accelLong\":0.34,\"accelVert\":0.0,\"accellYaw\":8.42,\"heading\":65.95,\"speed\":8.12,\"sizeLength\":500,\"sizeWidth\":200,\"latitude\":42.3296667,\"longitude\":-83.044539,\"elevation\":156.9,\"tempId\":\"C4290123\",\"year\":2015,\"month\":5,\"day\":13,\"hour\":15,\"minute\":52,\"second\":45.5,\"dateTime\":\"2015-06-13T19:52:45.500+0000\",\"avgSpeed\":2.22}", + "{\"className\":\"com.bah.ode.model.OdeVehicleDataFlat\",\"serialId\":\"10817812-036b-4d7b-867b-ae0bc62a2b3e.0\",\"receivedAt\":\"2015-07-22T19:21:16.413+0000\",\"groupId\":\"4130008F\",\"accelLong\":0.34,\"accelVert\":0.0,\"accellYaw\":8.42,\"heading\":65.95,\"speed\":8.12,\"sizeLength\":500,\"sizeWidth\":200,\"latitude\":42.3296667,\"longitude\":-83.044539,\"elevation\":156.9,\"tempId\":\"C4290123\",\"year\":2015,\"month\":5,\"day\":13,\"hour\":15,\"minute\":52,\"second\":45.5,\"dateTime\":\"2015-06-13T19:52:45.500+0000\",\"avgSpeed\":\"2.22\"}", ovdf.toString()); } @@ -201,7 +201,7 @@ public void testPutObject() { ObjectNode dm = JsonUtils.newNode(); dm.putObject("metadata"); dm.putObject("payload").setAll(JsonUtils.newObjectNode("key1", "value1")); - assertEquals("{\"metadata\":{},\"payload\":{\"key1\":value1}}", dm.toString()); + assertEquals("{\"metadata\":{},\"payload\":{\"key1\":\"value1\"}}", dm.toString()); } } diff --git a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/dds/DdsDepRequest.java b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/dds/DdsDepRequest.java index d47658251..8eeb712ed 100644 --- a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/dds/DdsDepRequest.java +++ b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/dds/DdsDepRequest.java @@ -15,11 +15,14 @@ ******************************************************************************/ package us.dot.its.jpo.ode.dds; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; /** - * "DEPOSIT: { \"systemDepositName\": \"%s\", \"encodeType\": \"%s\", \"encodedMsg\": \"%s\" }" + * "DEPOSIT: { \"systemDepositName\": \"%s\", \"encodeType\": \"%s\", + * \"encodedMsg\": \"%s\" }" * */ +@JsonPropertyOrder({ "systemDepositName", "encodeType", "encodedMsg" }) public class DdsDepRequest extends DdsRequest { private static final long serialVersionUID = 6066887685895268828L; @@ -28,7 +31,6 @@ public class DdsDepRequest extends DdsRequest { private String encodeType; private String encodedMsg; - public String getSystemDepositName() { return systemDepositName; } diff --git a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeAsdPayload.java b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeAsdPayload.java index be6e575ac..a2b9355c3 100644 --- a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeAsdPayload.java +++ b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeAsdPayload.java @@ -18,24 +18,14 @@ import us.dot.its.jpo.ode.plugin.j2735.DdsAdvisorySituationData; public class OdeAsdPayload extends OdeMsgPayload { - - private static final long serialVersionUID = 7061315628111448390L; - public OdeAsdPayload() { - this(new DdsAdvisorySituationData()); - } + private static final long serialVersionUID = 7061315628111448390L; - public OdeAsdPayload(DdsAdvisorySituationData asd) { - super(asd); - this.setData(asd); - } - - public DdsAdvisorySituationData getAsd() { - return (DdsAdvisorySituationData) getData(); - } - - public void setAsd(DdsAdvisorySituationData asd) { - setData(asd); - } + public OdeAsdPayload() { + this(new DdsAdvisorySituationData()); + } + public OdeAsdPayload(DdsAdvisorySituationData asd) { + super(asd); + } } diff --git a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeBsmMetadata.java b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeBsmMetadata.java index 2fe6dec92..3c5c0f92e 100644 --- a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeBsmMetadata.java +++ b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeBsmMetadata.java @@ -15,43 +15,48 @@ ******************************************************************************/ package us.dot.its.jpo.ode.model; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonPropertyOrder({ "bsmSource", "logFileName", "recordType", "securityResultCode", "receivedMessageDetails", + "encodings", "payloadType", "serialId", "odeReceivedAt", "schemaVersion", "maxDurationTime", "recordGeneratedAt", + "recordGeneratedBy", "sanitized" }) public class OdeBsmMetadata extends OdeLogMetadata { - private static final long serialVersionUID = -8601265839394150140L; + private static final long serialVersionUID = -8601265839394150140L; + + private String originIp; + + public enum BsmSource { + EV, RV, unknown + } - private String originIp; + private BsmSource bsmSource; - public enum BsmSource { - EV, RV, unknown - } + public OdeBsmMetadata() { + super(); + } - private BsmSource bsmSource; - - public OdeBsmMetadata() { - super(); - } + public OdeBsmMetadata(OdeMsgPayload payload) { + super(payload); + } - public OdeBsmMetadata(OdeMsgPayload payload) { - super(payload); - } + public OdeBsmMetadata(OdeMsgPayload payload, SerialId serialId, String receivedAt) { - public OdeBsmMetadata(OdeMsgPayload payload, SerialId serialId, String receivedAt) { - - } + } - public BsmSource getBsmSource() { - return bsmSource; - } + public BsmSource getBsmSource() { + return bsmSource; + } - public void setBsmSource(BsmSource bsmSource) { - this.bsmSource = bsmSource; - } + public void setBsmSource(BsmSource bsmSource) { + this.bsmSource = bsmSource; + } - public String getOriginIp() { - return originIp; - } + public String getOriginIp() { + return originIp; + } - public void setOriginIp(String originIp) { - this.originIp = originIp; - } + public void setOriginIp(String originIp) { + this.originIp = originIp; + } } diff --git a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeData.java b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeData.java index 3f0732dec..a00dadcd2 100644 --- a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeData.java +++ b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeData.java @@ -15,6 +15,9 @@ ******************************************************************************/ package us.dot.its.jpo.ode.model; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonPropertyOrder({ "metadata", "payload" }) public class OdeData extends OdeObject implements OdeFilterable { private static final long serialVersionUID = -7711340868799607662L; diff --git a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeLogMetadata.java b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeLogMetadata.java index 90f93f973..ffa206a34 100644 --- a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeLogMetadata.java +++ b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeLogMetadata.java @@ -18,6 +18,11 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonPropertyOrder({ "logFileName", "recordType", "securityResultCode", "receivedMessageDetails", "longitude", + "elevation", "speed", "heading", "rxSource", "encodings", "payloadType", "serialId", "odeReceivedAt", + "schemaVersion", "maxDurationTime", "recordGeneratedAt", "recordGeneratedBy", "sanitized" }) public class OdeLogMetadata extends OdeMsgMetadata { private static final long serialVersionUID = -8601265839394150140L; @@ -84,33 +89,33 @@ public OdeLogMetadata(String payloadType, SerialId serialId, String 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; + 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); - } + } else { + setRecordGeneratedBy(GeneratedBy.OBU); + } } - + public String getLogFileName() { return logFileName; } diff --git a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeMsgMetadata.java b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeMsgMetadata.java index 768865a57..4590491e9 100644 --- a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeMsgMetadata.java +++ b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeMsgMetadata.java @@ -15,8 +15,12 @@ ******************************************************************************/ package us.dot.its.jpo.ode.model; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + import us.dot.its.jpo.ode.util.DateTimeUtils; +@JsonPropertyOrder({ "logFileName", "recordType", "receivedMessageDetails", "payloadType", "serialId", + "odeReceivedAt", "schemaVersion", "maxDurationTime", "recordGeneratedAt", "recordGeneratedBy", "sanitized" }) public class OdeMsgMetadata extends OdeObject { public enum GeneratedBy { @@ -31,9 +35,9 @@ public enum GeneratedBy { private SerialId serialId; private String odeReceivedAt; private int schemaVersion; - private int maxDurationTime; - private String odePacketID; - private String odeTimStartDateTime; + private int maxDurationTime; + private String odePacketID; + private String odeTimStartDateTime; private String recordGeneratedAt; private GeneratedBy recordGeneratedBy; private boolean sanitized = false; @@ -95,33 +99,32 @@ public int getSchemaVersion() { public void setSchemaVersion(int aSchemaVersion) { schemaVersion = aSchemaVersion; } -public int getMaxDurationTime() { - return maxDurationTime; - } - public void setMaxDurationTime(int maxDurationTime) { - this.maxDurationTime = maxDurationTime; - } + public int getMaxDurationTime() { + return maxDurationTime; + } - public String getOdePacketID() { - return odePacketID; - } + public void setMaxDurationTime(int maxDurationTime) { + this.maxDurationTime = maxDurationTime; + } - public void setOdePacketID(String odePacketID) { - this.odePacketID = odePacketID; - } + public String getOdePacketID() { + return odePacketID; + } - + public void setOdePacketID(String odePacketID) { + this.odePacketID = odePacketID; + } - public String getOdeTimStartDateTime() { - return odeTimStartDateTime; - } + public String getOdeTimStartDateTime() { + return odeTimStartDateTime; + } - public void setOdeTimStartDateTime(String odeTimStartDateTime) { - this.odeTimStartDateTime = odeTimStartDateTime; - } + public void setOdeTimStartDateTime(String odeTimStartDateTime) { + this.odeTimStartDateTime = odeTimStartDateTime; + } -public String getRecordGeneratedAt() { + public String getRecordGeneratedAt() { return recordGeneratedAt; } @@ -145,7 +148,6 @@ public void setSanitized(boolean sanitized) { this.sanitized = sanitized; } - public static int getStaticSchemaVersion() { return staticSchemaVersion; } diff --git a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeTimPayload.java b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeTimPayload.java index b3ecd5565..b5e9e0e7b 100644 --- a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeTimPayload.java +++ b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/model/OdeTimPayload.java @@ -18,24 +18,15 @@ import us.dot.its.jpo.ode.plugin.j2735.OdeTravelerInformationMessage; public class OdeTimPayload extends OdeMsgPayload { - - private static final long serialVersionUID = 7061315628111448390L; - public OdeTimPayload() { - this(new OdeTravelerInformationMessage()); - } + private static final long serialVersionUID = 7061315628111448390L; - public OdeTimPayload(OdeTravelerInformationMessage tim) { - super(tim); - this.setData(tim); - } - - public OdeTravelerInformationMessage getTim() { - return (OdeTravelerInformationMessage) getData(); - } - - public void setTim(OdeTravelerInformationMessage tim) { - setData(tim); - } + public OdeTimPayload() { + this(new OdeTravelerInformationMessage()); + } + public OdeTimPayload(OdeTravelerInformationMessage tim) { + super(tim); + this.setData(tim); + } } diff --git a/jpo-ode-core/src/test/java/us/dot/its/jpo/ode/dds/DdsDepRequestTest.java b/jpo-ode-core/src/test/java/us/dot/its/jpo/ode/dds/DdsDepRequestTest.java index 256225340..5989cb514 100644 --- a/jpo-ode-core/src/test/java/us/dot/its/jpo/ode/dds/DdsDepRequestTest.java +++ b/jpo-ode-core/src/test/java/us/dot/its/jpo/ode/dds/DdsDepRequestTest.java @@ -57,7 +57,7 @@ public void testToString() { ddsDepRequest.setEncodeType(encodeType); ddsDepRequest.setSystemDepositName(depositName); String expectedStr = "DEPOSIT:{\"systemDepositName\":\"testDepositName\",\"encodeType\":\"hex\",\"dialogID\":0}"; - assertEquals(ddsDepRequest.toString(), expectedStr); + assertEquals(expectedStr, ddsDepRequest.toString()); } @Test diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/ieee1609dot2/Ieee1609Dot2DataTag.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/ieee1609dot2/Ieee1609Dot2DataTag.java index 90aad2018..a9027240b 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/ieee1609dot2/Ieee1609Dot2DataTag.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/ieee1609dot2/Ieee1609Dot2DataTag.java @@ -15,6 +15,8 @@ ******************************************************************************/ package us.dot.its.jpo.ode.plugin.ieee1609dot2; +import com.fasterxml.jackson.annotation.JsonProperty; + import us.dot.its.jpo.ode.plugin.asn1.Asn1Object; public class Ieee1609Dot2DataTag extends Asn1Object { @@ -23,6 +25,7 @@ public class Ieee1609Dot2DataTag extends Asn1Object { private Ieee1609Dot2Data Ieee1609Dot2Data; + @JsonProperty("Ieee1609Dot2Data") public Ieee1609Dot2Data getIeee1609Dot2Data() { return Ieee1609Dot2Data; } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/DsrcPosition3D.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/DsrcPosition3D.java index ece4a60f0..2bd069564 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/DsrcPosition3D.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/DsrcPosition3D.java @@ -15,18 +15,16 @@ ******************************************************************************/ package us.dot.its.jpo.ode.plugin.j2735; -import com.google.gson.annotations.SerializedName; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import us.dot.its.jpo.ode.plugin.asn1.Asn1Object; +@JsonPropertyOrder({ "lat", "long", "elevation" }) public class DsrcPosition3D extends Asn1Object { private static final long serialVersionUID = 1L; - - @SerializedName("lat") - private Long lat; // in degrees - @SerializedName("long") - private Long _long; // in degrees - @SerializedName("elevation") + private Long latitude; // in degrees + private Long longitude; // in degrees private Long elevation; // in meters public DsrcPosition3D() { @@ -35,27 +33,30 @@ public DsrcPosition3D() { public DsrcPosition3D(Long latitude, Long longitude, Long elevation) { super(); - this.lat = latitude; - this._long = longitude; + this.latitude = latitude; + this.longitude = longitude; this.elevation = elevation; } + @JsonProperty("lat") public Long getLatitude() { - return lat; + return latitude; } public void setLatitude(Long latitude) { - this.lat = latitude; + this.latitude = latitude; } + @JsonProperty("long") public Long getLongitude() { - return _long; + return longitude; } public void setLongitude(Long longitude) { - this._long = longitude; + this.longitude = longitude; } + @JsonProperty("elevation") public Long getElevation() { return elevation; } @@ -68,9 +69,9 @@ public void setElevation(Long elevation) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((_long == null) ? 0 : _long.hashCode()); + result = prime * result + ((longitude == null) ? 0 : longitude.hashCode()); result = prime * result + ((elevation == null) ? 0 : elevation.hashCode()); - result = prime * result + ((lat == null) ? 0 : lat.hashCode()); + result = prime * result + ((latitude == null) ? 0 : latitude.hashCode()); return result; } @@ -83,20 +84,20 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; DsrcPosition3D other = (DsrcPosition3D) obj; - if (_long == null) { - if (other._long != null) + if (longitude == null) { + if (other.longitude != null) return false; - } else if (!_long.equals(other._long)) + } else if (!longitude.equals(other.longitude)) return false; if (elevation == null) { if (other.elevation != null) return false; } else if (!elevation.equals(other.elevation)) return false; - if (lat == null) { - if (other.lat != null) + if (latitude == null) { + if (other.latitude != null) return false; - } else if (!lat.equals(other.lat)) + } else if (!latitude.equals(other.latitude)) return false; return true; } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735IntersectionGeometryList.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735IntersectionGeometryList.java index e81e17402..21b388786 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735IntersectionGeometryList.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735IntersectionGeometryList.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + import us.dot.its.jpo.ode.plugin.asn1.Asn1Object; public class J2735IntersectionGeometryList extends Asn1Object { @@ -12,11 +14,14 @@ public class J2735IntersectionGeometryList extends Asn1Object { */ private static final long serialVersionUID = 1L; private List intersectionGeometry = new ArrayList<>(); + + @JsonProperty("intersectionGeometry") public List getIntersections() { return intersectionGeometry; } + public void setIntersections(List intersectionGeometry) { this.intersectionGeometry = intersectionGeometry; } - + } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735LaneList.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735LaneList.java index 1e9780a86..6fc1ab2e2 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735LaneList.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735LaneList.java @@ -3,12 +3,15 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + import us.dot.its.jpo.ode.plugin.asn1.Asn1Object; public class J2735LaneList extends Asn1Object { private static final long serialVersionUID = 1L; private List GenericLane = new ArrayList<>(); + @JsonProperty("GenericLane") public List getLaneSet() { return GenericLane; } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735NodeListXY.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735NodeListXY.java index f2c91315b..9be72df3d 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735NodeListXY.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735NodeListXY.java @@ -1,5 +1,7 @@ package us.dot.its.jpo.ode.plugin.j2735; +import com.fasterxml.jackson.annotation.JsonProperty; + import us.dot.its.jpo.ode.plugin.asn1.Asn1Object; public class J2735NodeListXY extends Asn1Object { @@ -10,6 +12,7 @@ public class J2735NodeListXY extends Asn1Object { private J2735NodeSetXY nodes; private J2735ComputedLane computed; + @JsonProperty("nodes") public J2735NodeSetXY getNodes() { return nodes; } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735NodeSetXY.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735NodeSetXY.java index 8b412e5f1..536814d54 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735NodeSetXY.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735NodeSetXY.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + import us.dot.its.jpo.ode.plugin.asn1.Asn1Object; public class J2735NodeSetXY extends Asn1Object { @@ -11,6 +13,8 @@ public class J2735NodeSetXY extends Asn1Object { */ private static final long serialVersionUID = 1L; private List NodeXY = new ArrayList<>(); + + @JsonProperty("NodeXY") public List getNodes() { return NodeXY; } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalRequestList.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalRequestList.java index da0b45270..d04a54182 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalRequestList.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalRequestList.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + import us.dot.its.jpo.ode.plugin.asn1.Asn1Object; public class J2735SignalRequestList extends Asn1Object { @@ -10,6 +12,7 @@ public class J2735SignalRequestList extends Asn1Object { private static final long serialVersionUID = 1L; private List signalRequestPackage = new ArrayList<>(); + @JsonProperty("signalRequestPackage") public List getRequests() { return signalRequestPackage; } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalStatusList.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalStatusList.java index 2f3222f84..07af7772b 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalStatusList.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalStatusList.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + import us.dot.its.jpo.ode.plugin.asn1.Asn1Object; public class J2735SignalStatusList extends Asn1Object { @@ -10,6 +12,7 @@ public class J2735SignalStatusList extends Asn1Object { private static final long serialVersionUID = 1L; private List signalStatus = new ArrayList<>(); + @JsonProperty("signalStatus") public List getStatus() { return signalStatus; } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalStatusPackageList.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalStatusPackageList.java index 771742655..4c3747d4a 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalStatusPackageList.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/J2735SignalStatusPackageList.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + import us.dot.its.jpo.ode.plugin.asn1.Asn1Object; public class J2735SignalStatusPackageList extends Asn1Object { @@ -10,6 +12,7 @@ public class J2735SignalStatusPackageList extends Asn1Object { private static final long serialVersionUID = 1L; private List signalStatusPackage = new ArrayList<>(); + @JsonProperty("signalStatusPackage") public List getSigStatus() { return signalStatusPackage; } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/PivotPointDescriptionBuilder.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/PivotPointDescriptionBuilder.java index 9bd2a0238..4a01d0379 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/PivotPointDescriptionBuilder.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/PivotPointDescriptionBuilder.java @@ -34,13 +34,13 @@ private PivotPointDescriptionBuilder() { public static J2735PivotPointDescription genericPivotPointDescription(JsonNode ppd) { J2735PivotPointDescription gppd = new J2735PivotPointDescription(); - if (ppd.get(PIVOT_OFFSET).intValue() < PIVOT_OFFSET_LOWER_BOUND - || ppd.get(PIVOT_OFFSET).intValue() > PIVOT_OFFSET_UPPER_BOUND) { + if (ppd.get(PIVOT_OFFSET).asInt() < PIVOT_OFFSET_LOWER_BOUND + || ppd.get(PIVOT_OFFSET).asInt() > PIVOT_OFFSET_UPPER_BOUND) { throw new IllegalArgumentException("Pivot offset value out of bounds [-1024.1023]"); - } else if (ppd.get(PIVOT_OFFSET).intValue() == -1024) { + } else if (ppd.get(PIVOT_OFFSET).asInt() == -1024) { gppd.setPivotOffset(null); } else { - gppd.setPivotOffset(BigDecimal.valueOf(ppd.get(PIVOT_OFFSET).intValue(), 2)); + gppd.setPivotOffset(BigDecimal.valueOf(ppd.get(PIVOT_OFFSET).asInt(), 2)); } gppd.setPivotAngle(AngleBuilder.genericAngle(ppd.get("pivotAngle"))); diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverter.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverter.java index a1406f0ac..03035ccef 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverter.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverter.java @@ -40,90 +40,90 @@ public class TravelerMessageFromHumanToAsnConverter { - private static final String SPEED = "speed"; - private static final String TYPE = "type"; - private static final String ATTRIBUTES = "attributes"; - public static final String TRAVELER_INFORMATION = "TravelerInformation"; - private static final String EXTENT = "extent"; - private static final String UNITS = "units"; - private static final String DIRECTIONALITY = "directionality"; - private static final String CENTER = "center"; - private static final String NODE_LAT = "nodeLat"; - private static final String NODE_LONG = "nodeLong"; - private static final String Y = "y"; - private static final String X = "x"; - private static final String NODE_LAT_LON = "node-LatLon"; - private static final String LON = "lon"; - private static final String LAT = "lat"; - private static final String NODE_XY = "node-XY"; - private static final String NODE_XY2 = "NodeXY"; - private static final String COMPUTED = "computed"; - private static final String SPEED_LIMITS = "speedLimits"; - private static final String LANE_ANGLE = "laneAngle"; - private static final String LANE_CROWN_POINT_RIGHT = "laneCrownPointRight"; - private static final String LANE_CROWN_POINT_LEFT = "laneCrownPointLeft"; - private static final String LANE_CROWN_POINT_CENTER = "laneCrownPointCenter"; - private static final String D_ELEVATION = "dElevation"; - private static final String D_WIDTH = "dWidth"; - private static final String DATA = "data"; - private static final String OFFSET_X_AXIS = "offsetXaxis"; - private static final String OFFSET_Y_AXIS = "offsetYaxis"; - private static final String ROTATE_XY = "rotateXY"; - private static final String SCALE_X_AXIS = "scaleXaxis"; - private static final String SCALE_Y_AXIS = "scaleYaxis"; - private static final String NODE_LIST = "nodeList"; - private static final String REGION_POINT_SET = "regionPointSet"; - private static final String CIRCLE = "circle"; - private static final String SHAPE_POINT_SET = "shapePointSet"; - private static final String DELTA = "delta"; - private static final String OFFSET = "offset"; - private static final String NODES = "nodes"; - private static final String XY = "xy"; - private static final String LL = "ll"; - private static final String OLD_REGION = "oldRegion"; - private static final String GEOMETRY = "geometry"; - private static final String PATH = "path"; - private static final String DESCRIPTION = "description"; - private static final String CLOSED_PATH = "closedPath"; - private static final String ANCHOR = "anchor"; - private static final String ID = "id"; - private static final String REGION = "region"; - private static final String LANE_WIDTH = "laneWidth"; - private static final String ANCHOR_POSITION = "anchorPosition"; - private static final String REGULATOR_ID = "regulatorID"; - private static final String SEGMENT_ID = "segmentID"; - private static final String POSITION = "position"; - private static final String TEXT = "text"; - private static final String ITIS = "itis"; - private static final String ITEM = "item"; - private static final String START_DATE_TIME = "startDateTime"; - private static final String DURATION_TIME = "durationTime"; - // I know, it's misspelled and it has to stay that way. J2735 spec misspelled it - private static final String DURATON_TIME_MISSPELLED = "duratonTime"; - private static final String SSP_TIM_RIGHTS = "sspTimRights"; - private static final String SSP_MSG_TYPES = "sspMsgTypes"; - private static final String SSP_MSG_CONTENT = "sspMsgContent"; - private static final String DATAFRAMES = "dataframes"; - private static final String TIME_STAMP = "timeStamp"; - public static final String GEOGRAPHICAL_PATH_STRING = "GeographicalPath"; - public static final String REGIONS_STRING = "regions"; - public static final String TRAVELER_DATA_FRAME_STRING = "TravelerDataFrame"; - public static final String DATA_FRAMES_STRING = "dataFrames"; - public static final String SEQUENCE_STRING = "SEQUENCE"; - public static final String TCONTENT_STRING = "tcontent"; - // JSON cannot have empty fields like XML, so the XML must be modified by - // removing all flag field values - public static final String EMPTY_FIELD_FLAG = "EMPTY_TAG"; - public static final String BOOLEAN_OBJECT_TRUE = "BOOLEAN_OBJECT_TRUE"; - public static final String BOOLEAN_OBJECT_FALSE = "BOOLEAN_OBJECT_FALSE"; - - private static final Logger logger = LoggerFactory.getLogger(TravelerMessageFromHumanToAsnConverter.class); - - private TravelerMessageFromHumanToAsnConverter() { + private static final String SPEED = "speed"; + private static final String TYPE = "type"; + private static final String ATTRIBUTES = "attributes"; + public static final String TRAVELER_INFORMATION = "TravelerInformation"; + private static final String EXTENT = "extent"; + private static final String UNITS = "units"; + private static final String DIRECTIONALITY = "directionality"; + private static final String CENTER = "center"; + private static final String NODE_LAT = "nodeLat"; + private static final String NODE_LONG = "nodeLong"; + private static final String Y = "y"; + private static final String X = "x"; + private static final String NODE_LAT_LON = "node-LatLon"; + private static final String LON = "lon"; + private static final String LAT = "lat"; + private static final String NODE_XY = "node-XY"; + private static final String NODE_XY2 = "NodeXY"; + private static final String COMPUTED = "computed"; + private static final String SPEED_LIMITS = "speedLimits"; + private static final String LANE_ANGLE = "laneAngle"; + private static final String LANE_CROWN_POINT_RIGHT = "laneCrownPointRight"; + private static final String LANE_CROWN_POINT_LEFT = "laneCrownPointLeft"; + private static final String LANE_CROWN_POINT_CENTER = "laneCrownPointCenter"; + private static final String D_ELEVATION = "dElevation"; + private static final String D_WIDTH = "dWidth"; + private static final String DATA = "data"; + private static final String OFFSET_X_AXIS = "offsetXaxis"; + private static final String OFFSET_Y_AXIS = "offsetYaxis"; + private static final String ROTATE_XY = "rotateXY"; + private static final String SCALE_X_AXIS = "scaleXaxis"; + private static final String SCALE_Y_AXIS = "scaleYaxis"; + private static final String NODE_LIST = "nodeList"; + private static final String REGION_POINT_SET = "regionPointSet"; + private static final String CIRCLE = "circle"; + private static final String SHAPE_POINT_SET = "shapePointSet"; + private static final String DELTA = "delta"; + private static final String OFFSET = "offset"; + private static final String NODES = "nodes"; + private static final String XY = "xy"; + private static final String LL = "ll"; + private static final String OLD_REGION = "oldRegion"; + private static final String GEOMETRY = "geometry"; + private static final String PATH = "path"; + private static final String DESCRIPTION = "description"; + private static final String CLOSED_PATH = "closedPath"; + private static final String ANCHOR = "anchor"; + private static final String ID = "id"; + private static final String REGION = "region"; + private static final String LANE_WIDTH = "laneWidth"; + private static final String ANCHOR_POSITION = "anchorPosition"; + private static final String REGULATOR_ID = "regulatorID"; + private static final String SEGMENT_ID = "segmentID"; + private static final String POSITION = "position"; + private static final String TEXT = "text"; + private static final String ITIS = "itis"; + private static final String ITEM = "item"; + private static final String START_DATE_TIME = "startDateTime"; + private static final String DURATION_TIME = "durationTime"; + // I know, it's misspelled and it has to stay that way. J2735 spec misspelled it + private static final String DURATON_TIME_MISSPELLED = "duratonTime"; + private static final String SSP_TIM_RIGHTS = "sspTimRights"; + private static final String SSP_MSG_TYPES = "sspMsgTypes"; + private static final String SSP_MSG_CONTENT = "sspMsgContent"; + private static final String DATAFRAMES = "dataframes"; + private static final String TIME_STAMP = "timeStamp"; + public static final String GEOGRAPHICAL_PATH_STRING = "GeographicalPath"; + public static final String REGIONS_STRING = "regions"; + public static final String TRAVELER_DATA_FRAME_STRING = "TravelerDataFrame"; + public static final String DATA_FRAMES_STRING = "dataFrames"; + public static final String SEQUENCE_STRING = "SEQUENCE"; + public static final String TCONTENT_STRING = "tcontent"; + // JSON cannot have empty fields like XML, so the XML must be modified by + // removing all flag field values + public static final String EMPTY_FIELD_FLAG = "EMPTY_TAG"; + public static final String BOOLEAN_OBJECT_TRUE = "BOOLEAN_OBJECT_TRUE"; + public static final String BOOLEAN_OBJECT_FALSE = "BOOLEAN_OBJECT_FALSE"; + + private static final Logger logger = LoggerFactory.getLogger(TravelerMessageFromHumanToAsnConverter.class); + + private TravelerMessageFromHumanToAsnConverter() { super(); - } + } - public static void convertTravelerInputDataToEncodableTim(JsonNode tid) throws JsonUtilsException { + public static void convertTravelerInputDataToEncodableTim(JsonNode tid) throws JsonUtilsException { // msgCnt MsgCount, // timeStamp MinuteOfTheYear OPTIONAL // packetID UniqueMSGID OPTIONAL @@ -132,7 +132,7 @@ public static void convertTravelerInputDataToEncodableTim(JsonNode tid) throws J // Cast to ObjectNode to allow manipulation in place ObjectNode timDataObjectNode = (ObjectNode) tid.get("tim"); - + // timeStamp is optional if (timDataObjectNode.get(TIME_STAMP) != null) { timDataObjectNode.put(TIME_STAMP, @@ -145,7 +145,7 @@ public static void convertTravelerInputDataToEncodableTim(JsonNode tid) throws J timDataObjectNode.set(DATA_FRAMES_STRING, transformDataFrames(timDataObjectNode.get(DATAFRAMES))); timDataObjectNode.remove(DATAFRAMES); } - + public static ObjectNode transformDataFrames(JsonNode dataFrames) throws JsonUtilsException { if (dataFrames == null) { @@ -172,7 +172,7 @@ public static void replaceDataFrame(ObjectNode dataFrame) throws JsonUtilsExcept // INPUT ////// // "dataframes": [ - // + // // "startDateTime": "2017-08-02T22:25:00.000Z", // "durationTime": 1, // "frameType": "1", @@ -196,7 +196,7 @@ public static void replaceDataFrame(ObjectNode dataFrame) throws JsonUtilsExcept // "513" // ], // "url": "null" - // + // // ] /// OUTPUT: @@ -211,9 +211,8 @@ public static void replaceDataFrame(ObjectNode dataFrame) throws JsonUtilsExcept // sspTimRights does not need replacement // set frameType value - dataFrame.set("frameType", - JsonUtils.newNode().put(dataFrame.get("frameType").asText(), EMPTY_FIELD_FLAG)); - + dataFrame.set("frameType", JsonUtils.newNode().put(dataFrame.get("frameType").asText(), EMPTY_FIELD_FLAG)); + // replace sspMsgContent with sspMsgRights2 dataFrame.put("sspMsgRights2", dataFrame.get(SSP_MSG_CONTENT).asInt()); dataFrame.remove(SSP_MSG_CONTENT); @@ -249,7 +248,8 @@ public static long translateISOTimeStampToMinuteOfYear(String isoTime) { try { ZonedDateTime zDateTime = DateTimeUtils.isoDateTime(isoTime); startYear = zDateTime.getYear(); - startMinute = (int) Duration.between(DateTimeUtils.isoDateTime(startYear, 1, 1, 0, 0, 0, 0), zDateTime).toMinutes(); + startMinute = (int) Duration.between(DateTimeUtils.isoDateTime(startYear, 1, 1, 0, 0, 0, 0), zDateTime) + .toMinutes(); } catch (Exception e) { // NOSONAR logger.warn("Failed to parse datetime {}, defaulting to unknown value {}", isoTime, startMinute); } @@ -274,7 +274,8 @@ public static void replaceDataFrameTimestamp(ObjectNode dataFrame) { try { ZonedDateTime zDateTime = DateTimeUtils.isoDateTime(startDateTime); startYear = zDateTime.getYear(); - startMinute = (int)ChronoUnit.MINUTES.between(DateTimeUtils.isoDateTime(startYear, 1, 1, 0, 0, 0, 0), zDateTime); + startMinute = (int) ChronoUnit.MINUTES.between(DateTimeUtils.isoDateTime(startYear, 1, 1, 0, 0, 0, 0), + zDateTime); } catch (Exception e) { logger.warn("Failed to startDateTime {}, defaulting to unknown value {}.", startDateTime, startMinute); } @@ -302,7 +303,7 @@ public static void replaceContent(ObjectNode dataFrame) { //////// // "content": "advisory", // "items":["513", "Text you need to send", "'1234567'", "255"]}, - + // step 1, reformat item list ArrayNode items = (ArrayNode) dataFrame.get("items"); ArrayNode newItems = JsonUtils.newNode().arrayNode(); @@ -325,14 +326,14 @@ public static void replaceContent(ObjectNode dataFrame) { // step 2, set the content CHOICE String replacedContentName = dataFrame.get("content").asText(); if (replacedContentName.equals("Advisory")) - replacedContentName = "advisory"; - + replacedContentName = "advisory"; + // The following field is called "content" but this results in a // failed conversion to XML // see @us.dot.its.jpo.ode.traveler.TimController.publish dataFrame.set(TCONTENT_STRING, JsonUtils.newNode().set(replacedContentName, sequence)); dataFrame.remove("content"); -} + } public static JsonNode buildItem(String itemStr) { JsonNode item = null; @@ -410,7 +411,7 @@ public static void replaceRegion(ObjectNode region) throws JsonUtilsException { // "name": "Testing TIM", // "regulatorID": "0", // "segmentID": "33", - // "anchorPosition": + // "anchorPosition": // "latitude": "41.2500807", // "longitude": "-111.0093847", // "elevation": "2020.6969900289998" @@ -421,7 +422,7 @@ public static void replaceRegion(ObjectNode region) throws JsonUtilsException { // "description": "path", // "path": {}, // "direction": "0000000000001010" - // + // //// EXPECTED OUTPUT: // @@ -461,10 +462,9 @@ public static void replaceRegion(ObjectNode region) throws JsonUtilsException { region.set(ID, id); } // replace regulatorID and segmentID with id - ObjectNode id = JsonUtils.newNode() - .put(REGION,region.get(REGULATOR_ID).asInt()) - .put(ID, region.get(SEGMENT_ID).asInt()); - + ObjectNode id = JsonUtils.newNode().put(REGION, region.get(REGULATOR_ID).asInt()).put(ID, + region.get(SEGMENT_ID).asInt()); + region.set(ID, id); region.remove(REGULATOR_ID); region.remove(SEGMENT_ID); @@ -472,8 +472,8 @@ public static void replaceRegion(ObjectNode region) throws JsonUtilsException { // anchorPosition --> anchor (optional) JsonNode anchorPos = region.get(ANCHOR_POSITION); if (anchorPos != null) { - region.set(ANCHOR, JsonUtils.toObjectNode(Position3DBuilder.dsrcPosition3D( - Position3DBuilder.odePosition3D(region.get(ANCHOR_POSITION))).toJson())); + region.set(ANCHOR, JsonUtils.toObjectNode(Position3DBuilder + .dsrcPosition3D(Position3DBuilder.odePosition3D(region.get(ANCHOR_POSITION))).toJson())); region.remove(ANCHOR_POSITION); } @@ -485,13 +485,13 @@ public static void replaceRegion(ObjectNode region) throws JsonUtilsException { // directionality (optional) if (region.has(DIRECTIONALITY)) { - JsonNode directionality = region.get(DIRECTIONALITY); - String enumString = CommonUtils.enumToString(DirectionOfUseEnum.class, directionality.asText()); - if (enumString != null) { - region.set(DIRECTIONALITY, JsonUtils.newNode().put(enumString, EMPTY_FIELD_FLAG)); - } + JsonNode directionality = region.get(DIRECTIONALITY); + String enumString = CommonUtils.enumToString(DirectionOfUseEnum.class, directionality.asText()); + if (enumString != null) { + region.set(DIRECTIONALITY, JsonUtils.newNode().put(enumString, EMPTY_FIELD_FLAG)); + } } - + // closed path (optional) JsonNode closedPath = region.get(CLOSED_PATH); if (closedPath != null) { @@ -522,11 +522,11 @@ public static void replaceRegion(ObjectNode region) throws JsonUtilsException { private static void replacePath(ObjectNode pathNode) { //// EXPECTED INPUT: - // "path": + // "path": // "scale": "0", // "type": "ll", // "nodes": [] - // + // //// EXPECTED OUTPUT: // @@ -585,11 +585,11 @@ private static ArrayNode transformNodeSetLL(JsonNode nodes) { private static ObjectNode transformNodeLL(JsonNode oldNode) { //// EXPECTED INPUT: - // + // // "nodeLong": "0.0031024", // "nodeLat": "0.0014506", // "delta": "node-LL3" - // + // //// EXPECTED OUTPUT: // @@ -628,46 +628,52 @@ private static ObjectNode transformNodeLL(JsonNode oldNode) { return deltaNode; } -// -- Nodes with LL content Span at the equator when using a zoom of one: -// node-LL1 Node-LL-24B, -- within +- 22.634554 meters of last node -// node-LL2 Node-LL-28B, -- within +- 90.571389 meters of last node -// node-LL3 Node-LL-32B, -- within +- 362.31873 meters of last node -// node-LL4 Node-LL-36B, -- within +- 01.449308 Kmeters of last node -// node-LL5 Node-LL-44B, -- within +- 23.189096 Kmeters of last node -// node-LL6 Node-LL-48B, -- within +- 92.756481 Kmeters of last node -// node-LatLon Node-LLmD-64b, -- node is a full 32b Lat/Lon range + // -- Nodes with LL content Span at the equator when using a zoom of one: + // node-LL1 Node-LL-24B, -- within +- 22.634554 meters of last node + // node-LL2 Node-LL-28B, -- within +- 90.571389 meters of last node + // node-LL3 Node-LL-32B, -- within +- 362.31873 meters of last node + // node-LL4 Node-LL-36B, -- within +- 01.449308 Kmeters of last node + // node-LL5 Node-LL-44B, -- within +- 23.189096 Kmeters of last node + // node-LL6 Node-LL-48B, -- within +- 92.756481 Kmeters of last node + // node-LatLon Node-LLmD-64b, -- node is a full 32b Lat/Lon range private static String nodeOffsetPointLL(long transformedLat, long transformedLon) { - long transformedLatabs = Math.abs(transformedLat); - long transformedLonabs = Math.abs(transformedLon); - if (((transformedLatabs & (-1 << 11)) == 0 || (transformedLat<0 && (transformedLatabs ^ (1 << 11)) == 0)) - && (transformedLonabs & (-1 << 11)) == 0 || (transformedLon<0 && ((transformedLonabs ^ (1 << 11)) == 0))) { - // 11 bit value - return "node-LL1"; - } else if (((transformedLatabs & (-1 << 13)) == 0 || (transformedLat<0 && (transformedLatabs ^ (1 << 13)) == 0)) - && (transformedLonabs & (-1 << 13)) == 0 || (transformedLon<0 && ((transformedLonabs ^ (1 << 13)) == 0))){ - // 13 bit value - return "node-LL2"; - } else if (((transformedLatabs & (-1 << 15)) == 0 || (transformedLat<0 && (transformedLatabs ^ (1 << 15)) == 0)) - && (transformedLonabs & (-1 << 15)) == 0 || (transformedLon<0 && ((transformedLonabs ^ (1 << 15)) == 0))) { - // 15 bit value - return "node-LL3"; - } else if (((transformedLatabs & (-1 << 17)) == 0 || (transformedLat<0 && (transformedLatabs ^ (1 << 17)) == 0)) - && (transformedLonabs & (-1 << 17)) == 0 || (transformedLon<0 && ((transformedLonabs ^ (1 << 17)) == 0))) { - // 17 bit value - return "node-LL4"; - } else if (((transformedLatabs & (-1 << 21)) == 0 || (transformedLat<0 && (transformedLatabs ^ (1 << 21)) == 0)) - && (transformedLonabs & (-1 << 21)) == 0 || (transformedLon<0 && ((transformedLonabs ^ (1 << 21)) == 0))) { - // 21 bit value - return "node-LL5"; - } else if (((transformedLatabs & (-1 << 23)) == 0 || (transformedLat<0 && (transformedLatabs ^ (1 << 23)) == 0)) - && (transformedLonabs & (-1 << 23)) == 0 || (transformedLon<0 && ((transformedLonabs ^ (1 << 23)) == 0))){ - // 23 bit value - return "node-LL6"; - } else { - throw new IllegalArgumentException("Invalid node lat/long offset: " + transformedLat + "/" + transformedLon - + ". Values must be between a range of -0.8388608/+0.8388607 degrees."); - } - + long transformedLatabs = Math.abs(transformedLat); + long transformedLonabs = Math.abs(transformedLon); + if (((transformedLatabs & (-1 << 11)) == 0 || (transformedLat < 0 && (transformedLatabs ^ (1 << 11)) == 0)) + && (transformedLonabs & (-1 << 11)) == 0 + || (transformedLon < 0 && ((transformedLonabs ^ (1 << 11)) == 0))) { + // 11 bit value + return "node-LL1"; + } else if (((transformedLatabs & (-1 << 13)) == 0 || (transformedLat < 0 && (transformedLatabs ^ (1 << 13)) == 0)) + && (transformedLonabs & (-1 << 13)) == 0 + || (transformedLon < 0 && ((transformedLonabs ^ (1 << 13)) == 0))) { + // 13 bit value + return "node-LL2"; + } else if (((transformedLatabs & (-1 << 15)) == 0 || (transformedLat < 0 && (transformedLatabs ^ (1 << 15)) == 0)) + && (transformedLonabs & (-1 << 15)) == 0 + || (transformedLon < 0 && ((transformedLonabs ^ (1 << 15)) == 0))) { + // 15 bit value + return "node-LL3"; + } else if (((transformedLatabs & (-1 << 17)) == 0 || (transformedLat < 0 && (transformedLatabs ^ (1 << 17)) == 0)) + && (transformedLonabs & (-1 << 17)) == 0 + || (transformedLon < 0 && ((transformedLonabs ^ (1 << 17)) == 0))) { + // 17 bit value + return "node-LL4"; + } else if (((transformedLatabs & (-1 << 21)) == 0 || (transformedLat < 0 && (transformedLatabs ^ (1 << 21)) == 0)) + && (transformedLonabs & (-1 << 21)) == 0 + || (transformedLon < 0 && ((transformedLonabs ^ (1 << 21)) == 0))) { + // 21 bit value + return "node-LL5"; + } else if (((transformedLatabs & (-1 << 23)) == 0 || (transformedLat < 0 && (transformedLatabs ^ (1 << 23)) == 0)) + && (transformedLonabs & (-1 << 23)) == 0 + || (transformedLon < 0 && ((transformedLonabs ^ (1 << 23)) == 0))) { + // 23 bit value + return "node-LL6"; + } else { + throw new IllegalArgumentException("Invalid node lat/long offset: " + transformedLat + "/" + transformedLon + + ". Values must be between a range of -0.8388608/+0.8388607 degrees."); + } + } public static void replaceGeometry(ObjectNode geometry) { @@ -678,7 +684,7 @@ public static void replaceGeometry(ObjectNode geometry) { // circle Circle // direction does not need to be replaced - + // extent does not need to be replaced (optional) // replace lane width @@ -696,12 +702,12 @@ public static void replaceOldRegion(ObjectNode oldRegion) { // old region == ValidRegion // elements: // direction - no changes - + // extent - no changes JsonNode extentNode = oldRegion.get(EXTENT); String extent = CommonUtils.enumToString(Extent.ExtentEnum.class, extentNode.asText()); oldRegion.set(EXTENT, JsonUtils.newNode().put(extent, EMPTY_FIELD_FLAG)); - + // area - needs changes replaceArea(oldRegion.get("area")); } @@ -735,9 +741,8 @@ private static void replaceRegionPointSet(JsonNode regionPointSet) { // replace anchor (optional) if (updatedNode.get(ANCHOR_POSITION) != null) { - JsonUtils.addNode(updatedNode, ANCHOR, - Position3DBuilder.dsrcPosition3D( - Position3DBuilder.odePosition3D(updatedNode.get(ANCHOR_POSITION)))); + JsonUtils.addNode(updatedNode, ANCHOR, + Position3DBuilder.dsrcPosition3D(Position3DBuilder.odePosition3D(updatedNode.get(ANCHOR_POSITION)))); updatedNode.remove(ANCHOR_POSITION); } @@ -748,37 +753,35 @@ private static void replaceRegionPointSet(JsonNode regionPointSet) { public static void replaceCircle(JsonNode circle) { - // Circle ::= SEQUENCE + // Circle ::= SEQUENCE // center Position3D, // radius Radius-B12, // units DistanceUnits - // + // ObjectNode updatedNode = (ObjectNode) circle; - + JsonNode centerPosition = null; if (updatedNode.has(POSITION)) { - centerPosition = updatedNode.get(POSITION); - updatedNode.remove(POSITION); + centerPosition = updatedNode.get(POSITION); + updatedNode.remove(POSITION); } else { - centerPosition = updatedNode.get(CENTER); + centerPosition = updatedNode.get(CENTER); } - - // replace center - JsonUtils.addNode(updatedNode, CENTER, - Position3DBuilder.dsrcPosition3D( - Position3DBuilder.odePosition3D(centerPosition))); + // replace center + JsonUtils.addNode(updatedNode, CENTER, + Position3DBuilder.dsrcPosition3D(Position3DBuilder.odePosition3D(centerPosition))); // radius does not need replacement // replace units if (updatedNode.has(UNITS)) { - JsonNode units = updatedNode.get(UNITS); - String enumString = CommonUtils.enumToString(DistanceUnitsEnum.class, units.asText()); - if (enumString != null) { - updatedNode.set(UNITS, JsonUtils.newNode().put(enumString, EMPTY_FIELD_FLAG)); - } + JsonNode units = updatedNode.get(UNITS); + String enumString = CommonUtils.enumToString(DistanceUnitsEnum.class, units.asText()); + if (enumString != null) { + updatedNode.set(UNITS, JsonUtils.newNode().put(enumString, EMPTY_FIELD_FLAG)); + } } } @@ -793,9 +796,8 @@ public static void replaceShapePointSet(JsonNode shapePointSet) { // replace anchor if (updatedNode.has(ANCHOR)) { - JsonUtils.addNode(updatedNode, ANCHOR, - Position3DBuilder.dsrcPosition3D( - Position3DBuilder.odePosition3D(updatedNode.get(ANCHOR)))); + JsonUtils.addNode(updatedNode, ANCHOR, + Position3DBuilder.dsrcPosition3D(Position3DBuilder.odePosition3D(updatedNode.get(ANCHOR)))); } // replace lane width @@ -805,74 +807,74 @@ public static void replaceShapePointSet(JsonNode shapePointSet) { // replace directionality if (updatedNode.has(DIRECTIONALITY)) { - JsonNode directionality = updatedNode.get(DIRECTIONALITY); - String enumString = CommonUtils.enumToString(DirectionOfUseEnum.class, directionality.asText()); - if (enumString != null) { - updatedNode.set(DIRECTIONALITY, JsonUtils.newNode().put(enumString, EMPTY_FIELD_FLAG)); - } + JsonNode directionality = updatedNode.get(DIRECTIONALITY); + String enumString = CommonUtils.enumToString(DirectionOfUseEnum.class, directionality.asText()); + if (enumString != null) { + updatedNode.set(DIRECTIONALITY, JsonUtils.newNode().put(enumString, EMPTY_FIELD_FLAG)); + } } - + // replace node list if (updatedNode.has(NODE_LIST)) { - ObjectNode nodeList = (ObjectNode) updatedNode.get(NODE_LIST); - if (nodeList.has(NODES)) { - ArrayNode nodes = transformNodeSetXY(nodeList.get(NODES)); - nodeList.set(NODES, nodes); - } else if (nodeList.has(COMPUTED)) { - JsonNode computedLane = nodeList.get(COMPUTED); - replaceComputedLane(computedLane); - } + ObjectNode nodeList = (ObjectNode) updatedNode.get(NODE_LIST); + if (nodeList.has(NODES)) { + ArrayNode nodes = transformNodeSetXY(nodeList.get(NODES)); + nodeList.set(NODES, nodes); + } else if (nodeList.has(COMPUTED)) { + JsonNode computedLane = nodeList.get(COMPUTED); + replaceComputedLane(computedLane); + } } } public static void replaceComputedLane(JsonNode jsonNode) { ObjectNode updatedNode = (ObjectNode) jsonNode; - + // Nothing to do for referenceLaneId LaneID - - // offsetXaxis CHOICE - // small DrivenLineOffsetSm, - // large DrivenLineOffsetLg - // + + // offsetXaxis CHOICE + // small DrivenLineOffsetSm, + // large DrivenLineOffsetLg + // replaceScale(updatedNode, OFFSET_X_AXIS); - - // offsetYaxis CHOICE - // small DrivenLineOffsetSm, - // large DrivenLineOffsetLg - // + + // offsetYaxis CHOICE + // small DrivenLineOffsetSm, + // large DrivenLineOffsetLg + // replaceScale(updatedNode, OFFSET_Y_AXIS); - + // rotateXY Angle OPTIONAL if (updatedNode.has(ROTATE_XY)) { updatedNode.put(ROTATE_XY, AngleBuilder.angle(JsonUtils.decimalValue(updatedNode.get(ROTATE_XY)))); } - + // scaleXaxis Scale-B12 OPTIONAL if (updatedNode.has(SCALE_X_AXIS)) { updatedNode.put(SCALE_X_AXIS, ScaleB12Builder.scaleB12(JsonUtils.decimalValue(updatedNode.get(SCALE_X_AXIS)))); } - + // scaleYaxis Scale-B12 OPTIONAL if (updatedNode.has(SCALE_Y_AXIS)) { updatedNode.put(SCALE_Y_AXIS, ScaleB12Builder.scaleB12(JsonUtils.decimalValue(updatedNode.get(SCALE_Y_AXIS)))); } } - public static void replaceScale(ObjectNode updatedNode, String scale) { - if (updatedNode.has(scale)) { - int scaleX = updatedNode.get(scale).asInt(); - String key = "large"; - if (-2048 <= scaleX && scaleX <= 2047) { - key = "small"; + public static void replaceScale(ObjectNode updatedNode, String scale) { + if (updatedNode.has(scale)) { + int scaleX = updatedNode.get(scale).asInt(); + String key = "large"; + if (-2048 <= scaleX && scaleX <= 2047) { + key = "small"; + } + + ObjectNode node = JsonUtils.newObjectNode(key, scaleX); + updatedNode.set(scale, node); } - - ObjectNode node = JsonUtils.newObjectNode(key, scaleX); - updatedNode.set(scale, node); - } - } + } public static ArrayNode transformNodeSetXY(JsonNode inputNodeList) { - + //// EXPECTED INPUT: // "nodes": [] @@ -907,9 +909,9 @@ public static JsonNode transformNodeXY(JsonNode oldNode) { ObjectNode nodexy = transformNodeOffsetPointXY(oldNode); if (oldNode.has(ATTRIBUTES)) { - nodexy.set(ATTRIBUTES, transformNodeAttributeSetXY(oldNode.get(ATTRIBUTES))); + nodexy.set(ATTRIBUTES, transformNodeAttributeSetXY(oldNode.get(ATTRIBUTES))); } - + return nodexy; } @@ -932,11 +934,11 @@ private static ObjectNode transformNodeAttributeSetXY(JsonNode jsonNode) { updatedNode.set(DATA, transformLaneDataAttributeList(jsonNode.get(DATA))); } if (jsonNode.has(D_WIDTH)) { - updatedNode.put(D_WIDTH, OffsetXyBuilder.offsetXy(JsonUtils.decimalValue(jsonNode.get(D_WIDTH)))); + updatedNode.put(D_WIDTH, OffsetXyBuilder.offsetXy(JsonUtils.decimalValue(jsonNode.get(D_WIDTH)))); } if (jsonNode.has(D_ELEVATION)) { - updatedNode.put(D_ELEVATION, OffsetXyBuilder.offsetXy(JsonUtils.decimalValue(jsonNode.get(D_ELEVATION)))); + updatedNode.put(D_ELEVATION, OffsetXyBuilder.offsetXy(JsonUtils.decimalValue(jsonNode.get(D_ELEVATION)))); } return updatedNode; } @@ -972,14 +974,14 @@ public static void replaceLaneDataAttribute(JsonNode oldNode) { if (oldNode.has("pathEndPointAngle")) { // do nothing } else if (oldNode.has(LANE_CROWN_POINT_CENTER)) { - updatedNode.put(LANE_CROWN_POINT_CENTER, - RoadwayCrownAngleBuilder.roadwayCrownAngle(JsonUtils.decimalValue(updatedNode.get(LANE_CROWN_POINT_CENTER)))); + updatedNode.put(LANE_CROWN_POINT_CENTER, RoadwayCrownAngleBuilder + .roadwayCrownAngle(JsonUtils.decimalValue(updatedNode.get(LANE_CROWN_POINT_CENTER)))); } else if (oldNode.has(LANE_CROWN_POINT_LEFT)) { - updatedNode.put(LANE_CROWN_POINT_LEFT, - RoadwayCrownAngleBuilder.roadwayCrownAngle(JsonUtils.decimalValue(updatedNode.get(LANE_CROWN_POINT_LEFT)))); + updatedNode.put(LANE_CROWN_POINT_LEFT, RoadwayCrownAngleBuilder + .roadwayCrownAngle(JsonUtils.decimalValue(updatedNode.get(LANE_CROWN_POINT_LEFT)))); } else if (oldNode.has(LANE_CROWN_POINT_RIGHT)) { - updatedNode.put(LANE_CROWN_POINT_RIGHT, - RoadwayCrownAngleBuilder.roadwayCrownAngle(JsonUtils.decimalValue(updatedNode.get(LANE_CROWN_POINT_RIGHT)))); + updatedNode.put(LANE_CROWN_POINT_RIGHT, RoadwayCrownAngleBuilder + .roadwayCrownAngle(JsonUtils.decimalValue(updatedNode.get(LANE_CROWN_POINT_RIGHT)))); } else if (oldNode.has(LANE_ANGLE)) { updatedNode.put(LANE_ANGLE, MergeDivergeNodeAngleBuilder.mergeDivergeNodeAngle(JsonUtils.decimalValue(updatedNode.get(LANE_ANGLE)))); @@ -1006,14 +1008,14 @@ private static void replaceRegulatorySpeedLimit(JsonNode regulatorySpeedLimitNod // speed Velocity ObjectNode updatedNode = (ObjectNode) regulatorySpeedLimitNode; - + // type JsonNode typeNode = regulatorySpeedLimitNode.get(TYPE); String type = CommonUtils.enumToString(SpeedLimitTypeEnum.class, typeNode.asText()); if (type != null) { - updatedNode.set(TYPE, JsonUtils.newNode().put(type, EMPTY_FIELD_FLAG)); + updatedNode.set(TYPE, JsonUtils.newNode().put(type, EMPTY_FIELD_FLAG)); } - + // replace velocity updatedNode.put(SPEED, VelocityBuilder.velocity(JsonUtils.decimalValue(updatedNode.get(SPEED)))); @@ -1021,11 +1023,11 @@ private static void replaceRegulatorySpeedLimit(JsonNode regulatorySpeedLimitNod public static ObjectNode transformNodeOffsetPointXY(JsonNode oldNode) { //// EXPECTED INPUT: - // - // "nodeLong": "0.0031024", - // "nodeLat": "0.0014506", - // "delta": "node-LL3" - // + // + // "nodeLong": "0.0031024", + // "nodeLat": "0.0014506", + // "delta": "node-LL3" + // //// EXPECTED OUTPUT: // @@ -1060,9 +1062,9 @@ public static ObjectNode transformNodeOffsetPointXY(JsonNode oldNode) { Long transformedLat = LongitudeBuilder.j2735Longitude(latOffset); ObjectNode latLong = JsonUtils.newNode().put(LON, transformedLon).put(LAT, transformedLat); if (deltaText.equals(NODE_XY)) { - innerNode.set(nodeOffsetPointLL(transformedLat, transformedLon), latLong); + innerNode.set(nodeOffsetPointLL(transformedLat, transformedLon), latLong); } else { - innerNode.set(deltaText, latLong); + innerNode.set(deltaText, latLong); } } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/timstorage/Anchor.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/timstorage/Anchor.java index ab2733993..e2f56d73c 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/timstorage/Anchor.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/timstorage/Anchor.java @@ -23,16 +23,11 @@ @JsonPropertyOrder({ "lat", "long", "elevation" }) public class Anchor extends Asn1Object { private static final long serialVersionUID = 1L; - - @JsonProperty("lat") private String lat; - - @JsonProperty("long") private String llong; - - @JsonProperty("elevation") private String elevation; + @JsonProperty("lat") public String getLat() { return lat; } @@ -41,6 +36,7 @@ public void setLat(String lat) { this.lat = lat; } + @JsonProperty("long") public String getLlong() { return llong; } @@ -49,6 +45,7 @@ public void setLlong(String llong) { this.llong = llong; } + @JsonProperty("elevation") public String getElevation() { return elevation; } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/timstorage/MessageFrame.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/timstorage/MessageFrame.java index 1b72718b5..a0e18ec03 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/timstorage/MessageFrame.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/timstorage/MessageFrame.java @@ -15,15 +15,18 @@ ******************************************************************************/ package us.dot.its.jpo.ode.plugin.j2735.timstorage; +import com.fasterxml.jackson.annotation.JsonProperty; + import us.dot.its.jpo.ode.plugin.asn1.Asn1Object; import us.dot.its.jpo.ode.plugin.j2735.J2735MessageFrame; public class MessageFrame extends Asn1Object { private static final long serialVersionUID = 3450586016818874906L; - + private J2735MessageFrame MessageFrame; + @JsonProperty("MessageFrame") public J2735MessageFrame getMessageFrame() { return MessageFrame; } @@ -31,7 +34,5 @@ public J2735MessageFrame getMessageFrame() { public void setMessageFrame(J2735MessageFrame messageFrame) { MessageFrame = messageFrame; } - - } diff --git a/jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/BsmBuilderTest.java b/jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/BsmBuilderTest.java index ae1477828..5deaab2df 100644 --- a/jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/BsmBuilderTest.java +++ b/jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/BsmBuilderTest.java @@ -45,7 +45,6 @@ public void shouldTranslateBsm() throws BsmPart2ContentBuilderException { assertNotNull(actualBsm); String expected = "{\"coreData\":{\"msgCnt\":41,\"id\":\"4B3AD218\",\"secMark\":14206,\"position\":{\"latitude\":40.4740068,\"longitude\":-104.9692033,\"elevation\":1492.5},\"accelSet\":{\"accelLat\":0.00,\"accelLong\":0.23,\"accelVert\":0.00,\"accelYaw\":0.00},\"accuracy\":{\"semiMajor\":9.75,\"semiMinor\":12.70,\"orientation\":null},\"transmission\":\"NEUTRAL\",\"speed\":0.24,\"heading\":246.3125,\"angle\":null,\"brakes\":{\"wheelBrakes\":{\"leftFront\":false,\"rightFront\":false,\"unavailable\":true,\"leftRear\":false,\"rightRear\":false},\"traction\":\"unavailable\",\"abs\":\"unavailable\",\"scs\":\"unavailable\",\"brakeBoost\":\"unavailable\",\"auxBrakes\":\"unavailable\"},\"size\":{\"width\":200,\"length\":570}},\"partII\":[{\"id\":\"VehicleSafetyExtensions\",\"value\":{\"events\":null,\"pathHistory\":{\"initialPosition\":null,\"currGNSSstatus\":null,\"crumbData\":[{\"elevationOffset\":-0.3,\"heading\":null,\"latOffset\":-0.0000141,\"lonOffset\":0.0000065,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":6.70},{\"elevationOffset\":4.3,\"heading\":null,\"latOffset\":-0.0000294,\"lonOffset\":0.0000297,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":35.71},{\"elevationOffset\":0.7,\"heading\":null,\"latOffset\":-0.0000329,\"lonOffset\":0.0000170,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":51.50},{\"elevationOffset\":-0.3,\"heading\":null,\"latOffset\":-0.0000130,\"lonOffset\":-0.0000142,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":80.71},{\"elevationOffset\":-7.5,\"heading\":null,\"latOffset\":0.0000129,\"lonOffset\":-0.0000634,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":101.70},{\"elevationOffset\":-6.2,\"heading\":null,\"latOffset\":0.0000173,\"lonOffset\":-0.0000588,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":115.60},{\"elevationOffset\":-6.6,\"heading\":null,\"latOffset\":0.0000077,\"lonOffset\":-0.0000645,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":125.70},{\"elevationOffset\":-4.2,\"heading\":null,\"latOffset\":0.0000029,\"lonOffset\":-0.0000500,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":137.50},{\"elevationOffset\":-4.3,\"heading\":null,\"latOffset\":-0.0000045,\"lonOffset\":-0.0000123,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":157.10},{\"elevationOffset\":-4.3,\"heading\":null,\"latOffset\":-0.0000103,\"lonOffset\":-0.0000020,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":166.80},{\"elevationOffset\":-3.6,\"heading\":null,\"latOffset\":-0.0000054,\"lonOffset\":0.0000198,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":191.30},{\"elevationOffset\":1.9,\"heading\":null,\"latOffset\":-0.0000193,\"lonOffset\":-0.0000294,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":222.09},{\"elevationOffset\":2.8,\"heading\":null,\"latOffset\":-0.0000382,\"lonOffset\":-0.0000467,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":233.00},{\"elevationOffset\":1.8,\"heading\":null,\"latOffset\":-0.0000390,\"lonOffset\":-0.0000364,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":243.20},{\"elevationOffset\":-0.3,\"heading\":null,\"latOffset\":-0.0000178,\"lonOffset\":-0.0000120,\"posAccuracy\":null,\"speed\":null,\"timeOffset\":262.40}]},\"pathPrediction\":{\"confidence\":0.0,\"radiusOfCurve\":0.0},\"lights\":null}},{\"id\":\"SpecialVehicleExtensions\",\"value\":{\"vehicleAlerts\":null,\"description\":null,\"trailers\":{\"connection\":{\"pivotOffset\":1.00,\"pivotAngle\":null,\"pivots\":false},\"sspRights\":0,\"units\":[{\"isDolly\":false,\"width\":200,\"length\":600,\"height\":2.00,\"mass\":64000,\"bumperHeights\":null,\"centerOfGravity\":null,\"frontPivot\":{\"pivotOffset\":1.00,\"pivotAngle\":0.0000,\"pivots\":false},\"rearPivot\":null,\"rearWheelOffset\":null,\"positionOffset\":{\"x\":0.00,\"y\":0.00},\"elevationOffset\":null,\"crumbData\":[]}]}}},{\"id\":\"SupplementalVehicleExtensions\",\"value\":{\"vehicleAlerts\":null,\"description\":null,\"trailers\":null}}]}"; assertEquals(expected , actualBsm.toString()); - } } diff --git a/jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverterTest.java b/jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverterTest.java index 7c589e71b..214c832bd 100644 --- a/jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverterTest.java +++ b/jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverterTest.java @@ -42,13 +42,13 @@ public class TravelerMessageFromHumanToAsnConverterTest { @Mocked private Logger logger; - + @Before public void setup() { new MockUp() { @Mock public Logger getLogger(String value) { - return logger; + return logger; } }; } @@ -65,18 +65,18 @@ public void testAdvisoryNodeLL() throws JsonProcessingException, IOException, Js assertEquals(expectedTID.toString(), inputTID.toString()); JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e1) { - e1.printStackTrace(); - } catch (JsonUtilsException e1) { - e1.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e1) { + e1.printStackTrace(); + } catch (JsonUtilsException e1) { + e1.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - e.printStackTrace(); - } - // assertEquals("string", XML.toString(timObject)); + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + e.printStackTrace(); + } } @Test @@ -91,17 +91,18 @@ public void testWorkzoneNodeXYWithStringLatLon() throws JsonUtilsException { assertEquals(expectedTID.toString(), inputTID.toString()); JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - e.printStackTrace(); - } catch (JsonUtilsException e) { - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + e.printStackTrace(); + } catch (JsonUtilsException e) { + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + e.printStackTrace(); + } } @Test @@ -116,18 +117,19 @@ public void testGenericSignNodeXYWithNumericLatLon() throws JsonUtilsException { assertEquals(expectedTID.toString(), inputTID.toString()); JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - e.printStackTrace(); - } catch (JsonUtilsException e) { - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + e.printStackTrace(); + } catch (JsonUtilsException e) { + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @Test @@ -142,20 +144,21 @@ public void testGeometryUnavailable() throws JsonUtilsException { JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @@ -171,20 +174,21 @@ public void testGeometryExitServiceForward() throws JsonUtilsException { JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @@ -200,20 +204,21 @@ public void testGeometryAdvisoryReverse() throws JsonUtilsException { JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @@ -228,20 +233,21 @@ public void testRoadSignIDWorkzone() throws JsonUtilsException { assertEquals(expectedTID.toString(), inputTID.toString()); JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @Test @@ -256,20 +262,21 @@ public void testGeometryBothGenericSign() throws JsonUtilsException { JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @@ -284,20 +291,21 @@ public void testPathSpeedLimit() throws JsonUtilsException { assertEquals(expectedTID.toString(), inputTID.toString()); JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @Test @@ -338,12 +346,12 @@ public void testReplaceDataFrameTimestamp() { @Test public void testBuildItem() { - + String itisCode = "123"; String itis = "itis"; ObjectNode expectedItisNode = JsonUtils.newNode().put(itis, Integer.parseInt(itisCode)); ObjectNode expecteditem = (ObjectNode) JsonUtils.newNode().set("item", expectedItisNode); - + // build ITIS code JsonNode actualItem = TravelerMessageFromHumanToAsnConverter.buildItem(itisCode); assertEquals(expecteditem, actualItem); @@ -373,20 +381,21 @@ public void testOldRegionWithShapePointSetWithNodeList() throws JsonUtilsExcepti JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @@ -402,20 +411,21 @@ public void testOldRegionWithShapePointSetWithComputedLanesSmall() throws JsonUt JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @@ -431,20 +441,21 @@ public void testOldRegionWithShapePointSetWithComputedLanesLarge() throws JsonUt JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @@ -460,20 +471,21 @@ public void testOldRegionWithCircle() throws JsonUtilsException { JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } @@ -489,20 +501,21 @@ public void testOldRegionWithRegionPointSet() throws JsonUtilsException { JSONObject timObject = new JSONObject(); try { - timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, JsonUtils.toJSONObject(inputTID.toString())); - } catch (JSONException e) { - - e.printStackTrace(); - } catch (JsonUtilsException e) { - - e.printStackTrace(); - } + timObject.put(TravelerMessageFromHumanToAsnConverter.TRAVELER_INFORMATION, + JsonUtils.toJSONObject(inputTID.toString())); + } catch (JSONException e) { + + e.printStackTrace(); + } catch (JsonUtilsException e) { + + e.printStackTrace(); + } try { - assertNotNull(XML.toString(timObject)); - } catch (JSONException e) { - - e.printStackTrace(); - } + assertNotNull(XML.toString(timObject)); + } catch (JSONException e) { + + e.printStackTrace(); + } } } diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeSvcsApplication.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeSvcsApplication.java index 46f2b9ad0..5515f53aa 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeSvcsApplication.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeSvcsApplication.java @@ -25,6 +25,9 @@ import javax.management.NotCompliantMBeanException; import javax.management.ObjectName; +import org.snmp4j.security.AuthMD5; +import org.snmp4j.security.AuthSHA; +import org.snmp4j.security.SecurityProtocols; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -45,6 +48,9 @@ public static void main(String[] args) throws MalformedObjectNameException, Inte SystemConfig mBean = new SystemConfig(DEFAULT_NO_THREADS, DEFAULT_SCHEMA); ObjectName name = new ObjectName("us.dot.its.jpo.ode:type=SystemConfig"); mbs.registerMBean(mBean, name); + + SecurityProtocols.getInstance().addAuthenticationProtocol(new AuthSHA()); + SecurityProtocols.getInstance().addAuthenticationProtocol(new AuthMD5()); } @Bean diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimDepositController.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimDepositController.java index 4eac3888b..75e6a1c2c 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimDepositController.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimDepositController.java @@ -33,7 +33,6 @@ import org.springframework.web.bind.annotation.RestController; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.gson.JsonSyntaxException; import us.dot.its.jpo.ode.OdeProperties; import us.dot.its.jpo.ode.context.AppContext; @@ -83,7 +82,7 @@ public static class TimDepositControllerException extends Exception { public TimDepositControllerException(String errMsg) { super(errMsg); } - + } @Autowired @@ -122,8 +121,13 @@ public synchronized ResponseEntity depositTim(String jsonString, Request try { // Convert JSON to POJO odeTID = (OdeTravelerInputData) JsonUtils.fromJson(jsonString, OdeTravelerInputData.class); - request = odeTID.getRequest(); + if (odeTID == null) { + String errMsg = "Malformed or non-compliant JSON syntax."; + logger.error(errMsg); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, errMsg)); + } + request = odeTID.getRequest(); if (request == null) { throw new TimDepositControllerException("Request element is required as of version 3."); } @@ -138,40 +142,36 @@ public synchronized ResponseEntity depositTim(String jsonString, Request String errMsg = "Missing or invalid argument: " + e.getMessage(); logger.error(errMsg, e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, errMsg)); - } catch (JsonSyntaxException e) { - String errMsg = "Malformed or non-compliant JSON syntax."; - logger.error(errMsg, e); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, errMsg)); } // Add metadata to message and publish to kafka OdeTravelerInformationMessage tim = odeTID.getTim(); OdeMsgPayload timDataPayload = new OdeMsgPayload(tim); OdeRequestMsgMetadata timMetadata = new OdeRequestMsgMetadata(timDataPayload, request); - + // set packetID in tim Metadata - timMetadata.setOdePacketID(tim.getPacketID()); - // set maxDurationTime in tim Metadata and set latest startDatetime in tim - // metadata - 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 (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)); - } + timMetadata.setOdePacketID(tim.getPacketID()); + // set maxDurationTime in tim Metadata and set latest startDatetime in tim + // metadata + 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 (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)); + } // Setting the SerialId to OdeBradcastTim serialId to be changed to // J2735BroadcastTim serialId after the message has been published to // OdeTimBrodcast topic @@ -195,7 +195,6 @@ public synchronized ResponseEntity depositTim(String jsonString, Request // Now that the message gas been published to OdeBradcastTim topic, it should be // changed to J2735BroadcastTim serialId timMetadata.setSerialId(serialIdJ2735); - // Short circuit // If the TIM has no RSU/SNMP or SDW structures, we are done diff --git a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/OdePropertiesTest.java b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/OdePropertiesTest.java index dd1db40e9..e2fe073ce 100644 --- a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/OdePropertiesTest.java +++ b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/OdePropertiesTest.java @@ -26,268 +26,253 @@ import org.junit.Before; import org.junit.Test; +import org.springframework.boot.info.BuildProperties; import org.springframework.core.env.Environment; -import groovy.lang.MissingPropertyException; import mockit.Capturing; import mockit.Expectations; import mockit.Injectable; -import mockit.Mocked; +import mockit.Mock; +import mockit.MockUp; import mockit.Tested; import us.dot.its.jpo.ode.util.CommonUtils; public class OdePropertiesTest { - @Tested - OdeProperties testOdeProperties; - @Injectable - Environment mockEnv; + @Tested + OdeProperties testOdeProperties; + @Injectable + Environment mockEnv; + @Injectable + BuildProperties mockBuildProperties; - @Capturing - CommonUtils capturingCommonUtils; + @Capturing + CommonUtils capturingCommonUtils; - @Before - public void setup() { - new Expectations() { - { - CommonUtils.getEnvironmentVariable("DOCKER_HOST_IP"); - result = "testKafkaBrokers"; - } - }; - } - - @Test - public void testInit() { - new Expectations() { - { - } - }; - try { - new OdeProperties(); - } catch (Exception e) { - fail("Unexpected exception: " + e); + @Before + public void setup() { + new Expectations() { + { + CommonUtils.getEnvironmentVariable("DOCKER_HOST_IP"); + result = "testKafkaBrokers"; + } + }; } - } - @Test - public void initShouldCatchUnknownHostException(@Mocked final InetAddress mockInetAddress) { - try { - new Expectations() { - { - InetAddress.getLocalHost(); - result = new UnknownHostException("testException123"); + @Test + public void testInit() { + new Expectations() { + { + } + }; + try { + new OdeProperties(); + } catch (Exception e) { + fail("Unexpected exception: " + e); } - }; - } catch (Exception e) { - fail("Unexpected exception in expectations block: " + e); - } - - try { - new OdeProperties().initialize(); - } catch (Exception e) { - fail("Unexpected exception in init: " + e); } - } + + @Test + public void initShouldCatchUnknownHostException(@Capturing InetAddress capturingInetAddress) throws Exception { + // from jmockit dev history (https://jmockit.github.io/changes.html) + // as of versiofn 1.48, partial mocking of classes through Expectations has been + // dropped. MockUp is recommended alternative + new MockUp() { + @Mock + public InetAddress getLocalHost() throws UnknownHostException { + throw new UnknownHostException("testException123"); + } + }; - @Test - public void missingDockerHostIpShouldThrowException(@Mocked final InetAddress mockInetAddress) { - try { - new Expectations() { - { - CommonUtils.getEnvironmentVariable("DOCKER_HOST_IP"); - result = null; + try { + testOdeProperties.initialize(); + } catch (Exception e) { + fail("Unexpected exception in init: " + e); } - }; - } catch (Exception e) { - fail("Unexpected exception in expectations block: " + e); } - try { - new OdeProperties().initialize(); - } catch (Exception e) { - assertTrue(e instanceof MissingPropertyException); - } - } - - @Test - public void testSettersAndGetters() { + @Test + public void testSettersAndGetters() { - String testDdsCasPassword = "testDdsCasPassword123456"; - String testDdsCasUrl = "testDdsCasUrl123456"; - String testDdsCasUsername = "testDdsCasUsername123456"; - String testDdsWebsocketUrl = "testDdsWebsocketUrl123456"; - String testKafkaBrokers = "testKafkaBrokers123456"; - String testKafkaProducerType = "testKafkaProducerType123456"; - String testPluginsLocations = "testpluginsLocations123456"; - String testUploadLocationObuLog = "testuploadLocationObuLog123456"; - String testUploadLocationRoot = "testUploadLocationRoot123456"; - int testMessagesUntilTrustReestablished = 17; - String testCaCertPath = "testCaCertPath"; - String testSelfCertPath = "testSelfCertPath"; - String testSelfPrivateKeyReconstructionFilePath = "testSelfPrivateKeyReconstructionFilePath"; - String testSelfSigningPrivateKeyFilePath = "testSelfSigningPrivateKeyFilePath"; - String testKafkaTopicBsmFilteredJson = "testKafkaTopicBsmFilteredJson"; - boolean testVerboseJson = true; - int testRsuSrmSlots = 22; - int testTrustRetries = 23; - String testKafkaTopicOdeBsmPojo = "testKafkaTopicOdeBsmPojo"; - String testKafkaTopicOdeBsmJson = "testKafkaTopicOdeBsmJson"; - String testVersion = "1.1.0-SNAPSHOT"; - int testImportProcessorBufferSize = 83; + String testDdsCasPassword = "testDdsCasPassword123456"; + String testDdsCasUrl = "testDdsCasUrl123456"; + String testDdsCasUsername = "testDdsCasUsername123456"; + String testDdsWebsocketUrl = "testDdsWebsocketUrl123456"; + String testKafkaBrokers = "testKafkaBrokers123456"; + String testKafkaProducerType = "testKafkaProducerType123456"; + String testPluginsLocations = "testpluginsLocations123456"; + String testUploadLocationObuLog = "testuploadLocationObuLog123456"; + String testUploadLocationRoot = "testUploadLocationRoot123456"; + int testMessagesUntilTrustReestablished = 17; + String testCaCertPath = "testCaCertPath"; + String testSelfCertPath = "testSelfCertPath"; + String testSelfPrivateKeyReconstructionFilePath = "testSelfPrivateKeyReconstructionFilePath"; + String testSelfSigningPrivateKeyFilePath = "testSelfSigningPrivateKeyFilePath"; + String testKafkaTopicBsmFilteredJson = "testKafkaTopicBsmFilteredJson"; + boolean testVerboseJson = true; + int testRsuSrmSlots = 22; + int testTrustRetries = 23; + String testKafkaTopicOdeBsmPojo = "testKafkaTopicOdeBsmPojo"; + String testKafkaTopicOdeBsmJson = "testKafkaTopicOdeBsmJson"; + String testVersion = "1.1.0-SNAPSHOT"; + int testImportProcessorBufferSize = 83; - String[] testKafkaTopicsDisabled = new String[] { "testKafkaTopicsDisabled0" }; - Set testKafkaTopicsDisabledSet = new HashSet<>(); - testKafkaTopicsDisabledSet.add("testKafkaTopicsDisabledSet0"); + String[] testKafkaTopicsDisabled = new String[] { "testKafkaTopicsDisabled0" }; + Set testKafkaTopicsDisabledSet = new HashSet<>(); + testKafkaTopicsDisabledSet.add("testKafkaTopicsDisabledSet0"); - String testKafkaTopicAsn1DecoderInput = "testKafkaTopicAsn1DecoderInput"; - String testKafkaTopicAsn1DecoderOutput = "testKafkaTopicAsn1DecoderOutput"; - String testKafkaTopicAsn1EncoderInput = "testKafkaTopicAsn1EncoderInput"; - String testKafkaTopicAsn1EncoderOutput = "testKafkaTopicAsn1EncoderOutput"; - String testKafkaTopicOdeDNMsgJson = "testKafkaTopicOdeDNMsgJson"; - String testKafkaTopicOdeTimJson = "testKafkaTopicOdeTimJson"; - String testKafkaTopicOdeBsmDuringEventPojo = "testKafkaTopicOdeBsmDuringEventPojo"; - String testKafkaTopicOdeBsmRxPojo = "testKafkaTopicOdeBsmRxPojo"; - String testKafkaTopicOdeBsmTxPojo = "testKafkaTopicOdeBsmTxPojo"; - String testKafkaTopicOdeTimRxJson = "testKafkaTopicOdeTimRxJson"; - String testKafkaTopicOdeTimBroadcastPojo = "testKafkaTopicOdeTimBroadcastPojo"; - String testKafkaTopicOdeTimBroadcastJson = "testKafkaTopicOdeTimBroadcastJson"; - String testKafkaTopicJ2735TimBroadcastJson = "testKafkaTopicJ2735TimBroadcastJson"; - String testKafkaTopicFilteredOdeTimJson = "testKafkaTopicFilteredOdeTimJson"; - String testKafkaTopicDriverAlertJson = "testKafkaTopicDriverAlertJson"; + String testKafkaTopicAsn1DecoderInput = "testKafkaTopicAsn1DecoderInput"; + String testKafkaTopicAsn1DecoderOutput = "testKafkaTopicAsn1DecoderOutput"; + String testKafkaTopicAsn1EncoderInput = "testKafkaTopicAsn1EncoderInput"; + String testKafkaTopicAsn1EncoderOutput = "testKafkaTopicAsn1EncoderOutput"; + String testKafkaTopicOdeDNMsgJson = "testKafkaTopicOdeDNMsgJson"; + String testKafkaTopicOdeTimJson = "testKafkaTopicOdeTimJson"; + String testKafkaTopicOdeBsmDuringEventPojo = "testKafkaTopicOdeBsmDuringEventPojo"; + String testKafkaTopicOdeBsmRxPojo = "testKafkaTopicOdeBsmRxPojo"; + String testKafkaTopicOdeBsmTxPojo = "testKafkaTopicOdeBsmTxPojo"; + String testKafkaTopicOdeTimRxJson = "testKafkaTopicOdeTimRxJson"; + String testKafkaTopicOdeTimBroadcastPojo = "testKafkaTopicOdeTimBroadcastPojo"; + String testKafkaTopicOdeTimBroadcastJson = "testKafkaTopicOdeTimBroadcastJson"; + String testKafkaTopicJ2735TimBroadcastJson = "testKafkaTopicJ2735TimBroadcastJson"; + String testKafkaTopicFilteredOdeTimJson = "testKafkaTopicFilteredOdeTimJson"; + String testKafkaTopicDriverAlertJson = "testKafkaTopicDriverAlertJson"; - Integer testFileWatcherPeriod = 5; - String testSecuritySvcsSignatureUri = "testSecuritySvcsSignatureUri"; - String testRsuUsername = "testRsuUsername"; - String testRsuPassword = "testRsuPassword"; + Integer testFileWatcherPeriod = 5; + String testSecuritySvcsSignatureUri = "testSecuritySvcsSignatureUri"; + String testRsuUsername = "testRsuUsername"; + String testRsuPassword = "testRsuPassword"; - testOdeProperties.setDdsCasPassword(testDdsCasPassword); - testOdeProperties.setDdsCasUrl(testDdsCasUrl); - testOdeProperties.setDdsCasUsername(testDdsCasUsername); - testOdeProperties.setDdsWebsocketUrl(testDdsWebsocketUrl); - testOdeProperties.setEnv(mockEnv); - testOdeProperties.setEnvironment(mockEnv); - testOdeProperties.setKafkaBrokers(testKafkaBrokers); - testOdeProperties.setKafkaProducerType(testKafkaProducerType); - testOdeProperties.setPluginsLocations(testPluginsLocations); - testOdeProperties.setUploadLocationObuLog(testUploadLocationObuLog); - testOdeProperties.setUploadLocationRoot(testUploadLocationRoot); - testOdeProperties.setMessagesUntilTrustReestablished(testMessagesUntilTrustReestablished); - testOdeProperties.setCaCertPath(testCaCertPath); - testOdeProperties.setSelfCertPath(testSelfCertPath); - testOdeProperties.setSelfPrivateKeyReconstructionFilePath(testSelfPrivateKeyReconstructionFilePath); - testOdeProperties.setSelfSigningPrivateKeyFilePath(testSelfSigningPrivateKeyFilePath); - testOdeProperties.setKafkaTopicFilteredOdeBsmJson(testKafkaTopicBsmFilteredJson); - testOdeProperties.setVerboseJson(testVerboseJson); - testOdeProperties.setRsuSrmSlots(testRsuSrmSlots); - testOdeProperties.setTrustRetries(testTrustRetries); - testOdeProperties.setKafkaTopicOdeBsmPojo(testKafkaTopicOdeBsmPojo); - testOdeProperties.setKafkaTopicOdeBsmJson(testKafkaTopicOdeBsmJson); - testOdeProperties.setVersion(testVersion); - testOdeProperties.setImportProcessorBufferSize(testImportProcessorBufferSize); - testOdeProperties.setKafkaTopicsDisabled(testKafkaTopicsDisabled); - testOdeProperties.setKafkaTopicsDisabledSet(testKafkaTopicsDisabledSet); + testOdeProperties.setDdsCasPassword(testDdsCasPassword); + testOdeProperties.setDdsCasUrl(testDdsCasUrl); + testOdeProperties.setDdsCasUsername(testDdsCasUsername); + testOdeProperties.setDdsWebsocketUrl(testDdsWebsocketUrl); + testOdeProperties.setEnv(mockEnv); + testOdeProperties.setEnvironment(mockEnv); + testOdeProperties.setKafkaBrokers(testKafkaBrokers); + testOdeProperties.setKafkaProducerType(testKafkaProducerType); + testOdeProperties.setPluginsLocations(testPluginsLocations); + testOdeProperties.setUploadLocationObuLog(testUploadLocationObuLog); + testOdeProperties.setUploadLocationRoot(testUploadLocationRoot); + testOdeProperties.setMessagesUntilTrustReestablished(testMessagesUntilTrustReestablished); + testOdeProperties.setCaCertPath(testCaCertPath); + testOdeProperties.setSelfCertPath(testSelfCertPath); + testOdeProperties.setSelfPrivateKeyReconstructionFilePath(testSelfPrivateKeyReconstructionFilePath); + testOdeProperties.setSelfSigningPrivateKeyFilePath(testSelfSigningPrivateKeyFilePath); + testOdeProperties.setKafkaTopicFilteredOdeBsmJson(testKafkaTopicBsmFilteredJson); + testOdeProperties.setVerboseJson(testVerboseJson); + testOdeProperties.setRsuSrmSlots(testRsuSrmSlots); + testOdeProperties.setTrustRetries(testTrustRetries); + testOdeProperties.setKafkaTopicOdeBsmPojo(testKafkaTopicOdeBsmPojo); + testOdeProperties.setKafkaTopicOdeBsmJson(testKafkaTopicOdeBsmJson); + testOdeProperties.setVersion(testVersion); + testOdeProperties.setImportProcessorBufferSize(testImportProcessorBufferSize); + testOdeProperties.setKafkaTopicsDisabled(testKafkaTopicsDisabled); + testOdeProperties.setKafkaTopicsDisabledSet(testKafkaTopicsDisabledSet); - testOdeProperties.setKafkaTopicAsn1DecoderInput(testKafkaTopicAsn1DecoderInput); - testOdeProperties.setKafkaTopicAsn1DecoderOutput(testKafkaTopicAsn1DecoderOutput); - testOdeProperties.setKafkaTopicAsn1EncoderInput(testKafkaTopicAsn1EncoderInput); - testOdeProperties.setKafkaTopicAsn1EncoderOutput(testKafkaTopicAsn1EncoderOutput); - testOdeProperties.setKafkaTopicOdeDNMsgJson(testKafkaTopicOdeDNMsgJson); - testOdeProperties.setKafkaTopicOdeTimJson(testKafkaTopicOdeTimJson); - testOdeProperties.setKafkaTopicOdeBsmDuringEventPojo(testKafkaTopicOdeBsmDuringEventPojo); - testOdeProperties.setKafkaTopicOdeBsmRxPojo(testKafkaTopicOdeBsmRxPojo); - testOdeProperties.setKafkaTopicOdeBsmTxPojo(testKafkaTopicOdeBsmTxPojo); - testOdeProperties.setKafkaTopicOdeTimRxJson(testKafkaTopicOdeTimRxJson); - testOdeProperties.setKafkaTopicOdeTimBroadcastPojo(testKafkaTopicOdeTimBroadcastPojo); - testOdeProperties.setKafkaTopicOdeTimBroadcastJson(testKafkaTopicOdeTimBroadcastJson); - testOdeProperties.setKafkaTopicJ2735TimBroadcastJson(testKafkaTopicJ2735TimBroadcastJson); - testOdeProperties.setKafkaTopicFilteredOdeTimJson(testKafkaTopicFilteredOdeTimJson); - testOdeProperties.setKafkaTopicDriverAlertJson(testKafkaTopicDriverAlertJson); + testOdeProperties.setKafkaTopicAsn1DecoderInput(testKafkaTopicAsn1DecoderInput); + testOdeProperties.setKafkaTopicAsn1DecoderOutput(testKafkaTopicAsn1DecoderOutput); + testOdeProperties.setKafkaTopicAsn1EncoderInput(testKafkaTopicAsn1EncoderInput); + testOdeProperties.setKafkaTopicAsn1EncoderOutput(testKafkaTopicAsn1EncoderOutput); + testOdeProperties.setKafkaTopicOdeDNMsgJson(testKafkaTopicOdeDNMsgJson); + testOdeProperties.setKafkaTopicOdeTimJson(testKafkaTopicOdeTimJson); + testOdeProperties.setKafkaTopicOdeBsmDuringEventPojo(testKafkaTopicOdeBsmDuringEventPojo); + testOdeProperties.setKafkaTopicOdeBsmRxPojo(testKafkaTopicOdeBsmRxPojo); + testOdeProperties.setKafkaTopicOdeBsmTxPojo(testKafkaTopicOdeBsmTxPojo); + testOdeProperties.setKafkaTopicOdeTimRxJson(testKafkaTopicOdeTimRxJson); + testOdeProperties.setKafkaTopicOdeTimBroadcastPojo(testKafkaTopicOdeTimBroadcastPojo); + testOdeProperties.setKafkaTopicOdeTimBroadcastJson(testKafkaTopicOdeTimBroadcastJson); + testOdeProperties.setKafkaTopicJ2735TimBroadcastJson(testKafkaTopicJ2735TimBroadcastJson); + testOdeProperties.setKafkaTopicFilteredOdeTimJson(testKafkaTopicFilteredOdeTimJson); + testOdeProperties.setKafkaTopicDriverAlertJson(testKafkaTopicDriverAlertJson); - testOdeProperties.setFileWatcherPeriod(testFileWatcherPeriod); - testOdeProperties.setSecuritySvcsSignatureUri(testSecuritySvcsSignatureUri); - testOdeProperties.setRsuUsername(testRsuUsername); - testOdeProperties.setRsuPassword(testRsuPassword); + testOdeProperties.setFileWatcherPeriod(testFileWatcherPeriod); + testOdeProperties.setSecuritySvcsSignatureUri(testSecuritySvcsSignatureUri); + testOdeProperties.setRsuUsername(testRsuUsername); + testOdeProperties.setRsuPassword(testRsuPassword); - assertEquals("Incorrect testDdsCasPassword", testDdsCasPassword, testOdeProperties.getDdsCasPassword()); - assertEquals("Incorrect testDdsCasUrl", testDdsCasUrl, testOdeProperties.getDdsCasUrl()); - assertEquals("Incorrect testDdsCasUsername", testDdsCasUsername, testOdeProperties.getDdsCasUsername()); - assertEquals("Incorrect testDdsWebsocketUrl", testDdsWebsocketUrl, testOdeProperties.getDdsWebsocketUrl()); - assertEquals("Incorrect testEnv", mockEnv, testOdeProperties.getEnv()); - assertEquals("Incorrect testKafkaBrokers", testKafkaBrokers, testOdeProperties.getKafkaBrokers()); - assertEquals("Incorrect testKafkaProducerType", testKafkaProducerType, testOdeProperties.getKafkaProducerType()); - assertEquals("Incorrect testpluginsLocations", testPluginsLocations, testOdeProperties.getPluginsLocations()); - assertEquals("Incorrect testUploadLocationObuLog", testUploadLocationObuLog, - testOdeProperties.getUploadLocationObuLog()); - assertEquals("Incorrect testUploadLocationRoot", testUploadLocationRoot, - testOdeProperties.getUploadLocationRoot()); - assertEquals("Incorrect testMessagesUntilTrustReestablished", testMessagesUntilTrustReestablished, - testOdeProperties.getMessagesUntilTrustReestablished()); - assertEquals("Incorrect testCaCertPath", testCaCertPath, testOdeProperties.getCaCertPath()); - assertEquals("Incorrect testSelfCertPath", testSelfCertPath, testOdeProperties.getSelfCertPath()); - assertEquals("Incorrect testSelfPrivateKeyReconstructionFilePath", testSelfPrivateKeyReconstructionFilePath, - testOdeProperties.getSelfPrivateKeyReconstructionFilePath()); - assertEquals("Incorrect testSelfSigningPrivateKeyFilePath", testSelfSigningPrivateKeyFilePath, - testOdeProperties.getSelfSigningPrivateKeyFilePath()); - assertEquals("Incorrect testKafkaTopicBsmFilteredJson", testKafkaTopicBsmFilteredJson, - testOdeProperties.getKafkaTopicFilteredOdeBsmJson()); - assertEquals("Incorrect testVerboseJson", testVerboseJson, testOdeProperties.getVerboseJson()); - assertEquals("Incorrect testRsuSrmSlots", testRsuSrmSlots, testOdeProperties.getRsuSrmSlots()); - assertEquals("Incorrect testTrustRetries", testTrustRetries, testOdeProperties.getTrustRetries()); - assertEquals("Incorrect testKafkaTopicOdeBsmPojo", testKafkaTopicOdeBsmPojo, - testOdeProperties.getKafkaTopicOdeBsmPojo()); - assertEquals("Incorrect testKafkaTopicOdeBsmJson", testKafkaTopicOdeBsmJson, - testOdeProperties.getKafkaTopicOdeBsmJson()); - assertEquals("Incorrect testVersion", testVersion, testOdeProperties.getVersion()); - assertEquals("Incorrect testImportProcessorBufferSize", testImportProcessorBufferSize, - testOdeProperties.getImportProcessorBufferSize()); - assertEquals("Incorrect testKafkaTopicsDisabled", testKafkaTopicsDisabled[0], - testOdeProperties.getKafkaTopicsDisabled()[0]); - assertTrue("Incorrect testKafkaTopicsDisabledSet", - testOdeProperties.getKafkaTopicsDisabledSet().contains("testKafkaTopicsDisabledSet0")); + assertEquals("Incorrect testDdsCasPassword", testDdsCasPassword, testOdeProperties.getDdsCasPassword()); + assertEquals("Incorrect testDdsCasUrl", testDdsCasUrl, testOdeProperties.getDdsCasUrl()); + assertEquals("Incorrect testDdsCasUsername", testDdsCasUsername, testOdeProperties.getDdsCasUsername()); + assertEquals("Incorrect testDdsWebsocketUrl", testDdsWebsocketUrl, testOdeProperties.getDdsWebsocketUrl()); + assertEquals("Incorrect testEnv", mockEnv, testOdeProperties.getEnv()); + assertEquals("Incorrect testKafkaBrokers", testKafkaBrokers, testOdeProperties.getKafkaBrokers()); + assertEquals("Incorrect testKafkaProducerType", testKafkaProducerType, + testOdeProperties.getKafkaProducerType()); + assertEquals("Incorrect testpluginsLocations", testPluginsLocations, + testOdeProperties.getPluginsLocations()); + assertEquals("Incorrect testUploadLocationObuLog", testUploadLocationObuLog, + testOdeProperties.getUploadLocationObuLog()); + assertEquals("Incorrect testUploadLocationRoot", testUploadLocationRoot, + testOdeProperties.getUploadLocationRoot()); + assertEquals("Incorrect testMessagesUntilTrustReestablished", testMessagesUntilTrustReestablished, + testOdeProperties.getMessagesUntilTrustReestablished()); + assertEquals("Incorrect testCaCertPath", testCaCertPath, testOdeProperties.getCaCertPath()); + assertEquals("Incorrect testSelfCertPath", testSelfCertPath, testOdeProperties.getSelfCertPath()); + assertEquals("Incorrect testSelfPrivateKeyReconstructionFilePath", testSelfPrivateKeyReconstructionFilePath, + testOdeProperties.getSelfPrivateKeyReconstructionFilePath()); + assertEquals("Incorrect testSelfSigningPrivateKeyFilePath", testSelfSigningPrivateKeyFilePath, + testOdeProperties.getSelfSigningPrivateKeyFilePath()); + assertEquals("Incorrect testKafkaTopicBsmFilteredJson", testKafkaTopicBsmFilteredJson, + testOdeProperties.getKafkaTopicFilteredOdeBsmJson()); + assertEquals("Incorrect testVerboseJson", testVerboseJson, testOdeProperties.getVerboseJson()); + assertEquals("Incorrect testRsuSrmSlots", testRsuSrmSlots, testOdeProperties.getRsuSrmSlots()); + assertEquals("Incorrect testTrustRetries", testTrustRetries, testOdeProperties.getTrustRetries()); + assertEquals("Incorrect testKafkaTopicOdeBsmPojo", testKafkaTopicOdeBsmPojo, + testOdeProperties.getKafkaTopicOdeBsmPojo()); + assertEquals("Incorrect testKafkaTopicOdeBsmJson", testKafkaTopicOdeBsmJson, + testOdeProperties.getKafkaTopicOdeBsmJson()); + assertEquals("Incorrect testVersion", testVersion, testOdeProperties.getVersion()); + assertEquals("Incorrect testImportProcessorBufferSize", testImportProcessorBufferSize, + testOdeProperties.getImportProcessorBufferSize()); + assertEquals("Incorrect testKafkaTopicsDisabled", testKafkaTopicsDisabled[0], + testOdeProperties.getKafkaTopicsDisabled()[0]); + assertTrue("Incorrect testKafkaTopicsDisabledSet", + testOdeProperties.getKafkaTopicsDisabledSet().contains("testKafkaTopicsDisabledSet0")); - assertEquals("Incorrect testKafkaTopicAsn1DecoderInput", testKafkaTopicAsn1DecoderInput, - testOdeProperties.getKafkaTopicAsn1DecoderInput()); - assertEquals("Incorrect testKafkaTopicAsn1DecoderOutput", testKafkaTopicAsn1DecoderOutput, - testOdeProperties.getKafkaTopicAsn1DecoderOutput()); - assertEquals("Incorrect testKafkaTopicAsn1EncoderInput", testKafkaTopicAsn1EncoderInput, - testOdeProperties.getKafkaTopicAsn1EncoderInput()); - assertEquals("Incorrect testKafkaTopicAsn1EncoderOutput", testKafkaTopicAsn1EncoderOutput, - testOdeProperties.getKafkaTopicAsn1EncoderOutput()); - assertEquals("Incorrect testKafkaTopicOdeDNMsgJson", testKafkaTopicOdeDNMsgJson, - testOdeProperties.getKafkaTopicOdeDNMsgJson()); - assertEquals("Incorrect testKafkaTopicOdeTimJson", testKafkaTopicOdeTimJson, - testOdeProperties.getKafkaTopicOdeTimJson()); - assertEquals("Incorrect testKafkaTopicOdeBsmDuringEventPojo", testKafkaTopicOdeBsmDuringEventPojo, - testOdeProperties.getKafkaTopicOdeBsmDuringEventPojo()); - assertEquals("Incorrect testKafkaTopicOdeBsmRxPojo", testKafkaTopicOdeBsmRxPojo, - testOdeProperties.getKafkaTopicOdeBsmRxPojo()); - assertEquals("Incorrect testKafkaTopicOdeBsmTxPojo", testKafkaTopicOdeBsmTxPojo, - testOdeProperties.getKafkaTopicOdeBsmTxPojo()); - assertEquals("Incorrect testKafkaTopicOdeTimRxJson", testKafkaTopicOdeTimRxJson, - testOdeProperties.getKafkaTopicOdeTimRxJson()); - assertEquals("Incorrect testKafkaTopicOdeTimBroadcastPojo", testKafkaTopicOdeTimBroadcastPojo, - testOdeProperties.getKafkaTopicOdeTimBroadcastPojo()); - assertEquals("Incorrect testKafkaTopicOdeTimBroadcastJson", testKafkaTopicOdeTimBroadcastJson, - testOdeProperties.getKafkaTopicOdeTimBroadcastJson()); - assertEquals("Incorrect testKafkaTopicJ2735TimBroadcastJson", testKafkaTopicJ2735TimBroadcastJson, - testOdeProperties.getKafkaTopicJ2735TimBroadcastJson()); - assertEquals("Incorrect testKafkaTopicFilteredOdeTimJson", testKafkaTopicFilteredOdeTimJson, - testOdeProperties.getKafkaTopicFilteredOdeTimJson()); - assertEquals("Incorrect testKafkaTopicDriverAlertJson", testKafkaTopicDriverAlertJson, - testOdeProperties.getKafkaTopicDriverAlertJson()); + assertEquals("Incorrect testKafkaTopicAsn1DecoderInput", testKafkaTopicAsn1DecoderInput, + testOdeProperties.getKafkaTopicAsn1DecoderInput()); + assertEquals("Incorrect testKafkaTopicAsn1DecoderOutput", testKafkaTopicAsn1DecoderOutput, + testOdeProperties.getKafkaTopicAsn1DecoderOutput()); + assertEquals("Incorrect testKafkaTopicAsn1EncoderInput", testKafkaTopicAsn1EncoderInput, + testOdeProperties.getKafkaTopicAsn1EncoderInput()); + assertEquals("Incorrect testKafkaTopicAsn1EncoderOutput", testKafkaTopicAsn1EncoderOutput, + testOdeProperties.getKafkaTopicAsn1EncoderOutput()); + assertEquals("Incorrect testKafkaTopicOdeDNMsgJson", testKafkaTopicOdeDNMsgJson, + testOdeProperties.getKafkaTopicOdeDNMsgJson()); + assertEquals("Incorrect testKafkaTopicOdeTimJson", testKafkaTopicOdeTimJson, + testOdeProperties.getKafkaTopicOdeTimJson()); + assertEquals("Incorrect testKafkaTopicOdeBsmDuringEventPojo", testKafkaTopicOdeBsmDuringEventPojo, + testOdeProperties.getKafkaTopicOdeBsmDuringEventPojo()); + assertEquals("Incorrect testKafkaTopicOdeBsmRxPojo", testKafkaTopicOdeBsmRxPojo, + testOdeProperties.getKafkaTopicOdeBsmRxPojo()); + assertEquals("Incorrect testKafkaTopicOdeBsmTxPojo", testKafkaTopicOdeBsmTxPojo, + testOdeProperties.getKafkaTopicOdeBsmTxPojo()); + assertEquals("Incorrect testKafkaTopicOdeTimRxJson", testKafkaTopicOdeTimRxJson, + testOdeProperties.getKafkaTopicOdeTimRxJson()); + assertEquals("Incorrect testKafkaTopicOdeTimBroadcastPojo", testKafkaTopicOdeTimBroadcastPojo, + testOdeProperties.getKafkaTopicOdeTimBroadcastPojo()); + assertEquals("Incorrect testKafkaTopicOdeTimBroadcastJson", testKafkaTopicOdeTimBroadcastJson, + testOdeProperties.getKafkaTopicOdeTimBroadcastJson()); + assertEquals("Incorrect testKafkaTopicJ2735TimBroadcastJson", testKafkaTopicJ2735TimBroadcastJson, + testOdeProperties.getKafkaTopicJ2735TimBroadcastJson()); + assertEquals("Incorrect testKafkaTopicFilteredOdeTimJson", testKafkaTopicFilteredOdeTimJson, + testOdeProperties.getKafkaTopicFilteredOdeTimJson()); + assertEquals("Incorrect testKafkaTopicDriverAlertJson", testKafkaTopicDriverAlertJson, + testOdeProperties.getKafkaTopicDriverAlertJson()); - assertEquals("Incorrect testFileWatcherPeriod", testFileWatcherPeriod, testOdeProperties.getFileWatcherPeriod()); - assertEquals("Incorrect testSecuritySvcsSignatureUri", testSecuritySvcsSignatureUri, - testOdeProperties.getSecuritySvcsSignatureUri()); - assertEquals("Incorrect testRsuUsername", testRsuUsername, testOdeProperties.getRsuUsername()); - assertEquals("Incorrect RsuPassword", testRsuPassword, testOdeProperties.getRsuPassword()); + assertEquals("Incorrect testFileWatcherPeriod", testFileWatcherPeriod, + testOdeProperties.getFileWatcherPeriod()); + assertEquals("Incorrect testSecuritySvcsSignatureUri", testSecuritySvcsSignatureUri, + testOdeProperties.getSecuritySvcsSignatureUri()); + assertEquals("Incorrect testRsuUsername", testRsuUsername, testOdeProperties.getRsuUsername()); + assertEquals("Incorrect RsuPassword", testRsuPassword, testOdeProperties.getRsuPassword()); - OdeProperties.getJpoOdeGroupId(); - testOdeProperties.getHostId(); - testOdeProperties.getProperty("testProperty"); - testOdeProperties.getProperty("testProperty", 5); - testOdeProperties.getProperty("testProperty", "testDefaultValue"); - testOdeProperties.getUploadLocations(); - } + OdeProperties.getJpoOdeGroupId(); + testOdeProperties.getHostId(); + testOdeProperties.getProperty("testProperty"); + testOdeProperties.getProperty("testProperty", 5); + testOdeProperties.getProperty("testProperty", "testDefaultValue"); + testOdeProperties.getUploadLocations(); + } } diff --git a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/coder/stream/LogFileToAsn1CodecPublisherTest.java b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/coder/stream/LogFileToAsn1CodecPublisherTest.java index aa5dc1472..0072e2a85 100644 --- a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/coder/stream/LogFileToAsn1CodecPublisherTest.java +++ b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/coder/stream/LogFileToAsn1CodecPublisherTest.java @@ -50,12 +50,12 @@ public class LogFileToAsn1CodecPublisherTest { @Injectable StringPublisher injectableStringPublisher; - + @BeforeClass public static void setupClass() { - OdeMsgMetadata.setStaticSchemaVersion(OdeProperties.OUTPUT_SCHEMA_VERSION); + OdeMsgMetadata.setStaticSchemaVersion(OdeProperties.OUTPUT_SCHEMA_VERSION); } - + @Test public void testPublishInit(@Mocked LogFileParser mockLogFileParser) throws Exception { new Expectations() { @@ -68,12 +68,13 @@ public void testPublishInit(@Mocked LogFileParser mockLogFileParser) throws Exce } }; - List dataList = testLogFileToAsn1CodecPublisher.publish(new BufferedInputStream(new ByteArrayInputStream(new byte[0])), + List dataList = testLogFileToAsn1CodecPublisher.publish( + new BufferedInputStream(new ByteArrayInputStream(new byte[0])), "fileName", ImporterFileType.LEAR_LOG_FILE); assertTrue(dataList.isEmpty()); } - + @Test public void testPublishEOF(@Mocked LogFileParser mockLogFileParser) throws Exception { new Expectations() { @@ -86,31 +87,36 @@ public void testPublishEOF(@Mocked LogFileParser mockLogFileParser) throws Excep } }; - List dataList = testLogFileToAsn1CodecPublisher.publish(new BufferedInputStream(new ByteArrayInputStream(new byte[0])), + List dataList = testLogFileToAsn1CodecPublisher.publish( + new BufferedInputStream(new ByteArrayInputStream(new byte[0])), "fileName", ImporterFileType.LEAR_LOG_FILE); assertTrue(dataList.isEmpty()); } - + @Test(expected = IllegalArgumentException.class) public void testPublishThrowsIllegalArgumentException() throws Exception { - //If the filename does not follow expected filename pattern, IllegalArgumentException should be thrown + // If the filename does not follow expected filename pattern, + // IllegalArgumentException should be thrown testLogFileToAsn1CodecPublisher.publish(new BufferedInputStream(new ByteArrayInputStream(new byte[0])), "fileName", ImporterFileType.LEAR_LOG_FILE); fail("Expected an IllegalArgumentException to be thrown"); } - + @Test(expected = LogFileToAsn1CodecPublisherException.class) - public void testPublishThrowsLogFileToAsn1CodecPublisherException(@Mocked LogFileParser mockLogFileParser) throws Exception { + public void testPublishThrowsLogFileToAsn1CodecPublisherException(@Mocked LogFileParser mockLogFileParser) + throws Exception { new Expectations() { { - LogFileParser.factory(anyString); - result = mockLogFileParser; + LogFileParser.factory(anyString); + result = mockLogFileParser; /* - * If the embedded parser fails to parse a log file header, it may throw an exception - * which is then caught by the parser and re-thrown as LogFileToAsn1CodecPublisherException. - * This mocked object will simulate that eventuality. + * If the embedded parser fails to parse a log file header, it may throw an + * exception + * which is then caught by the parser and re-thrown as + * LogFileToAsn1CodecPublisherException. + * This mocked object will simulate that eventuality. */ mockLogFileParser.parseFile((BufferedInputStream) any, anyString); result = new LogFileToAsn1CodecPublisherException(anyString, (Exception) any); @@ -121,7 +127,7 @@ public void testPublishThrowsLogFileToAsn1CodecPublisherException(@Mocked LogFil "fileName", ImporterFileType.LEAR_LOG_FILE); fail("Expected an LogFileToAsn1CodecPublisherException to be thrown"); } - + @Test public void testPublishDecodeFailure(@Mocked LogFileParser mockLogFileParser) throws Exception { new Expectations() { @@ -134,186 +140,198 @@ public void testPublishDecodeFailure(@Mocked LogFileParser mockLogFileParser) th } }; - List dataList = testLogFileToAsn1CodecPublisher.publish(new BufferedInputStream(new ByteArrayInputStream(new byte[0])), + List dataList = testLogFileToAsn1CodecPublisher.publish( + new BufferedInputStream(new ByteArrayInputStream(new byte[0])), "fileName", ImporterFileType.LEAR_LOG_FILE); assertTrue(dataList.isEmpty()); } - + @Test public void testPublishBsmTxLogFile() throws Exception { - - byte[] buf = new byte[] { - (byte)0x00, //1. direction - (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 - }; - - String filename = RecordType.bsmTx.name() + GZ; - - BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); - - List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); - - for (OdeData data : dataList) { - assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), DateTimeUtils.nowZDT()) > 0); - data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); - data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); - assertEquals("{\"metadata\":{\"bsmSource\":\"EV\",\"logFileName\":\"bsmTx.gz\",\"recordType\":\"bsmTx\",\"securityResultCode\":\"success\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"NA\"},\"encodings\":[{\"elementName\":\"root\",\"elementType\":\"Ieee1609Dot2Data\",\"encodingRule\":\"COER\"},{\"elementName\":\"unsecuredData\",\"elementType\":\"MessageFrame\",\"encodingRule\":\"UPER\"}],\"payloadType\":\"us.dot.its.jpo.ode.model.OdeAsn1Payload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"maxDurationTime\":0,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"OBU\",\"sanitized\":false},\"payload\":{\"dataType\":\"us.dot.its.jpo.ode.model.OdeHexByteArray\",\"data\":{\"bytes\":\"038100400380\"}}}", data.toJson()); + + byte[] buf = new byte[] { + (byte) 0x00, // 1. direction + (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 + }; + + String filename = RecordType.bsmTx.name() + GZ; + + BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); + + List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); + + for (OdeData data : dataList) { + assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), + DateTimeUtils.nowZDT()) > 0); + data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); + data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); + var expected = "{\"metadata\":{\"bsmSource\":\"EV\",\"logFileName\":\"bsmTx.gz\",\"recordType\":\"bsmTx\",\"securityResultCode\":\"success\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"NA\"},\"encodings\":[{\"elementName\":\"root\",\"elementType\":\"Ieee1609Dot2Data\",\"encodingRule\":\"COER\"},{\"elementName\":\"unsecuredData\",\"elementType\":\"MessageFrame\",\"encodingRule\":\"UPER\"}],\"payloadType\":\"us.dot.its.jpo.ode.model.OdeAsn1Payload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"maxDurationTime\":0,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"OBU\",\"sanitized\":false},\"payload\":{\"dataType\":\"us.dot.its.jpo.ode.model.OdeHexByteArray\",\"data\":{\"bytes\":\"038100400380\"}}}"; + assertEquals(expected, data.toJson()); } } @Test public void testPublishDistressNotificationLogFile() throws Exception { - - byte[] buf = new byte[] { - (byte)0x6f, (byte)0x75, (byte)0x4d, (byte)0x19, //1.1 latitude - (byte)0xa4, (byte)0xa1, (byte)0x5c, (byte)0xce, //1.2 longitude - (byte)0x67, (byte)0x06, (byte)0x00, (byte)0x00, //1.3 elevation - (byte)0x04, (byte)0x00, //1.4 speed - (byte)0x09, (byte)0x27, //1.5 heading - (byte)0xa9, (byte)0x2c, (byte)0xe2, (byte)0x5a, //2. utcTimeInSec - (byte)0x8f, (byte)0x01, //3. mSec - (byte)0x00, //4. securityResultCode - (byte)0x06, (byte)0x00, //5.1 payloadLength - //5.2 payload - (byte)0x03, (byte)0x81, (byte)0x00, (byte)0x40, (byte)0x03, (byte)0x80 - }; - - String filename = RecordType.dnMsg.name() + GZ; - - BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); - - List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); - - for (OdeData data : dataList) { - assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), DateTimeUtils.nowZDT()) > 0); - data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); - data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); - assertEquals("{\"metadata\":{\"logFileName\":\"dnMsg.gz\",\"recordType\":\"dnMsg\",\"securityResultCode\":\"success\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"NA\"},\"encodings\":[{\"elementName\":\"root\",\"elementType\":\"Ieee1609Dot2Data\",\"encodingRule\":\"COER\"},{\"elementName\":\"unsecuredData\",\"elementType\":\"MessageFrame\",\"encodingRule\":\"UPER\"}],\"payloadType\":\"us.dot.its.jpo.ode.model.OdeAsn1Payload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"maxDurationTime\":0,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"OBU\",\"sanitized\":false},\"payload\":{\"dataType\":\"us.dot.its.jpo.ode.model.OdeHexByteArray\",\"data\":{\"bytes\":\"038100400380\"}}}", data.toJson()); + + byte[] buf = new byte[] { + (byte) 0x6f, (byte) 0x75, (byte) 0x4d, (byte) 0x19, // 1.1 latitude + (byte) 0xa4, (byte) 0xa1, (byte) 0x5c, (byte) 0xce, // 1.2 longitude + (byte) 0x67, (byte) 0x06, (byte) 0x00, (byte) 0x00, // 1.3 elevation + (byte) 0x04, (byte) 0x00, // 1.4 speed + (byte) 0x09, (byte) 0x27, // 1.5 heading + (byte) 0xa9, (byte) 0x2c, (byte) 0xe2, (byte) 0x5a, // 2. utcTimeInSec + (byte) 0x8f, (byte) 0x01, // 3. mSec + (byte) 0x00, // 4. securityResultCode + (byte) 0x06, (byte) 0x00, // 5.1 payloadLength + // 5.2 payload + (byte) 0x03, (byte) 0x81, (byte) 0x00, (byte) 0x40, (byte) 0x03, (byte) 0x80 + }; + + String filename = RecordType.dnMsg.name() + GZ; + + BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); + + List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); + + for (OdeData data : dataList) { + assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), + DateTimeUtils.nowZDT()) > 0); + data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); + data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); + var expected = "{\"metadata\":{\"logFileName\":\"dnMsg.gz\",\"recordType\":\"dnMsg\",\"securityResultCode\":\"success\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"NA\"},\"encodings\":[{\"elementName\":\"root\",\"elementType\":\"Ieee1609Dot2Data\",\"encodingRule\":\"COER\"},{\"elementName\":\"unsecuredData\",\"elementType\":\"MessageFrame\",\"encodingRule\":\"UPER\"}],\"payloadType\":\"us.dot.its.jpo.ode.model.OdeAsn1Payload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"maxDurationTime\":0,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"OBU\",\"sanitized\":false},\"payload\":{\"dataType\":\"us.dot.its.jpo.ode.model.OdeHexByteArray\",\"data\":{\"bytes\":\"038100400380\"}}}"; + assertEquals(expected, data.toJson()); } } @Test public void testPublishDriverAlertLogFile() throws Exception { - - byte[] buf = new byte[] { - (byte)0x6f, (byte)0x75, (byte)0x4d, (byte)0x19, //1.0 latitude - (byte)0xa4, (byte)0xa1, (byte)0x5c, (byte)0xce, //1.1 longitude - (byte)0x67, (byte)0x06, (byte)0x00, (byte)0x00, //1.2 elevation - (byte)0x04, (byte)0x00, //1.3 speed - (byte)0x09, (byte)0x27, //1.4 heading - (byte)0xa9, (byte)0x2c, (byte)0xe2, (byte)0x5a, //2. utcTimeInSec - (byte)0x8f, (byte)0x01, //3. mSec - (byte)0x11, (byte)0x00, //4.0 payloadLength - //4.1 payload - 'T', 'e', 's', 't', ' ', 'D', 'r', 'i', 'v', 'e', 'r', ' ', 'A', 'l', 'e', 'r', 't' - }; - - String filename = RecordType.driverAlert.name() + GZ; - - BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); - - List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); - - for (OdeData data : dataList) { - assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), DateTimeUtils.nowZDT()) > 0); - data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); - data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); - assertEquals("{\"metadata\":{\"logFileName\":\"driverAlert.gz\",\"recordType\":\"driverAlert\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"NA\"},\"payloadType\":\"us.dot.its.jpo.ode.model.OdeDriverAlertPayload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"maxDurationTime\":0,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"OBU\",\"sanitized\":false},\"payload\":{\"alert\":\"Test Driver Alert\"}}", data.toJson()); - } + + byte[] buf = new byte[] { + (byte) 0x6f, (byte) 0x75, (byte) 0x4d, (byte) 0x19, // 1.0 latitude + (byte) 0xa4, (byte) 0xa1, (byte) 0x5c, (byte) 0xce, // 1.1 longitude + (byte) 0x67, (byte) 0x06, (byte) 0x00, (byte) 0x00, // 1.2 elevation + (byte) 0x04, (byte) 0x00, // 1.3 speed + (byte) 0x09, (byte) 0x27, // 1.4 heading + (byte) 0xa9, (byte) 0x2c, (byte) 0xe2, (byte) 0x5a, // 2. utcTimeInSec + (byte) 0x8f, (byte) 0x01, // 3. mSec + (byte) 0x11, (byte) 0x00, // 4.0 payloadLength + // 4.1 payload + 'T', 'e', 's', 't', ' ', 'D', 'r', 'i', 'v', 'e', 'r', ' ', 'A', 'l', 'e', 'r', 't' + }; + + String filename = RecordType.driverAlert.name() + GZ; + + BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); + + List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); + + for (OdeData data : dataList) { + assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), + DateTimeUtils.nowZDT()) > 0); + data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); + data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); + var expected = "{\"metadata\":{\"logFileName\":\"driverAlert.gz\",\"recordType\":\"driverAlert\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"NA\"},\"payloadType\":\"us.dot.its.jpo.ode.model.OdeDriverAlertPayload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"maxDurationTime\":0,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"OBU\",\"sanitized\":false},\"payload\":{\"alert\":\"Test Driver Alert\"}}"; + assertEquals(expected, data.toJson()); + } } @Test public void testPublishRxMsgTIMLogFile() throws Exception { - - byte[] buf = new byte[] { - (byte)0x01, //1. RxSource = SAT - (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 - }; - - String filename = RecordType.rxMsg.name() + GZ; - - BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); - - List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); - - for (OdeData data : dataList) { - assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), DateTimeUtils.nowZDT()) > 0); - data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); - data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); - assertEquals("{\"metadata\":{\"logFileName\":\"rxMsg.gz\",\"recordType\":\"rxMsg\",\"securityResultCode\":\"success\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"SAT\"},\"encodings\":[{\"elementName\":\"root\",\"elementType\":\"Ieee1609Dot2Data\",\"encodingRule\":\"COER\"},{\"elementName\":\"unsecuredData\",\"elementType\":\"MessageFrame\",\"encodingRule\":\"UPER\"}],\"payloadType\":\"us.dot.its.jpo.ode.model.OdeAsn1Payload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"maxDurationTime\":0,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"TMC_VIA_SAT\",\"sanitized\":false},\"payload\":{\"dataType\":\"us.dot.its.jpo.ode.model.OdeHexByteArray\",\"data\":{\"bytes\":\"038100400380\"}}}", data.toJson()); - } + + byte[] buf = new byte[] { + (byte) 0x01, // 1. RxSource = SAT + (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 + }; + + String filename = RecordType.rxMsg.name() + GZ; + + BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); + + List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); + + for (OdeData data : dataList) { + assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), + DateTimeUtils.nowZDT()) > 0); + data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); + data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); + var expected = "{\"metadata\":{\"logFileName\":\"rxMsg.gz\",\"recordType\":\"rxMsg\",\"securityResultCode\":\"success\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"SAT\"},\"encodings\":[{\"elementName\":\"root\",\"elementType\":\"Ieee1609Dot2Data\",\"encodingRule\":\"COER\"},{\"elementName\":\"unsecuredData\",\"elementType\":\"MessageFrame\",\"encodingRule\":\"UPER\"}],\"payloadType\":\"us.dot.its.jpo.ode.model.OdeAsn1Payload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"maxDurationTime\":0,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"TMC_VIA_SAT\",\"sanitized\":false},\"payload\":{\"dataType\":\"us.dot.its.jpo.ode.model.OdeHexByteArray\",\"data\":{\"bytes\":\"038100400380\"}}}"; + assertEquals(expected, data.toJson()); + } } @Test public void testPublishRxMsgBSMLogFile() throws Exception { - - byte[] buf = new byte[] { - (byte)0x02, //1. RxSource = RV - (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 - }; - - String filename = RecordType.rxMsg.name() + GZ; - - BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); - - List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); - - for (OdeData data : dataList) { - assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), DateTimeUtils.nowZDT()) > 0); - data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); - data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); - assertEquals("{\"metadata\":{\"bsmSource\":\"RV\",\"logFileName\":\"rxMsg.gz\",\"recordType\":\"rxMsg\",\"securityResultCode\":\"success\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"RV\"},\"encodings\":[{\"elementName\":\"root\",\"elementType\":\"Ieee1609Dot2Data\",\"encodingRule\":\"COER\"},{\"elementName\":\"unsecuredData\",\"elementType\":\"MessageFrame\",\"encodingRule\":\"UPER\"}],\"payloadType\":\"us.dot.its.jpo.ode.model.OdeAsn1Payload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"maxDurationTime\":0,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"OBU\",\"sanitized\":false},\"payload\":{\"dataType\":\"us.dot.its.jpo.ode.model.OdeHexByteArray\",\"data\":{\"bytes\":\"038100400380\"}}}", data.toJson()); + + byte[] buf = new byte[] { + (byte) 0x02, // 1. RxSource = RV + (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 + }; + + String filename = RecordType.rxMsg.name() + GZ; + + BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); + + List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.LEAR_LOG_FILE); + + for (OdeData data : dataList) { + assertTrue(DateTimeUtils.difference(DateTimeUtils.isoDateTime(data.getMetadata().getOdeReceivedAt()), + DateTimeUtils.nowZDT()) > 0); + data.getMetadata().setOdeReceivedAt("2019-03-05T20:31:17.579Z"); + data.getMetadata().getSerialId().setStreamId("c7bbb42e-1e39-442d-98ac-62740ca50f92"); + var expected = "{\"metadata\":{\"bsmSource\":\"RV\",\"logFileName\":\"rxMsg.gz\",\"recordType\":\"rxMsg\",\"securityResultCode\":\"success\",\"receivedMessageDetails\":{\"locationData\":{\"latitude\":\"42.4506735\",\"longitude\":\"-83.2790108\",\"elevation\":\"163.9\",\"speed\":\"0.08\",\"heading\":\"124.9125\"},\"rxSource\":\"RV\"},\"encodings\":[{\"elementName\":\"root\",\"elementType\":\"Ieee1609Dot2Data\",\"encodingRule\":\"COER\"},{\"elementName\":\"unsecuredData\",\"elementType\":\"MessageFrame\",\"encodingRule\":\"UPER\"}],\"payloadType\":\"us.dot.its.jpo.ode.model.OdeAsn1Payload\",\"serialId\":{\"streamId\":\"c7bbb42e-1e39-442d-98ac-62740ca50f92\",\"bundleSize\":1,\"bundleId\":1,\"recordId\":0,\"serialNumber\":1},\"odeReceivedAt\":\"2019-03-05T20:31:17.579Z\",\"schemaVersion\":6,\"maxDurationTime\":0,\"recordGeneratedAt\":\"2018-04-26T19:46:49.399Z\",\"recordGeneratedBy\":\"OBU\",\"sanitized\":false},\"payload\":{\"dataType\":\"us.dot.its.jpo.ode.model.OdeHexByteArray\",\"data\":{\"bytes\":\"038100400380\"}}}"; + assertEquals(expected, data.toJson()); } } @Test public void testPublishNonLearLogFile() throws Exception { - - String filename = RecordType.rxMsg.name() + GZ; - String jsonData = "{\"fakeJsonKey\":\"fakeJsonValue\""; - byte[] buf = jsonData.getBytes(); - BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf )); + String filename = RecordType.rxMsg.name() + GZ; + + String jsonData = "{\"fakeJsonKey\":\"fakeJsonValue\""; + byte[] buf = jsonData.getBytes(); + BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(buf)); - /* - * This call to publish method does not actually try to parse the data. It short-circuits the parsing because - * currently we dont' support JSON input records. We may in the future. - */ - - List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.JSON_FILE); + /* + * This call to publish method does not actually try to parse the data. It + * short-circuits the parsing because + * currently we dont' support JSON input records. We may in the future. + */ - assertTrue(dataList.isEmpty()); + List dataList = testLogFileToAsn1CodecPublisher.publish(bis, filename, ImporterFileType.JSON_FILE); + + assertTrue(dataList.isEmpty()); } } diff --git a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimQueryControllerTest.java b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimQueryControllerTest.java index 882cc12aa..6be9d755d 100644 --- a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimQueryControllerTest.java +++ b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimQueryControllerTest.java @@ -58,6 +58,8 @@ public class TimQueryControllerTest { @Mocked PDU mockPDU; + private String defaultRSU = "{\"rsuTarget\":\"10.10.10.10\",\"rsuUsername\":\"user\",\"rsuPassword\":\"pass\",\"rsuRetries\":\"3\",\"rsuTimeout\":\"5000\"}"; + @Test public void nullRequestShouldReturnError() { ResponseEntity result = testTimQueryController.bulkQuery(null); @@ -85,7 +87,7 @@ public void snmpSessionExceptionShouldReturnError() { fail("Unexpected exception in expectations block: " + e); } - ResponseEntity actualResponse = testTimQueryController.bulkQuery("{\"request\":{},\"tim\":{}}"); + ResponseEntity actualResponse = testTimQueryController.bulkQuery(defaultRSU); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, actualResponse.getStatusCode()); assertTrue(actualResponse.getBody().contains("Failed to create SNMP session.")); } @@ -103,7 +105,7 @@ public void snmpSessionListenExceptionShouldReturnError() { fail("Unexpected exception in expectations block: " + e); } - ResponseEntity actualResponse = testTimQueryController.bulkQuery("{\"request\":{},\"tim\":{}}"); + ResponseEntity actualResponse = testTimQueryController.bulkQuery(defaultRSU); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, actualResponse.getStatusCode()); assertTrue(actualResponse.getBody().contains("Failed to create SNMP session.")); } @@ -123,7 +125,7 @@ public void testNullResponseReturnsTimeout() throws IOException { } }; - ResponseEntity actualResponse = testTimQueryController.bulkQuery("{\"request\":{},\"tim\":{}}"); + ResponseEntity actualResponse = testTimQueryController.bulkQuery(defaultRSU); assertEquals(HttpStatus.BAD_REQUEST, actualResponse.getStatusCode()); assertTrue(actualResponse.getBody().contains("Timeout, no response from RSU.")); } @@ -146,7 +148,7 @@ public void testNullResponseResponseReturnsTimeout() throws IOException { } }; - ResponseEntity actualResponse = testTimQueryController.bulkQuery("{\"request\":{},\"tim\":{}}"); + ResponseEntity actualResponse = testTimQueryController.bulkQuery(defaultRSU); assertEquals(HttpStatus.BAD_REQUEST, actualResponse.getStatusCode()); assertTrue(actualResponse.getBody().contains("Timeout, no response from RSU.")); } @@ -172,7 +174,7 @@ public void testSuccessfulQuery() throws IOException { } }; - ResponseEntity actualResponse = testTimQueryController.bulkQuery("{\"request\":{},\"tim\":{}}"); + ResponseEntity actualResponse = testTimQueryController.bulkQuery(defaultRSU); assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); assertTrue(actualResponse.getBody().contains("indicies_set")); } @@ -201,7 +203,7 @@ public void testSuccessfulPopulatedQuery() throws IOException { } }; - ResponseEntity actualResponse = testTimQueryController.bulkQuery("{\"request\":{},\"tim\":{}}"); + ResponseEntity actualResponse = testTimQueryController.bulkQuery(defaultRSU); assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); assertTrue(actualResponse.getBody().contains("indicies_set")); } 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 124336079..f03260e18 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 @@ -19,6 +19,8 @@ import mockit.Capturing; import mockit.Expectations; +import mockit.Mock; +import mockit.MockUp; import mockit.Mocked; import us.dot.its.jpo.ode.OdeProperties; import us.dot.its.jpo.ode.model.OdeMsgMetadata; @@ -28,6 +30,8 @@ import us.dot.its.jpo.ode.plugin.ServiceRequest; import us.dot.its.jpo.ode.plugin.SituationDataWarehouse.SDW; import us.dot.its.jpo.ode.plugin.j2735.DdsAdvisorySituationData; +import us.dot.its.jpo.ode.plugin.j2735.DdsGeoRegion; +import us.dot.its.jpo.ode.plugin.j2735.OdeGeoRegion; import us.dot.its.jpo.ode.plugin.j2735.builders.GeoRegionBuilder; import us.dot.its.jpo.ode.plugin.j2735.timstorage.TravelerInputData; import us.dot.its.jpo.ode.traveler.TimTransmogrifier.TimTransmogrifierException; @@ -187,6 +191,13 @@ public void testConvertToXMLASD(@Capturing DateTimeUtils capturingDateTimeUtils, } }; + new MockUp() { + @Mock + public DdsGeoRegion ddsGeoRegion(OdeGeoRegion serviceRegion) { + return new DdsGeoRegion(); + } + }; + SDW inputSDW = new SDW(); inputSDW.setDeliverystart("2017-06-01T17:47:11-05:00"); inputSDW.setDeliverystop("2018-03-01T17:47:11-05:15"); @@ -206,15 +217,13 @@ public void testConvertToXMLASD(@Capturing DateTimeUtils capturingDateTimeUtils, SerialId staticSerialId = new SerialId(); staticSerialId.setStreamId("6c33f802-418d-4b67-89d1-326b4fc8b1e3"); - + OdeMsgMetadata staticOdeMsgMetadata = new OdeMsgMetadata(); staticOdeMsgMetadata.setSchemaVersion(6); String actualXML = TimTransmogrifier.convertToXml(actualASD, encodableTID, staticOdeMsgMetadata, staticSerialId); - - assertEquals( - "us.dot.its.jpo.ode.model.OdeAsdPayload6c33f802-418d-4b67-89d1-326b4fc8b1e31000timeTime60false2017-06-01T17:47:11-05:002018-03-01T17:47:11-05:15MessageFrameMessageFrameUPERIeee1609Dot2DataIeee1609Dot2DataCOERAdvisorySituationDataAdvisorySituationDataUPERus.dot.its.jpo.ode.plugin.j2735.DdsAdvisorySituationData1565000000007876BA7F0000000017876BA7F2030000000000331", - actualXML); + String expected = "us.dot.its.jpo.ode.model.OdeAsdPayload6c33f802-418d-4b67-89d1-326b4fc8b1e31000timeTime60falsethirtyminutes2017-06-01T17:47:11-05:002018-03-01T17:47:11-05:15MessageFrameMessageFrameUPERIeee1609Dot2DataIeee1609Dot2DataCOERAdvisorySituationDataAdvisorySituationDataUPERus.dot.its.jpo.ode.plugin.j2735.DdsAdvisorySituationData1565000000007876BA7F0000000017876BA7F2030000000000331"; + assertEquals(expected, actualXML); } @Test @@ -248,15 +257,14 @@ public void testConvertToXMLMessageFrame(@Capturing DateTimeUtils capturingDateT SerialId staticSerialId = new SerialId(); staticSerialId.setStreamId("6c33f802-418d-4b67-89d1-326b4fc8b1e3"); - + OdeMsgMetadata staticOdeMsgMetadata = new OdeMsgMetadata(); staticOdeMsgMetadata.setSchemaVersion(6); String actualXML = TimTransmogrifier.convertToXml(null, encodableTID, staticOdeMsgMetadata, staticSerialId); + var expected = "us.dot.its.jpo.ode.model.OdeTimPayload6c33f802-418d-4b67-89d1-326b4fc8b1e31000timeTime60falsethirtyminutes2017-06-01T17:47:11-05:002018-03-01T17:47:11-05:15MessageFrameMessageFrameUPERMessageFrame31"; - assertEquals( - "us.dot.its.jpo.ode.model.OdeTimPayload6c33f802-418d-4b67-89d1-326b4fc8b1e31000timeTime60false2017-06-01T17:47:11-05:002018-03-01T17:47:11-05:15MessageFrameMessageFrameUPERMessageFrame31", - actualXML); + assertEquals(expected,actualXML); } @Test diff --git a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/upload/FileUploadControllerTest.java b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/upload/FileUploadControllerTest.java index 6bc125029..14c7416b2 100644 --- a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/upload/FileUploadControllerTest.java +++ b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/upload/FileUploadControllerTest.java @@ -18,6 +18,8 @@ import mockit.Capturing; import mockit.Expectations; import mockit.Injectable; +import mockit.Mock; +import mockit.MockUp; import mockit.Mocked; import org.junit.Before; import org.junit.Test; @@ -73,7 +75,7 @@ public void constructorShouldLaunchSevenThreads() { result = mockExecutorService; mockExecutorService.submit((Runnable) any); - times = 7; + times = 11; } }; testFileUploadController = new FileUploadController(mockStorageService, mockOdeProperties, diff --git a/pom.xml b/pom.xml index bbd330ca7..de4087cff 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ usdot-jpo-ode https://sonarcloud.io - 1.49 + 1.49 @@ -51,22 +51,22 @@ org.springframework.boot spring-boot-starter - - org.springframework.boot - spring-boot-starter-web - + + org.springframework.boot + spring-boot-starter-web + org.springframework.boot spring-boot-starter-test test - - - org.codehaus.groovy - groovy-all - 3.0.8 - pom - + + + org.codehaus.groovy + groovy-all + 3.0.8 + pom + org.jmockit jmockit @@ -76,15 +76,15 @@ junit junit - 4.13.1 + 4.13.2 test - + - - log4j - log4j - + + log4j + log4j + @@ -102,10 +102,10 @@ - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.9.0.2155 + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.9.0.2155 org.springframework.boot @@ -124,21 +124,28 @@ maven-surefire-plugin 3.0.0-M5 - -javaagent:${user.home}/.m2/repository/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar - + -javaagent:${user.home}/.m2/repository/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar + ${loader.path} ${project.build.directory} + + + org.apache.maven.surefire + surefire-junit47 + 3.0.0-M5 + + org.apache.maven.plugins maven-release-plugin 2.5.3 - + - + \ No newline at end of file