/** * 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; }
/** * main. * * @param args an array of {@link java.lang.String} objects. * @throws java.lang.Exception if any. */ public static void main(String[] args) throws Exception { CommandLine commandLine = ValidateUtils.parseArguments(args); if (commandLine.hasOption("h")) { displayHelpAndExit(); } String dataFolder = commandLine.getOptionValue("f", "../data/"); if (!commandLine.hasOption('v')) { // explicitely do not use LOV RDFUnitUtils.fillSchemaServiceFromLOV(); } // TODO hack until we fix this, configuration tries to laod schemas so they must be initialized // before RDFUnitUtils.fillSchemaServiceFromFile(dataFolder + "schemaDecl.csv"); // RDFUnitUtils.fillSchemaServiceFromFile(configuration.getDataFolder() + "schemaDecl.csv"); RDFUnitConfiguration configuration = null; try { configuration = ValidateUtils.getConfigurationFromArguments(commandLine); } catch (ParameterException e) { String message = e.getMessage(); if (message != null) { displayHelpAndExit(message); } else { displayHelpAndExit(); } } checkNotNull(configuration); if (!RDFUnitUtils.fileExists(configuration.getDataFolder())) { log.error("Path : " + configuration.getDataFolder() + " does not exists, use -f argument"); System.exit(1); } RDFUnit rdfunit = new RDFUnit(configuration.getDataFolder()); try { rdfunit.init(); } catch (RDFReaderException e) { displayHelpAndExit("Cannot read patterns and/or pattern generators"); } /* // Generates all tests from LOV for (Source s: SchemaService.getSourceListAll()) { s.setBaseCacheFolder("../data/tests/"); File f = new File(s.getTestFile()); if (!f.exists()) { List<TestCase> testsAuto = TestUtils.instantiateTestsFromAG(rdfunit.getAutoGenerators(), s); TestUtils.writeTestsToFile(testsAuto, s.getTestFile()); } } // */ final TestSource dataset = configuration.getTestSource(); /* </cliStuff> */ TestGeneratorExecutor testGeneratorExecutor = new TestGeneratorExecutor( configuration.isAutoTestsEnabled(), configuration.isTestCacheEnabled(), configuration.isManualTestsEnabled()); TestSuite testSuite = testGeneratorExecutor.generateTestSuite( configuration.getTestFolder(), dataset, rdfunit.getAutoGenerators()); TestExecutor testExecutor = TestExecutorFactory.createTestExecutor(configuration.getTestCaseExecutionType()); if (testExecutor == null) { displayHelpAndExit("Cannot initialize test executor. Exiting"); } SimpleTestExecutorMonitor testExecutorMonitor = new SimpleTestExecutorMonitor(); testExecutorMonitor.setExecutionType(configuration.getTestCaseExecutionType()); checkNotNull(testExecutor); testExecutor.addTestExecutorMonitor(testExecutorMonitor); // warning, caches intermediate results testExecutor.execute(dataset, testSuite); // Write results to RDFWriter () String filename = "../data/results/" + dataset.getPrefix() + "." + configuration.getTestCaseExecutionType().toString(); ArrayList<RDFWriter> outputWriters = new ArrayList<>(); for (SerializationFormat serializationFormat : configuration.getOutputFormats()) { outputWriters.add( RDFWriterFactory.createWriterFromFormat( filename, serializationFormat, configuration.getTestCaseExecutionType())); } RDFWriter resultWriter = new RDFMultipleWriter(outputWriters); try { resultWriter.write(testExecutorMonitor.getModel()); log.info("Results stored in: " + filename + ".*"); } catch (RDFWriterException e) { log.error("Cannot write tests to file: " + e.getMessage()); } // Calculate coverage if (configuration.isCalculateCoverageEnabled()) { Model model = ModelFactory.createDefaultModel(); PrefixNSService.setNSPrefixesInModel(model); for (TestCase ut : testSuite.getTestCases()) { model.add(ut.getUnitTestModel()); } TestCoverageEvaluator tce = new TestCoverageEvaluator(); tce.calculateCoverage( new QueryExecutionFactoryModel(model), dataset.getPrefix() + ".property.count", dataset.getPrefix() + ".class.count"); } }
/** * Constructor * * @param testCase the test case this result is related with */ protected BaseTestCaseResultImpl(TestCase testCase) { this(testCase.getTestURI(), testCase.getLogLevel(), testCase.getResultMessage()); }