You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Richard Cyganiak <ri...@cyganiak.de> on 2022/02/15 08:36:04 UTC

Idiom for creating test instances of Node, Triple, etc?

Hi list,

Is there a preferred way to create instances of Node, Triple and Graph (small) for Java-based automated tests?

Our product's test suite uses many different idioms for this, and I want to introduce more consistency, but don't want to find out later that there's a better idiom I wasn't aware of.

Thanks,
Richard

Re: Idiom for creating test instances of Node, Triple, etc?

Posted by Andy Seaborne <an...@apache.org>.
There are the functions in SSE.

e.g. Node SSE.parseNode(string)

It has built-in prefixes  so ":s" works.

SSE.parseNode(":s") -> NodeFactory.createURI("http://example/s");

Triples are 3-tuples: "(:s :p :o)" or "(triple :s :p :o)"

RDF-star supported SSE.parseNode("(qtriple :s :p :o)");
or <<>> syntax.

Graph graph = SSE.parseGraph
    ("(graph (:s :p 123) (:s :p2 'foo'@en) (:s :p3 '2022'^^xsd:gYear))");

StrUtils.strjoinNL(String...) helps with long strings.

Variant functions take a PrefixMapping.

I find that at some size, putting the data in a file and reading it is 
easier to work with.

     Andy

On 15/02/2022 08:36, Richard Cyganiak wrote:
> Hi list,
> 
> Is there a preferred way to create instances of Node, Triple and Graph (small) for Java-based automated tests?
> 
> Our product's test suite uses many different idioms for this, and I want to introduce more consistency, but don't want to find out later that there's a better idiom I wasn't aware of.
> 
> Thanks,
> Richard