parent
83dfe1a60c
commit
1e3b816ff5
@ -0,0 +1,87 @@
|
||||
package seng302.Data;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.DataInput.RaceDataSource;
|
||||
import seng302.DataInput.RaceXMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 25/04/17.
|
||||
*/
|
||||
public class BoatDataTest {
|
||||
|
||||
|
||||
private static final String ROOT_TAG = "BoatConfig";
|
||||
private static final String[] REQUIRED_TAGS = new String[]{
|
||||
"Boats", "GPSposition"
|
||||
};
|
||||
private static final String[] REQUIRED_ATTRIBUTES = new String[]{
|
||||
"SourceID", "ShapeID", "HullNum", "StoweName",
|
||||
"ShortName", "BoatName"
|
||||
};
|
||||
|
||||
String result;
|
||||
RaceDataSource raceDataSource;
|
||||
|
||||
@Before
|
||||
public void initReader() {
|
||||
try {
|
||||
raceDataSource = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
||||
BoatData boatData = new BoatData(raceDataSource.getBoats());
|
||||
result = boatData.createXML();
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlHasAllNecessaryTags() {
|
||||
|
||||
assertTrue(result.contains("<" + ROOT_TAG + ">"));
|
||||
for (String tag : REQUIRED_TAGS) {
|
||||
assertTrue(result.contains("<" + tag + ">") || result.contains("<" + tag + " "));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlHasAllNecessaryAttributes() {
|
||||
|
||||
for (String attribute : REQUIRED_ATTRIBUTES) {
|
||||
assertTrue(result.contains(attribute + "="));
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package seng302.Data;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.DataInput.RaceDataSource;
|
||||
import seng302.DataInput.RaceXMLReader;
|
||||
import seng302.DataInput.RegattaDataSource;
|
||||
import seng302.DataInput.RegattaXMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 25/04/17.
|
||||
*/
|
||||
public class RegattaDataTest {
|
||||
|
||||
private static final String ROOT_TAG = "RegattaConfig";
|
||||
private static final String[] REQUIRED_TAGS = new String[]{
|
||||
"RegattaID", "RegattaName", "CourseName", "CentralLatitude", "CentralLongitude",
|
||||
"CentralAltitude", "UtcOffset", "MagneticVariation"
|
||||
};
|
||||
String result;
|
||||
RegattaDataSource regattaDataSource;
|
||||
|
||||
@Before
|
||||
public void initReader() {
|
||||
try {
|
||||
regattaDataSource = new RegattaXMLReader("mockXML/regattaTest.xml");
|
||||
RegattaData regattaData = new RegattaData(regattaDataSource);
|
||||
result = regattaData.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package seng302.Mock;
|
||||
package seng302.DataInput;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
Loading…
Reference in new issue