Skip to content
Snippets Groups Projects
Commit f7c28421 authored by J. M. Bailey's avatar J. M. Bailey
Browse files

Test classes now working with junit 5

parent 6e36befc
No related branches found
No related tags found
No related merge requests found
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package edu.nps.moves.dis7;
/**
......@@ -16,6 +20,7 @@ public class CreateAllObjectTypesTest
@BeforeAll
public static void beforeAllTests()
{
System.out.println("CreateAllObjectTypesTest");
}
@AfterAll
......@@ -251,7 +256,7 @@ public class CreateAllObjectTypesTest
ex = t;
}
//temp assertNull(ex, "Exception should be null if successful creation of all objects");
assertNull(ex, "Exception should be null if successful creation of all objects");
}
String formatStr = "Name: %s\tDomain: %s\tKind: %s\tCategory: %s\tSubcategory: %s";
......@@ -266,7 +271,7 @@ public class CreateAllObjectTypesTest
String dom = ot.getDomain().toString();
String kind = ot.getObjectKind().toString();;
String nm = ot.getClass().getName();
System.out.println(String.format(formatStr, nm, dom, kind, ot.getCategory(), ot.getSubCategory()));
//System.out.println(String.format(formatStr, nm, dom, kind, ot.getCategory(), ot.getSubCategory()));
}
public static void main(String[] args)
......
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package edu.nps.moves.dis7;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.nio.ByteBuffer;
import java.util.HashSet;
......@@ -12,140 +15,145 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
*
* @author mike
*/
public class CreateAllPduTypesTest
{
public CreateAllPduTypesTest()
{
}
public CreateAllPduTypesTest()
{
}
@BeforeAll
public static void setUpClass()
{
System.out.println("CreateAllPduTypesTest");
}
@BeforeAll
public static void setUpClass()
{
}
@AfterAll
public static void tearDownClass()
{
}
@AfterAll
public static void tearDownClass()
{
}
@BeforeEach
public void setUp()
{
}
@BeforeEach
public void setUp()
{
}
@AfterEach
public void tearDown()
{
}
@AfterEach
public void tearDown()
{
}
HashSet<Object> pdus = new HashSet<>();
ByteBuffer buff = ByteBuffer.allocate(20000);
DataOutputStream dos = new DataOutputStream(new ByteArrayOutputStream());
private Throwable throwable;
HashSet<Object> pdus = new HashSet<>();
ByteBuffer buff = ByteBuffer.allocate(20000);
DataOutputStream dos = new DataOutputStream(new ByteArrayOutputStream());
@Test
public void testCreateAll()
{
Object o;
//0 == "other"
pdus.add(new EntityStatePdu()); //1
pdus.add(new FirePdu()); //2
pdus.add(new DetonationPdu()); //3
pdus.add(new CollisionPdu()); //4
pdus.add(new ServiceRequestPdu()); //5
pdus.add(new ResupplyOfferPdu()); //6
pdus.add(new ResupplyReceivedPdu()); //7
pdus.add(new ResupplyCancelPdu()); //8
pdus.add(new RepairCompletePdu()); //9
pdus.add(new RepairResponsePdu()); //10
pdus.add(new CreateEntityPdu()); //11
pdus.add(new RemoveEntityPdu()); //12
pdus.add(new StartResumePdu()); //13
pdus.add(new StopFreezePdu()); //14
pdus.add(new AcknowledgePdu()); //15
pdus.add(new ActionRequestPdu()); //16
pdus.add(new ActionResponsePdu()); //17
pdus.add(new DataQueryPdu()); //18
pdus.add(new SetDataPdu()); //19
pdus.add(new DataPdu()); //20
pdus.add(new EventReportPdu()); //21
pdus.add(new CommentPdu()); //22
pdus.add(new ElectromagneticEmissionPdu()); //23
pdus.add(new DesignatorPdu()); //24
pdus.add(new TransmitterPdu()); //25
pdus.add(new SignalPdu()); //26
pdus.add(new ReceiverPdu()); //27
pdus.add(new IFFPdu()); //28
pdus.add(new UnderwaterAcousticPdu()); //29
pdus.add(new SEESPdu()); //30
pdus.add(new IntercomSignalPdu()); //31
pdus.add(new IntercomControlPdu()); //32
pdus.add(new AggregateStatePdu()); //33
pdus.add(new IsGroupOfPdu()); //34
pdus.add(new TransferOwnershipPdu()); //35
pdus.add(new IsPartOfPdu()); //36
pdus.add(new MinefieldStatePdu()); //37
pdus.add(new MinefieldQueryPdu()); //38
pdus.add(new MinefieldDataPdu()); //39
pdus.add(new MinefieldResponseNACKPdu()); //40
pdus.add(new EnvironmentalProcessPdu()); //41
pdus.add(new GriddedDataPdu()); //42
pdus.add(new PointObjectStatePdu()); //43
pdus.add(new LinearObjectStatePdu()); //44
pdus.add(new ArealObjectStatePdu()); //45
pdus.add(new TSPIPdu()); //46
pdus.add(new AppearancePdu()); //47
pdus.add(new ArticulatedPartsPdu()); //48
pdus.add(new LEFirePdu()); //49
pdus.add(new LEDetonationPdu()); //50
pdus.add(new CreateEntityReliablePdu()); //51
pdus.add(new RemoveEntityReliablePdu()); //52
pdus.add(new StartResumeReliablePdu()); //53
pdus.add(new StopFreezeReliablePdu()); //54
pdus.add(new AcknowledgeReliablePdu()); //55
pdus.add(new ActionRequestReliablePdu()); //56
pdus.add(new ActionResponseReliablePdu()); //57
pdus.add(new DataQueryReliablePdu()); //58
pdus.add(new SetDataReliablePdu()); //59
pdus.add(new DataReliablePdu()); //60
pdus.add(new EventReportReliablePdu()); //61
pdus.add(new CommentReliablePdu()); //62
pdus.add(new RecordReliablePdu()); //63
pdus.add(new SetRecordReliablePdu()); //64
pdus.add(new RecordQueryReliablePdu()); //65
pdus.add(new CollisionElasticPdu()); //66
pdus.add(new EntityStateUpdatePdu()); //67
pdus.add(new DirectedEnergyFirePdu()); //68
pdus.add(new EntityDamageStatusPdu()); //69
pdus.add(new InformationOperationsActionPdu()); //70
pdus.add(new InformationOperationsReportPdu()); //71
pdus.add(new AttributePdu()); //72
/* marshal all */
System.out.println("marshalling");
pdus.stream().forEach(ob->{
try{
((Marshaller)ob).marshal(dos);
System.out.println("marshalled "+ob.getClass().getSimpleName());
}
catch(Exception ex) {
System.out.println("Error marshalling "+ob.getClass().getSimpleName() + ex.getClass().getSimpleName()+": "+ex.getLocalizedMessage());
}
});
@Test
public void testCreateAll()
{
try {
Object o;
//0 == "other"
pdus.add(new EntityStatePdu()); //1
pdus.add(new FirePdu()); //2
pdus.add(new DetonationPdu()); //3
pdus.add(new CollisionPdu()); //4
pdus.add(new ServiceRequestPdu()); //5
pdus.add(new ResupplyOfferPdu()); //6
pdus.add(new ResupplyReceivedPdu()); //7
pdus.add(new ResupplyCancelPdu()); //8
pdus.add(new RepairCompletePdu()); //9
pdus.add(new RepairResponsePdu()); //10
pdus.add(new CreateEntityPdu()); //11
pdus.add(new RemoveEntityPdu()); //12
pdus.add(new StartResumePdu()); //13
pdus.add(new StopFreezePdu()); //14
pdus.add(new AcknowledgePdu()); //15
pdus.add(new ActionRequestPdu()); //16
pdus.add(new ActionResponsePdu()); //17
pdus.add(new DataQueryPdu()); //18
pdus.add(new SetDataPdu()); //19
pdus.add(new DataPdu()); //20
pdus.add(new EventReportPdu()); //21
pdus.add(new CommentPdu()); //22
pdus.add(new ElectromagneticEmissionPdu()); //23
pdus.add(new DesignatorPdu()); //24
pdus.add(new TransmitterPdu()); //25
pdus.add(new SignalPdu()); //26
pdus.add(new ReceiverPdu()); //27
pdus.add(new IFFPdu()); //28
pdus.add(new UnderwaterAcousticPdu()); //29
pdus.add(new SEESPdu()); //30
pdus.add(new IntercomSignalPdu()); //31
pdus.add(new IntercomControlPdu()); //32
pdus.add(new AggregateStatePdu()); //33
pdus.add(new IsGroupOfPdu()); //34
pdus.add(new TransferOwnershipPdu()); //35
pdus.add(new IsPartOfPdu()); //36
pdus.add(new MinefieldStatePdu()); //37
pdus.add(new MinefieldQueryPdu()); //38
pdus.add(new MinefieldDataPdu()); //39
pdus.add(new MinefieldResponseNACKPdu()); //40
pdus.add(new EnvironmentalProcessPdu()); //41
pdus.add(new GriddedDataPdu()); //42
pdus.add(new PointObjectStatePdu()); //43
pdus.add(new LinearObjectStatePdu()); //44
pdus.add(new ArealObjectStatePdu()); //45
pdus.add(new TSPIPdu()); //46
pdus.add(new AppearancePdu()); //47
pdus.add(new ArticulatedPartsPdu()); //48
pdus.add(new LEFirePdu()); //49
pdus.add(new LEDetonationPdu()); //50
pdus.add(new CreateEntityReliablePdu()); //51
pdus.add(new RemoveEntityReliablePdu()); //52
pdus.add(new StartResumeReliablePdu()); //53
pdus.add(new StopFreezeReliablePdu()); //54
pdus.add(new AcknowledgeReliablePdu()); //55
pdus.add(new ActionRequestReliablePdu()); //56
pdus.add(new ActionResponseReliablePdu()); //57
pdus.add(new DataQueryReliablePdu()); //58
pdus.add(new SetDataReliablePdu()); //59
pdus.add(new DataReliablePdu()); //60
pdus.add(new EventReportReliablePdu()); //61
pdus.add(new CommentReliablePdu()); //62
pdus.add(new RecordReliablePdu()); //63
pdus.add(new SetRecordReliablePdu()); //64
pdus.add(new RecordQueryReliablePdu()); //65
pdus.add(new CollisionElasticPdu()); //66
pdus.add(new EntityStateUpdatePdu()); //67
pdus.add(new DirectedEnergyFirePdu()); //68
pdus.add(new EntityDamageStatusPdu()); //69
pdus.add(new InformationOperationsActionPdu()); //70
pdus.add(new InformationOperationsReportPdu()); //71
pdus.add(new AttributePdu()); //72
/* marshal all */
pdus.stream().forEach(ob -> {
try {
((Marshaller) ob).marshal(dos);
//System.out.println("marshalled " + ob.getClass().getSimpleName());
}
catch (Throwable t) {
throw new RuntimeException(t);
}
});
}
public static void main(String[] args)
{
new CreateAllPduTypesTest().testCreateAll();
}
catch (Throwable t) {
throwable = t;
t.printStackTrace();
}
assertNull(throwable, "Exception should be null if successful marshal");
}
public static void main(String[] args)
{
new CreateAllPduTypesTest().testCreateAll();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package edu.nps.moves.dis7;
import edu.nps.moves.dis7.enumerations.ActionResponseRequestStatus;
import edu.nps.moves.dis7.enumerations.VariableRecordType;
import edu.nps.moves.dis7.util.DisNetworking;
import edu.nps.moves.dis7.util.PduFactory;
import java.io.IOException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
*
* @author mike
*/
public class DataQueryPduRoundTrip
@DisplayName("Data Query Pdu Round Test")
public class DataQueryPduRoundTripTest
{
public DataQueryPduRoundTrip()
public DataQueryPduRoundTripTest()
{
}
@BeforeAll
public static void setUpClass()
{
System.out.println("DataQueryPduRoundTripTest");
}
@AfterAll
public static void tearDownClass()
{
}
@BeforeEach
public void setUp()
{
}
@AfterEach
public void tearDown()
{
......@@ -50,7 +43,7 @@ public class DataQueryPduRoundTrip
private static int REQUEST_ID = 0x00112233;
private static int TIME_INTERVAL = 0x15151515;
private static FixedDatum fixedDatum1 = new FixedDatum();
private static FixedDatum fixedDatum1 = new FixedDatum();
private static int fixedDatum1Value = 0x111111FF;
private static VariableRecordType fixedDatum1VarRecordType = VariableRecordType.$120_MM_HEAT_QUANTITY;
private static FixedDatum fixedDatum2 = new FixedDatum();
......@@ -59,11 +52,11 @@ public class DataQueryPduRoundTrip
private static FixedDatum fixedDatum3 = new FixedDatum();
private static int fixedDatum3Value = 0x333333FF;
private static VariableRecordType fixedDatum3VarRecordType = VariableRecordType.NUMBER_OF_INTERCEPTORS_FIRED;
private static VariableDatum variableDatum1 = new VariableDatum();
private static VariableRecordType variableDatum1Type = VariableRecordType.ADA_SHOOTING_STATUS;
private static byte[] variableDatum1Value = new String("varDatum1Value111").getBytes();
private static VariableDatum variableDatum2 = new VariableDatum();
private static VariableRecordType variableDatum2Type = VariableRecordType.ORDER_STATUS;
private static byte[] variableDatum2Value = new String("222varDatum1Value222").getBytes();
......@@ -71,81 +64,78 @@ public class DataQueryPduRoundTrip
static {
fixedDatum1.setFixedDatumValue(fixedDatum1Value);
fixedDatum1.setFixedDatumID(fixedDatum1VarRecordType);
fixedDatum2.setFixedDatumValue(fixedDatum2Value);
fixedDatum2.setFixedDatumID(fixedDatum2VarRecordType);
fixedDatum3.setFixedDatumValue(fixedDatum3Value);
fixedDatum3.setFixedDatumID(fixedDatum3VarRecordType);
variableDatum1.setVariableDatumID(variableDatum1Type);
variableDatum1.setVariableDatumValue(variableDatum1Value);
// variableDatum1.setVariableDatumLength(variableDatum1Value.length); // should be done automatically
// variableDatum1.setVariableDatumLength(variableDatum1Value.length); // should be done automatically
variableDatum2.setVariableDatumID(variableDatum2Type);
variableDatum2.setVariableDatumValue(variableDatum2Value);
// variableDatum2.setVariableDatumLength(variableDatum2Value.length); // should be done automatically
}
// variableDatum2.setVariableDatumLength(variableDatum2Value.length); // should be done automatically
}
private Pdu receivedPdu;
private Object waiter = new Object();
@Test
public void TestRoundTrip()
{
PduFactory factory = new PduFactory();
DataQueryPdu sendingPdu = factory.makeDataQueryPdu();
sendingPdu.setRequestID(REQUEST_ID);
sendingPdu.setTimeInterval(TIME_INTERVAL);
sendingPdu.getFixedDatums().add(fixedDatum1);
sendingPdu.getFixedDatums().add(fixedDatum2);
sendingPdu.getFixedDatums().add(fixedDatum3);
sendingPdu.getVariableDatums().add(variableDatum1);
sendingPdu.getVariableDatums().add(variableDatum2);
setUpReceiver();
try {
Thread.sleep(250l); // make sure receiver is listening
new DisNetworking().sendPdu(sendingPdu);
Thread.sleep(1000l); //(180*1000l));//waiter.wait();
}
catch(Exception ex) {
System.err.println("Error sending Multicast: "+ex.getLocalizedMessage());
System.exit(1);
}
@Test
public void testRoundTrip()
{
PduFactory factory = new PduFactory();
DataQueryPdu sendingPdu = factory.makeDataQueryPdu();
sendingPdu.setRequestID(REQUEST_ID);
sendingPdu.setTimeInterval(TIME_INTERVAL);
sendingPdu.getFixedDatums().add(fixedDatum1);
sendingPdu.getFixedDatums().add(fixedDatum2);
sendingPdu.getFixedDatums().add(fixedDatum3);
sendingPdu.getVariableDatums().add(variableDatum1);
sendingPdu.getVariableDatums().add(variableDatum2);
setUpReceiver();
try {
Thread.sleep(250l); // make sure receiver is listening
new DisNetworking().sendPdu(sendingPdu);
Thread.sleep(1000l);
}
catch (Exception ex) {
System.err.println("Error sending Multicast: " + ex.getLocalizedMessage());
System.exit(1);
}
// Compare
// If we made it this far, we've sent and received. Now compare.
if(receivedPdu.equalsImpl(sendingPdu))
System.out.println("passed test");
else
System.err.println("failed test");
}
private void setUpReceiver()
{
Thread rcvThread = new Thread( ()->{
try {
receivedPdu = new DisNetworking().receivePdu(); // blocks
}
catch(IOException ex) {
System.err.println("Error receiving Multicast: "+ex.getLocalizedMessage());
System.exit(1);
}
// waiter.notify();
});
rcvThread.setPriority(Thread.NORM_PRIORITY);
rcvThread.setDaemon(true);
rcvThread.start();
}
public static void main(String[] args)
{
new DataQueryPduRoundTrip().TestRoundTrip();
}
assertTrue(receivedPdu.equals(sendingPdu), "Sent and received pdu not the same");
}
private void setUpReceiver()
{
Thread rcvThread = new Thread(() -> {
try {
receivedPdu = new DisNetworking().receivePdu(); // blocks
}
catch (IOException ex) {
System.err.println("Error receiving Multicast: " + ex.getLocalizedMessage());
System.exit(1);
}
// waiter.notify();
});
rcvThread.setPriority(Thread.NORM_PRIORITY);
rcvThread.setDaemon(true);
rcvThread.start();
}
public static void main(String[] args)
{
new DataQueryPduRoundTripTest().testRoundTrip();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package edu.nps.moves.dis7;
import edu.nps.moves.dis7.enumerations.LandPlatformCapabilities;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
/**
*
* @author mike
*/
@DisplayName("Entity State Pdu Test")
public class EntityStatePduTest
{
@BeforeAll
public static void setUpClass()
{
}
@AfterAll
public static void tearDownClass()
{
}
@BeforeEach
public void setUp()
{
}
@AfterEach
public void tearDown()
{
}
@BeforeAll
public static void setUpClass()
{
System.out.println("EntityStatePduTest");
}
@AfterAll
public static void tearDownClass()
{
}
@BeforeEach
public void setUp()
{
}
@Test
public void testEntityCapabilities()
{
@AfterEach
public void tearDown()
{
}
@Test
public void testEntityCapabilities()
{
Throwable thr = null;
try {
EntityStatePdu espdu = new EntityStatePdu();
espdu.setCapabilities(new LandPlatformCapabilities());
}
catch (Throwable t) {
thr = t;
}
assertNull(thr, "Exception indicates error creating EntityStatePdu");
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package edu.nps.moves.dis7;
......@@ -10,38 +9,32 @@ import edu.nps.moves.dis7.enumerations.VariableRecordType;
import edu.nps.moves.dis7.util.DisNetworking;
import edu.nps.moves.dis7.util.PduFactory;
import java.io.IOException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
*
* @author mike
*/
public class FixedAndVariableDatumRoundTrip
@DisplayName("Fixed and Variable Datum Round Trip Test")
public class FixedAndVariableDatumRoundTripTest
{
public FixedAndVariableDatumRoundTrip()
public FixedAndVariableDatumRoundTripTest()
{
}
@BeforeAll
public static void setUpClass()
{
System.out.println("FixedAndVariableDatumRoundTripTest");
}
@AfterAll
public static void tearDownClass()
{
}
@BeforeEach
public void setUp()
{
}
@AfterEach
public void tearDown()
{
......@@ -49,8 +42,8 @@ public class FixedAndVariableDatumRoundTrip
private static int REQUEST_ID = 0x00112233;
private static ActionResponseRequestStatus REQUEST_STATUS = ActionResponseRequestStatus.RETRANSMIT_REQUEST_LATER;
private static FixedDatum fixedDatum1 = new FixedDatum();
private static FixedDatum fixedDatum1 = new FixedDatum();
private static int fixedDatum1Value = 0x111111FF;
private static VariableRecordType fixedDatum1VarRecordType = VariableRecordType.ACTIVATE_OWNSHIP;
private static FixedDatum fixedDatum2 = new FixedDatum();
......@@ -59,13 +52,13 @@ public class FixedAndVariableDatumRoundTrip
private static FixedDatum fixedDatum3 = new FixedDatum();
private static int fixedDatum3Value = 0x333333FF;
private static VariableRecordType fixedDatum3VarRecordType = VariableRecordType.SKE_FREQUENCY;
private static VariableDatum variableDatum1 = new VariableDatum();
private static VariableRecordType variableDatum1Type = VariableRecordType.ACLS_AIRCRAFT_REPORT;
private static String variableDatum1String = "varDatum1Value111";
private static byte[] variableDatum1Value = variableDatum1String.getBytes();
private static int variableDatum1LengthInBits = variableDatum1String.length()*8 -1; // test
private static int variableDatum1LengthInBits = variableDatum1String.length() * 8 - 1; // test
private static VariableDatum variableDatum2 = new VariableDatum();
private static VariableRecordType variableDatum2Type = VariableRecordType.Z_ACCELERATION;
private static byte[] variableDatum2Value = new String("222varDatum1Value222").getBytes();
......@@ -73,78 +66,76 @@ public class FixedAndVariableDatumRoundTrip
static {
fixedDatum1.setFixedDatumValue(fixedDatum1Value);
fixedDatum1.setFixedDatumID(fixedDatum1VarRecordType);
fixedDatum2.setFixedDatumValue(fixedDatum2Value);
fixedDatum2.setFixedDatumID(fixedDatum2VarRecordType);
fixedDatum3.setFixedDatumValue(fixedDatum3Value);
fixedDatum3.setFixedDatumID(fixedDatum3VarRecordType);
variableDatum1.setVariableDatumID(variableDatum1Type);
variableDatum1.setVariableDatumValue(variableDatum1Value);
variableDatum1.setVariableDatumLength(variableDatum1LengthInBits);
variableDatum2.setVariableDatumID(variableDatum2Type);
variableDatum2.setVariableDatumValue(variableDatum2Value);
variableDatum2.setVariableDatumLength(variableDatum2Value.length * 8); //in bits
}
}
private Pdu receivedPdu;
private Object waiter = new Object();
@Test
public void TestRoundTrip()
{
PduFactory factory = new PduFactory();
ActionResponsePdu sentPdu = factory.makeActionResponsePdu();
sentPdu.getFixedDatums().add(fixedDatum1);
sentPdu.getFixedDatums().add(fixedDatum2);
sentPdu.getFixedDatums().add(fixedDatum3);
sentPdu.getVariableDatums().add(variableDatum1);
sentPdu.getVariableDatums().add(variableDatum2);
setUpReceiver();
try {
Thread.sleep(250l); // make sure receiver is listening
new DisNetworking().sendPdu(sentPdu);
Thread.sleep(1000l); //(180*1000l));//waiter.wait();
}
catch(Exception ex) {
System.err.println("Error sending Multicast: "+ex.getLocalizedMessage());
System.exit(1);
}
@Test
public void TestRoundTrip()
{
PduFactory factory = new PduFactory();
ActionResponsePdu sentPdu = factory.makeActionResponsePdu();
sentPdu.getFixedDatums().add(fixedDatum1);
sentPdu.getFixedDatums().add(fixedDatum2);
sentPdu.getFixedDatums().add(fixedDatum3);
sentPdu.getVariableDatums().add(variableDatum1);
sentPdu.getVariableDatums().add(variableDatum2);
setUpReceiver();
try {
Thread.sleep(250l); // make sure receiver is listening
new DisNetworking().sendPdu(sentPdu);
Thread.sleep(1000l);
}
catch (Exception ex) {
System.err.println("Error sending Multicast: " + ex.getLocalizedMessage());
System.exit(1);
}
// Compare
// If we made it this far, we've sent and received. Now compare.
if(receivedPdu.equals(sentPdu))
System.out.println("passed test");
else
System.err.println("failed test");
}
private void setUpReceiver()
{
Thread rcvThread = new Thread( ()->{
try {
receivedPdu = new DisNetworking().receivePdu(); // blocks
}
catch(IOException ex) {
System.err.println("Error receiving Multicast: "+ex.getLocalizedMessage());
System.exit(1);
}
// waiter.notify();
});
rcvThread.setPriority(Thread.NORM_PRIORITY);
rcvThread.setDaemon(true);
rcvThread.start();
}
public static void main(String[] args)
{
new FixedAndVariableDatumRoundTrip().TestRoundTrip();
}
assertTrue(receivedPdu != null, "No response from network");
assertTrue(receivedPdu.equals(sentPdu),"Sent and received pdus not identical");
}
private void setUpReceiver()
{
Thread rcvThread = new Thread(() -> {
try {
receivedPdu = new DisNetworking().receivePdu(); // blocks
}
catch (IOException ex) {
System.err.println("Error receiving Multicast: " + ex.getLocalizedMessage());
System.exit(1);
}
// waiter.notify();
});
rcvThread.setPriority(Thread.NORM_PRIORITY);
rcvThread.setDaemon(true);
rcvThread.start();
}
public static void main(String[] args)
{
new FixedAndVariableDatumRoundTripTest().TestRoundTrip();
}
}
This diff is collapsed.
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
/**
* NullFieldsMarshallTest()); created on May 20, 2019 MOVES Institute Naval Postgraduate School, Monterey, CA, USA www.nps.edu
*
......@@ -11,14 +15,16 @@ import java.nio.ByteBuffer;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
@DisplayName("Null Fields Entity Marshal")
public class NullFieldsMarshallTest
@DisplayName("Null Fields Entity Marshall Test")
public class NullFieldsEntityMarshallTest
{
LAV_105 lav105;
@BeforeAll
public static void beforeAllTests()
{}
{
System.out.println("NullFieldsEntityMarshallTest");
}
@AfterAll
public static void afterAllTests()
......@@ -39,21 +45,19 @@ public class NullFieldsMarshallTest
@Test
public void testNoSpecificNoExtraMarshal()
{
System.out.println("Test no specific, no extra marshal");
Exception ex=null;
ByteBuffer bb = ByteBuffer.allocate(100);
try {
dumpET(lav105);
//dumpET(lav105);
lav105.marshal(bb);
dumpBb(bb);
System.out.println("Test complete, no exception");
//dumpBb(bb);
}
catch(Exception e) {
System.err.println(e.getClass().getSimpleName()+": "+e.getLocalizedMessage());
ex = e;
}
//temp assertNull(ex,"Exception should be null if successful marshal");
//temp assertEquals(8, bb.position(), "Marshalled array should be 8 bytes long");
assertNull(ex,"Exception should be null if successful marshal");
assertEquals(8, bb.position(), "Marshalled array should be 8 bytes long");
}
@Test
......@@ -97,7 +101,7 @@ public class NullFieldsMarshallTest
public static void main(String[] args)
{
NullFieldsMarshallTest inst = new NullFieldsMarshallTest();
NullFieldsEntityMarshallTest inst = new NullFieldsEntityMarshallTest();
inst.setUp();
inst.testNoSpecificNoExtraMarshal();
}
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package edu.nps.moves.dis7;
//import edu.nps.moves.dis.ObjectType;
import edu.nps.moves.dis7.objecttypes.LinearObject.Culturalfeature.Tracks_Tire.Tracks_Tire;
import edu.nps.moves.dis7.objecttypes.LinearObject.Obstacle.ConcertinaWire._2_Roll._2_Roll;
import java.nio.ByteBuffer;
......@@ -17,7 +15,10 @@ import static org.junit.jupiter.api.Assertions.assertNull;
public class ObjectTypeMarshallTest
{
@BeforeAll
public static void setUpClass(){}
public static void setUpClass()
{
System.out.println("ObjectTypeMarshallTest");
}
@AfterAll
public static void tearDownClass(){}
@BeforeEach
......@@ -32,7 +33,6 @@ public class ObjectTypeMarshallTest
try {
_2_Roll roll2 = new _2_Roll();
common(roll2);
System.out.println("testGoodMarshal successful");
}
catch (Throwable t) {
thr = t;
......@@ -47,7 +47,6 @@ public class ObjectTypeMarshallTest
try {
Tracks_Tire tracksTire = new Tracks_Tire();
common(tracksTire);
System.out.println("TestNoSubCategory successful");
}
catch (Throwable t) {
thr = t;
......
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package edu.nps.moves.dis7;
/**
......@@ -8,17 +12,17 @@ package edu.nps.moves.dis7;
import edu.nps.moves.dis7.enumerations.Country;
import edu.nps.moves.dis7.util.PduFactory;
import java.util.Arrays;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.assertNull;
@DisplayName("PduFactory All Pdus Create")
@DisplayName("Pdu Factory Test")
public class TestPduFactory1
public class PduFactoryTest
{
@BeforeAll
public static void beforeAllTests()
{
System.out.println("PduFactoryTest");
}
@AfterAll
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package edu.nps.moves.dis7;
import edu.nps.moves.dis7.enumerations.*;
import edu.nps.moves.dis7.util.DisNetworking;
import edu.nps.moves.dis7.util.PduFactory;
import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.*;
@DisplayName("Signal Pdus Test")
public class SignalPdusTest
......@@ -21,6 +16,7 @@ public class SignalPdusTest
@BeforeAll
public static void setUpClass()
{
System.out.println("SignalPdusTest");
}
@AfterAll
......@@ -62,14 +58,14 @@ public class SignalPdusTest
setUpReceiver();
try {
Thread.sleep(250l); // make sure receiver is listening
Thread.sleep(2000l); //250l); // make sure receiver is listening
DisNetworking disnet = new DisNetworking();
disnet.sendPdu(sigPdu);
disnet.sendPdu(sigPdu2);
disnet.sendPdu(isig);
disnet.sendPdu(isig2);
Thread.sleep(1000l); //(180*1000l));//waiter.wait();
Thread.sleep(3000l); //1000l); //(180*1000l));//waiter.wait();
}
catch (Exception ex) {
System.err.println("Error sending Multicast: " + ex.getLocalizedMessage());
......@@ -78,10 +74,10 @@ public class SignalPdusTest
// Compare
// If we made it this far, we've sent and received. Now compare.
if (receivedPdu.equals(sigPdu))
System.out.println("passed test");
else
System.err.println("failed test");
assertTrue(receivedPdu != null, "No response from network");
assertTrue(receivedPdu.equals(sigPdu),"Sent and received pdus not identical");
System.out.println("SignalPdusTest finished");
}
private void setUpReceiver()
......
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