Class TestUtil


  • public class TestUtil
    extends Object
    Support for testing iterator/list values against and expected set of answers.
    Author:
    Dave Reynolds
    • Constructor Summary

      Constructors 
      Constructor Description
      TestUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static String baseURIFixture()
      Return a base URI that is guaranteed not to resolve.
      static boolean isOnlyValue​(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.RDFNode object)
      Test that the given resource/property has the given object value and ONLY the given object value.
      static org.apache.jena.rdf.model.Model modelFixture​(String content)
      Create a Model as a text fixture
      static org.apache.jena.rdf.model.Property propertyFixture​(org.apache.jena.rdf.model.Model m, String uri)
      Return a property with the given URI.
      static org.apache.jena.rdf.model.Resource resourceFixture​(String src)
      Return a resource which is the (assumed sole) root subject of the model given by the turtle source.
      static org.apache.jena.rdf.model.Resource resourceFixture​(org.apache.jena.rdf.model.Model m, String uri)
      Return a resource with the given URI.
      static <E> void testArray​(E[] actual, E[] expected)  
      static <E> void testArray​(Collection<E> actual, E[] expected)  
      static <E> void testArray​(Iterator<E> actual, E[] expected)  
      static void testResourcesMatch​(org.apache.jena.rdf.model.Resource expected, org.apache.jena.rdf.model.Resource actual, org.apache.jena.rdf.model.Property... omit)
      Compare the properties of two resources, omitting any of the list of blocked properties.
    • Constructor Detail

      • TestUtil

        public TestUtil()
    • Method Detail

      • testArray

        public static <E> void testArray​(E[] actual,
                                         E[] expected)
      • testArray

        public static <E> void testArray​(Collection<E> actual,
                                         E[] expected)
      • testArray

        public static <E> void testArray​(Iterator<E> actual,
                                         E[] expected)
      • modelFixture

        public static org.apache.jena.rdf.model.Model modelFixture​(String content)
        Create a Model as a text fixture
        Parameters:
        content - The model content in Turtle. Common prefixes may be assumed.
        Returns:
        A new model containing triples parsed from the content
      • resourceFixture

        public static org.apache.jena.rdf.model.Resource resourceFixture​(org.apache.jena.rdf.model.Model m,
                                                                         String uri)
        Return a resource with the given URI.
        Parameters:
        m - Optional model. If null, the resource will be created using the ResourceFactory
        uri - Resource URI. If the URI starts with http:, it will be left intact otherwise it is assumed relative to the baseURIFixture()
        Returns:
        A resource
      • resourceFixture

        public static org.apache.jena.rdf.model.Resource resourceFixture​(String src)
        Return a resource which is the (assumed sole) root subject of the model given by the turtle source. Common prefixes are assumed.
      • propertyFixture

        public static org.apache.jena.rdf.model.Property propertyFixture​(org.apache.jena.rdf.model.Model m,
                                                                         String uri)
        Return a property with the given URI.
        Parameters:
        m - Optional model. If null, the property will be created using the ResourceFactory
        uri - Resource URI. If the URI starts with http:, it will be left intact otherwise it is assumed relative to the baseURIFixture()
        Returns:
        A property
      • baseURIFixture

        public static String baseURIFixture()
        Return a base URI that is guaranteed not to resolve.
        Returns:
        "http://example.test/test#"
      • isOnlyValue

        public static boolean isOnlyValue​(org.apache.jena.rdf.model.Resource subject,
                                          org.apache.jena.rdf.model.Property predicate,
                                          org.apache.jena.rdf.model.RDFNode object)
        Test that the given resource/property has the given object value and ONLY the given object value.
        Parameters:
        subject - subject resource
        predicate - property to test
        object - the expected value or null to not test the value, just that there is one
      • testResourcesMatch

        public static void testResourcesMatch​(org.apache.jena.rdf.model.Resource expected,
                                              org.apache.jena.rdf.model.Resource actual,
                                              org.apache.jena.rdf.model.Property... omit)
        Compare the properties of two resources, omitting any of the list of blocked properties. Single, unadorned, bNode values on the expected resource are treated as wild cards, the actual is required to just have some value for that property.