Search in sources :

Example 56 with ProcessRemark

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

the class AbstractRuleImplementationTestCase method checkRemarkIsPresent.

/**
     * 
     * @param processResult
     * @param testSolution
     * @param remarkMessageCode
     * @param remarkTarget
     * @param position
     * @param emptySnippet
     * @param evidencePairs 
     */
protected void checkRemarkIsPresent(ProcessResult processResult, TestSolution testSolution, String remarkMessageCode, String remarkTarget, int position, boolean emptySnippet, Pair<String, String>... evidencePairs) {
    if (((LinkedHashSet) processResult.getRemarkSet()).toArray()[position - 1] instanceof SourceCodeRemark) {
        SourceCodeRemark sourceCodeRemark = ((SourceCodeRemark) ((LinkedHashSet) processResult.getRemarkSet()).toArray()[position - 1]);
        Logger.getLogger(this.getClass()).debug(sourceCodeRemark.getMessageCode());
        assertEquals(remarkMessageCode, sourceCodeRemark.getMessageCode());
        assertEquals(testSolution, sourceCodeRemark.getIssue());
        Logger.getLogger(this.getClass()).debug(sourceCodeRemark.getIssue());
        if (remarkTarget.equals("EMPTY_TARGET")) {
            assertEquals(-1, sourceCodeRemark.getLineNumber());
        } else {
            assertEquals(remarkTarget, sourceCodeRemark.getTarget());
            Logger.getLogger(this.getClass()).debug(sourceCodeRemark.getTarget());
            if (!emptySnippet) {
                assertNotNull("Snippet is empty but shouldn't !!! ", sourceCodeRemark.getSnippet());
            }
        }
        if (evidencePairs.length == 0) {
            assertNull("Evidence Element list is not empty but should be !!! ", sourceCodeRemark.getElementList());
            return;
        }
        // check number of evidence elements and their value
        assertEquals(evidencePairs.length, sourceCodeRemark.getElementList().size());
        Object[] evEls = sourceCodeRemark.getElementList().toArray();
        for (int i = 0; i < evEls.length; i++) {
            EvidenceElement ee = (EvidenceElement) evEls[i];
            Logger.getLogger(this.getClass()).debug(ee.getEvidence().getCode());
            Logger.getLogger(this.getClass()).debug(ee.getValue());
            assertEquals(evidencePairs[i].getLeft(), ee.getEvidence().getCode());
            assertTrue("Wrong evidence element : expected[" + evidencePairs[i].getRight() + "] actual[" + ee.getValue() + "]", StringUtils.contains(ee.getValue(), evidencePairs[i].getRight()));
        }
    } else {
        ProcessRemark processRemark = (ProcessRemark) (((LinkedHashSet) processResult.getRemarkSet()).toArray()[position - 1]);
        Logger.getLogger(this.getClass()).debug(processRemark.getMessageCode());
        assertEquals(remarkMessageCode, processRemark.getMessageCode());
        assertEquals(testSolution, processRemark.getIssue());
        assertNull(processRemark.getElementList());
    }
}
Also used : EvidenceElement(org.asqatasun.entity.audit.EvidenceElement) SourceCodeRemark(org.asqatasun.entity.audit.SourceCodeRemark) ProcessRemark(org.asqatasun.entity.audit.ProcessRemark)

Aggregations

ProcessRemark (org.asqatasun.entity.audit.ProcessRemark)56 ProcessResult (org.asqatasun.entity.audit.ProcessResult)41 SourceCodeRemark (org.asqatasun.entity.audit.SourceCodeRemark)31 LinkedHashSet (java.util.LinkedHashSet)23 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)6 TestSolutionHandler (org.asqatasun.ruleimplementation.TestSolutionHandler)6 TestSolutionHandlerImpl (org.asqatasun.ruleimplementation.TestSolutionHandlerImpl)6 Element (org.jsoup.nodes.Element)6 ProcessRemarkService (org.asqatasun.service.ProcessRemarkService)5 EvidenceElement (org.asqatasun.entity.audit.EvidenceElement)4