Added boat data xml tests
#story[778]
This commit is contained in:
@@ -44,7 +44,6 @@ public class RaceData {
|
|||||||
courseLimit = dataSource.getBoundary();
|
courseLimit = dataSource.getBoundary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String createXML() {
|
public String createXML() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -148,8 +147,6 @@ public class RaceData {
|
|||||||
StreamResult result = new StreamResult(stringWriter);
|
StreamResult result = new StreamResult(stringWriter);
|
||||||
transformer.transform(source,result);
|
transformer.transform(source,result);
|
||||||
|
|
||||||
System.out.println(stringWriter.toString());
|
|
||||||
|
|
||||||
return stringWriter.toString();
|
return stringWriter.toString();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,8 +58,9 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
* Read the files
|
* Read the files
|
||||||
*/
|
*/
|
||||||
private void read() {
|
private void read() {
|
||||||
readID();
|
|
||||||
readCourse();
|
readCourse();
|
||||||
|
readID();
|
||||||
readLegs();
|
readLegs();
|
||||||
readMarkers();
|
readMarkers();
|
||||||
readBoats();
|
readBoats();
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package seng302.Data;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import seng302.Mock.RaceDataSource;
|
||||||
|
import seng302.RaceXMLReader;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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().equals(newId));
|
||||||
|
assertTrue(raceDataSource.getRaceType().equals(newRaceType));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,40 +1,46 @@
|
|||||||
<race>
|
<race>
|
||||||
|
<raceId>5326</raceId>
|
||||||
<boats>
|
<boats>
|
||||||
<boat>
|
<boat>
|
||||||
<name>ORACLE TEAM USA</name>
|
<name>ORACLE TEAM USA</name>
|
||||||
<speed>20</speed>
|
<speed>20</speed>
|
||||||
<abbr>USA</abbr>
|
<abbr>USA</abbr>
|
||||||
|
<sourceID>121</sourceID>
|
||||||
<colour>BLUEVIOLET</colour>
|
<colour>BLUEVIOLET</colour>
|
||||||
</boat>
|
</boat>
|
||||||
<boat>
|
<boat>
|
||||||
<name>Land Rover BAR</name>
|
<name>Land Rover BAR</name>
|
||||||
<speed>30</speed>
|
<speed>30</speed>
|
||||||
<abbr>GBR</abbr>
|
<abbr>GBR</abbr>
|
||||||
|
<sourceID>122</sourceID>
|
||||||
<colour>BLACK</colour>
|
<colour>BLACK</colour>
|
||||||
</boat>
|
</boat>
|
||||||
<boat>
|
<boat>
|
||||||
<name>SoftBank Team Japan</name>
|
<name>SoftBank Team Japan</name>
|
||||||
<speed>25</speed>
|
<speed>25</speed>
|
||||||
<abbr>JPN</abbr>
|
<abbr>JPN</abbr>
|
||||||
|
<sourceID>123</sourceID>
|
||||||
<colour>RED</colour>
|
<colour>RED</colour>
|
||||||
</boat>
|
</boat>
|
||||||
<boat>
|
<boat>
|
||||||
<name>Groupama Team France</name>
|
<name>Groupama Team France</name>
|
||||||
<speed>20</speed>
|
<speed>20</speed>
|
||||||
<abbr>FRA</abbr>
|
<abbr>FRA</abbr>
|
||||||
|
<sourceID>124</sourceID>
|
||||||
<colour>ORANGE</colour>
|
<colour>ORANGE</colour>
|
||||||
</boat>
|
</boat>
|
||||||
<boat>
|
<boat>
|
||||||
<name>Artemis Racing</name>
|
<name>Artemis Racing</name>
|
||||||
<speed>29</speed>
|
<speed>29</speed>
|
||||||
<abbr>SWE</abbr>
|
<abbr>SWE</abbr>
|
||||||
|
<sourceID>125</sourceID>
|
||||||
<colour>DARKOLIVEGREEN</colour>
|
<colour>DARKOLIVEGREEN</colour>
|
||||||
</boat>
|
</boat>
|
||||||
<boat>
|
<boat>
|
||||||
<name>Emirates Team New Zealand</name>
|
<name>Emirates Team New Zealand</name>
|
||||||
<speed>62</speed>
|
<speed>62</speed>
|
||||||
<abbr>NZL</abbr>
|
<abbr>NZL</abbr>
|
||||||
|
<sourceID>126</sourceID>
|
||||||
<colour>LIMEGREEN</colour>
|
<colour>LIMEGREEN</colour>
|
||||||
</boat>
|
</boat>
|
||||||
</boats>
|
</boats>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<race>
|
<race>
|
||||||
|
<raceId>5326</raceId>
|
||||||
<boats>
|
<boats>
|
||||||
<boat>
|
<boat>
|
||||||
<name>ORACLE TEAM USA</name>
|
<name>ORACLE TEAM USA</name>
|
||||||
|
|||||||
Reference in New Issue
Block a user