Search in sources :

Example 1 with TestSolution

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

the class CriterionStatisticsDAOImpl method findCriterionStatisticsByWebResource.

@Override
public Collection<CriterionStatistics> findCriterionStatisticsByWebResource(WebResource webResource, String theme, Collection<String> testSolutions) {
    boolean hasTheme = false;
    if (theme != null && !StringUtils.equals(theme, selectAllThemeKey)) {
        hasTheme = true;
    }
    boolean hasTestSolution = false;
    if (!testSolutions.isEmpty()) {
        hasTestSolution = true;
    }
    StringBuilder strb = new StringBuilder();
    strb.append("SELECT cs FROM ");
    strb.append(getEntityClass().getName());
    strb.append(" cs ");
    strb.append(" JOIN cs.webResourceStatistics wrs ");
    if (hasTheme) {
        strb.append(" JOIN cs.criterion cr ");
    }
    strb.append(" WHERE wrs.webResource=:webResource ");
    if (hasTheme) {
        strb.append(" AND cr.theme.code=:theme ");
    }
    if (hasTestSolution) {
        strb.append(" AND cs.criterionResult IN (:testSolution) ");
    }
    Query query = entityManager.createQuery(strb.toString());
    query.setParameter("webResource", webResource);
    if (hasTestSolution) {
        Collection<TestSolution> solutions = new ArrayList<TestSolution>();
        for (String solution : testSolutions) {
            solutions.add(TestSolution.valueOf(solution));
        }
        query.setParameter("testSolution", solutions);
    }
    if (hasTheme) {
        query.setParameter("theme", theme);
    }
    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) TestSolution(org.asqatasun.entity.audit.TestSolution) ArrayList(java.util.ArrayList) NoResultException(javax.persistence.NoResultException)

Example 2 with TestSolution

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

the class ContrastChecker method checkDomElements.

/**
     * 
     * @param sspHandler
     * @param domElements
     * @param testSolutionHandler
     * 
     * @throws ContrastCheckerParseResultException
     */
private void checkDomElements(SSPHandler sspHandler, Collection<DomElement> domElements, TestSolutionHandler testSolutionHandler) throws ContrastCheckerParseResultException {
    for (DomElement domElement : domElements) {
        // to "-1"
        if (isElementPartOfTheScope(domElement)) {
            String bgColor = domElement.getBgColor();
            String fgColor = domElement.getFgColor();
            if (ContrastHelper.isColorTestable(fgColor) && ContrastHelper.isColorTestable(bgColor)) {
                elementCounter++;
                Double contrast = ContrastHelper.getConstrastRatio(fgColor, bgColor);
                if (contrast < contrastRatio) {
                    LOGGER.debug(" cssPath " + domElement.getPath() + " " + +contrast);
                    DecimalFormatSymbols decimalSymbol = new DecimalFormatSymbols(Locale.getDefault());
                    decimalSymbol.setDecimalSeparator('.');
                    TestSolution elementSolution = createRemarkOnBadContrastElement(sspHandler, domElement, new DecimalFormat("#.00", decimalSymbol).format(contrast));
                    testSolutionHandler.addTestSolution(elementSolution);
                } else {
                    LOGGER.debug(" good luminosity " + domElement.getPath() + " " + +contrast);
                }
            } else {
                elementCounter++;
                createNmiRemarkForManualCheckElement(sspHandler, domElement);
                testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
                LOGGER.debug(" nmi " + domElement.getPath());
            }
        }
    }
}
Also used : DomElement(org.asqatasun.rules.domelement.DomElement) DecimalFormatSymbols(java.text.DecimalFormatSymbols) TestSolution(org.asqatasun.entity.audit.TestSolution) DecimalFormat(java.text.DecimalFormat)

Example 3 with TestSolution

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

the class ContrastChecker method createRemarkOnBadContrastElement.

/**
     * 
     * @param sspHandler
     * @param domElement
     * @param contrast
     * @return the TestSolution
     */
private TestSolution createRemarkOnBadContrastElement(SSPHandler sspHandler, DomElement domElement, String contrast) throws ContrastCheckerParseResultException {
    TestSolution testSolution;
    String msgCode;
    if (domElement.isHidden()) {
        // if the result is hidden, the result is NEED_MORE_INFO
        testSolution = TestSolution.NEED_MORE_INFO;
        msgCode = BAD_CONTRAST_HIDDEN_ELEMENT_MSG;
    } else if (alternativeContrastMechanismPresent) {
        // An alternative contrast mechanism is provided
        testSolution = TestSolution.NEED_MORE_INFO;
        msgCode = BAD_CONTRAST_BUT_ALT_MECHANISM_MSG;
    } else {
        // By default the result is failed
        testSolution = TestSolution.FAILED;
        msgCode = BAD_CONTRAST_MSG;
    }
    Element element = DomElementExtractor.getElementFromDomElement(domElement, sspHandler);
    if (element != null) {
        Collection<EvidenceElement> eeList = new LinkedList<>();
        eeList.add(getEvidenceElement(FG_COLOR_EE, domElement.getFgColor()));
        eeList.add(getEvidenceElement(BG_COLOR_EE, domElement.getBgColor()));
        eeList.add(getEvidenceElement(CONTRAST_EE, contrast));
        addSourceCodeRemark(testSolution, element, msgCode, eeList);
    } else {
        // the test returns not_tested to avoid false positive results
        throw new ContrastCheckerParseResultException();
    }
    return testSolution;
}
Also used : ContrastCheckerParseResultException(org.asqatasun.rules.elementchecker.contrast.exception.ContrastCheckerParseResultException) EvidenceElement(org.asqatasun.entity.audit.EvidenceElement) TestSolution(org.asqatasun.entity.audit.TestSolution) DomElement(org.asqatasun.rules.domelement.DomElement) Element(org.jsoup.nodes.Element) EvidenceElement(org.asqatasun.entity.audit.EvidenceElement)

Example 4 with TestSolution

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

the class ChildElementPresenceChecker method checkChildElementPresence.

/**
     * This methods checks whether elements have a child element of a given 
     * type.
     * 
     * @param elementToTest
     * @param elements
     * @param testSolutionHandler 
     */
private void checkChildElementPresence(String elementToTest, Elements elements, TestSolutionHandler testSolutionHandler) {
    if (elements.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    TestSolution testSolution = TestSolution.PASSED;
    for (Element el : elements) {
        if (el.getElementsByTag(elementToTest).size() >= minimumNumberOfChildRequired) {
            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 5 with TestSolution

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

the class RuleHelper method synthesizeTestSolutionCollection.

/**
     *
     * @param testSolutionCollection
     *            the test solution collection to synthesize
     * @return the synthesis of the test solution collection
     */
public static TestSolution synthesizeTestSolutionCollection(Collection<TestSolution> testSolutionCollection) {
    boolean hasPassed = false;
    boolean hasFailed = false;
    boolean hasNMI = false;
    for (TestSolution result : testSolutionCollection) {
        switch(result) {
            case PASSED:
                hasPassed = true;
                break;
            case FAILED:
                hasFailed = true;
                break;
            case NEED_MORE_INFO:
                hasNMI = true;
                break;
            default:
        }
    }
    if (hasFailed) {
        return TestSolution.FAILED;
    }
    if (hasNMI) {
        return TestSolution.NEED_MORE_INFO;
    }
    if (hasPassed) {
        return TestSolution.PASSED;
    }
    return TestSolution.NOT_APPLICABLE;
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution)

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