use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class ReportHelperTest method failedConcepts.
@Test
public void failedConcepts() {
Result<Concept> infoConceptResult = mockResult("test:infoConcept", Concept.class, Result.Status.FAILURE, Severity.INFO);
Result<Concept> minorConceptResult = mockResult("test:minorConcept", Concept.class, Result.Status.FAILURE, Severity.MINOR);
Result<Concept> majorConceptResult = mockResult("test:majorConcept", Concept.class, Result.Status.FAILURE, Severity.MAJOR);
Map<String, Result<Concept>> conceptResults = new HashMap<>();
conceptResults.put("test:infoConcept", infoConceptResult);
conceptResults.put("test:minorConcept", minorConceptResult);
conceptResults.put("test:majorConcept", majorConceptResult);
when(inMemoryReportWriter.getConceptResults()).thenReturn(conceptResults);
int violations = reportHelper.verifyConceptResults(Severity.MINOR, Severity.MAJOR, inMemoryReportWriter);
assertThat(violations, equalTo(1));
verifyMessages(debugMessages, ReportHelper.CONCEPT_FAILED_HEADER, "Concept: test:infoConcept", "Severity: INFO");
verifyMessages(warnMessages, ReportHelper.CONCEPT_FAILED_HEADER, "Concept: test:minorConcept", "Severity: MINOR");
verifyMessages(errorMessages, ReportHelper.CONCEPT_FAILED_HEADER, "Concept: test:majorConcept", "Severity: MAJOR");
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class XmlReportTestHelper method createXmlWithUmlauts.
public static String createXmlWithUmlauts(String description) throws ReportException {
StringWriter writer = new StringWriter();
XmlReportWriter xmlReportWriter = new XmlReportWriter(writer);
xmlReportWriter.begin();
Concept concept = Concept.Builder.newConcept().id("mein:Konzept").description(description).severity(Severity.MAJOR).executable(new CypherExecutable("match...")).verification(ROW_COUNT_VERIFICATION).report(Report.Builder.newInstance().primaryColumn("c2").get()).get();
Map<String, Severity> concepts = new HashMap<>();
concepts.put("mein:Konzept", Severity.INFO);
Group group = Group.Builder.newGroup().id("default").description("Meine Gruppe").conceptIds(concepts).get();
xmlReportWriter.beginGroup(group);
xmlReportWriter.beginConcept(concept);
List<Map<String, Object>> rows = new ArrayList<>();
rows.add(createRow());
Result<Concept> result = new Result<>(concept, Result.Status.SUCCESS, Severity.CRITICAL, Arrays.asList(C1, C2), rows);
xmlReportWriter.setResult(result);
xmlReportWriter.endConcept();
xmlReportWriter.endGroup();
xmlReportWriter.end();
return writer.toString();
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class ReportHelperTest method failedConstraintsWithOverriddenSeverity.
@Test
public void failedConstraintsWithOverriddenSeverity() {
Map<String, Object> infoRow = new HashMap<>();
infoRow.put("InfoElement", "InfoValue");
Result<Constraint> infoConstraintResult = mockResult("test:infoConstraint", Constraint.class, Result.Status.FAILURE, Severity.INFO, Severity.MINOR, Collections.singletonList(infoRow));
Map<String, Object> minorRow = new HashMap<>();
minorRow.put("MinorElement", "MinorValue");
Result<Constraint> minorConstraintResult = mockResult("test:minorConstraint", Constraint.class, Result.Status.FAILURE, Severity.MINOR, Severity.MAJOR, Collections.singletonList(minorRow));
Map<String, Object> majorRow = new HashMap<>();
majorRow.put("MajorElement", "MajorValue");
Result<Constraint> majorConstraintResult = mockResult("test:majorConstraint", Constraint.class, Result.Status.FAILURE, Severity.MAJOR, Severity.CRITICAL, Collections.singletonList(majorRow));
Map<String, Result<Constraint>> constraintResults = new HashMap<>();
constraintResults.put("test:infoConstraint", infoConstraintResult);
constraintResults.put("test:minorConstraint", minorConstraintResult);
constraintResults.put("test:majorConstraint", majorConstraintResult);
when(inMemoryReportWriter.getConstraintResults()).thenReturn(constraintResults);
int violations = reportHelper.verifyConstraintResults(Severity.MAJOR, Severity.CRITICAL, inMemoryReportWriter);
assertThat(violations, equalTo(1));
verifyMessages(debugMessages, ReportHelper.CONSTRAINT_VIOLATION_HEADER, "Constraint: test:infoConstraint", "Severity: MINOR (from INFO)", "InfoElement=InfoValue");
verifyMessages(warnMessages, ReportHelper.CONSTRAINT_VIOLATION_HEADER, "Constraint: test:minorConstraint", "Severity: MAJOR (from MINOR)", "MinorElement=MinorValue");
verifyMessages(errorMessages, ReportHelper.CONSTRAINT_VIOLATION_HEADER, "Constraint: test:majorConstraint", "Severity: CRITICAL (from MAJOR)", "MajorElement=MajorValue");
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class AnalyzerVisitor method executeScript.
/**
* Execute an analysis script
*
* @param <T>
* The result type.
* @param scriptExecutable
* The script.
* @param ruleParameters
* @param severity
* The severity. @return The result.
* @throws RuleExecutorException
* If script execution fails.
*/
private <T extends ExecutableRule> Result<T> executeScript(T executable, ScriptExecutable scriptExecutable, Map<String, Object> ruleParameters, Severity severity) throws RuleExecutorException {
String language = scriptExecutable.getLanguage();
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
if (scriptEngine == null) {
List<String> availableLanguages = new ArrayList<>();
for (ScriptEngineFactory factory : scriptEngineManager.getEngineFactories()) {
availableLanguages.addAll(factory.getNames());
}
throw new RuleExecutorException("Cannot resolve scripting engine for '" + language + "', available languages are " + availableLanguages);
}
// Set default variables
scriptEngine.put(ScriptVariable.STORE.getVariableName(), store);
scriptEngine.put(ScriptVariable.RULE.getVariableName(), executable);
scriptEngine.put(ScriptVariable.SEVERITY.getVariableName(), severity);
// Set rule parameters
for (Map.Entry<String, Object> entry : ruleParameters.entrySet()) {
scriptEngine.put(entry.getKey(), entry.getValue());
}
Object scriptResult;
try {
scriptResult = scriptEngine.eval(scriptExecutable.getSource());
} catch (ScriptException e) {
throw new RuleExecutorException("Cannot execute script.", e);
}
if (!(scriptResult instanceof Result)) {
throw new RuleExecutorException("Script returned an invalid result type, expected " + Result.class.getName() + " but got " + scriptResult);
}
return Result.class.cast(scriptResult);
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class AnalyzerVisitor method visitConcept.
@Override
public boolean visitConcept(Concept concept, Severity effectiveSeverity) throws RuleExecutorException {
try {
store.beginTransaction();
ConceptDescriptor conceptDescriptor = store.find(ConceptDescriptor.class, concept.getId());
Result.Status status;
if (conceptDescriptor == null || configuration.isExecuteAppliedConcepts()) {
logger.info("Applying concept '" + concept.getId() + "' with severity: '" + concept.getSeverity().getInfo(effectiveSeverity) + "'.");
reportPlugin.beginConcept(concept);
Result<Concept> result = execute(concept, effectiveSeverity);
reportPlugin.setResult(result);
status = result.getStatus();
if (conceptDescriptor == null) {
conceptDescriptor = store.create(ConceptDescriptor.class);
conceptDescriptor.setId(concept.getId());
conceptDescriptor.setStatus(result.getStatus());
}
reportPlugin.endConcept();
} else {
status = conceptDescriptor.getStatus();
}
store.commitTransaction();
return Result.Status.SUCCESS.equals(status);
} catch (XOException e) {
store.rollbackTransaction();
throw new RuleExecutorException("Cannot apply concept " + concept.getId(), e);
}
}
Aggregations