Skip to content
Snippets Groups Projects
Commit 7efdcaf6 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

add FirePdu test, update javadoc and design pattern

parent 58f803e6
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,7 @@ public class CommentPdusTest ...@@ -50,6 +50,7 @@ public class CommentPdusTest
disNetworkInterface = null; disNetworkInterface = null;
} }
/** Test PDU sending, receiving, marshalling (serialization) and unmarshalling (deserialization) */
@Test @Test
public void testRoundTrip() public void testRoundTrip()
{ {
...@@ -66,6 +67,8 @@ public class CommentPdusTest ...@@ -66,6 +67,8 @@ public class CommentPdusTest
testOne(pduFactory.makeCommentReliablePdu("xyz R first message","mno R second message", "jkl R third message")); testOne(pduFactory.makeCommentReliablePdu("xyz R first message","mno R second message", "jkl R third message"));
} }
/** Test single PDU for correctness according to all contained fields in this PDU type
* @param newPdu PDU of interest */
private void testOne(Pdu newPdu) private void testOne(Pdu newPdu)
{ {
sendPdu(newPdu); // will wait a while sendPdu(newPdu); // will wait a while
......
...@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.*; ...@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.*;
@DisplayName("Entity State Pdu Test") @DisplayName("Entity State Pdu Test")
public class EntityStatePduTest extends PduTest public class EntityStatePduTest extends PduTest
{ {
/** Test PDU sending, receiving, marshalling (serialization) and unmarshalling (deserialization) */
@Test @Test
@Override @Override
public void testRoundTrip() public void testRoundTrip()
...@@ -48,6 +49,8 @@ public class EntityStatePduTest extends PduTest ...@@ -48,6 +49,8 @@ public class EntityStatePduTest extends PduTest
testOnePdu(espdu.setEntityID(entityID).setEntityType(entityType)); testOnePdu(espdu.setEntityID(entityID).setEntityType(entityType));
} }
/** Test single PDU for correctness according to all contained fields in this PDU type
* @param newPdu PDU of interest*/
@Override @Override
protected void testOnePdu(Pdu newPdu) protected void testOnePdu(Pdu newPdu)
{ {
......
/**
* Copyright (c) 2008-2020, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* This work is provided under a BSD open-source license, see project license.html and license.txt
*/
package edu.nps.moves.dis7;
import edu.nps.moves.dis7.entities.usa.munition.other.M1A2;
import edu.nps.moves.dis7.enumerations.Country;
import edu.nps.moves.dis7.enumerations.EntityKind;
import edu.nps.moves.dis7.utilities.PduFactory;
import edu.nps.moves.dis7.enumerations.PlatformDomain;
import edu.nps.moves.dis7.pdus.Domain;
import edu.nps.moves.dis7.pdus.EntityID;
import edu.nps.moves.dis7.pdus.FirePdu;
import edu.nps.moves.dis7.pdus.EntityType;
import edu.nps.moves.dis7.pdus.Pdu;
import edu.nps.moves.dis7.pdus.PduBase;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
@DisplayName("Fire Pdu Test")
public class FirePduTest extends PduTest
{
/** Test PDU sending, receiving, marshalling (serialization) and unmarshalling (deserialization) */
@Test
@Override
public void testRoundTrip()
{
PduFactory pduFactory = new PduFactory();
FirePdu firePdu = pduFactory.makeFirePdu();
// TODO alternate constructors and utility methods
EntityID entityID = new EntityID().setSiteID((short)1).setApplicationID((short)2).setEntityID((short)3);
EntityType entityType = new EntityType()
.setEntityKind (EntityKind.PLATFORM).setEntityKind(EntityKind.PLATFORM) //(short) 1); // Platform (vs lifeform, munition, sensor, etc.); //(short) 1); // Platform (vs lifeform, munition, sensor, etc.)
.setCountry (Country.UNITED_STATES_OF_AMERICA_USA) // 225 USA
.setDomain (Domain.inst(PlatformDomain.LAND)) // Land (vs air, surface, subsurface, space)
.setCategory ((byte) 1) // Tank
.setSubCategory((byte) 1) // M1 Abrams
.setSpecific ((byte) 3); // M1A2 Abrams
// TODO update PDU-specific tests
// firePdu.setEntityType(entityType);
// // Alternate way using entity jar(s)
// firePdu.setEntityType(new edu.nps.moves.dis7.entities.usa.platform.land.M1A2());
// // or simply use an enumeration by name, with accompanying import statement above
// firePdu.setEntityType(new M1A2());
//
// testOnePdu(firePdu);
// testOnePdu(firePdu.setEntityID(entityID).setEntityType(entityType));
}
/** Test single PDU for correctness according to all contained fields in this PDU type
* @param newPdu PDU of interest */
@Override
protected void testOnePdu(Pdu newPdu)
{
sendPdu(newPdu); // will wait a while
assertTrue(receivedPdu != null, "No response from network receive");
assertEquals ( newPdu.getProtocolVersion(), receivedPdu.getProtocolVersion(), "mismatched ProtocolVersion");
// TODO compatibility version
assertEquals ( newPdu.getExerciseID(), receivedPdu.getExerciseID(), "mismatched ExerciseID");
assertEquals ( newPdu.getPduType(), receivedPdu.getPduType(), "mismatched PduType");
assertEquals ( newPdu.getProtocolFamily(), receivedPdu.getProtocolFamily(), "mismatched ProtocolFamily"); // derived from PduType
assertEquals(((PduBase)newPdu).getPduStatus(), ((PduBase)receivedPdu).getPduStatus(), "mismatched PduStatus");
assertEquals(((PduBase)newPdu).getPadding(), ((PduBase)receivedPdu).getPadding(), "mismatched header padding");
// TODO HDR length
assertEquals (newPdu.getTimestamp(), receivedPdu.getTimestamp(), "mismatched Timestamp");
// can cast PDUs at this point since PduType matched
FirePdu newEspdu = (FirePdu) newPdu;
FirePdu receivedEspdu = (FirePdu) newPdu;
// assertEquals (newEspdu.getEntityID(), receivedEspdu.getEntityID(), "mismatched EntityID");
// // TODO Sequence number
// assertEquals (newEspdu.getEntityType(), receivedEspdu.getEntityType(), "mismatched EntityType");
// // padding?
// assertEquals (newEspdu.getEntityAppearance(), receivedEspdu.getEntityAppearance(), "mismatched EntityAppearance");
// assertEquals (newEspdu.getCapabilities(), receivedEspdu.getCapabilities(), "mismatched EntityCapabilities");
// assertEquals (newEspdu.getEntityLocation(), receivedEspdu.getEntityLocation(), "mismatched EntityLocation");
// assertEquals (newEspdu.getEntityOrientation(), receivedEspdu.getEntityOrientation(), "mismatched EntityOrientation");
// assertEquals (newEspdu.getForceId(), receivedEspdu.getForceId(), "mismatched EntityForceId");
// assertEquals (newEspdu.getMarking(), receivedEspdu.getMarking(), "mismatched Marking");
// assertEquals (newEspdu.getDeadReckoningParameters(), receivedEspdu.getDeadReckoningParameters(), "mismatched DeadReckoningParameters");
//
// // attached parts, utility method for NumberVariableParameters
// assertEquals (newEspdu.getVariableParameters(), receivedEspdu.getVariableParameters(), "mismatched VariableParameters");
// assertEquals (newEspdu.getEntityLinearVelocity(), receivedEspdu.getEntityLinearVelocity(), "mismatched EntityLinearVelocity");
// trace option to compare strings, JSON or XML
if (false) // true || !newEspdu.toString().equals(receivedEspdu.toString()))
{
System.err.println(" newEspdu=" + newEspdu.toString());
System.err.println("receivedEspdu=" + receivedEspdu.toString());
}
assertEquals (newEspdu.toString(), receivedEspdu.toString(), "mismatched toString()");
// built-in object comparison
assertTrue (newEspdu.equalsImpl(receivedEspdu), "FirePdu.equalsImpl() built-in object comparison");
// final recheck that everything adds up
assertEquals(newPdu.getMarshalledSize(),receivedPdu.getMarshalledSize(),
"Marshalled size mismatch," +
"sent (" + newPdu.getMarshalledSize() + " bytes) and " +
"recieved (" + receivedPdu.getMarshalledSize() + " bytes)");
assertEquals (newPdu.getLength(), receivedPdu.getLength(), "mismatched length"); // from Pdu superclass
// comparison of class Pdu is questionable
// assertTrue(compare(newPdu,receivedPdu), "compare() method failed for original and received PDUs");
receivedPdu = null; // ensure cleared prior to next test
}
public static void main(String[] args)
{
FirePduTest firePduTest = new FirePduTest();
firePduTest.setUp();
firePduTest.testRoundTrip();
firePduTest.tearDown();
}
}
...@@ -99,9 +99,16 @@ abstract public class PduTest ...@@ -99,9 +99,16 @@ abstract public class PduTest
} }
} }
/** Compare all values of these two obects and report if identical
* @param pdu1 first pdu
* @param pdu2 second pdu
* @return true if identical values found */
protected boolean compare(Pdu pdu1, Pdu pdu2) protected boolean compare(Pdu pdu1, Pdu pdu2)
{ {
return pdu1.equalsImpl(pdu2); boolean result = (pdu1 != null) && (pdu2 != null) &&
pdu1.getPduType().equals(pdu2.getPduType()) &&
pdu1.equalsImpl(pdu2);
return result;
} }
protected void setUpReceiver(Pdu newPdu) protected void setUpReceiver(Pdu newPdu)
...@@ -109,8 +116,11 @@ abstract public class PduTest ...@@ -109,8 +116,11 @@ abstract public class PduTest
receivedPdu = newPdu; receivedPdu = newPdu;
} }
/** Test PDU sending, receiving, marshalling (serialization) and unmarshalling (deserialization) */
public abstract void testRoundTrip(); public abstract void testRoundTrip();
/** Test single PDU for correctness according to all contained fields in this PDU type
* @param newPdu PDU of interest*/
protected abstract void testOnePdu(Pdu newPdu); protected abstract void testOnePdu(Pdu newPdu);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment