Re-refactored Event class

#story[881]
main
Erika Savell 9 years ago
parent e7f84eaf83
commit a35d9cbc5a

@ -4,6 +4,7 @@ import org.xml.sax.SAXException;
import seng302.DataInput.*;
import seng302.Exceptions.StreamedCourseXMLException;
import seng302.MockOutput;
import seng302.Networking.Messages.Enums.MessageType;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
@ -36,7 +37,7 @@ public class Event {
}
/**
* Send the initial race data and then begin race simulation
* Sends the initial race data and then begins race simulation
*/
public void start() {
try {
@ -49,38 +50,31 @@ public class Event {
}
}
/**
* Sends out each xml string, via the mock output
*/
private void sendXMLs() {
System.out.println("Sending Regatta");
mockOutput.setRegattaXml(regattaXML);
mockOutput.parseXMLString(regattaXML, 26);
mockOutput.parseXMLString(regattaXML, MessageType.XMLMESSAGE.getValue());
System.out.println("Sending Race");
mockOutput.setRaceXml(raceXML);
System.out.println(raceXML);
mockOutput.parseXMLString(raceXML, 26);
mockOutput.parseXMLString(raceXML, MessageType.XMLMESSAGE.getValue());
System.out.println("Sending Boat");
mockOutput.setBoatsXml(boatXML);
mockOutput.parseXMLString(boatXML, 26);
mockOutput.parseXMLString(boatXML, MessageType.XMLMESSAGE.getValue());
}
/**
* Format time data and return it.
* @param time time data.
* @return formatted time data.
* Sets the xml description of the race to show the race was created now, and starts in 3 minutes
* @param raceXML
* @return String containing edited xml
*/
private String toTruncatedString(ZonedDateTime time) {
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
String text = dateFormat.format(time);
return text;
}
private String getRaceXMLAtCurrentTime(String raceXML) {
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
ZonedDateTime creationTime = ZonedDateTime.now();
return raceXML.replace("CREATION_TIME", toTruncatedString(creationTime))
.replace("START_TIME", toTruncatedString(creationTime.plusMinutes(3)));
return raceXML.replace("CREATION_TIME", dateFormat.format(creationTime))
.replace("START_TIME", dateFormat.format(creationTime.plusMinutes(3)));
}
}

@ -113,7 +113,7 @@ public class Race implements Runnable {
for (int i = 0; i < startingBoats.size(); i++) {
Boat boat = startingBoats.get((i + boatOffset) % startingBoats.size());
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), 0);
boatStatuses.add(new BoatStatus(boat.getSourceID(), BoatStatusEnum.RACING, boat.getCurrentLeg().getLegNumber()));
boatStatuses.add(new BoatStatus(boat.getSourceID(), BoatStatusEnum.PRESTART, boat.getCurrentLeg().getLegNumber()));
}
boatOffset = (boatOffset + 1) % (startingBoats.size());

@ -1,87 +0,0 @@
//package seng302.Data;
//
//
//import org.junit.Before;
//import org.junit.Test;
//import org.xml.sax.SAXException;
//import seng302.DataInput.RaceDataSource;
//import seng302.DataInput.RaceXMLReader;
//
//import javax.xml.parsers.ParserConfigurationException;
//import java.io.IOException;
//
//import static junit.framework.TestCase.assertTrue;
//
///**
// * Created by esa46 on 25/04/17.
// */
//public class BoatDataTest {
//
//
// private static final String ROOT_TAG = "BoatConfig";
// private static final String[] REQUIRED_TAGS = new String[]{
// "Boats", "GPSposition"
// };
// private static final String[] REQUIRED_ATTRIBUTES = new String[]{
// "SourceID", "ShapeID", "HullNum", "StoweName",
// "ShortName", "BoatName"
// };
//
// String result;
// RaceDataSource raceDataSource;
//
// @Before
// public void initReader() {
// try {
// raceDataSource = new RaceXMLReader("raceXML/bermuda_AC35.xml");
// BoatData boatData = new BoatData(raceDataSource.getBoats());
// result = boatData.createXML();
//
//
// } catch (IOException e) {
// e.printStackTrace();
// } catch (SAXException e) {
// e.printStackTrace();
// } catch (ParserConfigurationException e) {
// e.printStackTrace();
// }
// }
//
// @Test
// public void xmlHasAllNecessaryTags() {
//
// assertTrue(result.contains("<" + ROOT_TAG + ">"));
// for (String tag : REQUIRED_TAGS) {
// assertTrue(result.contains("<" + tag + ">") || result.contains("<" + tag + " "));
// }
// }
//
// @Test
// public void xmlHasAllNecessaryAttributes() {
//
// for (String attribute : REQUIRED_ATTRIBUTES) {
// assertTrue(result.contains(attribute + "="));
// }
// }
//
// @Test
// public void allTagsAreTerminated() {
//
// for (String tag : REQUIRED_TAGS) {
// int lastIndex = 0;
// String openTag = "<" + tag + ">";
// String closeTag = "</" + tag + ">";
// while (lastIndex < result.length() && lastIndex > 0) {
// lastIndex = result.indexOf(openTag, lastIndex);
// if (lastIndex > 0) {
//
// lastIndex = result.indexOf(closeTag, lastIndex);
// assertTrue(lastIndex > 0);
// }
// }
// }
// }
//
//
//
//}

@ -1,83 +0,0 @@
//package seng302.Data;
//
//import org.junit.Before;
//import org.junit.Test;
//import org.xml.sax.SAXException;
//import seng302.DataInput.RaceDataSource;
//import seng302.DataInput.RaceXMLReader;
//
//import javax.xml.parsers.ParserConfigurationException;
//import java.io.IOException;
//
//import static junit.framework.TestCase.assertTrue;
//
///**
// * Created by esa46 on 25/04/17.
// */
//public class RaceDataTest {
//
// private static final String ROOT_TAG = "Race";
// private static final String[] REQUIRED_TAGS = new String[]{
// "RaceID", "RaceType", "CreationTimeDate", "RaceStartTime", "Participants", "Yacht",
// "CompoundMarkSequence", "Course", "CompoundMark", "Mark", "CourseLimit", "Limit"
// };
// String result;
// RaceDataSource raceDataSource;
//
// @Before
// public void initReader() {
// try {
// raceDataSource = new RaceXMLReader("raceXML/bermuda_AC35.xml");
// RaceData raceData = new RaceData(raceDataSource);
// result = raceData.createXML();
//
//
// } catch (IOException e) {
// e.printStackTrace();
// } catch (SAXException e) {
// e.printStackTrace();
// } catch (ParserConfigurationException e) {
// e.printStackTrace();
// }
// }
//
// @Test
// public void xmlHasAllNecessaryFields() {
//
// assertTrue(result.contains("<" + ROOT_TAG + ">"));
// for (String tag : REQUIRED_TAGS) {
// System.out.println(tag);
// assertTrue(result.contains("<" + tag + ">") || result.contains("<" + tag + " "));
// }
// }
//
// @Test
// public void allTagsAreTerminated() {
//
// for (String tag : REQUIRED_TAGS) {
// int lastIndex = 0;
// String openTag = "<" + tag + ">";
// String closeTag = "</" + tag + ">";
// while (lastIndex < result.length() && lastIndex > 0) {
// lastIndex = result.indexOf(openTag, lastIndex);
// if (lastIndex > 0) {
//
// lastIndex = result.indexOf(closeTag, lastIndex);
// assertTrue(lastIndex > 0);
// }
// }
// }
// }
//
//
// @Test
// public void idAndTypeAreEquivalent() {
// String newId = result.substring(result.indexOf("<RaceID>") + 8, result.indexOf("</RaceID>"));
// String newRaceType = result.substring(result.indexOf("<RaceType>") + 10, result.indexOf("</RaceType>"));
//
// assertTrue(raceDataSource.getRaceId() == Integer.parseInt(newId));
// assertTrue(raceDataSource.getRaceType().equals(newRaceType));
// }
//
//
//}

@ -1,73 +0,0 @@
package seng302.Data;
import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXException;
import seng302.DataInput.RaceDataSource;
import seng302.DataInput.RegattaDataSource;
import seng302.DataInput.RegattaXMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import static junit.framework.TestCase.assertTrue;
/**
* Created by esa46 on 25/04/17.
*/
public class RegattaDataTest {
private static final String ROOT_TAG = "RegattaConfig";
private static final String[] REQUIRED_TAGS = new String[]{
"RegattaID", "RegattaName", "CourseName", "CentralLatitude", "CentralLongitude",
"CentralAltitude", "UtcOffset", "MagneticVariation"
};
String result;
RegattaDataSource regattaDataSource;
@Before
public void initReader() {
try {
regattaDataSource = new RegattaXMLReader("mockXML/regattaTest.xml");
RegattaData regattaData = new RegattaData(regattaDataSource);
result = regattaData.createXML();
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
@Test
public void xmlHasAllNecessaryFields() {
assertTrue(result.contains("<" + ROOT_TAG + ">"));
for (String tag : REQUIRED_TAGS) {
System.out.println(tag);
assertTrue(result.contains("<" + tag + ">") || result.contains("<" + tag + " "));
}
}
@Test
public void allTagsAreTerminated() {
for (String tag : REQUIRED_TAGS) {
int lastIndex = 0;
String openTag = "<" + tag + ">";
String closeTag = "</" + tag + ">";
while (lastIndex < result.length() && lastIndex > 0) {
lastIndex = result.indexOf(openTag, lastIndex);
if (lastIndex > 0) {
lastIndex = result.indexOf(closeTag, lastIndex);
assertTrue(lastIndex > 0);
}
}
}
}
}
Loading…
Cancel
Save