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