Transferring files from my laptop to desktop to work on, may be broken.
This commit is contained in:
Generated
-3
@@ -1,3 +0,0 @@
|
|||||||
<component name="CopyrightManager">
|
|
||||||
<settings default="" />
|
|
||||||
</component>
|
|
||||||
@@ -5,6 +5,7 @@ import mock.model.MockRace;
|
|||||||
import mock.model.Polars;
|
import mock.model.Polars;
|
||||||
import mock.xml.RaceXMLCreator;
|
import mock.xml.RaceXMLCreator;
|
||||||
import network.Messages.LatestMessages;
|
import network.Messages.LatestMessages;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
import shared.dataInput.*;
|
import shared.dataInput.*;
|
||||||
import shared.enums.XMLFileType;
|
import shared.enums.XMLFileType;
|
||||||
import shared.exceptions.InvalidBoatDataException;
|
import shared.exceptions.InvalidBoatDataException;
|
||||||
@@ -14,6 +15,7 @@ import shared.exceptions.XMLReaderException;
|
|||||||
import shared.model.Constants;
|
import shared.model.Constants;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
@@ -43,8 +45,14 @@ public class Event {
|
|||||||
* Constructs an event, using various XML files.
|
* Constructs an event, using various XML files.
|
||||||
*/
|
*/
|
||||||
private Event() {
|
private Event() {
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
this.raceXML = getRaceXMLAtCurrentTime(RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90));
|
this.raceXML = getRaceXMLAtCurrentTime(RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90));
|
||||||
|
} catch (SAXException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
System.out.println(this.raceXML);
|
System.out.println(this.raceXML);
|
||||||
this.boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatsSinglePlayer.xml", StandardCharsets.UTF_8);
|
this.boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatsSinglePlayer.xml", StandardCharsets.UTF_8);
|
||||||
this.regattaXML = XMLReader.readXMLFileToString("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
|
this.regattaXML = XMLReader.readXMLFileToString("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package mock.xml;
|
package mock.xml;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
import shared.dataInput.RaceXMLReader;
|
import shared.dataInput.RaceXMLReader;
|
||||||
import shared.enums.XMLFileType;
|
import shared.enums.XMLFileType;
|
||||||
import shared.exceptions.InvalidRaceDataException;
|
import shared.exceptions.InvalidRaceDataException;
|
||||||
@@ -9,10 +11,24 @@ import shared.model.Corner;
|
|||||||
import shared.model.GPSCoordinate;
|
import shared.model.GPSCoordinate;
|
||||||
import shared.model.Mark;
|
import shared.model.Mark;
|
||||||
|
|
||||||
|
import javax.xml.XMLConstants;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import javax.xml.bind.util.JAXBSource;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.Source;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.validation.Schema;
|
||||||
|
import javax.xml.validation.SchemaFactory;
|
||||||
|
import javax.xml.validation.Validator;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper Class for creating a Race XML
|
* Helper Class for creating a Race XML
|
||||||
@@ -138,10 +154,10 @@ public class RaceXMLCreator {
|
|||||||
* @throws InvalidRaceDataException if the race is invalid
|
* @throws InvalidRaceDataException if the race is invalid
|
||||||
* @throws JAXBException if the Race class cannot be parsed into a xml.
|
* @throws JAXBException if the Race class cannot be parsed into a xml.
|
||||||
*/
|
*/
|
||||||
public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException {
|
public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException, IOException, SAXException, ParserConfigurationException {
|
||||||
RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath);
|
RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath);
|
||||||
|
|
||||||
Race race = copyRace(reader);
|
Race race = readRace(RaceXMLCreator.class.getClassLoader().getResource(s).getFile());
|
||||||
|
|
||||||
double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position());
|
double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position());
|
||||||
|
|
||||||
@@ -246,4 +262,33 @@ public class RaceXMLCreator {
|
|||||||
return Math.atan2(dy, dx)/Math.PI * 180;
|
return Math.atan2(dy, dx)/Math.PI * 180;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Race readRace(String file) throws IOException, SAXException, JAXBException, ParserConfigurationException {
|
||||||
|
//validateRace(file);
|
||||||
|
|
||||||
|
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
|
Document document = parser.parse(new File(file));
|
||||||
|
|
||||||
|
JAXBContext jc = JAXBContext.newInstance(Race.class);
|
||||||
|
Unmarshaller unmarshaller = jc.createUnmarshaller();
|
||||||
|
|
||||||
|
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||||
|
URL schemaURL = RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd");// The URL to your XML Schema;
|
||||||
|
Schema schema = sf.newSchema(schemaURL);
|
||||||
|
unmarshaller.setSchema(schema);
|
||||||
|
|
||||||
|
return (Race) unmarshaller.unmarshal(new DOMSource(document));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean validateRace(String file) throws SAXException, IOException, ParserConfigurationException {
|
||||||
|
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
|
Document document = parser.parse(new File(file));
|
||||||
|
|
||||||
|
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||||
|
URL schemaURL = RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd");// The URL to your XML Schema;
|
||||||
|
Schema schema = sf.newSchema(schemaURL);
|
||||||
|
Validator validator = schema.newValidator();
|
||||||
|
validator.validate(new DOMSource(document));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package mock.xml;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import shared.dataInput.RaceXMLReader;
|
||||||
|
import shared.exceptions.InvalidRaceDataException;
|
||||||
|
import shared.exceptions.XMLReaderException;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
public class RaceXMLCreatorTest {
|
||||||
|
|
||||||
|
String fileToTest = "mock/mockXML/raceSchemaTest.xml";
|
||||||
|
@Mock
|
||||||
|
RaceXMLReader reader;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws XMLReaderException, JAXBException, InvalidRaceDataException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLineAngleTest(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user