You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Thomas Marsh <tm...@thetus.com> on 2013/11/07 01:31:09 UTC

making unit tests with jena

Hello jena folks,
We have a system that translates OWL into our own XML language and it 
uses Jena to do this.
We would like to write unit tests for our translation process so that we 
can verify our code correctness.  To do this, we would supply Jena 
domain objects (Resource, Statement, etc) to our code, and then verify 
that the objects that were returned are what we expected, given the 
input of a particular Jena object.

For example:  We have a factory that constructs an object given a 
Restriction. The test would be to supply a Jena Restriction that is a 
datatype restriction and then check that what our code returned is 
appropriate for a datatype Restriction. However, we need to 
programmatically create Jena resources (such as Restriction) and be able 
to make it a datatype restriction.  They want the resources to be 
standalone and with the minimal statements that we are able to specify. 
  We don't want to have to make an OWL file to do this.  Do you have any 
suggestions?
thanks!
-thomas


Re: making unit tests with jena

Posted by Joshua TAYLOR <jo...@gmail.com>.
What have you tried so far that _didn't_ work for you?  This code
creates a Restriction on a property and the model contains just three
statements. There's no OWL file.
===

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class RestrictionExample {
    public static void main(String[] args) {
        final OntModel model = ModelFactory.createOntologyModel(
OntModelSpec.OWL_DL_MEM );
        final OntProperty p = model.createOntProperty( "http://example.org/p" );
        model.createRestriction( p );
        model.write( System.out, "TTL" );
    }
}

===

@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://example.org/p>
      a       rdf:Property .

[]    a       owl:Restriction ;
      owl:onProperty <http://example.org/p> .

===

On Wed, Nov 6, 2013 at 7:31 PM, Thomas Marsh <tm...@thetus.com> wrote:
> Hello jena folks,
> We have a system that translates OWL into our own XML language and it uses
> Jena to do this.
> We would like to write unit tests for our translation process so that we can
> verify our code correctness.  To do this, we would supply Jena domain
> objects (Resource, Statement, etc) to our code, and then verify that the
> objects that were returned are what we expected, given the input of a
> particular Jena object.
>
> For example:  We have a factory that constructs an object given a
> Restriction. The test would be to supply a Jena Restriction that is a
> datatype restriction and then check that what our code returned is
> appropriate for a datatype Restriction. However, we need to programmatically
> create Jena resources (such as Restriction) and be able to make it a
> datatype restriction.  They want the resources to be standalone and with the
> minimal statements that we are able to specify.  We don't want to have to
> make an OWL file to do this.  Do you have any suggestions?
> thanks!
> -thomas
>



-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/