Moved mock.app.App#readFile(...) to shared.dataInput.XMLReader#readXMLFileToString(...).

Did the bare minimum to get the mock.model, mock.dataInput, shared.model tests working - many of them need to be tidied/refactored/moved as they don't take into account most of the refactorings.
This commit is contained in:
fjc40
2017-07-19 22:30:21 +12:00
parent d0c6b5f716
commit 10e80bca05
22 changed files with 836 additions and 493 deletions
+3 -24
View File
@@ -34,9 +34,9 @@ public class App extends Application {
try {
Polars boatPolars = PolarParser.parse("mock/polars/acc_polars.csv");
String regattaXML = readFile("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
String raceXML = readFile("mock/mockXML/raceTest.xml", StandardCharsets.UTF_8);
String boatXML = readFile("mock/mockXML/boatTest.xml", StandardCharsets.UTF_8);
String regattaXML = XMLReader.readXMLFileToString("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
String raceXML = XMLReader.readXMLFileToString("mock/mockXML/raceTest.xml", StandardCharsets.UTF_8);
String boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatTest.xml", StandardCharsets.UTF_8);
Event raceEvent = new Event(raceXML, regattaXML, boatXML, boatPolars);
raceEvent.start();
@@ -48,27 +48,6 @@ public class App extends Application {
}
}
/**
* Reads the Initial Race XML files that are necessary to run the mock.
* @param path path of the XML
* @param encoding encoding of the xml
* @return A string containing the contents of the specified file.
* @throws IOException No file etc
* @throws ParserConfigurationException Issue with the XML formatting
* @throws SAXException Issue with XML formatting
* @throws TransformerException Issue with the XML format
*/
private String readFile(String path, Charset encoding) throws IOException, ParserConfigurationException, SAXException, TransformerException {
InputSource fXmlFile = new InputSource(getClass().getClassLoader().getResourceAsStream(path));
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
return XMLReader.getContents(doc);
}
}
@@ -164,8 +164,8 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
}
/**
* Get the marker BOats that are participating in this race
* @return Dictionary of the Markers BOats that are in this race indexed by their Source ID.
* Get the marker Boats that are participating in this race
* @return Dictionary of the Markers Boats that are in this race indexed by their Source ID.
*/
@Override
public Map<Integer, Mark> getMarkerBoats() {
@@ -3,6 +3,7 @@ package shared.dataInput;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import shared.exceptions.XMLReaderException;
@@ -16,6 +17,7 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/**
@@ -134,4 +136,28 @@ public abstract class XMLReader {
return stringWriter.toString();
}
/**
* Reads the an XML file, as a resource, into a string.
* @param path path of the XML
* @param encoding encoding of the xml
* @return A string containing the contents of the specified file.
* @throws IOException No file etc
* @throws ParserConfigurationException Issue with the XML formatting
* @throws SAXException Issue with XML formatting
* @throws TransformerException Issue with the XML format
*/
public static String readXMLFileToString(String path, Charset encoding) throws IOException, ParserConfigurationException, SAXException, TransformerException {
InputSource fileSource = new InputSource(XMLReader.class.getClassLoader().getResourceAsStream(path));
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fileSource);
doc.getDocumentElement().normalize();
return XMLReader.getContents(doc);
}
}