org.apache.jena.vocabulary.DCTerms Java Examples

The following examples show how to use org.apache.jena.vocabulary.DCTerms. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RDF2RDFStarTest.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
@Test
public void doubleNestedSubject() {
	
	final String filename = "DoubleNestedSubject.ttl";
       final Graph g = convertAndLoadIntoGraph(filename);
	
       assertEquals( 1, g.size() );
       
       final Triple t = g.find().next();
       assertTrue( t.getSubject() instanceof Node_Triple );
       assertFalse( t.getPredicate() instanceof Node_Triple );
       assertFalse( t.getObject() instanceof Node_Triple );

       final Triple et = ( (Node_Triple) t.getSubject() ).get();
       assertFalse( et.getSubject() instanceof Node_Triple );
       assertFalse( et.getPredicate() instanceof Node_Triple );
       assertTrue( et.getObject() instanceof Node_Triple );
       
       final Triple eet = ( (Node_Triple) et.getObject() ).get();
       assertEquals( DCTerms.created.asNode(), eet.getPredicate() );
}
 
Example #2
Source File: SkolemizerTest.java    From Processor with Apache License 2.0 6 votes vote down vote up
/**
 * Test of getLiteral method, of class Skolemizer.
 */
@Test
public void testGetLiteral()
{
    Model model = ModelFactory.createDefaultModel();
    Literal secondTitle = model.createLiteral("Second");
    Literal firstTitle = model.createLiteral("First");

    Resource second = model.createResource().
            addLiteral(DCTerms.title, secondTitle);
    Resource first = model.createResource().
            addLiteral(DCTerms.title, firstTitle).
            addProperty(FOAF.primaryTopic, second);
    
    Literal firstResult = skolemizer.getLiteral(first, "title");
    assertEquals(firstTitle, firstResult);
    Literal secondResult = skolemizer.getLiteral(first, "primaryTopic.title");
    assertEquals(secondTitle, secondResult);
    Literal resultFail1 = skolemizer.getLiteral(first, "primaryTopic");
    assertNull(resultFail1); // primaryTopic is a resource, not a literal
    Literal resultFail2 = skolemizer.getLiteral(first, "whatever");
    assertNull(resultFail2); // no such property
}
 
Example #3
Source File: SkolemizerTest.java    From Processor with Apache License 2.0 6 votes vote down vote up
/**
 * Test of getResource method, of class Skolemizer.
 */
@Test
public void testGetResource()
{
    Model model = ModelFactory.createDefaultModel();

    Resource second = model.createResource().
            addLiteral(DCTerms.title, "Second");
    Resource first = model.createResource().
            addLiteral(DCTerms.title, "First").
            addProperty(FOAF.primaryTopic, second);
    
    Resource secondResult = skolemizer.getResource(first, "primaryTopic");
    assertEquals(second, secondResult);
    Resource resultFail1 = skolemizer.getResource(first, "title");
    assertNull(resultFail1); // title is a literal, not a resource
    Resource resultFail2 = skolemizer.getResource(first, "primaryTopic.title");
    assertNull(resultFail2); // title is a literal, not a resource
    Resource resultFail3 = skolemizer.getResource(first, "whatever");
    assertNull(resultFail3); // no such property
}
 
Example #4
Source File: EarlReporter.java    From teamengine with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the list of conformance classes to the TestRun resource. A
 * conformance class corresponds to a {@literal <test>} tag in the TestNG
 * suite definition; it is represented as an earl:TestRequirement resource.
 * 
 * @param earl
 *            An RDF model containing EARL statements.
 * @param testList
 *            The list of test sets comprising the test suite.
 */
void addTestRequirements(Model earl, final List<XmlTest> testList) {
    Seq reqs = earl.createSeq();
    String key = null;
    for (XmlTest xmlTest : testList) {
        String testName = xmlTest.getName();
        Resource testReq = earl.createResource(testName.replaceAll("\\s", "-"),
                EARL.TestRequirement);
        testReq.addProperty(DCTerms.title, testName);
        String testOptionality = xmlTest.getParameter(CITE.CC_OPTIONALITY);
        if (null != testOptionality && !testOptionality.isEmpty()) {
            testReq.addProperty(CITE.optionality, testOptionality);
        }
        if (isBasicConformanceClass(testName)) {
          testReq.addProperty(CITE.isBasic, "true");
        }
        reqs.add(testReq);
    }
    this.testRun.addProperty(CITE.requirements, reqs);
}
 
Example #5
Source File: EarlReporter.java    From teamengine with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the test inputs to the TestRun resource. Each input is an anonymous
 * member of an unordered collection (rdf:Bag). A {@value #TEST_RUN_ID}
 * parameter is treated in special manner: its value is set as the value of
 * the standard dct:identifier property.
 * 
 * @param earl
 *            An RDF model containing EARL statements.
 * @param params
 *            A collection of name-value pairs gleaned from the test suite
 *            parameters.
 */
void addTestInputs(Model earl, final Map<String, String> params) {
    Bag inputs = earl.createBag();
    for (Map.Entry<String, String> param : params.entrySet()) {
        if (param.getKey().equals(TEST_RUN_ID)) {
            this.testRun.addProperty(DCTerms.identifier, param.getValue());
        } else {
            if (param.getValue().isEmpty())
                continue;
            Resource testInput = earl.createResource();
            testInput.addProperty(DCTerms.title, param.getKey());
            testInput.addProperty(DCTerms.description, param.getValue());
            inputs.add(testInput);
        }
    }
    this.testRun.addProperty(CITE.inputs, inputs);
}
 
Example #6
Source File: JenaIOServiceTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@BeforeEach
@SuppressWarnings("unchecked")
void setUp() {
    initMocks(this);
    final Map<String, String> namespaces = new HashMap<>();
    namespaces.put("dcterms", DCTerms.NS);
    namespaces.put("rdf", uri);

    service = new JenaIOService(mockNamespaceService, null, mockCache,
            "http://www.w3.org/ns/anno.jsonld,,,", "http://www.trellisldp.org/ns/", false);

    service2 = new JenaIOService(mockNamespaceService, mockRdfaWriterService, mockCache, emptySet(),
            singleton("http://www.w3.org/ns/"), false);

    service3 = new JenaIOService(mockNamespaceService, null, mockCache, emptySet(), emptySet(), true);

    when(mockNamespaceService.getNamespaces()).thenReturn(namespaces);
    when(mockCache.get(anyString(), any(Function.class))).thenAnswer(inv -> {
        final String key = inv.getArgument(0);
        final Function<String, String> mapper = inv.getArgument(1);
        return mapper.apply(key);
    });
}
 
Example #7
Source File: RDF2RDFStarTest.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
@Test
public void doubleNestedObject() {
	
	final String filename = "DoubleNestedObject.ttl";
       final Graph g = convertAndLoadIntoGraph(filename);
	
       assertEquals( 1, g.size() );
       
       final Triple t = g.find().next();
       assertFalse( t.getSubject() instanceof Node_Triple );
       assertFalse( t.getPredicate() instanceof Node_Triple );
       assertTrue( t.getObject() instanceof Node_Triple );
       
       final Triple et = ( (Node_Triple) t.getObject() ).get();
       assertFalse( et.getSubject() instanceof Node_Triple );
       assertFalse( et.getPredicate() instanceof Node_Triple );
       assertTrue( et.getObject() instanceof Node_Triple );
       
       final Triple eet = ( (Node_Triple) et.getObject() ).get();
       assertEquals( DCTerms.created.asNode(), eet.getPredicate() );
}
 
Example #8
Source File: RDF2RDFStarTest.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
@Test
public void nestedSubjectAndObject() {
	
	final String filename = "NestedSubjectAndObject.ttl";
       final Graph g = convertAndLoadIntoGraph(filename);
	
       assertEquals( 1, g.size() );
       
       final Triple t = g.find().next();
       assertTrue( t.getSubject() instanceof Node_Triple );
       assertFalse( t.getPredicate() instanceof Node_Triple );
       assertTrue( t.getObject() instanceof Node_Triple );
       
       final Triple st = ( (Node_Triple) t.getSubject() ).get();
       assertEquals( DCTerms.creator.asNode(), st.getPredicate() );
       
       final Triple ot = ( (Node_Triple) t.getObject() ).get();
       assertEquals( DCTerms.created.asNode(), ot.getPredicate() );
}
 
Example #9
Source File: RDF2RDFStarTest.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
@Test
public void nestedObject() {
	
	final String filename = "NestedObject.ttl";
       final Graph g = convertAndLoadIntoGraph(filename);
	
       assertEquals( 1, g.size() );
       
       final Triple t = g.find().next();
       assertFalse( t.getSubject() instanceof Node_Triple );
       assertFalse( t.getPredicate() instanceof Node_Triple );
       assertTrue( t.getObject() instanceof Node_Triple );
       
       final Triple et = ( (Node_Triple) t.getObject() ).get();
       assertEquals( DCTerms.creator.asNode(), et.getPredicate() );
       
}
 
Example #10
Source File: RDF2RDFStarTest.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
@Test
public void nestedSubject() {
	
	final String filename = "NestedSubject.ttl";
       final Graph g = convertAndLoadIntoGraph(filename);
       
       assertEquals( 1, g.size() );
       
       final Triple t = g.find().next();
       assertTrue( t.getSubject() instanceof Node_Triple );
       assertFalse( t.getPredicate() instanceof Node_Triple );
       assertFalse( t.getObject() instanceof Node_Triple );

       assertEquals( DCTerms.source.asNode(), t.getPredicate() );

       final Triple et = ( (Node_Triple) t.getSubject() ).get();
       assertEquals( DCTerms.creator.asNode(), et.getPredicate() );
}
 
Example #11
Source File: TestGeneratorWriter.java    From RDFUnit with Apache License 2.0 6 votes vote down vote up
@Override
public Resource write(Model model) {
    Resource resource = ElementWriter.copyElementResourceInModel(testGenerator, model);

    resource
            .addProperty(RDF.type, RDFUNITv.TestGenerator)
            .addProperty(DCTerms.description, testGenerator.getDescription())
            .addProperty(RDFUNITv.sparqlGenerator, testGenerator.getQuery())
            .addProperty(RDFUNITv.basedOnPattern, ElementWriter.copyElementResourceInModel(testGenerator.getPattern(), model));


    for (ResultAnnotation resultAnnotation: testGenerator.getAnnotations()) {
        Resource annotationResource = ResultAnnotationWriter.create(resultAnnotation).write(model);
        resource.addProperty(RDFUNITv.resultAnnotation, annotationResource);
    }

    return resource;
}
 
Example #12
Source File: PatternWriter.java    From RDFUnit with Apache License 2.0 6 votes vote down vote up
@Override
public Resource write(Model model) {
    Resource resource = ElementWriter.copyElementResourceInModel(pattern, model);

    resource
            .addProperty(RDF.type, RDFUNITv.Pattern)
            .addProperty(DCTerms.identifier, pattern.getId())
            .addProperty(DCTerms.description, pattern.getDescription())
            .addProperty(RDFUNITv.sparqlWherePattern, pattern.getSparqlWherePattern());

    if (pattern.getSparqlPatternPrevalence().isPresent()) {
        resource.addProperty(RDFUNITv.sparqlPrevalencePattern, pattern.getSparqlPatternPrevalence().get());
    }

    for (PatternParameter patternParameter: pattern.getParameters()) {
        Resource parameter = PatternParameterWriter.create(patternParameter).write(model);
        resource.addProperty(RDFUNITv.parameter, parameter);
    }

    for (ResultAnnotation resultAnnotation: pattern.getResultAnnotations()) {
        Resource annotationResource = ResultAnnotationWriter.create(resultAnnotation).write(model);
        resource.addProperty(RDFUNITv.resultAnnotation, annotationResource);
    }

    return resource;
}
 
Example #13
Source File: SkolemizerTest.java    From Processor with Apache License 2.0 6 votes vote down vote up
/**
 * Test of getNameValueMap method, of class Skolemizer.
 */
@Test
public void testGetNameValueMap()
{
    UriTemplateParser parser = new UriTemplateParser("{name}/{title}|{smth}|{primaryTopic.title}");
    Model model = ModelFactory.createDefaultModel();
    Literal secondTitle = model.createLiteral("Second");
    Literal firstTitle = model.createLiteral("First");

    Resource second = model.createResource().
            addLiteral(DCTerms.title, secondTitle);
    Resource first = model.createResource().
            addLiteral(DCTerms.title, firstTitle).
            addProperty(FOAF.primaryTopic, second);
    
    Map<String, String> expected = new HashMap<>();
    expected.put("title", firstTitle.getString());
    expected.put("primaryTopic.title", secondTitle.getString());
    
    Map<String, String> result = skolemizer.getNameValueMap(first, parser);
    assertEquals(expected, result);
}
 
Example #14
Source File: SkolemizerTest.java    From Processor with Apache License 2.0 6 votes vote down vote up
/**
 * Test of build method, of class Skolemizer.
 */
@Test
public void testBuild_Model()
{
    Model expected = ModelFactory.createDefaultModel();
    Resource expAbsolute = expected.createResource(baseUriBuilder.clone().path(absoluteId).build().toString()).
            addProperty(RDF.type, absolutePathClass).
            addLiteral(DCTerms.identifier, absoluteId);
    Resource expRelative = expected.createResource(absolutePathBuilder.clone().path(relativeId).build().toString()).
            addProperty(RDF.type, relativePathClass).
            addLiteral(DCTerms.identifier, relativeId);
    Resource expThing = expected.createResource(absolutePathBuilder.clone().path(thingTitle).fragment(thingFragment).build().toString()).
            addProperty(RDF.type, thingClass).
            addLiteral(DCTerms.title, thingTitle);
    Resource expImported = expected.createResource(absolutePathBuilder.clone().path(thingTitle).fragment(thingFragment).build().toString()).
            addProperty(RDF.type, importedClass).
            addLiteral(DCTerms.title, thingTitle);
    Resource expRestricted = expected.createResource(UriBuilder.fromUri(restrictionValue).clone().path(restrictedId).build().toString()).
            addProperty(RDF.type, restrictedClass).
            addLiteral(DCTerms.identifier, restrictedId);        
    expRelative.addProperty(FOAF.primaryTopic, expThing);
    expThing.addProperty(FOAF.isPrimaryTopicOf, expRelative);
    
    Model result = skolemizer.build(input);
    assertTrue(result.isIsomorphicWith(expected));
}
 
Example #15
Source File: RDFToManifest.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
protected OntModel getOntModel() {
	OntModel ontModel = createOntologyModel(OWL_DL_MEM_RULE_INF);
	ontModel.setNsPrefix("foaf", foaf.NS);
	ontModel.setNsPrefix("prov", prov.NS);
	ontModel.setNsPrefix("ore", ore.NS);
	ontModel.setNsPrefix("pav", pav.NS);
	ontModel.setNsPrefix("dct", DCTerms.NS);
	// ontModel.getDocumentManager().loadImports(foaf.getOntModel());
	return ontModel;
}
 
Example #16
Source File: CtlEarlReporter.java    From teamengine with Apache License 2.0 5 votes vote down vote up
/**
 * This method is used to add test inputs in to earl report.
 *
 * @param earl
 *            Model object to add the result into it.
 * @param params
 *            The variable is type of Map with all the user input.
 */
private void addTestInputs( Model earl, Map<String, String> params ) {
    Bag inputs = earl.createBag();
    if ( !params.equals( "" ) && params != null ) {
        String value = "";
        for ( String key : params.keySet() ) {
            value = params.get( key );
            Resource testInputs = earl.createResource();
            testInputs.addProperty( DCTerms.title, key );
            testInputs.addProperty( DCTerms.description, value );
            inputs.add( testInputs );
        }
    }
    this.testRun.addProperty( CITE.inputs, inputs );
}
 
Example #17
Source File: Location.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Override
public Resource createResource(Model model, Resource parent) {
    addNsPrefix(model);
    Resource location = model.createResource(DCTerms.Location);
    for (Geometry geometry : getGeometries()) {
        geometry.addToResource(model, location);
    }
    return location;
}
 
Example #18
Source File: DefaultRdfaWriterServiceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
    initMocks(this);
    final Map<String, String> namespaces = new HashMap<>();
    namespaces.put("dc", DCTerms.NS);
    namespaces.put("rdf", RDF.uri);
    namespaces.put("dcmitype", "http://purl.org/dc/dcmitype/");
    when(mockNamespaceService.getNamespaces()).thenReturn(namespaces);

    service = new DefaultRdfaWriterService(mockNamespaceService);

}
 
Example #19
Source File: DefaultRdfaWriterServiceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
static Stream<Triple> getTriples() {
    final Node sub = createURI("trellis:data/resource");
    final Node bn = createBlankNode();
    return of(
            create(sub, DCTerms.title.asNode(), createLiteral("A title")),
            create(sub, DCTerms.subject.asNode(), bn),
            create(bn, DCTerms.title.asNode(), createLiteral("Other title")),
            create(sub, DCTerms.spatial.asNode(), createURI("http://sws.geonames.org/4929022/")),
            create(sub, DCTerms.spatial.asNode(), createURI("http://sws.geonames.org/4929023/")),
            create(sub, DCTerms.spatial.asNode(), createURI("http://sws.geonames.org/4929024/")),
            create(sub, RDF.type.asNode(), DCTypes.Text.asNode()))
        .map(JenaCommonsRDF::fromJena);
}
 
Example #20
Source File: DefaultRdfaWriterServiceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
static Stream<Triple> getTriples2() {
    final Node sub = createURI("trellis:data/resource");
    final Node other = createURI("mailto:[email protected]");
    final Node bn = createBlankNode();
    return of(
            create(sub, DCTerms.subject.asNode(), bn),
            create(sub, DCTerms.spatial.asNode(), createURI("http://sws.geonames.org/4929022/")),
            create(bn, RDF.type.asNode(), DCTypes.Text.asNode()),
            create(bn, DCTerms.subject.asNode(), other),
            create(sub, RDF.type.asNode(), DCTypes.Text.asNode()))
        .map(JenaCommonsRDF::fromJena);
}
 
Example #21
Source File: ExceptionMapperBase.java    From Processor with Apache License 2.0 5 votes vote down vote up
public Resource toResource(Exception ex, Response.StatusType status, Resource statusResource)
{
    if (ex == null) throw new IllegalArgumentException("Exception cannot be null");
    if (status == null) throw new IllegalArgumentException("Response.Status cannot be null");

    Resource resource = ModelFactory.createDefaultModel().createResource().
            addProperty(RDF.type, HTTP.Response).
            addLiteral(HTTP.statusCodeValue, status.getStatusCode()).
            addLiteral(HTTP.reasonPhrase, status.getReasonPhrase());

    if (statusResource != null) resource.addProperty(HTTP.sc, statusResource);
    if (ex.getMessage() != null) resource.addLiteral(DCTerms.title, ex.getMessage());
    
    return resource;
}
 
Example #22
Source File: CtlEarlReporter.java    From teamengine with Apache License 2.0 5 votes vote down vote up
private Model initializeModel( String suiteName ) {
    Model model = ModelFactory.createDefaultModel();
    Map<String, String> nsBindings = new HashMap<>();
    nsBindings.put( "earl", EARL.NS_URI );
    nsBindings.put( "dct", DCTerms.NS );
    nsBindings.put( "cite", CITE.NS_URI );
    nsBindings.put( "http", HTTP.NS_URI );
    nsBindings.put( "cnt", CONTENT.NS_URI );
    model.setNsPrefixes( nsBindings );
    this.testRun = model.createResource( CITE.TestRun );
    this.testRun.addProperty( DCTerms.title, suiteName );
    String nowUTC = ZonedDateTime.now( ZoneId.of( "Z" ) ).format( DateTimeFormatter.ISO_INSTANT );
    this.testRun.addProperty( DCTerms.created, nowUTC );
    this.assertor = model.createResource( "https://github.com/opengeospatial/teamengine", EARL.Assertor );
    this.assertor.addProperty( DCTerms.title, "OGC TEAM Engine", this.langCode );
    this.assertor.addProperty( DCTerms.description,
                               "Official test harness of the OGC conformance testing program (CITE).",
                               this.langCode );
    /*
     * Map<String, String> params = suite.getXmlSuite().getAllParameters(); String iut = params.get("iut"); if (null
     * == iut) { // non-default parameter refers to test subject--use first URI value for (Map.Entry<String, String>
     * param : params.entrySet()) { try { URI uri = URI.create(param.getValue()); iut = uri.toString(); } catch
     * (IllegalArgumentException e) { continue; } } } if (null == iut) { throw new
     * NullPointerException("Unable to find URI reference for IUT in test run parameters." ); }
     */

    this.testSubject = model.createResource( "", EARL.TestSubject );
    return model;
}
 
Example #23
Source File: CtlEarlReporter.java    From teamengine with Apache License 2.0 5 votes vote down vote up
private void processTestResult( Element childlogElement, TestInfo testDetails, Resource earlResult ) {
    switch ( testDetails.result ) {
    case 0:
        earlResult.addProperty( EARL.outcome, CITE.Continue );
        this.cContinueCount++;
        break;
    case 2:
        earlResult.addProperty( EARL.outcome, CITE.Not_Tested );
        this.cNotTestedCount++;
        break;
    case 6: // Fail
        earlResult.addProperty( EARL.outcome, EARL.Fail );
        String errorMessage = parseTextContent( childlogElement, "exception" );
        if ( errorMessage != null ) {
            earlResult.addProperty( DCTerms.description, errorMessage );
        }
        this.cFailCount++;
        break;
    case 3:
        earlResult.addProperty( EARL.outcome, EARL.NotTested );
        this.cSkipCount++;
        break;
    case 4:
        earlResult.addProperty( EARL.outcome, CITE.Warning );
        this.cWarningCount++;
        break;
    case 5:
        earlResult.addProperty( EARL.outcome, CITE.Inherited_Failure );
        this.cInheritedFailureCount++;
        break;
    default:
        earlResult.addProperty( EARL.outcome, EARL.Pass );
        this.cPassCount++;
        break;
    }
}
 
Example #24
Source File: EarlReporter.java    From teamengine with Apache License 2.0 5 votes vote down vote up
/**
 * Creates EARL statements for the entire collection of test suite results.
 * Each test subset is defined by a {@literal <test>} tag in the suite
 * definition; these correspond to earl:TestRequirement resources in the
 * model.
 * 
 * @param model
 *            An RDF Model containing EARL statements.
 * @param results
 *            A Map containing the actual test results, where the key is the
 *            name of a test subset (conformance class).
 */
void processSuiteResults(Model model, Map<String, ISuiteResult> results) {
    for (Map.Entry<String, ISuiteResult> entry : results.entrySet()) {
        String testName = entry.getKey();
        String testReqName = testName.replaceAll("\\s", "-");
        // can return existing resource in model
        Resource testReq = model.createResource(testReqName);
        ITestContext testContext = entry.getValue().getTestContext();
        int nPassed = testContext.getPassedTests().size();
        int nSkipped = testContext.getSkippedTests().size();
        int nFailed = testContext.getFailedTests().size();
        testReq.addLiteral(CITE.testsPassed, new Integer(nPassed));
        testReq.addLiteral(CITE.testsFailed, new Integer(nFailed));
        testReq.addLiteral(CITE.testsSkipped, new Integer(nSkipped));
        if (nPassed + nFailed == 0) {
            testReq.addProperty(DCTerms.description,
                    "A precondition was not met. All tests in this set were skipped.");
        }
        if(isBasicConformanceClass(testName)){
          if(nFailed > 0){
            areCoreConformanceClassesPassed = false;
          }              
        }
        processTestResults(model, testContext.getFailedTests());
        processTestResults(model, testContext.getSkippedTests());
        processTestResults(model, testContext.getPassedTests());
    }
}
 
Example #25
Source File: StatusTestCaseResultReader.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
@Override
public StatusTestCaseResult read(final Resource resource) {
    checkNotNull(resource);

    TestCaseResult test = TestCaseResultReader.create(DCTerms.description, RDFUNITv.testCaseLogLevel).read(resource);

    TestCaseResultStatus status = null;
    for (Statement smt : resource.listProperties(RDFUNITv.resultStatus).toList()) {
        status = TestCaseResultStatus.resolve(smt.getObject().asResource().getURI());
    }
    checkNotNull(status);

    return new StatusTestCaseResultImpl(resource, test.getTestCaseUri(), test.getSeverity(), test.getMessage(), test.getTimestamp(), status);
}
 
Example #26
Source File: PatternParameterWriter.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
@Override
public Resource write(Model model) {
    Resource resource = ElementWriter.copyElementResourceInModel(patternParameter, model);

    resource
            .addProperty(RDF.type, RDFUNITv.Parameter)
            .addProperty(DCTerms.identifier, patternParameter.getId())
            .addProperty(RDFUNITv.parameterConstraint, model.createResource(patternParameter.getConstraint().getUri()));

    if (patternParameter.getConstraintPattern().isPresent()) {
        resource.addProperty(RDFUNITv.constraintPattern, patternParameter.getConstraintPattern().get());
    }

    return resource;
}
 
Example #27
Source File: CtlEarlReporter.java    From teamengine with Apache License 2.0 4 votes vote down vote up
private void addTestRequirements( Model earl, TestInfo testInfo ) {
    Resource testReq = earl.createResource( testInfo.testName.replaceAll( "\\s", "-" ), EARL.TestRequirement );
    testReq.addProperty( DCTerms.title, testInfo.testName );
    testReq.addProperty( CITE.isBasic, Boolean.toString( testInfo.isBasic ) );
    this.reqs.add( testReq );
}
 
Example #28
Source File: CtlEarlReporter.java    From teamengine with Apache License 2.0 4 votes vote down vote up
private void processTestResults( Model earl, Element logElement, NodeList logList, String conformanceClass,
                                 Resource parentTestCase )
                        throws UnsupportedEncodingException {
    NodeList childtestcallList = logElement.getElementsByTagName( "testcall" );

    for ( int l = 0; l < childtestcallList.getLength(); l++ ) {
        Element childtestcallElement = (Element) childtestcallList.item( l );
        String testcallPath = childtestcallElement.getAttribute( "path" );

        Element childlogElement = findMatchingLogElement( logList, testcallPath );

        if ( childlogElement == null )
            throw new NullPointerException( "Failed to get Test-Info due to null log element." );
        TestInfo testDetails = getTestinfo( childlogElement );

        // create earl:Assertion
        GregorianCalendar calTime = new GregorianCalendar( TimeZone.getDefault() );
        Resource assertion = earl.createResource( "assert-" + ++this.resultCount, EARL.Assertion );
        assertion.addProperty( EARL.mode, EARL.AutomaticMode );
        assertion.addProperty( EARL.assertedBy, this.assertor );
        assertion.addProperty( EARL.subject, this.testSubject );
        // link earl:TestResult to earl:Assertion
        Resource earlResult = earl.createResource( "result-" + this.resultCount, EARL.TestResult );
        earlResult.addProperty( DCTerms.date, earl.createTypedLiteral( calTime ) );

        processTestResult( childlogElement, testDetails, earlResult );
        processRequests( earlResult, childlogElement, earl );

        assertion.addProperty( EARL.result, earlResult );
        // link earl:TestCase to earl:Assertion and earl:TestRequirement
        String testName = testDetails.testName;
        StringBuilder testCaseId = new StringBuilder( testcallPath );
        testCaseId.append( '#' ).append( testName );
        Resource testCase = earl.createResource( testCaseId.toString(), EARL.TestCase );
        testCase.addProperty( DCTerms.title, testName );
        testCase.addProperty( DCTerms.description, testDetails.assertion );
        assertion.addProperty( EARL.test, testCase );

        if ( parentTestCase != null )
            parentTestCase.addProperty( DCTerms.hasPart, testCase );
        else
            earl.createResource( conformanceClass ).addProperty( DCTerms.hasPart, testCase );
        processTestResults( earl, childlogElement, logList, conformanceClass, testCase );
    }
}
 
Example #29
Source File: TestCaseResultWriter.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
@Override
public Resource write(Model model) {
    Resource resource;
    if (testCaseResult.getElement().isAnon()) {
        resource = model.createResource(JenaUtils.getUniqueIri(executionUri + "/"));
    } else {
        resource = ElementWriter.copyElementResourceInModel(testCaseResult, model);
    }

    // general properties
    resource
            .addProperty(RDF.type, RDFUNITv.TestCaseResult)
            .addProperty(PROV.wasGeneratedBy, model.createResource(executionUri))
            .addProperty(RDFUNITv.testCase, model.createResource(testCaseResult.getTestCaseUri()))
            .addProperty(DCTerms.date, model.createTypedLiteral(testCaseResult.getTimestamp(), XSDDatatype.XSDdateTime));

    if (testCaseResult instanceof StatusTestCaseResult) {
        resource
                .addProperty(RDF.type, RDFUNITv.StatusTestCaseResult)
                .addProperty(RDFUNITv.resultStatus, model.createResource(((StatusTestCaseResult) testCaseResult).getStatus().getUri()))
                .addProperty(DCTerms.description, testCaseResult.getMessage())
                .addProperty(RDFUNITv.testCaseLogLevel, model.createResource(testCaseResult.getSeverity().getUri()))
                ;
    }

    if (testCaseResult instanceof AggregatedTestCaseResult) {
        resource
                .addProperty(RDF.type, RDFUNITv.AggregatedTestResult)
                .addProperty(RDFUNITv.resultCount,
                        ResourceFactory.createTypedLiteral(Long.toString(((AggregatedTestCaseResult) testCaseResult).getErrorCount()), XSDDatatype.XSDinteger))
                .addProperty(RDFUNITv.resultPrevalence,
                        ResourceFactory.createTypedLiteral(Long.toString(((AggregatedTestCaseResult) testCaseResult).getPrevalenceCount().orElse(-1L)), XSDDatatype.XSDinteger));
    }

    if (testCaseResult instanceof ShaclLiteTestCaseResult) {
        resource.addProperty(RDF.type, SHACL.ValidationResult)
        ;
    }

    if (testCaseResult instanceof ShaclTestCaseResult) {

        Collection<PropertyValuePair> annotations = ((ShaclTestCaseResult) testCaseResult).getResultAnnotations();
        for (PropertyValuePair annotation : annotations) {
            for (RDFNode rdfNode : annotation.getValues()) {


                if (rdfNode.isAnon() && annotation.getProperty().equals(SHACL.resultPath)) {
                    resource.getModel().add(reanonimisePathBlankNodes(resource, rdfNode));
                } else {
                    resource.addProperty(annotation.getProperty(), rdfNode);
                }

            }
        }
        boolean containsMessage = annotations.stream().anyMatch(an -> an.getProperty().equals(SHACL.message));
        if (!containsMessage) {
            resource.addProperty(SHACL.message, testCaseResult.getMessage());
        }
        boolean containsFocusNode = annotations.stream().anyMatch(an -> an.getProperty().equals(SHACL.focusNode));
        if (!containsFocusNode) {
            resource.addProperty(SHACL.focusNode, ((ShaclTestCaseResult) testCaseResult).getFailingNode());
        }
        boolean containsSeverity = annotations.stream().anyMatch(an -> an.getProperty().equals(SHACL.severity));
        if (!containsSeverity) {
            resource.addProperty(SHACL.severity, ResourceFactory.createResource(testCaseResult.getSeverity().getUri()));
        }
    }


    return resource;
}
 
Example #30
Source File: EarlReporter.java    From teamengine with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes the test results graph with basic information about the
 * assertor (earl:Assertor) and test subject (earl:TestSubject).
 * 
 * @param suite
 *            Information about the test suite.
 * @return An RDF Model containing EARL statements.
 */
Model initializeModel(ISuite suite) {
    Model model = ModelFactory.createDefaultModel();
    Map<String, String> nsBindings = new HashMap<>();
    nsBindings.put("earl", EARL.NS_URI);
    nsBindings.put("dct", DCTerms.NS);
    nsBindings.put("cite", CITE.NS_URI);
    nsBindings.put("http", HTTP.NS_URI);
    nsBindings.put("cnt", CONTENT.NS_URI);
    model.setNsPrefixes(nsBindings);
    suiteName = suite.getName();
    this.testRun = model.createResource(CITE.TestRun);
    this.testRun.addProperty(DCTerms.title, suite.getName());
    String nowUTC = ZonedDateTime.now(ZoneId.of("Z")).format(DateTimeFormatter.ISO_INSTANT);
    this.testRun.addProperty(DCTerms.created, nowUTC);
    this.assertor = model.createResource("https://github.com/opengeospatial/teamengine",
            EARL.Assertor);
    this.assertor.addProperty(DCTerms.title, "OGC TEAM Engine", this.langCode);
    this.assertor.addProperty(DCTerms.description,
            "Official test harness of the OGC conformance testing program (CITE).",
            this.langCode);
    Map<String, String> params = suite.getXmlSuite().getAllParameters();
    String iut = params.get("iut");
    if (null == iut) {
        // non-default parameter refers to test subject--use first URI value
        for (Map.Entry<String, String> param : params.entrySet()) {
            try {
                URI uri = URI.create(param.getValue());
                iut = uri.toString();
            } catch (IllegalArgumentException e) {
                continue;
            }
        }
    }
    if (null == iut) {
        throw new NullPointerException(
                "Unable to find URI reference for IUT in test run parameters.");
    }
    this.testSubject = model.createResource(iut, EARL.TestSubject);
    return model;
}