Search in sources :

Example 26 with TestSolution

use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.

the class DOMHandlerImpl method checkAttributeValueNotEmpty.

/**
     * @deprecated Kept for backward compatibility.
     * @param attributeName
     *            the name of the attribute to check
     * @return
     */
@Override
@Deprecated
public TestSolution checkAttributeValueNotEmpty(String attributeName) {
    Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
    for (Node workingElement : selectedElementList) {
        TestSolution result = TestSolution.PASSED;
        Node attribute = workingElement.getAttributes().getNamedItem(attributeName);
        if (attribute != null) {
            if (attribute.getNodeValue().length() == 0) {
                result = TestSolution.FAILED;
                addSourceCodeRemark(result, workingElement, "ValueEmpty", attributeName);
            }
        } else {
            result = TestSolution.NOT_APPLICABLE;
        }
        resultSet.add(result);
    }
    return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Node(org.w3c.dom.Node)

Example 27 with TestSolution

use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.

the class DOMHandlerImpl method checkTextContentAndAttributeValue.

/**
     * @deprecated Kept for backward compatibility.
     * @param attributeName
     * @param blacklist
     *            the list of prevented values
     * @param whitelist
     *            the list of granted values
     * @return
     */
@Override
@Deprecated
public TestSolution checkTextContentAndAttributeValue(String attributeName, Collection<String> blacklist, Collection<String> whitelist) {
    if (whitelist == null) {
        whitelist = new ArrayList<String>();
    }
    if (blacklist == null) {
        blacklist = new ArrayList<String>();
    }
    Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
    for (Node workingElement : selectedElementList) {
        TestSolution result = TestSolution.NEED_MORE_INFO;
        boolean isInWhiteList = false;
        boolean isInBlackList = false;
        String textContent = workingElement.getTextContent();
        Node attribute = workingElement.getAttributes().getNamedItem(attributeName);
        for (String text : blacklist) {
            if (textContent.toLowerCase().equals(text.toLowerCase())) {
                isInBlackList = true;
                addSourceCodeRemark(result, workingElement, "BlackListedValue", textContent);
                break;
            }
            if (attribute != null) {
                if (attribute.getNodeValue().toLowerCase().equals(text.toLowerCase())) {
                    isInBlackList = true;
                    addSourceCodeRemark(result, workingElement, "BlackListedValue", attributeName);
                    break;
                }
            }
        }
        for (String text : whitelist) {
            if (textContent.toLowerCase().equals(text.toLowerCase())) {
                isInWhiteList = true;
                break;
            }
            if (attribute != null) {
                if (attribute.getNodeValue().toLowerCase().equals(text.toLowerCase())) {
                    isInWhiteList = true;
                    break;
                }
            }
        }
        if (isInBlackList && isInWhiteList) {
            throw new RuntimeException(new IncoherentValueDomainsException());
        }
        if (isInWhiteList) {
            result = TestSolution.PASSED;
        }
        if (isInBlackList) {
            result = TestSolution.FAILED;
        }
        if (result.equals(TestSolution.NEED_MORE_INFO)) {
            addSourceCodeRemark(result, workingElement, "VerifyValue", attributeName);
        }
        resultSet.add(result);
    }
    return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Node(org.w3c.dom.Node) IncoherentValueDomainsException(org.asqatasun.exception.IncoherentValueDomainsException)

Example 28 with TestSolution

use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.

the class DOMHandlerImpl method checkTextContentValueNotEmpty.

/**
     * @deprecated Kept for backward compatibility.
     * @return
     */
@Override
@Deprecated
public TestSolution checkTextContentValueNotEmpty() {
    Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
    for (Node workingElement : selectedElementList) {
        TestSolution result = TestSolution.PASSED;
        if (workingElement.getTextContent().length() == 0) {
            result = TestSolution.FAILED;
            addSourceCodeRemark(result, workingElement, "ValueEmpty", workingElement.getNodeValue());
        }
        resultSet.add(result);
    }
    return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Node(org.w3c.dom.Node)

Example 29 with TestSolution

use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.

the class DOMHandlerImpl method checkEachWithXpath.

/**
     * @deprecated Kept for backward compatibility.
     * @param expr
     * @return
     */
@Override
@Deprecated
public TestSolution checkEachWithXpath(String expr) {
    Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
    for (Node node : selectedElementList) {
        TestSolution tempResult = TestSolution.PASSED;
        try {
            XPathExpression xPathExpression = xpath.compile(expr);
            Boolean check = (Boolean) xPathExpression.evaluate(node, XPathConstants.BOOLEAN);
            if (!check.booleanValue()) {
                tempResult = TestSolution.FAILED;
            // addSourceCodeRemark(result, node,
            // "wrong value, does not respect xpath expression : " +
            // expr, node.getNodeValue());
            }
        } catch (XPathExpressionException ex) {
            LOGGER.error(ex.getMessage() + " occured requesting " + expr + " on " + ssp.getURI());
            throw new RuntimeException(ex);
        }
        resultSet.add(tempResult);
    }
    return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Node(org.w3c.dom.Node)

Example 30 with TestSolution

use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.

the class DOMHandlerImpl method checkChildNodeExists.

@Override
public TestSolution checkChildNodeExists(String childNodeName) {
    if (messageCode == null) {
        messageCode = CHILD_NODE_MISSING_MSG_CODE;
    }
    Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
    for (Node workingElement : selectedElementList) {
        TestSolution result = TestSolution.PASSED;
        NodeList childNodes = workingElement.getChildNodes();
        boolean found = false;
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node childNode = childNodes.item(i);
            if (childNode.getNodeName().equalsIgnoreCase(childNodeName)) {
                found = true;
                break;
            }
        }
        if (!found) {
            result = TestSolution.FAILED;
            addSourceCodeRemark(result, workingElement, messageCode, childNodeName);
        }
        resultSet.add(result);
    }
    return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList)

Aggregations

TestSolution (org.asqatasun.entity.audit.TestSolution)37 Node (org.w3c.dom.Node)13 Element (org.jsoup.nodes.Element)11 IncoherentValueDomainsException (org.asqatasun.exception.IncoherentValueDomainsException)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 ProcessResult (org.asqatasun.entity.audit.ProcessResult)2 CriterionStatistics (org.asqatasun.entity.statistics.CriterionStatistics)2 ThemeStatistics (org.asqatasun.entity.statistics.ThemeStatistics)2 DomElement (org.asqatasun.rules.domelement.DomElement)2 ProcessRemarkService (org.asqatasun.service.ProcessRemarkService)2 NodeList (org.w3c.dom.NodeList)2 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NoResultException (javax.persistence.NoResultException)1 Query (javax.persistence.Query)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 EvidenceElement (org.asqatasun.entity.audit.EvidenceElement)1