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

refactor superclass for future shared use, test sat

parent ad838432
No related branches found
No related tags found
No related merge requests found
...@@ -4,56 +4,19 @@ ...@@ -4,56 +4,19 @@
*/ */
package edu.nps.moves.dis7; package edu.nps.moves.dis7;
import edu.nps.moves.dis7.*;
import edu.nps.moves.dis7.entities.usa.munition.other.M1A2; import edu.nps.moves.dis7.entities.usa.munition.other.M1A2;
import edu.nps.moves.dis7.enumerations.Country; import edu.nps.moves.dis7.enumerations.Country;
import edu.nps.moves.dis7.enumerations.EntityKind; import edu.nps.moves.dis7.enumerations.EntityKind;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import edu.nps.moves.dis7.utilities.PduFactory; import edu.nps.moves.dis7.utilities.PduFactory;
import edu.nps.moves.dis7.enumerations.PlatformDomain; 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 extends PduTest
{ {
DisThreadedNetworkInterface disNetworkInterface;
Pdu receivedPdu;
DisThreadedNetworkInterface.PduListener pduListener;
@BeforeAll
public static void setUpClass()
{
System.out.println("EntityStatePduTest");
}
@AfterAll
public static void tearDownClass()
{
}
@BeforeEach
public void setUp()
{
disNetworkInterface = new DisThreadedNetworkInterface();
pduListener = new DisThreadedNetworkInterface.PduListener() {
@Override
public void incomingPdu(Pdu newPdu) {
setUpReceiver(newPdu);
}
};
disNetworkInterface.addListener(pduListener);
}
@AfterEach
public void tearDown()
{
disNetworkInterface.removeListener(pduListener);
disNetworkInterface.kill();
disNetworkInterface = null;
}
@Test @Test
@Override
public void testRoundTrip() public void testRoundTrip()
{ {
PduFactory pduFactory = new PduFactory(); PduFactory pduFactory = new PduFactory();
...@@ -75,11 +38,12 @@ public class EntityStatePduTest ...@@ -75,11 +38,12 @@ public class EntityStatePduTest
// or simply use an enumeration by name, with accompanying import statement above // or simply use an enumeration by name, with accompanying import statement above
espdu.setEntityType(new M1A2()); espdu.setEntityType(new M1A2());
testOne(espdu); testOnePdu(espdu);
testOne(espdu.setEntityID(entityID).setEntityType(entityType)); testOnePdu(espdu.setEntityID(entityID).setEntityType(entityType));
} }
private void testOne(Pdu newPdu) @Override
protected void testOnePdu(Pdu newPdu)
{ {
sendPdu(newPdu); // will wait a while sendPdu(newPdu); // will wait a while
assertTrue(receivedPdu != null, "No response from network receive"); assertTrue(receivedPdu != null, "No response from network receive");
...@@ -134,34 +98,12 @@ public class EntityStatePduTest ...@@ -134,34 +98,12 @@ public class EntityStatePduTest
receivedPdu = null; // ensure cleared prior to next test receivedPdu = null; // ensure cleared prior to next test
} }
private void sendPdu(Pdu pdu) public static void main(String[] args)
{ {
try { EntityStatePduTest entityStatePduTest = new EntityStatePduTest();
disNetworkInterface.send(pdu);
Thread.sleep(100); entityStatePduTest.setUp();
} entityStatePduTest.testRoundTrip();
catch (InterruptedException ex) { entityStatePduTest.tearDown();
System.err.println("Error sending Multicast: " + ex.getLocalizedMessage());
System.exit(1);
} }
}
private boolean compare(Pdu pdu1, Pdu pdu2)
{
return pdu1.equalsImpl(pdu2);
}
private void setUpReceiver(Pdu newPdu)
{
receivedPdu = newPdu;
}
public static void main(String[] args)
{
EntityStatePduTest entityStatePduTest = new EntityStatePduTest();
entityStatePduTest.setUp();
entityStatePduTest.testRoundTrip();
entityStatePduTest.tearDown();
}
} }
/* Copyright (c) 1995-2020 held by the author(s). All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the names of the Naval Postgraduate School (NPS)
Modeling Virtual Environments and Simulation (MOVES) Institute
(https://www.nps.edu and https://my.nps.edu/web/moves)
nor the names of its contributors may be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package edu.nps.moves.dis7;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
/**
*
* @author brutzman
*/
abstract public class PduTest
{
@BeforeAll
public static void setUpClass()
{
System.out.println("EntityStatePduTest");
}
@AfterAll
public static void tearDownClass()
{
}
DisThreadedNetworkInterface disNetworkInterface;
Pdu receivedPdu;
DisThreadedNetworkInterface.PduListener pduListener;
@BeforeEach
public void setUp()
{
disNetworkInterface = new DisThreadedNetworkInterface();
pduListener = new DisThreadedNetworkInterface.PduListener()
{
@Override
public void incomingPdu(Pdu newPdu)
{
setUpReceiver(newPdu);
}
};
disNetworkInterface.addListener(pduListener);
}
@AfterEach
public void tearDown()
{
disNetworkInterface.removeListener(pduListener);
disNetworkInterface.kill();
disNetworkInterface = null;
}
protected void sendPdu(Pdu pdu)
{
try
{
disNetworkInterface.send(pdu);
Thread.sleep(100);
} catch (InterruptedException ex)
{
System.err.println("Error sending Multicast: " + ex.getLocalizedMessage());
System.exit(1);
}
}
protected boolean compare(Pdu pdu1, Pdu pdu2)
{
return pdu1.equalsImpl(pdu2);
}
protected void setUpReceiver(Pdu newPdu)
{
receivedPdu = newPdu;
}
public abstract void testRoundTrip();
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