Search in sources :

Example 6 with TestSolution

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

the class CompositeChecker method callCheckers.

/**
     * Check the pertinence of a text by calling recursively the checkers 
     * loaded by the instance. If no checker returns failed, a sourceCodeRemark
     * is created with a manual check message. To respect the ElementChecker 
     * interface, the check method is called with an elementHandler instance as
     * argument. This instance only contains the current checked element.
     * 
     * @param sspHandler
     * @param elementHandler
     * @return the solution of the pertinence check
     */
protected TestSolution callCheckers(SSPHandler sspHandler, ElementHandler<Element> elementHandler) {
    TestSolutionHandler globalTestSolutionHandler = new TestSolutionHandlerImpl();
    for (ElementChecker ec : checkers) {
        TestSolutionHandler testSolutionHandler = new TestSolutionHandlerImpl();
        ec.check(sspHandler, elementHandler, testSolutionHandler);
        TestSolution checkerSolution = testSolutionHandler.getTestSolution();
        Logger.getLogger(this.getClass()).debug("Checker " + ec.getClass() + " returned " + checkerSolution);
        if (isOrCombinaison && (checkerSolution.equals(ec.getFailureSolution()) || checkerSolution.equals(TestSolution.NOT_APPLICABLE))) {
            return checkerSolution;
        }
        globalTestSolutionHandler.addTestSolution(checkerSolution);
    }
    return createSolutionFromCheckersResult(globalTestSolutionHandler.getTestSolution(), elementHandler);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler)

Example 7 with TestSolution

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

the class AttributeOnChildElementPresenceChecker method checkChildElementWithAttributePresence.

/**
     * This methods checks whether elements have a child element of with a given 
     * attribute.
     * 
     * @param elements
     * @param testSolutionHandler 
     */
private void checkChildElementWithAttributePresence(Elements elements, TestSolutionHandler testSolutionHandler) {
    if (elements.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    TestSolution testSolution = TestSolution.PASSED;
    for (Element el : elements) {
        if (!el.getElementsByAttribute(attributeName).isEmpty()) {
            testSolution = setTestSolution(testSolution, getSuccessSolution());
            addSourceCodeRemark(getSuccessSolution(), el, getSuccessMsgCode());
        } else {
            testSolution = setTestSolution(testSolution, getFailureSolution());
            addSourceCodeRemark(getFailureSolution(), el, getFailureMsgCode());
        }
    }
    testSolutionHandler.addTestSolution(testSolution);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Element(org.jsoup.nodes.Element)

Example 8 with TestSolution

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

the class AttributePresenceChecker method checkAttributePresence.

/**
     * This methods checks whether a given attribute is present for a set of 
     * elements
     * 
     * @param elements
     * @param testSolutionHandler
     */
private void checkAttributePresence(Elements elements, TestSolutionHandler testSolutionHandler) {
    if (elements.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    TestSolution testSolution = TestSolution.PASSED;
    for (Element el : elements) {
        if (!el.hasAttr(attributeName)) {
            testSolution = setTestSolution(testSolution, getFailureSolution());
            createSourceCodeRemark(getFailureSolution(), el, getFailureMsgCode());
        } else {
            testSolution = setTestSolution(testSolution, getSuccessSolution());
            createSourceCodeRemark(getSuccessSolution(), el, getSuccessMsgCode());
        }
    }
    testSolutionHandler.addTestSolution(testSolution);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Element(org.jsoup.nodes.Element)

Example 9 with TestSolution

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

the class ElementPresenceChecker method checkElementPresence.

/**
     * This methods checks whether a given element is present on the page.
     *
     * @param elements
     * @param testSolutionHandler
     */
private void checkElementPresence(Elements elements, TestSolutionHandler testSolutionHandler) {
    TestSolution checkResult = getFailureSolution();
    if (!elements.isEmpty() && ((!checkUnicity) || (checkUnicity && elements.size() == 1))) {
        checkResult = getSuccessSolution();
        for (Element el : elements) {
            createSourceCodeRemark(getSuccessSolution(), el, getSuccessMsgCode());
        }
    } else if (checkUnicity && elements.size() > 1 && StringUtils.isNotBlank(messageCodeOnMultipleElements)) {
        for (Element el : elements) {
            addSourceCodeRemark(getFailureSolution(), el, messageCodeOnMultipleElements);
        }
    } else if (StringUtils.isNotBlank(getFailureMsgCode())) {
        getProcessRemarkService().addProcessRemark(getFailureSolution(), getFailureMsgCode());
    }
    testSolutionHandler.addTestSolution(checkResult);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Element(org.jsoup.nodes.Element)

Example 10 with TestSolution

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

the class HeadingsHierarchyChecker method checkHeadingsHierarchy.

/**
     * This methods checks whether the headings hierarchy is well-structured
     *
     * @param elements
     * @param testSolutionHandler
     */
private void checkHeadingsHierarchy(Elements elements, TestSolutionHandler testSolutionHandler) {
    if (elements.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    TestSolution checkResult = TestSolution.PASSED;
    Iterator<Element> iter = elements.iterator();
    // we get the index of the first element for further test
    Element element = iter.next();
    int indexOfReference = getHeaderIndex(element);
    int currentIndex;
    int previousIndex = indexOfReference;
    Element elementOfReference = element;
    Element previousElement = element;
    while (iter.hasNext()) {
        element = iter.next();
        currentIndex = getHeaderIndex(element);
        if (currentIndex != -1) {
            if (currentIndex - previousIndex >= 2) {
                checkResult = TestSolution.FAILED;
                addSourceCodeRemark(TestSolution.FAILED, element, HEADER_NOT_HIERARCHICALLY_WELL_DEFINED_MSG, getEvidenceElement(PREVIOUS_H_TAG_INDEX_EE, getEvidenceElementMsg(previousIndex, previousElement)));
            } else if (currentIndex < indexOfReference) {
                checkResult = TestSolution.FAILED;
                addSourceCodeRemark(TestSolution.FAILED, element, HEADER_NOT_HIERARCHICALLY_WELL_DEFINED_MSG, getEvidenceElement(FIRST_H_TAG_INDEX_EE, getEvidenceElementMsg(indexOfReference, elementOfReference)));
            }
            previousIndex = currentIndex;
            previousElement = element;
        }
    }
    testSolutionHandler.addTestSolution(checkResult);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Element(org.jsoup.nodes.Element)

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