Switched mock to send out official xmls.
- Not reading official xmls yet #story[881], #pair[cbt24, esa46]
This commit is contained in:
@@ -13,6 +13,10 @@ import seng302.Model.Event;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class App extends Application {
|
||||
|
||||
@@ -25,6 +29,13 @@ public class App extends Application {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static String readFile(String path, Charset encoding) throws IOException {
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package seng302.DataInput;
|
||||
|
||||
import seng302.Model.Boat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 10/05/17.
|
||||
*/
|
||||
public interface BoatDataSource {
|
||||
List<Boat> getBoats();
|
||||
List<Boat> getMarkerBoats();
|
||||
}
|
||||
@@ -10,7 +10,11 @@ import seng302.Exceptions.InvalidRaceDataException;
|
||||
import seng302.Exceptions.InvalidRegattaDataException;
|
||||
import seng302.MockOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
|
||||
/**
|
||||
@@ -38,60 +42,38 @@ public class Event {
|
||||
* Send the initial race data and then begin race simulation
|
||||
*/
|
||||
public void start() {
|
||||
System.out.println("Sending Regatta");
|
||||
sendRegattaData();
|
||||
System.out.println("Sending Race");
|
||||
sendRaceData();
|
||||
System.out.println("Sending Boat");
|
||||
sendBoatData();
|
||||
|
||||
sendXMLs();
|
||||
int scaleFactor = 5;//TEMP - was 15.
|
||||
Race newRace = new Race(raceDataSource, scaleFactor, mockOutput);
|
||||
new Thread((newRace)).start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send XML string of initial regatta data to the visualiser
|
||||
* @throws InvalidRegattaDataException Invalid regatta
|
||||
*/
|
||||
public void sendRegattaData() throws InvalidRegattaDataException {
|
||||
private void sendXMLs() {
|
||||
try {
|
||||
|
||||
System.setOut(System.out);
|
||||
RegattaData regattaData = new RegattaData(regattaDataSource);
|
||||
String xmlString = regattaData.createXML();
|
||||
System.out.println("Sending Regatta");
|
||||
String regattaData = readFile("mock/src/main/resources/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
|
||||
mockOutput.setRegattaXml(regattaData);
|
||||
mockOutput.parseXMLString(regattaData, 26);
|
||||
|
||||
System.out.println(xmlString);
|
||||
mockOutput.setRegattaXml(xmlString);
|
||||
mockOutput.parseXMLString(xmlString, 26);
|
||||
System.out.println("Sending Race");
|
||||
String raceData = readFile("mock/src/main/resources//mockXML/raceTest.xml", StandardCharsets.UTF_8);
|
||||
mockOutput.setRaceXml(raceData);
|
||||
mockOutput.parseXMLString(raceData, 26);
|
||||
|
||||
System.out.println("Sending Boat");
|
||||
String boatData = readFile("mock/src/main/resources/mockXML/boatTest.xml", StandardCharsets.UTF_8);
|
||||
mockOutput.setBoatsXml(boatData);
|
||||
mockOutput.parseXMLString(boatData, 26);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send XML string of initial race data to the visualiser
|
||||
* @throws InvalidRaceDataException Invalid race
|
||||
*/
|
||||
public void sendRaceData() throws InvalidRaceDataException {
|
||||
RaceData raceData = new RaceData(raceDataSource);
|
||||
//Serialize race data to an XML as a string.
|
||||
String xmlString = raceData.createXML();
|
||||
System.out.println(xmlString);
|
||||
mockOutput.setRaceXml(xmlString);
|
||||
mockOutput.parseXMLString(xmlString, 26);
|
||||
static String readFile(String path, Charset encoding) throws IOException {
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send XML string of initial boat data to the visualiser
|
||||
* @throws InvalidBoatDataException Invalid boat
|
||||
*/
|
||||
public void sendBoatData() throws InvalidBoatDataException {
|
||||
BoatData boatData = new BoatData(raceDataSource.getBoats());
|
||||
//Serialize race data to an XML as a string.
|
||||
String xmlString = boatData.createXML();
|
||||
System.out.println(xmlString);
|
||||
mockOutput.setBoatsXml(xmlString);
|
||||
mockOutput.parseXMLString(xmlString, 26);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user