use of com.sldeditor.common.xml.ui.XMLSetFieldLiteralInt in project sldeditor by robward-scisys.
the class SLDOutputTest method testValue.
/**
* Test value.
*
* @param sldContentString the sld content string
* @param selectionData the selection data
* @param field the field
* @param testValue the test value
* @return true, if successful
*/
public boolean testValue(String sldContentString, TreeSelectionData selectionData, FieldIdEnum field, XMLFieldBase testValue) {
boolean passed = false;
String extractedString = getString(sldContentString, selectionData, field, null);
if (testValue instanceof XMLSetFieldLiteralString) {
XMLSetFieldLiteralString stringLiteral = (XMLSetFieldLiteralString) testValue;
String valueToTest = stringLiteral.getValue();
passed = (valueToTest.compareTo(extractedString) == 0);
if (!passed) {
System.out.println(String.format("Value to test : '%s' Extracted : '%s'", valueToTest, extractedString));
}
} else if (testValue instanceof XMLSetFieldLiteralDouble) {
XMLSetFieldLiteralDouble doubleLiteral = (XMLSetFieldLiteralDouble) testValue;
if ((extractedString != null) && !extractedString.isEmpty()) {
Double convertedValue = Double.valueOf(extractedString);
passed = (Math.abs(convertedValue - doubleLiteral.getValue()) < 0.001);
}
if (!passed) {
System.out.println(String.format("Value to test : '%f' Extracted : '%s'", doubleLiteral.getValue(), extractedString));
}
} else if (testValue instanceof XMLSetFieldLiteralInt) {
XMLSetFieldLiteralInt intLiteral = (XMLSetFieldLiteralInt) testValue;
if ((extractedString != null) && !extractedString.isEmpty()) {
passed = (Integer.valueOf(extractedString).intValue() == intLiteral.getValue().intValue());
}
} else if (testValue instanceof XMLSetFieldLiteralBoolean) {
XMLSetFieldLiteralBoolean booleanLiteral = (XMLSetFieldLiteralBoolean) testValue;
if ((extractedString != null) && !extractedString.isEmpty()) {
passed = (Boolean.valueOf(extractedString) == booleanLiteral.getValue());
}
}
System.out.println("Checking value : " + field + " " + extractedString + " " + (passed ? "PASS" : "FAIL"));
return passed;
}
Aggregations