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

upgrade test to match CommentsPduTest, TODO extract abstract interfaces

parent b778d661
No related branches found
No related tags found
No related merge requests found
...@@ -4,13 +4,22 @@ ...@@ -4,13 +4,22 @@
*/ */
package edu.nps.moves.dis7; package edu.nps.moves.dis7;
import edu.nps.moves.dis7.enumerations.LandPlatformCapabilities; import edu.nps.moves.dis7.entities.usa.platform.land.M1A2;
import edu.nps.moves.dis7.enumerations.Country;
import edu.nps.moves.dis7.enumerations.EntityKind;
import edu.nps.moves.dis7.utilities.DisThreadedNetIF;
import edu.nps.moves.dis7.utilities.PduFactory;
import edu.nps.moves.dis7.enumerations.PlatformDomain;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@DisplayName("Entity State Pdu Test") @DisplayName("Entity State Pdu Test")
public class EntityStatePduTest public class EntityStatePduTest
{ {
DisThreadedNetIF disThreadedNetworkInterface;
Pdu receivedPdu;
DisThreadedNetIF.PduListener pduListener;
@BeforeAll @BeforeAll
public static void setUpClass() public static void setUpClass()
{ {
...@@ -25,29 +34,89 @@ public class EntityStatePduTest ...@@ -25,29 +34,89 @@ public class EntityStatePduTest
@BeforeEach @BeforeEach
public void setUp() public void setUp()
{ {
disThreadedNetworkInterface = new DisThreadedNetIF();
pduListener = new DisThreadedNetIF.PduListener() {
@Override
public void incomingPdu(Pdu newPdu) {
setUpReceiver(newPdu);
}
};
disThreadedNetworkInterface.addListener(pduListener);
} }
@AfterEach @AfterEach
public void tearDown() public void tearDown()
{ {
disThreadedNetworkInterface.removeListener(pduListener);
disThreadedNetworkInterface.kill();
disThreadedNetworkInterface = null;
} }
@Test @Test
public void testEntityCapabilities() public void testRoundTrip()
{
PduFactory pduFactory = new PduFactory();
EntityStatePdu espdu = pduFactory.makeEntityStatePdu();
// 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
espdu.setEntityType(entityType);
// Alternate way using entity jar(s)
espdu.setEntityType(new edu.nps.moves.dis7.entities.usa.platform.land.M1A2());
// or simply use an enumeration by name, with accompanying import statement above
espdu.setEntityType(new M1A2());
testOne(espdu);
testOne(espdu.setEntityID(entityID).setEntityType(entityType));
}
private void testOne(Pdu newPdu)
{
sendPdu(newPdu); // will wait a while
assertTrue(receivedPdu != null, "No response from network receive");
assertTrue(compare(newPdu,receivedPdu), "Comparison failed");
assertEqual(newPdu.getMarshalledSize(),receivedPdu),getMarshalledSize(),"Marshalled size mismatch," +
"sent (" + newPdu.getMarshalledSize() + " bytes) and " +
"recieved (" + receivedPdu.getMarshalledSize() + " bytes)");
receivedPdu = null; // ensure cleared prior to next test
}
private void sendPdu(Pdu pdu)
{ {
Throwable thr = null;
try { try {
EntityStatePdu espdu = new EntityStatePdu(); disThreadedNetworkInterface.send(pdu);
espdu.setCapabilities(new LandPlatformCapabilities()); Thread.sleep(100);
} }
catch (Throwable t) { catch (InterruptedException ex) {
thr = t; System.err.println("Error sending Multicast: " + ex.getLocalizedMessage());
System.exit(1);
} }
assertNull(thr, "Exception indicates error creating EntityStatePdu"); }
private boolean compare(Pdu pdu1, Pdu pdu2)
{
return pdu1.equals(pdu2);
}
private void setUpReceiver(Pdu newPdu)
{
receivedPdu = newPdu;
} }
public static void main(String[] args) public static void main(String[] args)
{ {
new EntityStatePduTest().testEntityCapabilities(); EntityStatePduTest entityStatePduTest = new EntityStatePduTest();
entityStatePduTest.setUp();
entityStatePduTest.testRoundTrip();
entityStatePduTest.tearDown();
} }
} }
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