use of com.buschmais.jqassistant.core.report.api.model.Result in project jqa-core-framework by buschmais.
the class ReportHelperTest method failedConstraintsWithOverriddenSeverity.
@Test
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, 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, 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, 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.report.api.model.Result in project jqa-core-framework by buschmais.
the class ReportHelperTest method failedConcepts.
@Test
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.report.api.model.Result in project jqa-core-framework by buschmais.
the class ScriptRuleInterpreterPlugin method execute.
@Override
public <T extends ExecutableRule<?>> Result<T> execute(T executableRule, Map<String, Object> ruleParameters, Severity severity, AnalyzerContext context) throws RuleException {
Executable<String> executable = executableRule.getExecutable();
String language = executable.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 RuleException("Cannot resolve scripting engine for '" + language + "', available languages are " + availableLanguages);
}
// Set default variables
scriptEngine.put(ScriptVariable.STORE.getVariableName(), context.getStore());
scriptEngine.put(ScriptVariable.CONTEXT.getVariableName(), context);
scriptEngine.put(ScriptVariable.RULE.getVariableName(), executableRule);
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(executable.getSource());
} catch (ScriptException e) {
throw new RuleException("Cannot execute script.", e);
}
if (!(scriptResult instanceof Result)) {
throw new RuleException("Script returned an invalid result type, expected " + Result.class.getName() + " but got " + scriptResult);
}
return Result.class.cast(scriptResult);
}
use of com.buschmais.jqassistant.core.report.api.model.Result in project jqa-core-framework by buschmais.
the class AnalyzerRuleVisitorTest method executeConstraint.
@Test
void executeConstraint() throws RuleException {
doReturn(Result.Status.FAILURE).when(analyzerContext).verify(eq(constraint), anyList(), anyList());
analyzerRuleVisitor.visitConstraint(constraint, Severity.BLOCKER);
ArgumentCaptor<Map> argumentCaptor = ArgumentCaptor.forClass(Map.class);
verify(store).executeQuery(eq(statement), argumentCaptor.capture());
Map<String, Object> parameters = argumentCaptor.getValue();
assertThat(parameters.get(PARAMETER_WITHOUT_DEFAULT), equalTo("value"));
assertThat(parameters.get(PARAMETER_WITH_DEFAULT), equalTo("defaultValue"));
verify(reportWriter).beginConstraint(constraint);
ArgumentCaptor<Result> resultCaptor = ArgumentCaptor.forClass(Result.class);
verify(reportWriter).setResult(resultCaptor.capture());
Result result = resultCaptor.getValue();
assertThat(result.getStatus(), equalTo(Result.Status.FAILURE));
assertThat(result.getSeverity(), equalTo(Severity.BLOCKER));
verify(reportWriter).endConstraint();
}
use of com.buschmais.jqassistant.core.report.api.model.Result in project jqa-core-framework by buschmais.
the class AnalyzerRuleVisitorTest method columnOrder.
/**
* Verifies that columns of a query a reported in the order given by the query.
*
* @throws RuleException
* If the test fails.
*/
@Test
void columnOrder() throws RuleException {
analyzerRuleVisitor.visitConcept(concept, Severity.MINOR);
ArgumentCaptor<Result> resultCaptor = ArgumentCaptor.forClass(Result.class);
verify(reportWriter).setResult(resultCaptor.capture());
Result capturedResult = resultCaptor.getValue();
assertThat("The reported column names must match the given column names.", capturedResult.getColumnNames(), equalTo(columnNames));
List<Map<String, Object>> capturedRows = capturedResult.getRows();
assertThat("Expecting one row.", capturedRows.size(), equalTo(1));
Map<String, Object> capturedRow = capturedRows.get(0);
assertThat("The reported column names must match the given column names.", new ArrayList<>(capturedRow.keySet()), equalTo(columnNames));
}
Aggregations