-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
49 junit integration #51
Changes from 25 commits
5de7e5a
a2f7a0c
d231712
afbddf6
32546a2
9290099
3b03d32
34ea733
3d6519e
ddde8e0
648b776
36939d2
2fec46c
2ca56f4
bf11bd9
c18d44d
8a1178d
f95f66c
4922452
bd1b387
6e44d17
a482784
acb6f4a
88700d0
1c4e466
e4b2330
30ebf63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
RDFUnit - JUnit Integration | ||
========== | ||
|
||
RDFUnit-JUnit Integration provides an interface to JUnit via a dedicated Runner which exposes single RDFUnit Test Cases as Unit-Tests. | ||
|
||
### Usage | ||
```java | ||
|
||
@RunWith(RdfUnitJunitRunner.class) | ||
@Schema(uri = "ontologies/foaf.rdf") | ||
public static class TestRunner { | ||
|
||
@ControlledVocabulary | ||
public RDFReader getCVs() { | ||
return new RDFModelReader(ModelFactory | ||
.createDefaultModel() | ||
.read("cv/required-cv.rdf")); | ||
} | ||
|
||
@TestInput | ||
public RDFReader getInputData() { | ||
return new RDFModelReader(ModelFactory | ||
.createDefaultModel() | ||
.read("inputmodels/foaf.rdf")); | ||
} | ||
|
||
} | ||
``` | ||
|
||
### What the RdfUnitJunitRunner will do: | ||
|
||
1. Validate the Test-Class: `@Schema` and `@TestInput` must be declared; `@ControlledVocabulary` is optional | ||
2. Run the Test Generators against the Schema (can be local file or dereferencable URI) | ||
3. Create generated TestCases for each `@TestInput` | ||
4. Run tests individually hooked into the JUnit-Runtime | ||
|
||
### What is currently not supported | ||
- Manual Tests | ||
- LOV integration | ||
- JUnit: `@Rule`, `@Before`, `@After` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>rdfunit-parent</artifactId> | ||
<groupId>org.aksw.rdfunit</groupId> | ||
<version>0.7.19-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>rdfunit-junit</artifactId> | ||
<name>RDFUnit - JUnit Integration</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.aksw.rdfunit</groupId> | ||
<artifactId>rdfunit-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.aksw.rdfunit.junit; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface ControlledVocabulary { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.aksw.rdfunit.junit; | ||
|
||
import org.junit.runners.model.InitializationError; | ||
|
||
/** | ||
* Simplify initialization checks and error message formatting. | ||
* | ||
* @see <a href="https://code.google.com/p/guava-libraries/wiki/PreconditionsExplained">Guava Preconditions</a> | ||
*/ | ||
class InitializationSupport { | ||
|
||
static <T> T checkNotNull( | ||
T t, | ||
String stringFormatMessagePattern, | ||
Object... patternReplacements | ||
) throws InitializationError { | ||
checkState( | ||
t != null, | ||
stringFormatMessagePattern, | ||
patternReplacements | ||
); | ||
return t; | ||
} | ||
|
||
static void checkState( | ||
boolean expressionResult, | ||
String stringFormatMessagePattern, | ||
Object... patternReplacements | ||
) throws InitializationError { | ||
if (expressionResult) { | ||
return; | ||
} | ||
throw new InitializationError(String.format(stringFormatMessagePattern, patternReplacements)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.aksw.rdfunit.junit; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import com.hp.hpl.jena.rdf.model.ResourceFactory; | ||
import org.aksw.rdfunit.tests.results.RLOGTestCaseResult; | ||
import org.aksw.rdfunit.tests.results.TestCaseResult; | ||
import org.junit.runners.model.Statement; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class RLOGStatement extends Statement { | ||
|
||
private final RdfUnitJunitStatusTestExecutor rdfUnitJunitStatusTestExecutor; | ||
private final RdfUnitJunitTestCase testCase; | ||
|
||
RLOGStatement(RdfUnitJunitStatusTestExecutor rdfUnitJunitStatusTestExecutor, RdfUnitJunitTestCase testCase) { | ||
this.rdfUnitJunitStatusTestExecutor = rdfUnitJunitStatusTestExecutor; | ||
this.testCase = testCase; | ||
} | ||
|
||
@Override | ||
public void evaluate() throws Throwable { | ||
final Collection<TestCaseResult> testCaseResults = rdfUnitJunitStatusTestExecutor.runTest(testCase); | ||
final Collection<RLOGTestCaseResult> remainingResults = new ArrayList<>(); | ||
for (TestCaseResult t : testCaseResults) { | ||
RLOGTestCaseResult r = (RLOGTestCaseResult) t; | ||
if (!resourceIsPartOfInputModel(r)) { | ||
continue; | ||
} | ||
remainingResults.add(r); | ||
} | ||
final StringBuilder b = new StringBuilder(); | ||
b.append(testCase.getTestCase().getResultMessage()).append(":\n"); | ||
for (RLOGTestCaseResult r : remainingResults) { | ||
b.append("\t").append(r.getResource()).append("\n"); | ||
} | ||
assertThat(b.toString(), remainingResults.isEmpty()); | ||
} | ||
|
||
private boolean resourceIsPartOfInputModel(RLOGTestCaseResult r) { | ||
return testCase.getTestInputModel().contains( | ||
ResourceFactory.createResource(r.getResource()), null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks if the failing resource is part of the I wonder if we should change this to be: "does the input model contain a statement, which defines the failing resource?", i.e. something along:
|
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear what
@ControlledVocabulary
doesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is meant to be loaded along with the data (which is what I guess from the code) should be renamed to something like
@AdditionalData
but this can also be constructed directly on the@InputModel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Point - 'ControlledVocabulary' is just our use case (as we're loading CVs as additional data) but in general terms
@AdditionalData
is more suited.In fact it gets merged with each InputModel later, but we need to keep both separated to figure out if the offending resources found during test execution is actually part of the InputModel or not.