parent
d05d7271fc
commit
03f63b2c61
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue