Search in sources :

Example 11 with TestSolution

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

the class DOMHandlerImpl method checkAttributeValueIsEmpty.

/**
     * @deprecated Kept for backward compatibility.
     * @param attributeName
     *            the name of the attribute to check
     * @return
     */
@Override
@Deprecated
public TestSolution checkAttributeValueIsEmpty(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, "ValueNotEmpty", 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 12 with TestSolution

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

the class DOMHandlerImpl method checkContentNotEmpty.

/**
     * @deprecated Kept for backward compatibility.
     * @return
     */
@Override
@Deprecated
public TestSolution checkContentNotEmpty() {
    Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
    for (Node workingElement : selectedElementList) {
        TestSolution result = TestSolution.PASSED;
        if (workingElement.getTextContent().trim().isEmpty() && (workingElement.getChildNodes().getLength() == 0 || (workingElement.getChildNodes().getLength() == 1 && workingElement.getChildNodes().item(0).getNodeName().equalsIgnoreCase("#text")))) {
            result = TestSolution.FAILED;
            addSourceCodeRemark(result, workingElement, "ValueEmpty", workingElement.getNodeName());
        }
        resultSet.add(result);
    }
    return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Node(org.w3c.dom.Node)

Example 13 with TestSolution

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

the class DOMHandlerImpl method checkAttributeValueLengthLower.

/**
     * @deprecated Kept for backward compatibility.
     * @param attributeName
     *            the name of the attribute to check
     * @param length
     *            the length of the attribute value to check
     * @param defaultFailResult
     *            the default return value if the check processing fails
     * @return
     */
@Override
@Deprecated
public TestSolution checkAttributeValueLengthLower(String attributeName, int length, TestSolution defaultFailResult) {
    Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
    for (Node workingElement : selectedElementList) {
        TestSolution result = TestSolution.PASSED;
        String textContent = workingElement.getTextContent();
        if (textContent.length() > length) {
            result = defaultFailResult;
            addSourceCodeRemark(result, workingElement, "LengthTooLong", textContent);
        }
        resultSet.add(result);
    }
    return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Node(org.w3c.dom.Node)

Example 14 with TestSolution

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

the class DOMHandlerImpl method checkTextContentValue.

@Override
public TestSolution checkTextContentValue(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 isInBlackList = false;
        boolean isInWhiteList = false;
        String textContent = workingElement.getTextContent();
        for (String text : blacklist) {
            if (textContent.toLowerCase().equals(text.toLowerCase())) {
                isInBlackList = true;
                break;
            }
        }
        for (String text : whitelist) {
            if (textContent.toLowerCase().equals(text.toLowerCase())) {
                isInWhiteList = true;
                break;
            }
        }
        if (isInBlackList && isInWhiteList) {
            throw new RuntimeException(new IncoherentValueDomainsException());
        }
        if (isInBlackList) {
            result = TestSolution.FAILED;
            addSourceCodeRemark(result, workingElement, "BlackListedValue", textContent);
        }
        if (isInWhiteList) {
            result = TestSolution.PASSED;
        }
        if (result.equals(TestSolution.NEED_MORE_INFO)) {
            addSourceCodeRemark(result, workingElement, "VerifyValue", textContent);
        }
        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 15 with TestSolution

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

the class DOMHandlerImpl method checkAttributeExists.

@Override
public TestSolution checkAttributeExists(String attributeName) {
    if (messageCode == null) {
        messageCode = ATTRIBUTE_MISSING_MSG_CODE;
    }
    Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
    for (Node workingElement : selectedElementList) {
        TestSolution processResult = TestSolution.PASSED;
        Node attribute = workingElement.getAttributes().getNamedItem(attributeName);
        if (attribute == null) {
            processResult = TestSolution.FAILED;
            addSourceCodeRemark(processResult, workingElement, messageCode, attributeName);
        }
        resultSet.add(processResult);
    }
    return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Node(org.w3c.dom.Node)

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