Skip to content

Commit

Permalink
ODE-781 Test fixture changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hmusavi committed Jul 23, 2018
1 parent 86b6146 commit 1fe6ed0
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 325 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public class InetPointTest {
@Capturing
InetAddress capturingInetAddress;

@Mocked
UnknownHostException mockUnknownHostException;

@Test
public void testStringConstructorCreatesAddress() {
try {
Expand Down Expand Up @@ -105,19 +102,9 @@ public void testToStringMethodIPV6() {

@Test
public void testToStringException() {
try {
new Expectations() {
{
InetAddress.getByAddress((byte[]) any).getHostAddress();
result = mockUnknownHostException;
}
};
assertEquals(
"InetPoint { port = 5 (0x5); address = 00000000000000000000000000000000 (IPv6, ?); forward = false }",
"InetPoint { port = 5 (0x5); address = 00000000000000000000000000000000 (IPv6, null); forward = false }",
new InetPoint(new byte[16], 5).toString());
} catch (UnknownHostException e) {
fail("Unexpected exception: " + e);
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package us.dot.its.jpo.ode.dds;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.junit.Test;
import mockit.*;

import mockit.Mocked;
import us.dot.its.jpo.ode.dds.DdsRequest.Dialog;
import us.dot.its.jpo.ode.model.StatusTag;

Expand All @@ -19,10 +21,10 @@ public void testConstructor1() {
}

@Test
public void testConstructor2(@Mocked StatusTag tag, @Mocked String encoding, @Mocked Dialog dialog) {
DdsStatusMessage ddsStatusMessage = new DdsStatusMessage(tag, encoding, dialog);
public void testConstructor2(@Mocked StatusTag tag, @Mocked Dialog dialog) {
DdsStatusMessage ddsStatusMessage = new DdsStatusMessage(tag, "UPER", dialog);
assertEquals(ddsStatusMessage.getTag(), tag);
assertEquals(ddsStatusMessage.getEncoding(), encoding);
assertEquals(ddsStatusMessage.getEncoding(), "UPER");
assertEquals(ddsStatusMessage.getDialog(), dialog);

ddsStatusMessage.setTag(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;

import mockit.Mocked;
import mockit.StrictExpectations;
import mockit.integration.junit4.JMockit;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import mockit.Expectations;
import mockit.Mocked;
import mockit.integration.junit4.JMockit;
import us.dot.its.jpo.ode.wrapper.WebSocketEndpoint.WebSocketException;

@RunWith(JMockit.class)
Expand Down Expand Up @@ -166,7 +165,7 @@ public void testConnect() throws URISyntaxException, WebSocketException, Deploym
final WebSocketEndpoint<Integer> wsClient = new WebSocketEndpoint<Integer>(
"http:https://host:port/path", null, null, null, handler, null);

new StrictExpectations() {{
new Expectations() {{
ContainerProvider.getWebSocketContainer(); result = container;
container.connectToServer(
wsClient, wsClient.getWsConfig(), wsClient.getUri());
Expand All @@ -185,7 +184,7 @@ public void testClose() throws URISyntaxException, DeploymentException, IOExcept
final WebSocketEndpoint<Integer> wsClient = new WebSocketEndpoint<Integer>(
"http:https://host:port/path", null, null, null, handler, null);

new StrictExpectations() {{
new Expectations() {{
ContainerProvider.getWebSocketContainer(); result = container;
container.connectToServer(
wsClient, wsClient.getWsConfig(), wsClient.getUri());
Expand Down Expand Up @@ -215,7 +214,7 @@ public void testSend() throws URISyntaxException, DeploymentException, IOExcepti

final String message = "Test Message";

new StrictExpectations() {{
new Expectations() {{
ContainerProvider.getWebSocketContainer(); result = container;
container.connectToServer(
wsClient, wsClient.getWsConfig(), wsClient.getUri());
Expand Down
8 changes: 8 additions & 0 deletions jpo-ode-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,13 @@
<artifactId>fedgov-cv-security-2016</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,22 @@

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import mockit.Expectations;
import mockit.Mocked;

/**
* Test class for TravelerMessageFromHumanToAsnConverter.translateISOTimeStampToMinuteOfYear()
*
*/
@Ignore
public class TimeStampConverterTest {

@Mocked private static Logger logger;

@BeforeClass
public static void classSetup() {
new Expectations(LoggerFactory.class) {
{
LoggerFactory.getLogger(TravelerMessageFromHumanToAsnConverter.class);
result = logger;
}
};
}

@Before
public void setup() {
new Expectations(LoggerFactory.class) {
{
logger.warn(anyString);
}
};
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,20 @@

import org.json.JSONObject;
import org.json.XML;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.node.ObjectNode;

import mockit.Expectations;
import mockit.Mocked;
import us.dot.its.jpo.ode.util.JsonUtils;
import us.dot.its.jpo.ode.util.JsonUtils.JsonUtilsException;

@Ignore
public class TravelerMessageFromHumanToAsnConverterTest {

@Test
public void testRealJson(@Mocked Logger logger) throws JsonProcessingException, IOException, JsonUtilsException {
new Expectations(LoggerFactory.class) {
{
LoggerFactory.getLogger(TravelerMessageFromHumanToAsnConverter.class);
result = logger;
logger.warn("test");
}
};
public void testRealJson() throws JsonProcessingException, IOException, JsonUtilsException {

ObjectNode inputTID = JsonUtils.toObjectNode(
"{ \"tim\": { \"index\": \"13\", \"packetID\": \"2\", \"msgCnt\": \"1\", \"timeStamp\": \"2017-12-01T17:47:11-05:00\", \"urlB\": \"null\", \"dataframes\": [ { \"startDateTime\": \"2017-08-02T22:25:00.000Z\", \"durationTime\": 1, \"frameType\": \"1\", \"sspTimRights\": \"0\", \"msgID\": \"RoadSignID\", \"position\": { \"latitude\": \"41.678473\", \"longitude\": \"-108.782775\", \"elevation\": \"917.1432\" }, \"viewAngle\": \"1010101010101010\", \"mutcd\": \"5\", \"crc\": \"0000000000000000\", \"priority\": \"0\", \"sspLocationRights\": \"3\", \"regions\": [ { \"name\": \"Testing TIM\", \"regulatorID\": \"0\", \"segmentID\": \"33\", \"anchorPosition\": { \"latitude\": \"41.2500807\", \"longitude\": \"-111.0093847\", \"elevation\": \"2020.6969900289998\" }, \"laneWidth\": \"7\", \"directionality\": \"3\", \"closedPath\": \"false\", \"description\": \"path\", \"path\": { \"scale\": \"0\", \"type\": \"ll\", \"nodes\": [ { \"nodeLong\": \"0.0031024\", \"nodeLat\": \"0.0014506\", \"delta\": \"node-LL3\" }, { \"nodeLong\": \"0.0030974\", \"nodeLat\": \"0.0014568\", \"delta\": \"node-LL3\" }, { \"nodeLong\": \"0.0030983\", \"nodeLat\": \"0.0014559\", \"delta\": \"node-LL3\" }, { \"nodeLong\": \"0.0030980\", \"nodeLat\": \"0.0014563\", \"delta\": \"node-LL3\" }, { \"nodeLong\": \"0.0030982\", \"nodeLat\": \"0.0014562\", \"delta\": \"node-LL3\" } ] }, \"direction\": \"0000000000001010\" } ], \"sspMsgTypes\": \"2\", \"sspMsgContent\": \"3\", \"content\": \"Advisory\", \"items\": [\"513\",\"some text\", \"'98765\"], \"url\": \"null\" } ] }, \"rsus\": [ { \"rsuTarget\": \"192.168.1.1\", \"rsuUsername\": \"user\", \"rsuPassword\": \"password\", \"rsuRetries\": \"1\", \"rsuTimeout\": \"2000\" } ], \"snmp\": { \"rsuid\": \"00000083\", \"msgid\": \"31\", \"mode\": \"1\", \"channel\": \"178\", \"interval\": \"2\", \"deliverystart\": \"2017-06-01T17:47:11-05:00\", \"deliverystop\": \"2018-01-01T17:47:11-05:15\", \"enable\": \"1\", \"status\": \"4\" } }");
Expand All @@ -49,14 +38,7 @@ public void testRealJson(@Mocked Logger logger) throws JsonProcessingException,
}

@Test
public void test2(@Mocked Logger logger) throws JsonUtilsException {
new Expectations(LoggerFactory.class) {
{
LoggerFactory.getLogger(TravelerMessageFromHumanToAsnConverter.class);
result = logger;
logger.warn("test");
}
};
public void test2() throws JsonUtilsException {

ObjectNode inputTID = JsonUtils.toObjectNode(
"{\"tim\":{\"msgCnt\":\"1\",\"timeStamp\":431644,\"packetID\":\"3\",\"urlB\":\"null\",\"dataFrames\":[{\"TravelerDataFrame\":{\"frameType\":{\"1\":\"EMPTY_TAG\"},\"sspTimRights\":\"1\",\"msgID\":\"RoadSignID\",\"position\":{\"latitude\":\"40.573068\",\"longitude\":\"-105.049016\",\"elevation\":\"1500.8999999999999\"},\"viewAngle\":\"1111111111111111\",\"mutcd\":\"2\",\"crc\":\"0000000000000000\",\"priority\":\"5\",\"sspLocationRights\":\"1\",\"regions\":[{\"GeographicalPath\":{\"name\":\"Testing TIM\",\"laneWidth\":0,\"directionality\":{\"both\":\"EMPTY_TAG\"},\"closedPath\":\"BOOLEAN_OBJECT_FALSE\",\"description\":{\"path\":{\"scale\":\"0\",\"offset\":{\"xy\":{\"nodes\":{\"NodeXY\":[{\"delta\":{\"node-LatLon\":{\"lon\":0,\"lat\":0}}},{\"delta\":{\"node-LatLon\":{\"lon\":0,\"lat\":0}}},{\"delta\":{\"node-LatLon\":{\"lon\":0,\"lat\":0}}},{\"delta\":{\"node-LatLon\":{\"lon\":0,\"lat\":0}}},{\"delta\":{\"node-LatLon\":{\"lon\":0,\"lat\":0}}},{\"delta\":{\"node-LatLon\":{\"lon\":0,\"lat\":0}}},{\"delta\":{\"node-LatLon\":{\"lon\":0,\"lat\":0}}},{\"delta\":{\"node-LatLon\":{\"lon\":0,\"lat\":0}}},{\"delta\":{\"node-LatLon\":{\"lon\":0,\"lat\":0}}},{\"delta\":{\"node-LatLon\":{\"lon\":0,\"lat\":0}}}]}}}}},\"direction\":\"1111111111111111\",\"id\":{\"region\":0,\"id\":33},\"anchor\":{\"lat\":0,\"long\":0,\"elevation\":0}}}],\"url\":\"null\",\"sspMsgRights2\":1,\"sspMsgRights1\":1,\"duratonTime\":100,\"startYear\":2017,\"startTime\":420802,\"tcontent\":{\"advisory\":{\"SEQUENCE\":[{\"item\":{\"itis\":513}},{\"item\":{\"text\":\"some text\"}},{\"item\":{\"text\":\"98765\"}}]}}}}]},\"rsus\":[{\"rsuRetries\":\"3\",\"rsuTimeout\":\"5000\",\"rsuUsername\":\"v3user\",\"rsuPassword\":\"password\",\"rsuTarget\":\"192.168.0.145\",\"indicies\":[1,2]}],\"snmp\":{\"rsuid\":\"00000083\",\"msgid\":\"31\",\"mode\":\"1\",\"channel\":\"178\",\"interval\":\"2\",\"deliverystart\":\"2017-06-01T17:47:11-05:00\",\"deliverystop\":\"2018-01-01T17:47:11-05:15\",\"enable\":\"1\",\"status\":\"4\"},\"sdw\":{\"ttl\":\"oneday\",\"serviceRegion\":{\"nwCorner\":{\"latitude\":\"45.035685245316394\",\"longitude\":\"-110.95195770263672\"},\"seCorner\":{\"latitude\":\"40.96538194577477\",\"longitude\":\"-104.15382385253906\"}}}}");
Expand All @@ -73,15 +55,7 @@ public void test2(@Mocked Logger logger) throws JsonUtilsException {
}

@Test
public void testTranslateISOTimeStampToMinuteOfYear(@Mocked Logger logger) {
new Expectations(LoggerFactory.class) {
{
LoggerFactory.getLogger(TravelerMessageFromHumanToAsnConverter.class);
result = logger;
logger.warn("test");
}
};

public void testTranslateISOTimeStampToMinuteOfYear() {
assertEquals(232800,
TravelerMessageFromHumanToAsnConverter.translateISOTimeStampToMinuteOfYear(
"2018-06-11T16:00:00.000Z"));
Expand All @@ -97,15 +71,7 @@ public void testTranslateISOTimeStampToMinuteOfYear(@Mocked Logger logger) {
}

@Test
public void testReplaceDataFrameTimestamp(@Mocked Logger logger) {
new Expectations(LoggerFactory.class) {
{
LoggerFactory.getLogger(TravelerMessageFromHumanToAsnConverter.class);
result = logger;
logger.warn("test");
}
};

public void testReplaceDataFrameTimestamp() {
String fieldName = "startDateTime";
ObjectNode startDateTime = JsonUtils.newNode().put(fieldName, "2018-06-11T16:00:00.000Z");
TravelerMessageFromHumanToAsnConverter.replaceDataFrameTimestamp(startDateTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.oss.asn1.COERCoder;
import com.oss.asn1.DecodeFailedException;
import com.oss.asn1.DecodeNotSupportedException;
import com.oss.asn1.EncodeFailedException;
import com.oss.asn1.ValidateFailedException;
import com.oss.asn1.ValidateNotSupportedException;

Expand Down Expand Up @@ -47,16 +46,11 @@ public class Oss1609dot2CoderTest {
@Capturing
COERCoder capturingCOERCoder;

@Mocked
EncodeFailedException mockFailedEncodeException;

@Mocked
Ieee1609Dot2Data mockIeee1609Dot2Data;

@Capturing
DatatypeConverter capturingDatatypeConverter;
@Mocked
DecodeFailedException mockDecodeFailedException;

@Capturing
LoggerFactory capturingLoggerFactory; // needed otherwise test fails
Expand All @@ -72,21 +66,6 @@ public void constructorGetsCoerEncoder() {
new Oss1609dot2Coder();
}

@Test
public void shouldCatchByteDecodingExceptionAndReturnsNull() {
try {
new Expectations() {
{
capturingCOERCoder.decode((InputStream) any, (Ieee1609Dot2Data) any);
result = mockFailedEncodeException;
}
};
} catch (DecodeFailedException | DecodeNotSupportedException e) {
fail("Unexpected errror: " + e);
}
assertNull(testOss1609dot2Coder.decodeIeee1609Dot2DataBytes(new byte[] { 1, 2, 3 }));
}

@Test
public void successfulByteDecodingReturnsObject() {
try {
Expand All @@ -102,21 +81,6 @@ public void successfulByteDecodingReturnsObject() {
assertEquals(mockIeee1609Dot2Data, testOss1609dot2Coder.decodeIeee1609Dot2DataBytes(new byte[] { 1, 2, 3 }));
}

@Test
public void failedHexDecodingReturnsNull() {
try {
new Expectations() {
{
capturingCOERCoder.decode((InputStream) any, (Ieee1609Dot2Data) any);
result = mockFailedEncodeException;
}
};
} catch (DecodeFailedException | DecodeNotSupportedException e) {
fail("Unexpected errror: " + e);
}
assertNull(testOss1609dot2Coder.decodeIeee1609Dot2DataHex("test hex message"));
}

@Test
public void successfulHexDecodingReturnsObject() {
try {
Expand All @@ -135,17 +99,6 @@ public void successfulHexDecodingReturnsObject() {
@Test
public void failedInputStreamDecodingReturnsNull() {

try {
new Expectations() {
{
capturingCOERCoder.decode((InputStream) any, (Ieee1609Dot2Data) any);
result = mockFailedEncodeException;
}
};
} catch (DecodeFailedException | DecodeNotSupportedException e) {
fail("Unexpected errror: " + e);
}

BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(new byte[] {1,2,3}));
assertNull(testOss1609dot2Coder.decodeIeee1609Dot2DataStream(bis));
}
Expand Down Expand Up @@ -178,30 +131,17 @@ public void successfulInputStreamDecodingReturnsObject() {

@Test
public void handleDecodeExceptionDecodeNotSupported(@Mocked AbstractData mockAbstractData) {
new Expectations() {
{
mockDecodeFailedException.getDecodedData();
result = mockAbstractData;
}
};
testOss1609dot2Coder.handleDecodeException(mockDecodeFailedException);
testOss1609dot2Coder.handleDecodeException(new Exception());
}

@Test
public void handleDecodeExceptionDecodeNotSupportedNull() {
new Expectations() {
{
mockDecodeFailedException.getDecodedData();
result = null;
}
};
testOss1609dot2Coder.handleDecodeException(mockDecodeFailedException);
testOss1609dot2Coder.handleDecodeException(new Exception());
}

@Test
public void handleDecodeExceptionDecodeNotSupportedException(
@Injectable DecodeNotSupportedException injectableDecodeNotSupportedException) {
testOss1609dot2Coder.handleDecodeException(injectableDecodeNotSupportedException);
public void handleDecodeExceptionDecodeNotSupportedException() {
testOss1609dot2Coder.handleDecodeException(new Exception());
}

@Test
Expand Down
Loading

0 comments on commit 1fe6ed0

Please sign in to comment.