Search in sources :

Example 6 with ElementChecker

use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.

the class LinkTitlePertinenceChecker method addCheckers.

/**
 */
private void addCheckers() {
    ElementChecker ec = new TextEmptinessChecker(titleAttrElementBuilder, EMPTY_LINK_TITLE_MSG, null, getEeAttributeNames());
    ec.setTextElementBuilder(linkTextElementBuilder);
    addChecker(ec);
    ec = new TextOnlyContainsNonAlphanumericalCharactersChecker(titleAttrElementBuilder, getFailureSolution(), NOT_PERTINENT_LINK_TITLE_MSG, getEeAttributeNames());
    ec.setTextElementBuilder(linkTextElementBuilder);
    addChecker(ec);
    ec = new TextBelongsToBlackListChecker(titleAttrElementBuilder, LINK_TEXT_BL_NOM_NAME, getFailureSolution(), NOT_PERTINENT_LINK_TITLE_MSG, getEeAttributeNames());
    // this set is used extract linkText
    ec.setTextElementBuilder(linkTextElementBuilder);
    addChecker(ec);
    TestSolution strictCheckerSolution = TestSolution.FAILED;
    String strictCheckerMsg = NOT_PERTINENT_LINK_TITLE_MSG;
    if (isEqualContentAuthorized) {
        strictCheckerSolution = NEED_MORE_INFO;
        strictCheckerMsg = SUSPECTED_PERTINENT_LINK_TITLE_MSG;
    }
    TextNotIdenticalToAttributeChecker strictChecker = new TextNotIdenticalToAttributeChecker(getTextElementBuilder(), titleAttrElementBuilder, new ImmutablePair<>(strictCheckerSolution, strictCheckerMsg), new ImmutablePair<>(PASSED, ""), getEeAttributeNames());
    strictChecker.setStrictEquality(true);
    strictChecker.setTextElementBuilder(linkTextElementBuilder);
    addChecker(strictChecker);
    ElementChecker containChecker = new TextNotIdenticalToAttributeChecker(getTextElementBuilder(), titleAttrElementBuilder, new ImmutablePair<>(NEED_MORE_INFO, SUSPECTED_PERTINENT_LINK_TITLE_MSG), new ImmutablePair<>(NEED_MORE_INFO, SUSPECTED_NOT_PERTINENT_LINK_TITLE_MSG), getEeAttributeNames());
    containChecker.setTextElementBuilder(linkTextElementBuilder);
    addChecker(containChecker);
}
Also used : TextBelongsToBlackListChecker(org.asqatasun.rules.elementchecker.text.TextBelongsToBlackListChecker) TextNotIdenticalToAttributeChecker(org.asqatasun.rules.elementchecker.text.TextNotIdenticalToAttributeChecker) TextEmptinessChecker(org.asqatasun.rules.elementchecker.text.TextEmptinessChecker) TestSolution(org.asqatasun.entity.audit.TestSolution) TextOnlyContainsNonAlphanumericalCharactersChecker(org.asqatasun.rules.elementchecker.text.TextOnlyContainsNonAlphanumericalCharactersChecker) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker)

Example 7 with ElementChecker

use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.

the class Rgaa30Rule100102 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    // Attributes checks
    for (Map.Entry<String, ElementHandler> attrElementHandlerMapEntry : attrElementHandlerMap.entrySet()) {
        ElementChecker attrEc = new ElementWithAttributePresenceChecker(new ImmutablePair(TestSolution.FAILED, PRESENTATION_ATTR_DETECTED_MSG), new ImmutablePair(TestSolution.PASSED, ""), attrElementHandlerMapEntry.getKey());
        attrEc.check(sspHandler, attrElementHandlerMapEntry.getValue(), testSolutionHandler);
    }
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ElementWithAttributePresenceChecker(org.asqatasun.rules.elementchecker.element.ElementWithAttributePresenceChecker) ElementHandler(org.asqatasun.ruleimplementation.ElementHandler) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with ElementChecker

use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.

the class Rgaa30Rule080901 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    if (linkWithoutTarget.isEmpty()) {
        sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(NO_PATTERN_DETECTED_MSG, this.getTest().getCode()));
        testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
        return;
    }
    ElementChecker linkWithoutTargetChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, LINK_WITHOUT_TARGET_MSG), new ImmutablePair(TestSolution.PASSED, ""));
    linkWithoutTargetChecker.check(sspHandler, linkWithoutTarget, testSolutionHandler);
}
Also used : ElementPresenceChecker(org.asqatasun.rules.elementchecker.element.ElementPresenceChecker) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker)

Example 9 with ElementChecker

use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.

the class Rgaa40Rule100102 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    // Attributes checks
    for (Map.Entry<String, ElementHandler> attrElementHandlerMapEntry : attrElementHandlerMap.entrySet()) {
        ElementChecker attrEc = new ElementWithAttributePresenceChecker(new ImmutablePair(TestSolution.FAILED, PRESENTATION_ATTR_DETECTED_MSG), new ImmutablePair(TestSolution.PASSED, ""), attrElementHandlerMapEntry.getKey());
        attrEc.check(sspHandler, attrElementHandlerMapEntry.getValue(), testSolutionHandler);
    }
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ElementWithAttributePresenceChecker(org.asqatasun.rules.elementchecker.element.ElementWithAttributePresenceChecker) ElementHandler(org.asqatasun.ruleimplementation.ElementHandler) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with ElementChecker

use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.

the class Rgaa40Rule080901 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    if (linkWithoutTarget.isEmpty() && tagWithoutContent.isEmpty() && consecutiveBrElement.isEmpty()) {
        sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(NO_PATTERN_DETECTED_MSG, this.getTest().getCode()));
        testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
        return;
    }
    // Links without target
    ElementChecker linkWithoutTargetChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, LINK_WITHOUT_TARGET_MSG), new ImmutablePair(TestSolution.PASSED, ""));
    linkWithoutTargetChecker.check(sspHandler, linkWithoutTarget, testSolutionHandler);
    // Tags (p, li, ...) without content
    ElementChecker tagWithoutContentChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, TAGS_WITHOUT_CONTENT_USED_FOR_LAYOUT_PURPOSE_MSG), new ImmutablePair(TestSolution.PASSED, ""));
    tagWithoutContentChecker.check(sspHandler, tagWithoutContent, testSolutionHandler);
    // Consecutive <br> tags without text in between
    ElementChecker consecutiveBrElementChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, CONSECUTIVE_TAGS_USED_FOR_LAYOUT_PURPOSE_MSG), new ImmutablePair(TestSolution.PASSED, ""));
    consecutiveBrElementChecker.check(sspHandler, consecutiveBrElement, testSolutionHandler);
}
Also used : ElementPresenceChecker(org.asqatasun.rules.elementchecker.element.ElementPresenceChecker) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker)

Aggregations

ElementChecker (org.asqatasun.rules.elementchecker.ElementChecker)39 ElementPresenceChecker (org.asqatasun.rules.elementchecker.element.ElementPresenceChecker)30 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)21 HashMap (java.util.HashMap)8 Map (java.util.Map)8 ElementHandler (org.asqatasun.ruleimplementation.ElementHandler)8 ElementWithAttributePresenceChecker (org.asqatasun.rules.elementchecker.element.ElementWithAttributePresenceChecker)5 TextEmptinessChecker (org.asqatasun.rules.elementchecker.text.TextEmptinessChecker)5 TextAttributeOfElementBuilder (org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder)5 Element (org.jsoup.nodes.Element)5 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)4 AttributePresenceChecker (org.asqatasun.rules.elementchecker.attribute.AttributePresenceChecker)4 IdUnicityChecker (org.asqatasun.rules.elementchecker.attribute.IdUnicityChecker)3 TextLengthChecker (org.asqatasun.rules.elementchecker.text.TextLengthChecker)2 TestSolution (org.asqatasun.entity.audit.TestSolution)1 TextBelongsToBlackListChecker (org.asqatasun.rules.elementchecker.text.TextBelongsToBlackListChecker)1 TextNotIdenticalToAttributeChecker (org.asqatasun.rules.elementchecker.text.TextNotIdenticalToAttributeChecker)1 TextOnlyContainsNonAlphanumericalCharactersChecker (org.asqatasun.rules.elementchecker.text.TextOnlyContainsNonAlphanumericalCharactersChecker)1 SimpleTextElementBuilder (org.asqatasun.rules.textbuilder.SimpleTextElementBuilder)1