fixed the unit test for the xml helper

This commit is contained in:
paul-loedige 2020-12-27 14:03:07 +01:00
parent 33e5d3106e
commit b250d243c4

View File

@ -5,6 +5,7 @@ import com.example.aped.utils.XMLHandler;
import org.junit.Test;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.IOException;
import java.util.Dictionary;
import java.util.List;
@ -14,13 +15,15 @@ import javax.xml.parsers.ParserConfigurationException;
import static org.junit.Assert.*;
public class XMLHandlerUnitTest {
private String xmlPath="src/main/java/com/example/aped/xml/Test.xml";
private String xsdPath="src/main/java/com/example/aped/xml/config.xsd";
private String xmlPath="src/main/res/raw/XML/Test.xml";
private String xsdPath="src/main/res/raw/XML/config.xsd";
private File xmlFile = new File(xmlPath);
private File xsdFile = new File(xsdPath);
@Test
public void TestFiles_AreValid(){
try{
XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath);
XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile);
}catch(IOException | ParserConfigurationException | SAXException e){
System.out.println("XMLHandler failed");
assert(false);
@ -33,7 +36,7 @@ public class XMLHandlerUnitTest {
@Test
public void Test_getDeviceNames(){
try{
XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath);
XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile);
List<String> deviceNames = xmlHandler.getDeviceNames();
assertArrayEquals(new String[]{"example","sensorarray"},deviceNames.toArray());
}catch(IOException | ParserConfigurationException | SAXException e){
@ -45,7 +48,7 @@ public class XMLHandlerUnitTest {
@Test
public void TestInput_SimpleValueInfo(){
try{
XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath);
XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile);
Dictionary<String, Object> valueInfo = xmlHandler.getValueInfo("example");
assertEquals("{factor=1.0, type=boolean, unit=, offset=0.0}",valueInfo.toString());
}catch(IOException | ParserConfigurationException | SAXException e){
@ -57,7 +60,7 @@ public class XMLHandlerUnitTest {
@Test
public void TestInput_ComplexValueInfo(){
try{
XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath);
XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile);
Dictionary<String, Object> valueInfo = xmlHandler.getValueInfo("sensorarray");
assertEquals("{factor=2.5, type=int, unit=°C, offset=1.2}",valueInfo.toString());
}catch(IOException | ParserConfigurationException | SAXException e){
@ -69,7 +72,7 @@ public class XMLHandlerUnitTest {
@Test
public void TestInput_SimplePort(){
try{
XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath);
XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile);
Dictionary<String, Object> port = xmlHandler.getPort("example");
assertEquals("{pins=[GPIO_2], protocol=DI}",port.toString());
}catch(IOException | ParserConfigurationException | SAXException e){
@ -81,7 +84,7 @@ public class XMLHandlerUnitTest {
@Test
public void TestInput_ComplexPort(){
try{
XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath);
XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile);
Dictionary<String, Object> port = xmlHandler.getPort("sensorarray");
assertEquals("{pins=[GPIO_3, GPIO_4, GPIO_5, GPIO_6], protocol=DI}",port.toString());
}catch(IOException | ParserConfigurationException | SAXException e){