Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AKSW RDFUnit ShaclTestGenerator Generate

From Leeroopedia
Knowledge Sources
Domains Semantic_Web, SHACL, Test_Generation
Last Updated 2026-10-16 00:00 GMT

Overview

Concrete test generator that converts SHACL shapes from a schema model into executable RDFUnit test cases via the ShaclModel engine.

Description

The ShaclTestGenerator implements `RdfUnitTestGenerator` to produce test cases from SHACL shapes. It delegates to `ShaclModel`, which parses the schema's RDF model for SHACL shapes, converts each shape's constraints into test cases (component constraints like sh:minCount, SPARQL constraints, and logical constraints), and injects target definitions. The generator is always included in the generator chain by `TestGeneratorFactory.create()` regardless of auto-test settings, ensuring SHACL validation is always available.

Usage

  • SHACL-only validation: Use `ShaclTestGenerator` standalone when only SHACL shapes are available.
  • As part of composite chain: Automatically included by `TestGeneratorFactory.create()` alongside TAG generators.
  • Standalone factory access: Use `TestGeneratorFactory.createShaclOnly()` for SHACL-only generation.

Code Reference

Source Location

  • Repository: AKSW/RDFUnit
  • File: rdfunit-core/src/main/java/org/aksw/rdfunit/tests/generators/ShaclTestGenerator.java

Signature

public class ShaclTestGenerator implements RdfUnitTestGenerator {

    @Override
    public Collection<? extends GenericTestCase> generate(SchemaSource source);
    // Creates ShaclModel from source.getModel(), calls generateTestCases()

    @Override
    public Collection<? extends GenericTestCase> generate(TestSource source);
    // returns ImmutableList.of() for TestSource
}

Import

import org.aksw.rdfunit.tests.generators.ShaclTestGenerator;

I/O Contract

Inputs

Name Type Required Description
source SchemaSource Yes Schema source containing SHACL shapes in its RDF model

Outputs

Name Type Description
generate() returns Collection<? extends GenericTestCase> Set of SHACL-based test cases

Usage Examples

Generate Tests from SHACL Shapes

import org.aksw.rdfunit.sources.SchemaSourceFactory;
import org.aksw.rdfunit.tests.generators.ShaclTestGenerator;

// Load schema containing SHACL shapes
SchemaSource schema = SchemaSourceFactory.createSchemaSourceSimple("custom",
    "http://example.org/shapes.ttl");

// Generate SHACL test cases
ShaclTestGenerator generator = new ShaclTestGenerator();
Collection<? extends GenericTestCase> tests = generator.generate(schema);

System.out.println("Generated " + tests.size() + " SHACL tests");

SHACL-Only via Factory

import org.aksw.rdfunit.tests.generators.TestGeneratorFactory;

RdfUnitTestGenerator shaclOnly = TestGeneratorFactory.createShaclOnly();
Collection<? extends GenericTestCase> tests = shaclOnly.generate(schema);

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment