use of org.asqatasun.exception.IncoherentValueDomainsException in project Asqatasun by Asqatasun.
the class DOMHandlerImpl method checkTextContentValue.
@Override
public TestSolution checkTextContentValue(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 isInBlackList = false;
boolean isInWhiteList = false;
String textContent = workingElement.getTextContent();
for (String text : blacklist) {
if (textContent.toLowerCase().equals(text.toLowerCase())) {
isInBlackList = true;
break;
}
}
for (String text : whitelist) {
if (textContent.toLowerCase().equals(text.toLowerCase())) {
isInWhiteList = true;
break;
}
}
if (isInBlackList && isInWhiteList) {
throw new RuntimeException(new IncoherentValueDomainsException());
}
if (isInBlackList) {
result = TestSolution.FAILED;
addSourceCodeRemark(result, workingElement, "BlackListedValue", textContent);
}
if (isInWhiteList) {
result = TestSolution.PASSED;
}
if (result.equals(TestSolution.NEED_MORE_INFO)) {
addSourceCodeRemark(result, workingElement, "VerifyValue", textContent);
}
resultSet.add(result);
}
return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}
use of org.asqatasun.exception.IncoherentValueDomainsException 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.exception.IncoherentValueDomainsException 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);
}
Aggregations