use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class AnalyserImpl method computeAuditStatisticsFromPrList.
/**
* To avoid multiple count requests to the db, the audits statistics are
* computing by iterating through the ProcessResult list. The criterion
* statistics and the theme statistics are collected on the fly while
* parsing the collection of ProcessResult
*
* @param wrStatistics
* @return
*/
private WebResourceStatistics computeAuditStatisticsFromPrList(WebResourceStatistics wrStatistics) {
int nbOfPassed = 0;
int nbOfFailed = 0;
int nbOfNmi = 0;
int nbOfNa = 0;
int nbOfDetected = 0;
int nbOfSuspected = 0;
int nbOfNt = 0;
for (ProcessResult pr : netResultList) {
TestSolution prResult = (TestSolution) pr.getValue();
switch(prResult) {
case PASSED:
nbOfPassed++;
break;
case FAILED:
nbOfFailed++;
break;
case NOT_APPLICABLE:
nbOfNa++;
break;
case NEED_MORE_INFO:
case DETECTED:
case SUSPECTED_FAILED:
case SUSPECTED_PASSED:
nbOfNmi++;
break;
case NOT_TESTED:
nbOfNt++;
break;
}
addResultToCriterionCounterMap(prResult, pr.getTest().getCriterion());
addResultToThemeCounterMap(prResult, pr.getTest().getCriterion().getTheme());
}
// code couldn't have been adapted, all theses values are set to -1
if (nbOfFailed + nbOfNa + nbOfNmi + nbOfPassed + nbOfDetected + nbOfSuspected == 0) {
nbOfFailed = nbOfNa = nbOfNmi = nbOfPassed = nbOfSuspected = nbOfDetected = -1;
}
wrStatistics.setNbOfFailed(nbOfFailed);
wrStatistics.setNbOfInvalidTest(nbOfFailed);
wrStatistics.setNbOfPassed(nbOfPassed);
wrStatistics.setNbOfNmi(nbOfNmi);
wrStatistics.setNbOfNa(nbOfNa);
wrStatistics.setNbOfDetected(nbOfDetected);
wrStatistics.setNbOfSuspected(nbOfSuspected);
wrStatistics.setNbOfNotTested(nbOfNt);
setWeightedResult(wrStatistics);
// criterionStatistics to the current webResourceStatistics
for (CriterionStatistics cs : csMap.values()) {
computeCriterionResult(cs);
wrStatistics.addCriterionStatistics(cs);
}
// Link each themeStatistics to the current webResourceStatistics
for (ThemeStatistics ts : tsMap.values()) {
wrStatistics.addThemeStatistics(ts);
}
wrStatistics.setAudit(audit);
return wrStatistics;
}
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) {
if (testSolutionCollection.isEmpty()) {
return TestSolution.NOT_APPLICABLE;
}
boolean hasPassed = false;
boolean hasFailed = false;
boolean hasNMI = false;
if (testSolutionCollection.size() == 1 && testSolutionCollection.iterator().next().equals(TestSolution.NOT_TESTED)) {
return TestSolution.NOT_TESTED;
}
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;
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class DOMHandlerImpl method checkTextContentValueLengthLower.
/**
* @deprecated Kept for backward compatibility.
* @param length
* the length of the text content to check
* @param defaultFailResult
* the default return value if the check processing fails
* @return
*/
@Override
@Deprecated
public TestSolution checkTextContentValueLengthLower(int length, TestSolution defaultFailResult) {
Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
for (Node workingElement : selectedElementList) {
TestSolution result = TestSolution.PASSED;
String textContent = workingElement.getTextContent();
if (textContent.length() > length) {
result = defaultFailResult;
addSourceCodeRemark(result, workingElement, "LengthTooLong", textContent);
}
resultSet.add(result);
}
return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class DOMHandlerImpl method checkNodeValue.
@Override
public TestSolution checkNodeValue(Collection<String> blacklist, Collection<String> whitelist, TestSolution testSolution, String erroMessageCode) {
if (whitelist == null) {
whitelist = new ArrayList<String>();
}
if (blacklist == null) {
blacklist = new ArrayList<String>();
}
Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
for (Node workingElement : selectedElementList) {
TestSolution result = TestSolution.NEED_MORE_INFO;
boolean isInBlackList = false;
boolean isInWhiteList = false;
String nodeValue = workingElement.getTextContent().trim();
for (String text : blacklist) {
if (nodeValue.toLowerCase().equals(text.toLowerCase())) {
isInBlackList = true;
break;
}
}
for (String text : whitelist) {
if (nodeValue.toLowerCase().equals(text.toLowerCase())) {
isInWhiteList = true;
break;
}
}
if (isInBlackList && isInWhiteList) {
throw new RuntimeException(new IncoherentValueDomainsException());
}
if (isInBlackList) {
result = testSolution;
addSourceCodeRemark(result, workingElement, erroMessageCode, nodeValue);
}
if (isInWhiteList) {
result = TestSolution.PASSED;
}
// if (result.equals(TestSolution.NEED_MORE_INFO)) {
// addSourceCodeRemark(result, workingElement, "VerifyValue",
// nodeValue);
// }
resultSet.add(result);
}
return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class DOMHandlerImpl method checkChildNodeExistsRecursively.
/**
* @deprecated Kept for backward compatibility.
* @param childNodeName
* the name of the childnode to check
* @return
*/
@Override
@Deprecated
public TestSolution checkChildNodeExistsRecursively(String childNodeName) {
Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
for (Node workingElement : selectedElementList) {
TestSolution result = TestSolution.PASSED;
boolean found = false;
NodeList childNodes = workingElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
if (checkChildNodeExistsRecursively(childNodeName, childNodes.item(i))) {
found = true;
break;
}
}
if (!found) {
result = TestSolution.FAILED;
addSourceCodeRemark(result, workingElement, "ChildNodeMissing", childNodeName);
}
resultSet.add(result);
}
return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
Aggregations