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 javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.IOException;
|
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 {
|
public class App extends Application {
|
||||||
|
|
||||||
@@ -25,6 +29,13 @@ public class App extends Application {
|
|||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static String readFile(String path, Charset encoding) throws IOException {
|
||||||
|
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||||
|
return new String(encoded, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
try {
|
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.Exceptions.InvalidRegattaDataException;
|
||||||
import seng302.MockOutput;
|
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
|
* Send the initial race data and then begin race simulation
|
||||||
*/
|
*/
|
||||||
public void start() {
|
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.
|
int scaleFactor = 5;//TEMP - was 15.
|
||||||
Race newRace = new Race(raceDataSource, scaleFactor, mockOutput);
|
Race newRace = new Race(raceDataSource, scaleFactor, mockOutput);
|
||||||
new Thread((newRace)).start();
|
new Thread((newRace)).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
private void sendXMLs() {
|
||||||
* Send XML string of initial regatta data to the visualiser
|
try {
|
||||||
* @throws InvalidRegattaDataException Invalid regatta
|
|
||||||
*/
|
|
||||||
public void sendRegattaData() throws InvalidRegattaDataException {
|
|
||||||
|
|
||||||
System.setOut(System.out);
|
System.out.println("Sending Regatta");
|
||||||
RegattaData regattaData = new RegattaData(regattaDataSource);
|
String regattaData = readFile("mock/src/main/resources/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
|
||||||
String xmlString = regattaData.createXML();
|
mockOutput.setRegattaXml(regattaData);
|
||||||
|
mockOutput.parseXMLString(regattaData, 26);
|
||||||
|
|
||||||
System.out.println(xmlString);
|
System.out.println("Sending Race");
|
||||||
mockOutput.setRegattaXml(xmlString);
|
String raceData = readFile("mock/src/main/resources//mockXML/raceTest.xml", StandardCharsets.UTF_8);
|
||||||
mockOutput.parseXMLString(xmlString, 26);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static String readFile(String path, Charset encoding) throws IOException {
|
||||||
* Send XML string of initial race data to the visualiser
|
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||||
* @throws InvalidRaceDataException Invalid race
|
return new String(encoded, encoding);
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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