Search in sources :

Example 1 with XMLSetFieldLiteralInt

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;
}
Also used : XMLSetFieldLiteralString(com.sldeditor.common.xml.ui.XMLSetFieldLiteralString) XMLSetFieldLiteralInt(com.sldeditor.common.xml.ui.XMLSetFieldLiteralInt) XMLSetFieldLiteralBoolean(com.sldeditor.common.xml.ui.XMLSetFieldLiteralBoolean) XMLSetFieldLiteralDouble(com.sldeditor.common.xml.ui.XMLSetFieldLiteralDouble) XMLSetFieldLiteralString(com.sldeditor.common.xml.ui.XMLSetFieldLiteralString) XMLSetFieldLiteralDouble(com.sldeditor.common.xml.ui.XMLSetFieldLiteralDouble)

Aggregations

XMLSetFieldLiteralBoolean (com.sldeditor.common.xml.ui.XMLSetFieldLiteralBoolean)1 XMLSetFieldLiteralDouble (com.sldeditor.common.xml.ui.XMLSetFieldLiteralDouble)1 XMLSetFieldLiteralInt (com.sldeditor.common.xml.ui.XMLSetFieldLiteralInt)1 XMLSetFieldLiteralString (com.sldeditor.common.xml.ui.XMLSetFieldLiteralString)1