/** * Uses the {@link IBaseDataObject#getDataObjectUUID()} from bdo to attempt to retrieve the object * from the {@link ObjectService}. If the object is retrieved then it is check for null and * equality. */ private void assertObjectExists(final IBaseDataObject bdo) { IBaseDataObject retrievedDataObject = null; try { retrievedDataObject = getObject(bdo.getDataObjectUUID()); } catch (MuthurException e) { fail(e.getLocalizedMessage()); } assert (retrievedDataObject != null); assertTrue(retrievedDataObject.equals(bdo)); }
/* * (non-Javadoc) * * @see com.csc.muthur.server.model.event.AbstractEvent#getDataBlockElement() */ public Element getDataBlockElement() { Element dataBlockElement = new Element(EventAttributeName.dataBlock.toString()); if (dataObject != null) { Element dataObjectAsXMLElement = new Element(EventAttributeName.dataObjectAsXML.toString()); dataBlockElement.addContent(dataObjectAsXMLElement); // let the sub-class add the specific data elements for that class // dataObject.buildDataObjectAsXMLElement(dataObjectAsXMLElement); } Element nextEle = new Element(EventAttributeName.dataType.toString()).setText(dataType.toString()); dataBlockElement.addContent(nextEle); nextEle = new Element(EventAttributeName.federationExecutionModelHandle.toString()) .setText(getFederationExecutionModelHandle()); dataBlockElement.addContent(nextEle); return dataBlockElement; }
/** @param objectAsXML */ public void initialization(final String objectAsXML) throws MuthurException { super.initialization(objectAsXML); dataObject = DataObjectFactory.getDataObject(getDataType()); if (dataObject == null) { throw new MuthurException( "DataObjectFactory.getDataObject() returned a null object for [" + getDataType() + "]"); } dataObject.initialization(objectAsXML); }
/** * Uses the {@link IBaseDataObject#getDataObjectUUID()} from bdo to attempt to retrieve the object * from the {@link ObjectService}. If the object is retrieved then it is check for null and * equality. */ private void assertObjectDeleted(final IBaseDataObject bdo) { IBaseDataObject retrievedDataObject = null; try { retrievedDataObject = getObject(bdo.getDataObjectUUID()); } catch (MuthurException e) { fail(e.getLocalizedMessage()); } assert (retrievedDataObject == null); }
/* * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((dataObject == null) ? 0 : dataObject.hashCode()); result = prime * result + ((dataType == null) ? 0 : dataType.hashCode()); result = prime * result + ((getFederationExecutionModelHandle() == null) ? 0 : getFederationExecutionModelHandle().hashCode()); return result; }
/* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (getClass() != obj.getClass()) { return false; } UpdateObjectRequest other = (UpdateObjectRequest) obj; if (dataObject == null) { if (other.dataObject != null) { return false; } } else if (!dataObject.equals(other.dataObject)) { return false; } if (dataType == null) { if (other.dataType != null) { return false; } } else if (!dataType.equals(other.dataType)) { return false; } if (getFederationExecutionModelHandle() == null) { if (other.getFederationExecutionModelHandle() != null) { return false; } } else if (!getFederationExecutionModelHandle() .equals(other.getFederationExecutionModelHandle())) { return false; } return true; }
@Test public void testCreateOrUpdateObjectRequestWithAircraftTaxOutObject() { AircraftTaxiOut atod = null; try { atod = new AircraftTaxiOut(tailNumber, acid); } catch (Exception e) { fail(e.getLocalizedMessage()); } assertNotNull(atod); assertEquals(atod.getCallSign(), acid); assertEquals(atod.getTailNumber(), tailNumber); assertNotNull(atod.getDataObjectUUID()); assertFalse(atod.getDataObjectUUID().equalsIgnoreCase("")); assertTrue(atod.getObjectCreateTimeMSecs() != 0L); // gate taxiing from atod.setTaxiOutGate("C17"); // taxi out data atod.setTaxiOutTimeMSecs(System.currentTimeMillis() + 30); // create a CreateOrUpdateObjectRequest CreateOrUpdateObjectRequest cor = new CreateOrUpdateObjectRequest(); assertNotNull(cor); cor.setFederationExecutionHandle(UUID.randomUUID().toString()); cor.setFederateRegistrationHandle(UUID.randomUUID().toString()); cor.setFederationExecutionModelHandle(UUID.randomUUID().toString()); cor.setSourceOfEvent("NexSim"); cor.setDataObject(atod); // serialize the object String corAsXML = cor.serialize(); // do standard validation assertNotNull(corAsXML); assertFalse(corAsXML.equals("")); // create another object from previous object's serialized form CreateOrUpdateObjectRequest objectFromXML = new CreateOrUpdateObjectRequest(); try { objectFromXML.initialization(corAsXML); } catch (MuthurException e) { fail(e.getLocalizedMessage()); } // ensure that the two objects are equal assertTrue(objectFromXML.equals(cor)); // get the serialized version of the new object String newObjSerializedAsXML = objectFromXML.serialize(); assertNotNull(newObjSerializedAsXML); assertFalse(newObjSerializedAsXML.equals("")); IBaseDataObject bdo = objectFromXML.getDataObject(); assertNotNull(bdo); assertTrue(bdo instanceof AircraftTaxiOut); /** Initialize the internal data object from the serialized containing object */ try { bdo.initialization(newObjSerializedAsXML); } catch (MuthurException e) { fail(e.getLocalizedMessage()); } // check the serialized form of the data object String bdoSerialized = bdo.serialize(); assertNotNull(bdoSerialized); }
@Test public void testCreateOrUpdateObjectRequestWithFlightPositionObject() { FlightPosition flightPosition = null; try { flightPosition = new FlightPosition(tailNumber, acid); } catch (Exception e) { fail(e.getLocalizedMessage()); } assertNotNull(flightPosition); assertEquals(flightPosition.getCallSign(), acid); assertEquals(flightPosition.getTailNumber(), tailNumber); assertNotNull(flightPosition.getDataObjectUUID()); assertFalse(flightPosition.getDataObjectUUID().equalsIgnoreCase("")); assertTrue(flightPosition.getObjectCreateTimeMSecs() != 0L); // position data flightPosition.setLatitudeDegrees(42.65); flightPosition.setLongitudeDegrees(-76.72); flightPosition.setAltitudeFt(30000); flightPosition.setGroundspeedKts(400); flightPosition.setHeadingDegrees(90); flightPosition.setAirspeedKts(444); flightPosition.setPitchDegrees(0.5); flightPosition.setRollDegrees(0); flightPosition.setYawDegrees(0); flightPosition.setSector("ZOB48"); flightPosition.setCenter("ZOB"); flightPosition.setVerticalspeedKts(verticalspeedKts); flightPosition.setAircraftOnGround(aircraftOnGround); flightPosition.setAircraftTransmissionFrequency(aircraftTransmissionFrequency); flightPosition.setSquawkCode(squawkCode); flightPosition.setIdent(ident); // create a CreateOrUpdateObjectRequest CreateOrUpdateObjectRequest cor = new CreateOrUpdateObjectRequest(); assertNotNull(cor); cor.setFederationExecutionHandle(UUID.randomUUID().toString()); cor.setFederateRegistrationHandle(UUID.randomUUID().toString()); cor.setFederationExecutionModelHandle(UUID.randomUUID().toString()); cor.setSourceOfEvent("NexSim"); cor.setDataObject(flightPosition); // serialize the object String corAsXML = cor.serialize(); // do standard validation assertNotNull(corAsXML); assertFalse(corAsXML.equals("")); // create another object from previous object's serialized form CreateOrUpdateObjectRequest objectFromXML = new CreateOrUpdateObjectRequest(); try { objectFromXML.initialization(corAsXML); } catch (MuthurException e) { fail(e.getLocalizedMessage()); } // ensure that the two objects are equal assertTrue(objectFromXML.equals(cor)); // get the serialized version of the new object String newObjSerializedAsXML = objectFromXML.serialize(); assertNotNull(newObjSerializedAsXML); assertFalse(newObjSerializedAsXML.equals("")); IBaseDataObject bdo = objectFromXML.getDataObject(); assertNotNull(bdo); assertTrue(bdo instanceof FlightPosition); /** Initialize the internal data object from the serialized containing object */ try { bdo.initialization(newObjSerializedAsXML); } catch (MuthurException e) { fail(e.getLocalizedMessage()); } // check the serialized form of the data object String bdoSerialized = bdo.serialize(); assertNotNull(bdoSerialized); }
@Test public void testCreateOrUpdateObjectRequestWithFlightPlanObject() { FlightPlan flightPlan = null; try { flightPlan = new FlightPlan(tailNumber, acid); } catch (MuthurException e) { fail(e.getLocalizedMessage()); } assertNotNull(flightPlan); assertEquals(flightPlan.getCallSign(), acid); assertEquals(flightPlan.getTailNumber(), tailNumber); assertNotNull(flightPlan.getDataObjectUUID()); assertFalse(flightPlan.getDataObjectUUID().equalsIgnoreCase("")); assertTrue(flightPlan.getObjectCreateTimeMSecs() != 0L); // flight plan data flightPlan.setSource("Flight"); flightPlan.setAircraftType("B771"); flightPlan.setPlannedDepartureTimeMSecs(System.currentTimeMillis() + 10); flightPlan.setPlannedDepartureRunway("1R"); flightPlan.setPlannedTaxiOutGate("D31"); flightPlan.setDepartureFix("DEFIX"); flightPlan.setDepartureCenter("ZID"); flightPlan.setPlannedArrivalTimeMSecs(System.currentTimeMillis() + 20); flightPlan.setPlannedArrivalRunway("8L"); flightPlan.setPlannedTaxiInGate("C11"); flightPlan.setArrivalCenter("ZBW"); flightPlan.setArrivalFix("ARFIX"); flightPlan.setCruiseSpeedKts(400); flightPlan.setCruiseAltitudeFt(330); flightPlan.setRoutePlan("IND..ROD.J29.PLB.J595.BGR..BGR"); flightPlan.setPhysicalAircraftClass("J"); flightPlan.setWeightAircraftClass("H"); flightPlan.setUserAircraftClass("C"); flightPlan.setNumOfAircraft(1); flightPlan.setAirborneEquipmentQualifier("R"); flightPlan.setFlightPlanStatus(FlightPlanStatus.CANCELLED); // create a CreateOrUpdateObjectRequest CreateOrUpdateObjectRequest cor = new CreateOrUpdateObjectRequest(); assertNotNull(cor); cor.setFederationExecutionHandle(UUID.randomUUID().toString()); cor.setFederateRegistrationHandle(UUID.randomUUID().toString()); cor.setFederationExecutionModelHandle(UUID.randomUUID().toString()); cor.setSourceOfEvent("NexSim"); cor.setDataObject(flightPlan); // serialize the object String corAsXML = cor.serialize(); writeToFile(cor, false); // do standard validation assertNotNull(corAsXML); assertFalse(corAsXML.equals("")); // create another object from previous object's serialized form CreateOrUpdateObjectRequest objectFromXML = new CreateOrUpdateObjectRequest(); try { objectFromXML.initialization(corAsXML); } catch (MuthurException e) { fail(e.getLocalizedMessage()); } // ensure that the two objects are equal assertTrue(objectFromXML.equals(cor)); // get the serialized version of the new object String newObjSerializedAsXML = objectFromXML.serialize(); assertNotNull(newObjSerializedAsXML); assertFalse(newObjSerializedAsXML.equals("")); IBaseDataObject bdo = objectFromXML.getDataObject(); assertNotNull(bdo); assertTrue(bdo instanceof FlightPlan); /** Initialize the internal data object from the serialized containing object */ try { bdo.initialization(newObjSerializedAsXML); } catch (MuthurException e) { fail(e.getLocalizedMessage()); } // check the serialized form of the data object String bdoSerialized = bdo.serialize(); assertNotNull(bdoSerialized); }
/** @param dataObject the dataObject to set */ public final void setDataObject(IBaseDataObject dataObject) { if (dataObject != null) { dataType = dataObject.getDataType(); this.dataObject = dataObject; } }