Skip to content

Commit

Permalink
Merge pull request usdot-jpo-ode#295 from usdot-jpo-ode/ode-971
Browse files Browse the repository at this point in the history
ODE 971 - Improve test coverage and cleanup
  • Loading branch information
hmusavi authored Jan 22, 2019
2 parents 6c8888c + c1d03da commit 7e35539
Show file tree
Hide file tree
Showing 254 changed files with 4,398 additions and 11,619 deletions.
69 changes: 36 additions & 33 deletions docs/ODESwagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ paths:
description: ODE version information returned
schema:
$ref: '#/definitions/versionResponse'

/tim/query:
post:
summary: Query an RSU for set TIMs
Expand Down Expand Up @@ -311,7 +311,7 @@ definitions:
"2017-08-03T22:25:36.297Z".
packetId:
type: string
description: Provides a unique message ID to given in a 9 byte hex string
description: Provides a unique message ID, in a 9-digit hex string.
urlB:
type: string
description: Standard URL link to designated resource.
Expand Down Expand Up @@ -422,7 +422,7 @@ definitions:
description: >-
A link to any other incident information data that may be available in
the normal ATIS incident description or other messages, a 4-digit hex
string or 16-digit binary string.
string.
RoadSignID:
type: object
properties:
Expand All @@ -442,8 +442,7 @@ definitions:
crc:
type: string
description: >-
Message cyclic-redundancy-check code in 4-digit hex string or 16-digit
binary string.
Message cyclic-redundancy-check code in 4-digit hex string.
Region:
type: object
properties:
Expand Down Expand Up @@ -483,27 +482,21 @@ definitions:
laneID:
type: integer
description: 'LaneID [0..255]'
offsetSmallX:
type: number
description: 'Reference lane offset measured in meters [-20.47..20.47m].'
offsetLargeX:
offsetXaxis:
type: number
description: 'Reference lane offset measured in meters [-327.67..327.67m].'
offsetSmallY:
type: number
description: 'Reference lane offset measured in meters [-20.47..20.47m].'
offsetLargeY:
offsetYaxis:
type: number
description: 'Reference lane offset measured in meters [-32767..327.67m].'
angle:
description: 'Reference lane offset measured in meters [-327.67..327.67m].'
rotateXY:
type: number
description: 'Lane rotation measured in degrees [0..359.9875] in steps of 0.0125.'
xScale:
description: 'Lane rotation measured in degrees [0..359.9875].'
scaleXaxis:
type: number
description: 'Scale factor in percent [0..202.35%] in steps of 0.05.'
yScale:
description: 'Scale factor in percent [0..202.35%].'
scaleYaxis:
type: number
description: 'Scale factor in percent [0..202.35%] in steps of 0.05.'
description: 'Scale factor in percent [0..202.35%].'
Path:
type: object
properties:
Expand Down Expand Up @@ -601,12 +594,12 @@ definitions:
type: integer
area:
type: string
regionPoint:
$ref: '#/definitions/RegionPoint'
regionPointSet:
$ref: '#/definitions/RegionPointSet'
circle:
$ref: '#/definitions/Circle'
shapePoint:
$ref: '#/definitions/ShapePoint'
shapePointSet:
$ref: '#/definitions/ShapePointSet'
Circle:
type: object
properties:
Expand All @@ -616,22 +609,32 @@ definitions:
type: integer
units:
type: integer
ShapePoint:
ShapePointSet:
type: object
properties:
position:
anchor:
$ref: '#/definitions/OdePosition3D'
directionality:
laneWidth:
type: integer
nodeType:
directionality:
type: string
computedLane:
$ref: '#/definitions/ComputedLane'
nodexy:
description: one of ENUMERATED {
unavailable (0), -- unknown or NA, not typically used in valid expressions
forward (1), -- direction of travel follows node ordering
reverse (2), -- direction of travel is the reverse of node ordering
both (3) -- direction of travel allowed in both directions
nodeList:
$ref: '#/definitions/NodeListXY'
NodeListXY:
type: object
properties:
nodes:
type: array
items:
$ref: '#/definitions/NodeXY'
RegionPoint:
$ref: '#/definitions/Node'
computed:
$ref: '#/definitions/ComputedLane'
RegionPointSet:
type: object
properties:
position:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ public byte[] getBundle() {
if ( point == null )
return payload;
int payloadLength = payload != null ? payload.length : 0;
int HEADER_LENGTH = MIN_BUNDLE_LENGTH - 4 + point.address.length;
byte [] bundle = new byte[HEADER_LENGTH + payloadLength];
ByteBuffer buffer = ByteBuffer.allocate(HEADER_LENGTH).order(ByteOrder.BIG_ENDIAN);
int headerLength = MIN_BUNDLE_LENGTH - 4 + point.address.length;
byte [] bundle = new byte[headerLength + payloadLength];
ByteBuffer buffer = ByteBuffer.allocate(headerLength).order(ByteOrder.BIG_ENDIAN);
buffer.putInt(MAGIC_NUMBER);
buffer.putInt(point.port);
buffer.put((byte)(point.address.length == 16 ? 1 : 0));
buffer.put(point.address);
byte[] header = buffer.array();
assert(header.length == HEADER_LENGTH);
assert(header.length == headerLength);
CrcCccitt.setMsgCRC(header);
System.arraycopy(header, 0, bundle, 0, HEADER_LENGTH);
System.arraycopy(header, 0, bundle, 0, headerLength);
if ( payload != null )
System.arraycopy(payload, 0, bundle, HEADER_LENGTH, payloadLength);
System.arraycopy(payload, 0, bundle, headerLength, payloadLength);
return bundle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
*/
public class InetPacketSender {

private static final Logger log = Logger.getLogger(InetPacketSender.class);
private static final String INVALID_PARAMETERS_MSG = "Invalid Parameters. Parameters destination point and payload can not be null";

private static final Logger log = Logger.getLogger(InetPacketSender.class);

/**
* Inet address and port to forward packets to
Expand Down Expand Up @@ -90,7 +92,7 @@ public void send(DatagramPacket packet) throws InetPacketException {
*/
public void forward(InetPoint dstPoint, byte[] payload) throws InetPacketException {
if ( dstPoint == null || payload == null )
throw new InetPacketException("Invalid Parameters. Parameters destination point and payload can not be null");
throw new InetPacketException(INVALID_PARAMETERS_MSG);
if ( frwdPoint == null )
log.warn("Couldn't forward packet. Reason: Forwarding destination is not defined.");
if ( frwdPoint != null && (dstPoint.isIPv6Address() || isForwardAll()) ) {
Expand All @@ -110,7 +112,7 @@ public void forward(InetPoint dstPoint, byte[] payload) throws InetPacketExcepti
*/
public void forward(InetPoint dstPoint, byte[] payload, boolean fromForwarder) throws InetPacketException {
if ( dstPoint == null || payload == null )
throw new InetPacketException("Invalid Parameters. Parameters destination point and payload can not be null");
throw new InetPacketException(INVALID_PARAMETERS_MSG);
if ( frwdPoint != null && (dstPoint.isIPv6Address() || isForwardAll() || fromForwarder) ) {
send(frwdPoint, new InetPacket(dstPoint, payload).getBundle());
} else {
Expand All @@ -127,20 +129,14 @@ public void forward(InetPoint dstPoint, byte[] payload, boolean fromForwarder) t
*/
public void send(InetPoint dstPoint, byte[] payload) throws InetPacketException {
if ( dstPoint == null || payload == null )
throw new InetPacketException("Invalid Parameters. Parameters destination point and payload can not be null");
DatagramSocket sock = null;
try {
throw new InetPacketException(INVALID_PARAMETERS_MSG);
try(DatagramSocket sock = new DatagramSocket()) {
DatagramPacket packet = new DatagramPacket(payload, payload.length, dstPoint.getInetAddress(), dstPoint.port);
sock = new DatagramSocket();
sock.send(packet);
} catch (SocketException ex) {
throw new InetPacketException("Couldn't send packet because socket closed.", ex);
} catch (IOException ex) {
throw new InetPacketException("Couldn't send packet due to IO exception.", ex);
} finally {
if ( sock != null ) {
sock.close();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
import java.net.InetAddress;
import java.net.UnknownHostException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import us.dot.its.jpo.ode.util.CodecUtils;

public class InetPoint {
final public byte[] address;
final public int port;
final public boolean forward;
private final Logger logger = LoggerFactory.getLogger(this.getClass());

public final byte[] address;
public final int port;
public final boolean forward;

public InetPoint(String host, int port, boolean forward) throws UnknownHostException {
this(InetAddress.getByName(host).getAddress(), port, forward);
Expand All @@ -34,7 +39,9 @@ public InetPoint(byte[] address, int port) {
}

public InetPoint(byte[] address, int port, boolean forward ) {
assert(address != null);
if (address == null) {
throw new IllegalArgumentException("IP Address is required");
}
this.address = address;
this.port = port;
this.forward = forward;
Expand All @@ -54,6 +61,7 @@ public String toString() {
try {
host = InetAddress.getByAddress(address).getHostAddress();
} catch (UnknownHostException e) {
logger.error("Error", e);
}
return String.format("%s { port = %d (0x%x); address = %s (%s, %s); forward = %s }",
getClass().getSimpleName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,19 @@ public static List<URL> getClasspath() {

return classpath;
}

public static String enumToString(Class<?> clazz, String enumNameOrOrdinal) {

String enumName = null;
try {
Object[] enumConstants = clazz.getEnumConstants();
if (enumConstants != null) {
int enumOrdinal = Integer.parseInt(enumNameOrOrdinal);
enumName = enumConstants[enumOrdinal].toString();
}
} catch (NumberFormatException e) {
enumName = enumNameOrOrdinal;
}
return enumName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package us.dot.its.jpo.ode.util;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
Expand Down Expand Up @@ -166,4 +167,14 @@ public static HashMap<String, JsonNode> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Object fromXml(String xml, Class<?> clazz) throws XmlUtilsException {
* @param arrayNode: The array node to be embedded in a ObjectNode
* @return OBjectNode representation of the given arrayNode redy to be converted to XML
*/
public static ObjectNode createEmbeddedJsonArrayForXmlConversion(String childKey, ArrayNode arrayNode) {
public static ObjectNode createEmbeddedJsonArrayForXmlConversion(String childKey, JsonNode arrayNode) {
ObjectNode childNode = staticXmlMapper.createObjectNode();
childNode.set(childKey, arrayNode);
return childNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public class InetPacketFunctionalTest {
@Capturing
Thread capturingThread;

private static boolean isVerbose = true;
private static boolean isVerbose = false;

@Test
@Test
public void testConstrcutor() throws UnknownHostException {
InetPacket pkt = new InetPacket("bah.com", 1111, null);

Expand Down
Loading

0 comments on commit 7e35539

Please sign in to comment.