/** * Instantiates a new Aggregated test case result. * * @param testCase the test case * @param status the status * @param errorCount the error count * @param prevalenceCount the prevalence count */ public AggregatedTestCaseResultImpl( TestCase testCase, TestCaseResultStatus status, long errorCount, long prevalenceCount) { this( testCase.getTestURI(), testCase.getLogLevel(), testCase.getResultMessage(), status, errorCount, prevalenceCount); }
/** {@inheritDoc} */ @Override protected Collection<TestCaseResult> executeSingleTest(TestSource testSource, TestCase testCase) throws TestCaseExecutionException { Collection<TestCaseResult> testCaseResults = new ArrayList<>(); PropertyValuePairSet.PropertyValuePairSetBuilder annotationSetBuilder = PropertyValuePairSet.builder(); try (QueryExecution qe = testSource .getExecutionFactory() .createQueryExecution(queryGenerationFactory.getSparqlQuery(testCase))) { ResultSet results = qe.execSelect(); ExtendedTestCaseResultImpl.Builder resultBuilder = null; String prevResource = ""; while (results.hasNext()) { QuerySolution qs = results.next(); String resource = qs.get("this").toString(); if (qs.get("this").isLiteral()) { resource = StringUtils.getHashFromString(resource); } String message = testCase.getResultMessage(); if (qs.contains("message")) { message = qs.get("message").toString(); } RLOGLevel logLevel = testCase.getLogLevel(); // If resource != before // we add the previous result in the list if (!prevResource.equals(resource)) { // The very first time we enter, result = null and we don't add any result if (resultBuilder != null) { testCaseResults.add( resultBuilder .setResultAnnotations(annotationSetBuilder.build().getAnnotations()) .build()); } resultBuilder = new ExtendedTestCaseResultImpl.Builder( testCase.getTestURI(), logLevel, message, resource); annotationSetBuilder = PropertyValuePairSet.builder(); // reset // get static annotations for new test for (ResultAnnotation resultAnnotation : testCase.getResultAnnotations()) { // Get values if (resultAnnotation.getAnnotationValue().isPresent()) { annotationSetBuilder.annotation( PropertyValuePair.create( resultAnnotation.getAnnotationProperty(), resultAnnotation.getAnnotationValue().get())); } } } // result must be initialized by now checkNotNull(resultBuilder); // get annotations from the SPARQL query for (ResultAnnotation resultAnnotation : testCase.getVariableAnnotations()) { // Get the variable name if (resultAnnotation.getAnnotationVarName().isPresent()) { String variable = resultAnnotation.getAnnotationVarName().get().trim(); // If it exists, add it in the Set if (qs.contains(variable)) { annotationSetBuilder.annotation( PropertyValuePair.create( resultAnnotation.getAnnotationProperty(), qs.get(variable))); } } } } // Add last result (if query return any) if (resultBuilder != null) { testCaseResults.add( resultBuilder .setResultAnnotations(annotationSetBuilder.build().getAnnotations()) .build()); } } catch (QueryExceptionHTTP e) { checkQueryResultStatus(e); } return testCaseResults; }
/** * Constructor * * @param testCase the test case this result is related with */ protected BaseTestCaseResultImpl(TestCase testCase) { this(testCase.getTestURI(), testCase.getLogLevel(), testCase.getResultMessage()); }