use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class DOMHandlerImpl method checkAttributeValueNotEmpty.
/**
* @deprecated Kept for backward compatibility.
* @param attributeName
* the name of the attribute to check
* @return
*/
@Override
@Deprecated
public TestSolution checkAttributeValueNotEmpty(String attributeName) {
Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
for (Node workingElement : selectedElementList) {
TestSolution result = TestSolution.PASSED;
Node attribute = workingElement.getAttributes().getNamedItem(attributeName);
if (attribute != null) {
if (attribute.getNodeValue().length() == 0) {
result = TestSolution.FAILED;
addSourceCodeRemark(result, workingElement, "ValueEmpty", attributeName);
}
} else {
result = TestSolution.NOT_APPLICABLE;
}
resultSet.add(result);
}
return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class DOMHandlerImpl method checkTextContentAndAttributeValue.
/**
* @deprecated Kept for backward compatibility.
* @param attributeName
* @param blacklist
* the list of prevented values
* @param whitelist
* the list of granted values
* @return
*/
@Override
@Deprecated
public TestSolution checkTextContentAndAttributeValue(String attributeName, Collection<String> blacklist, Collection<String> whitelist) {
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 isInWhiteList = false;
boolean isInBlackList = false;
String textContent = workingElement.getTextContent();
Node attribute = workingElement.getAttributes().getNamedItem(attributeName);
for (String text : blacklist) {
if (textContent.toLowerCase().equals(text.toLowerCase())) {
isInBlackList = true;
addSourceCodeRemark(result, workingElement, "BlackListedValue", textContent);
break;
}
if (attribute != null) {
if (attribute.getNodeValue().toLowerCase().equals(text.toLowerCase())) {
isInBlackList = true;
addSourceCodeRemark(result, workingElement, "BlackListedValue", attributeName);
break;
}
}
}
for (String text : whitelist) {
if (textContent.toLowerCase().equals(text.toLowerCase())) {
isInWhiteList = true;
break;
}
if (attribute != null) {
if (attribute.getNodeValue().toLowerCase().equals(text.toLowerCase())) {
isInWhiteList = true;
break;
}
}
}
if (isInBlackList && isInWhiteList) {
throw new RuntimeException(new IncoherentValueDomainsException());
}
if (isInWhiteList) {
result = TestSolution.PASSED;
}
if (isInBlackList) {
result = TestSolution.FAILED;
}
if (result.equals(TestSolution.NEED_MORE_INFO)) {
addSourceCodeRemark(result, workingElement, "VerifyValue", attributeName);
}
resultSet.add(result);
}
return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class DOMHandlerImpl method checkTextContentValueNotEmpty.
/**
* @deprecated Kept for backward compatibility.
* @return
*/
@Override
@Deprecated
public TestSolution checkTextContentValueNotEmpty() {
Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
for (Node workingElement : selectedElementList) {
TestSolution result = TestSolution.PASSED;
if (workingElement.getTextContent().length() == 0) {
result = TestSolution.FAILED;
addSourceCodeRemark(result, workingElement, "ValueEmpty", workingElement.getNodeValue());
}
resultSet.add(result);
}
return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class DOMHandlerImpl method checkEachWithXpath.
/**
* @deprecated Kept for backward compatibility.
* @param expr
* @return
*/
@Override
@Deprecated
public TestSolution checkEachWithXpath(String expr) {
Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
for (Node node : selectedElementList) {
TestSolution tempResult = TestSolution.PASSED;
try {
XPathExpression xPathExpression = xpath.compile(expr);
Boolean check = (Boolean) xPathExpression.evaluate(node, XPathConstants.BOOLEAN);
if (!check.booleanValue()) {
tempResult = TestSolution.FAILED;
// addSourceCodeRemark(result, node,
// "wrong value, does not respect xpath expression : " +
// expr, node.getNodeValue());
}
} catch (XPathExpressionException ex) {
LOGGER.error(ex.getMessage() + " occured requesting " + expr + " on " + ssp.getURI());
throw new RuntimeException(ex);
}
resultSet.add(tempResult);
}
return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class DOMHandlerImpl method checkChildNodeExists.
@Override
public TestSolution checkChildNodeExists(String childNodeName) {
if (messageCode == null) {
messageCode = CHILD_NODE_MISSING_MSG_CODE;
}
Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
for (Node workingElement : selectedElementList) {
TestSolution result = TestSolution.PASSED;
NodeList childNodes = workingElement.getChildNodes();
boolean found = false;
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
if (childNode.getNodeName().equalsIgnoreCase(childNodeName)) {
found = true;
break;
}
}
if (!found) {
result = TestSolution.FAILED;
addSourceCodeRemark(result, workingElement, messageCode, childNodeName);
}
resultSet.add(result);
}
return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
Aggregations