Search in sources :

Example 16 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 17 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 18 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 19 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)

Example 20 with TestSolution

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

the class SeoRule01081 method processImpl.

@Override
protected ProcessResult processImpl(SSPHandler sspHandler) {
    ProcessRemarkService processRemarkService = sspHandler.getProcessRemarkService();
    processRemarkService.resetService();
    TestSolution testSolution = TestSolution.PASSED;
    try {
        URL url = new URL(sspHandler.getSSP().getURI());
        if (StringUtils.isNotBlank(url.getPath()) && url.getPath().contains("_")) {
            testSolution = TestSolution.FAILED;
            processRemarkService.addProcessRemark(TestSolution.FAILED, RemarkMessageStore.URL_PATH_UNDERSCORE_DETECTED);
        }
    } catch (MalformedURLException ex) {
        testSolution = TestSolution.NOT_APPLICABLE;
    }
    return processResultDataService.getDefiniteResult(test, sspHandler.getPage(), testSolution, processRemarkService.getRemarkList());
}
Also used : MalformedURLException(java.net.MalformedURLException) TestSolution(org.asqatasun.entity.audit.TestSolution) URL(java.net.URL) ProcessRemarkService(org.asqatasun.service.ProcessRemarkService)

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