use of nl.basjes.parse.useragent.AbstractUserAgentAnalyzerDirect.GetAllPathsAnalyzer in project yauaa by nielsbasjes.
the class TestUserAgentFlattening method validateUserAgent.
private void validateUserAgent(String useragent, String... requiredValues) {
boolean developmentMode = requiredValues.length == 0;
if (developmentMode) {
LOG.info("Developing {}", useragent);
} else {
LOG.info("Validating {}", useragent);
}
StringBuilder sb = new StringBuilder(2048);
sb.append('\n');
sb.append("|====================================== \n");
sb.append("| ").append(useragent).append('\n');
sb.append("|-------------------------------------- \n");
GetAllPathsAnalyzer analyzer = UserAgentAnalyzer.getAllPathsAnalyzer(useragent);
UserAgent parsedUseragent = analyzer.getResult();
if (parsedUseragent.hasAmbiguity()) {
sb.append("| Ambiguity \n");
}
if (parsedUseragent.hasSyntaxError()) {
sb.append("| Syntax Error \n");
}
List<String> paths = analyzer.getValues();
boolean ok = true;
for (String value : requiredValues) {
if (paths.contains(value)) {
sb.append("| : ").append(value).append('\n');
} else {
sb.append("| Missing --> : ").append(value).append('\n');
ok = false;
}
}
if (requiredValues.length == 0 || !ok) {
sb.append("|-------------------------------------- \n");
for (String value : paths) {
if (value.contains("=")) {
sb.append(" ,\"").append(value.replaceAll("\\\"", "\\\\\"")).append("\"\n");
}
}
sb.append("|====================================== \n");
}
if (developmentMode) {
LOG.info(sb.toString());
return;
}
if (!ok) {
LOG.error(sb.toString());
fail("Not everything was found");
}
}
Aggregations